-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from izumin5210/todos-with-dagger2
Add todos-with-dagger sample
- Loading branch information
Showing
35 changed files
with
816 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
include ':droidux', ':droidux-processor', ':middlewares:droidux-thunk', ':examples:todomvc', ':examples:todos-with-undo' | ||
include ':droidux', ':droidux-processor', ':middlewares:droidux-thunk', ':examples:todomvc', ':examples:todos-with-undo', ':todos-with-dagger' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'com.android.databinding' | ||
apply plugin: 'com.neenbedankt.android-apt' | ||
apply plugin: 'me.tatarka.retrolambda' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.2" | ||
|
||
defaultConfig { | ||
applicationId "info.izumin.android.droidux.example.todoswithdagger" | ||
minSdkVersion 15 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
packagingOptions { | ||
exclude 'META-INF/services/javax.annotation.processing.Processor' | ||
} | ||
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 'io.reactivex:rxjava:1.0.15' | ||
compile 'io.reactivex:rxandroid:1.0.1' | ||
compile project(':droidux') | ||
apt project(':droidux-processor') | ||
compile 'com.android.support:appcompat-v7:23.1.0' | ||
compile 'com.android.support:design:23.1.0' | ||
compile 'com.google.code.gson:gson:2.4' | ||
compile 'com.google.dagger:dagger:2.0' | ||
apt 'com.google.dagger:dagger-compiler:2.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 /usr/local/opt/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 *; | ||
#} |
13 changes: 13 additions & 0 deletions
13
...androidTest/java/info/izumin/android/droidux/example/todoswithdagger/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package info.izumin.android.droidux.example.todoswithdagger; | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="info.izumin.android.droidux.example.todoswithdagger"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme" | ||
android:name=".App"> | ||
<activity android:name=".module.main.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
44 changes: 44 additions & 0 deletions
44
todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package info.izumin.android.droidux.example.todoswithdagger; | ||
|
||
import android.app.Application; | ||
|
||
import info.izumin.android.droidux.example.todoswithdagger.entity.TodoList; | ||
import info.izumin.android.droidux.example.todoswithdagger.reducer.TodoListReducer; | ||
|
||
/** | ||
* Created by izumin on 11/4/15. | ||
*/ | ||
public class App extends Application { | ||
public static final String TAG = App.class.getSimpleName(); | ||
|
||
private RootStore store; | ||
private AppComponent component; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
setupStore(); | ||
setupGraph(); | ||
} | ||
|
||
public RootStore getStore() { | ||
return store; | ||
} | ||
|
||
public AppComponent getComponent() { | ||
return component; | ||
} | ||
|
||
private void setupStore() { | ||
store = new DroiduxRootStore.Builder() | ||
.setInitialState(new TodoList()) | ||
.setReducer(new TodoListReducer()) | ||
.build(); | ||
} | ||
|
||
private void setupGraph() { | ||
component = DaggerAppComponent.builder() | ||
.appModule(new AppModule(this)) | ||
.build(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...agger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/AppComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package info.izumin.android.droidux.example.todoswithdagger; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import dagger.Component; | ||
import info.izumin.android.droidux.example.todoswithdagger.module.main.MainActivityComponent; | ||
import info.izumin.android.droidux.example.todoswithdagger.module.main.MainActivityModule; | ||
|
||
/** | ||
* Created by izumin on 11/29/15. | ||
*/ | ||
@Singleton | ||
@Component( | ||
modules = AppModule.class | ||
) | ||
public interface AppComponent { | ||
MainActivityComponent createMainActivityComponent(MainActivityModule module); | ||
} |
25 changes: 25 additions & 0 deletions
25
...h-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/AppModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package info.izumin.android.droidux.example.todoswithdagger; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
|
||
/** | ||
* Created by izumin on 11/29/15. | ||
*/ | ||
@Module | ||
public class AppModule { | ||
|
||
private final App app; | ||
|
||
public AppModule(App app) { | ||
this.app = app; | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
RootStore provideRootStore() { | ||
return app.getStore(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...h-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/RootStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package info.izumin.android.droidux.example.todoswithdagger; | ||
|
||
import info.izumin.android.droidux.Action; | ||
import info.izumin.android.droidux.annotation.Store; | ||
import info.izumin.android.droidux.example.todoswithdagger.entity.TodoList; | ||
import info.izumin.android.droidux.example.todoswithdagger.reducer.TodoListReducer; | ||
import rx.Observable; | ||
|
||
/** | ||
* Created by izumin on 11/29/15. | ||
*/ | ||
@Store(TodoListReducer.class) | ||
public interface RootStore { | ||
TodoList todoList(); | ||
Observable<TodoList> observeTodoList(); | ||
Observable<Action> dispatch(Action action); | ||
} |
27 changes: 27 additions & 0 deletions
27
...c/main/java/info/izumin/android/droidux/example/todoswithdagger/action/AddTodoAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package info.izumin.android.droidux.example.todoswithdagger.action; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import info.izumin.android.droidux.Action; | ||
|
||
/** | ||
* Created by izumin on 11/4/15. | ||
*/ | ||
public class AddTodoAction implements Action { | ||
public static final String TAG = AddTodoAction.class.getSimpleName(); | ||
|
||
private final String text; | ||
|
||
public AddTodoAction(String text) { | ||
this.text = text; | ||
} | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new Gson().toJson(this); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../info/izumin/android/droidux/example/todoswithdagger/action/ClearCompletedTodoAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package info.izumin.android.droidux.example.todoswithdagger.action; | ||
|
||
import info.izumin.android.droidux.Action; | ||
|
||
/** | ||
* Created by izumin on 11/5/15. | ||
*/ | ||
public class ClearCompletedTodoAction implements Action { | ||
public static final String TAG = ClearCompletedTodoAction.class.getSimpleName(); | ||
} |
27 changes: 27 additions & 0 deletions
27
...ain/java/info/izumin/android/droidux/example/todoswithdagger/action/DeleteTodoAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package info.izumin.android.droidux.example.todoswithdagger.action; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import info.izumin.android.droidux.Action; | ||
|
||
/** | ||
* Created by izumin on 11/5/15. | ||
*/ | ||
public class DeleteTodoAction implements Action { | ||
public static final String TAG = DeleteTodoAction.class.getSimpleName(); | ||
|
||
private final long id; | ||
|
||
public DeleteTodoAction(long id) { | ||
this.id = id; | ||
} | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new Gson().toJson(this); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...info/izumin/android/droidux/example/todoswithdagger/action/ToggleCompletedTodoAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package info.izumin.android.droidux.example.todoswithdagger.action; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import info.izumin.android.droidux.Action; | ||
|
||
/** | ||
* Created by izumin on 11/5/15. | ||
*/ | ||
public class ToggleCompletedTodoAction implements Action { | ||
public static final String TAG = ToggleCompletedTodoAction.class.getSimpleName(); | ||
|
||
private final int id; | ||
|
||
public ToggleCompletedTodoAction(int id) { | ||
this.id = id; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new Gson().toJson(this); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...ain/java/info/izumin/android/droidux/example/todoswithdagger/adapter/TodoListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package info.izumin.android.droidux.example.todoswithdagger.adapter; | ||
|
||
import android.content.Context; | ||
import android.databinding.DataBindingUtil; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.BaseAdapter; | ||
|
||
import info.izumin.android.droidux.example.todoswithdagger.App; | ||
import info.izumin.android.droidux.example.todoswithdagger.R; | ||
import info.izumin.android.droidux.example.todoswithdagger.RootStore; | ||
import info.izumin.android.droidux.example.todoswithdagger.databinding.ListItemTodoBinding; | ||
import info.izumin.android.droidux.example.todoswithdagger.entity.TodoList; | ||
|
||
/** | ||
* Created by izumin on 11/4/15. | ||
*/ | ||
public class TodoListAdapter extends BaseAdapter { | ||
public static final String TAG = TodoListAdapter.class.getSimpleName(); | ||
|
||
private static final int LAYOUT_RES_ID = R.layout.list_item_todo; | ||
|
||
private final LayoutInflater inflater; | ||
private final RootStore store; | ||
|
||
public TodoListAdapter(Context context) { | ||
super(); | ||
this.inflater = LayoutInflater.from(context); | ||
this.store = ((App) context.getApplicationContext()).getStore(); | ||
this.store.observeTodoList().subscribe(todoList -> notifyDataSetChanged()); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return store.todoList().size(); | ||
} | ||
|
||
@Override | ||
public TodoList.Todo getItem(int position) { | ||
return store.todoList().get(position); | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
return getItem(position).getId(); | ||
} | ||
|
||
@Override | ||
public View getView(int position, View convertView, ViewGroup parent) { | ||
ListItemTodoBinding binding; | ||
if (convertView == null) { | ||
binding = DataBindingUtil.inflate(inflater, LAYOUT_RES_ID, parent, false); | ||
convertView = binding.getRoot(); | ||
convertView.setTag(binding); | ||
} else { | ||
binding = (ListItemTodoBinding) convertView.getTag(); | ||
} | ||
|
||
binding.setTodo(getItem(position)); | ||
|
||
return convertView; | ||
} | ||
} |
Oops, something went wrong.