-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.2" | ||
|
||
defaultConfig { | ||
applicationId "com.gunhansancar.eventbusexample" | ||
minSdkVersion 15 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:23.2.0' | ||
compile 'com.android.support:recyclerview-v7:23.2.0' | ||
|
||
compile 'org.greenrobot:eventbus:3.0.0' | ||
compile 'com.jakewharton:butterknife:7.0.1' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/gunhansancar/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.gunhansancar.eventbusexample; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.gunhansancar.eventbusexample" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
<service android:name=".service.MyService"/> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.gunhansancar.eventbusexample; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.support.v7.widget.helper.ItemTouchHelper; | ||
import android.widget.Toast; | ||
|
||
import com.gunhansancar.eventbusexample.adapter.SimpleRecyclerAdapter; | ||
import com.gunhansancar.eventbusexample.event.ServiceEvent; | ||
import com.gunhansancar.eventbusexample.event.SimpleEvent; | ||
import com.gunhansancar.eventbusexample.service.MyService; | ||
|
||
import org.greenrobot.eventbus.EventBus; | ||
import org.greenrobot.eventbus.Subscribe; | ||
import org.greenrobot.eventbus.ThreadMode; | ||
|
||
import butterknife.Bind; | ||
import butterknife.ButterKnife; | ||
import butterknife.OnClick; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
@Bind(R.id.recyclerView) RecyclerView recyclerView; | ||
private SimpleRecyclerAdapter adapter; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
ButterKnife.bind(this); | ||
|
||
adapter = new SimpleRecyclerAdapter(); | ||
|
||
recyclerView.setHasFixedSize(true); | ||
recyclerView.setLayoutManager(new LinearLayoutManager(this)); | ||
recyclerView.setAdapter(adapter); | ||
|
||
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback); | ||
itemTouchHelper.attachToRecyclerView(recyclerView); | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
EventBus.getDefault().register(this); | ||
} | ||
|
||
@Override | ||
public void onStop() { | ||
EventBus.getDefault().unregister(this); | ||
super.onStop(); | ||
} | ||
|
||
@OnClick(R.id.startButton) | ||
public void onStartClicked() { | ||
Toast.makeText(this, "Timer is started.", Toast.LENGTH_SHORT).show(); | ||
startService(new Intent(this, MyService.class)); | ||
} | ||
|
||
@OnClick(R.id.stopButton) | ||
public void onStopClicked() { | ||
Toast.makeText(this, "Timer is stopped.", Toast.LENGTH_SHORT).show(); | ||
EventBus.getDefault().post(new ServiceEvent()); | ||
} | ||
|
||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true) | ||
public void onEvent(SimpleEvent event) { | ||
adapter.append(event); | ||
recyclerView.scrollToPosition(adapter.getItemCount() - 1); | ||
} | ||
|
||
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) { | ||
@Override | ||
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) { | ||
adapter.delete(viewHolder.getAdapterPosition()); | ||
} | ||
}; | ||
|
||
} |