Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to RxJava2 #52

Merged
merged 20 commits into from
Jan 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make compile passing
  • Loading branch information
wakwak3125 committed Jan 2, 2018
commit 62c3e88caeb367d7b6c469e984ad333125cbaa48
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.DeclaredType;

import io.reactivex.Flowable;
import io.reactivex.Observable;

/**
* Created by izumin on 11/28/15.
Expand All @@ -32,7 +32,7 @@ enum Kind {
UNKNOWN
}

private static final Class OBSERVE_METHOD_CLASS = Flowable.class;
private static final Class OBSERVE_METHOD_CLASS = Observable.class;

private final ExecutableElement element;
private final StoreModel storeModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static class Counter {
"import info.izumin.android.droidux.BaseStore;",
"import info.izumin.android.droidux.processor.fixture.Counter;",
"import info.izumin.android.droidux.processor.fixture.CounterReducer;",
"import rx.Observable;",
"import io.reactivex.Observable;",
"@Store({CounterReducer.class})",
"public interface RootStore extends BaseStore {",
" Counter counter();",
Expand All @@ -107,7 +107,7 @@ public static class Counter {
"import info.izumin.android.droidux.processor.fixture.CounterReducer;",
"import java.util.ArrayList;",
"import java.util.List;",
"import rx.Observable;",
"import io.reactivex.Observable;",
"",
"public final class DroiduxRootStore extends BaseObservable implements RootStore {",
" private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;",
Expand Down Expand Up @@ -184,7 +184,7 @@ public static class BindableCounter {
"import info.izumin.android.droidux.BaseStore;",
"import info.izumin.android.droidux.processor.fixture.Counter;",
"import info.izumin.android.droidux.processor.fixture.CounterReducer;",
"import rx.Observable;",
"import io.reactivex.Observable;",
"@Store({CounterReducer.class})",
"public interface RootStore extends BaseStore, android.databinding.Observable {",
" @Bindable Counter counter();",
Expand All @@ -205,7 +205,7 @@ public static class BindableCounter {
"import info.izumin.android.droidux.processor.fixture.CounterReducer;",
"import java.util.ArrayList;",
"import java.util.List;",
"import rx.Observable;",
"import io.reactivex.Observable;",
"",
"public final class DroiduxRootStore extends BaseObservable implements RootStore {",
" private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;",
Expand Down Expand Up @@ -315,7 +315,7 @@ public static class CombinedTwoReducers {
"import info.izumin.android.droidux.processor.fixture.TodoListReducer;",
"import java.util.ArrayList;",
"import java.util.List;",
"import rx.Observable;",
"import io.reactivex.Observable;",
"",
"public final class DroiduxRootStore extends BaseObservable implements RootStore {",
" private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;",
Expand Down Expand Up @@ -421,7 +421,7 @@ public static class CombinedReducerAndBindableReducer {
"import info.izumin.android.droidux.processor.fixture.TodoListReducer;",
"import info.izumin.android.droidux.processor.fixture.Counter;",
"import info.izumin.android.droidux.processor.fixture.TodoList;",
"import rx.Observable;",
"import io.reactivex.Observable;",
"@Store({CounterReducer.class, TodoListReducer.class})",
"public interface RootStore extends BaseStore, android.databinding.Observable {",
" Counter counter();",
Expand All @@ -446,7 +446,7 @@ public static class CombinedReducerAndBindableReducer {
"import info.izumin.android.droidux.processor.fixture.TodoListReducer;",
"import java.util.ArrayList;",
"import java.util.List;",
"import rx.Observable;",
"import io.reactivex.Observable;",
"",
"public final class DroiduxRootStore extends BaseObservable implements RootStore {",
" private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;",
Expand Down
4 changes: 2 additions & 2 deletions droidux/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'com.novoda.bintray-release'

targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_1_7

dependencies {
compile "io.reactivex.rxjava2:rxjava:${project.rxJava2Version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.subjects.BehaviorSubject;

/**
Expand All @@ -25,12 +26,8 @@ protected StoreImpl(T state, R reducer) {
listeners = new HashSet<>();
}

public Flowable<T> observe() {
return observe(BackpressureStrategy.DROP);
}

public Flowable<T> observe(BackpressureStrategy strategy) {
return subject.toFlowable(strategy);
public Observable<T> observe() {
return subject;
}

public T getState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
import info.izumin.android.droidux.example.todomvc.action.ClearCompletedTodoAction;
import info.izumin.android.droidux.example.todomvc.action.DeleteTodoAction;
import info.izumin.android.droidux.example.todomvc.action.ToggleCompletedTodoAction;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.subjects.PublishSubject;
import io.reactivex.Single;
import io.reactivex.subjects.SingleSubject;

/**
* Created by izumin on 11/5/15.
Expand Down Expand Up @@ -41,8 +40,9 @@ public void onCreate() {

observeOnClickBtnAddTodo()
.filter(s -> !s.isEmpty())
.flatMap(s -> store.dispatch(new AddTodoAction(s)))
.subscribeOn(AndroidSchedulers.mainThread())
.flatMap(s -> store.dispatch(new AddTodoAction(s)).toMaybe())
/*TODO: Version up RxAndroid*/
/*.subscribeOn(AndroidSchedulers.mainThread())*/
.subscribe(action -> {
editNewTodo.setText("");
Toast.makeText(activity, R.string.toast_add_todo, Toast.LENGTH_SHORT).show();
Expand All @@ -54,7 +54,8 @@ public void onCreate() {

observeOnLongClickListItem()
.flatMap(id -> store.dispatch(new DeleteTodoAction(id)))
.subscribeOn(AndroidSchedulers.mainThread())
/*TODO: Version up RxAndroid*/
/*.subscribeOn(AndroidSchedulers.mainThread())*/
.subscribe(action -> {
Toast.makeText(activity, R.string.toast_delete_todo, Toast.LENGTH_SHORT).show();
});
Expand All @@ -72,27 +73,27 @@ public boolean onOptionItemSelected(MenuItem item) {
}
}

private Observable<String> observeOnClickBtnAddTodo() {
PublishSubject<String> subject= PublishSubject.create();
btnAddTodo.setOnClickListener(v -> subject.onNext(editNewTodo.getText().toString()));
private Single<String> observeOnClickBtnAddTodo() {
SingleSubject<String> subject = SingleSubject.create();
btnAddTodo.setOnClickListener(v -> subject.onSuccess(editNewTodo.getText().toString()));
return subject;
}

private Observable<Long> observeOnClickListItem() {
PublishSubject<Long> subject = PublishSubject.create();
listTodo.setOnItemClickListener((parent, view, position, id) -> subject.onNext(id));
private Single<Long> observeOnClickListItem() {
SingleSubject<Long> subject = SingleSubject.create();
listTodo.setOnItemClickListener((parent, view, position, id) -> subject.onSuccess(id));
return subject;
}

private Observable<Long> observeOnLongClickListItem() {
PublishSubject<Long> subject = PublishSubject.create();
private Single<Long> observeOnLongClickListItem() {
SingleSubject<Long> subject = SingleSubject.create();
listTodo.setOnItemLongClickListener((parent, view, position, id) -> {
new AlertDialog.Builder(activity)
.setTitle(R.string.dialog_delete_todo_title)
.setMessage(activity.getString(R.string.dialog_delete_todo_message,
store.todoList().getTodoById((int) id).getText()))
.setPositiveButton(R.string.dialog_delete_todo_btn_positive, (dialog, which) -> {
subject.onNext(id);
subject.onSuccess(id);
})
.setNeutralButton(R.string.dialog_delete_todo_btn_neutral, (dialog, which) -> {
dialog.dismiss();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import info.izumin.android.droidux.annotation.Store;
import info.izumin.android.droidux.example.todomvc.entity.TodoList;
import info.izumin.android.droidux.example.todomvc.reducer.TodoListReducer;
import rx.Observable;
import io.reactivex.Observable;

/**
* Created by izumin on 11/29/15.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import info.izumin.android.droidux.Action;
import info.izumin.android.droidux.Middleware;
import info.izumin.android.droidux.example.todomvc.RootStore;
import io.reactivex.Single;
import rx.Observable;

/**
Expand All @@ -14,15 +15,15 @@ public class Logger extends Middleware<RootStore> {
public static final String TAG = Logger.class.getSimpleName();

@Override
public Observable<Action> beforeDispatch(Action action) {
public Single<Action> beforeDispatch(Action action) {
Log.d("[prev todo]", getStore().todoList().toString());
Log.d("[" + action.getClass().getSimpleName() + "]", action.toString());
return Observable.just(action);
return Single.just(action);
}

@Override
public Observable<Action> afterDispatch(Action action) {
public Single<Action> afterDispatch(Action action) {
Log.d("[next todo]", getStore().todoList().toString());
return Observable.just(action);
return Single.just(action);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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;
import io.reactivex.Observable;

/**
* Created by izumin on 11/29/15.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import info.izumin.android.droidux.example.todoswithdagger.action.ClearNewTodoTextAction;
import info.izumin.android.droidux.example.todoswithdagger.action.DeleteTodoAction;
import info.izumin.android.droidux.example.todoswithdagger.action.ToggleCompletedTodoAction;
import rx.android.schedulers.AndroidSchedulers;
import rx.subjects.PublishSubject;
import rx.subscriptions.CompositeSubscription;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.subjects.SingleSubject;

/**
* Created by izumin on 11/5/15.
Expand All @@ -20,56 +19,56 @@ public class MainPresenter {
private final MainView view;
private final RootStore store;

private final PublishSubject<String> clickAddTodoSubject = PublishSubject.create();
private final PublishSubject<Long> clickItemSubject = PublishSubject.create();
private final PublishSubject<Long> longClickItemSubject = PublishSubject.create();
private final SingleSubject<String> clickAddTodoSubject = SingleSubject.create();
private final SingleSubject<Long> clickItemSubject = SingleSubject.create();
private final SingleSubject<Long> longClickItemSubject = SingleSubject.create();

private CompositeSubscription subscriptions;
private CompositeDisposable compositeDisposable;

public MainPresenter(MainView view, RootStore store) {
this.view = view;
this.store = store;
}

void onStart() {
subscriptions = new CompositeSubscription();
compositeDisposable = new CompositeDisposable();

subscriptions.add(clickAddTodoSubject
compositeDisposable.add(clickAddTodoSubject
.filter(s -> !s.isEmpty())
.flatMap(s -> store.dispatch(new AddTodoAction(s)))
.subscribeOn(AndroidSchedulers.mainThread())
.flatMap(_a -> store.dispatch(new ClearNewTodoTextAction()))
.flatMap(s -> store.dispatch(new AddTodoAction(s)).toMaybe())
/*TODO: Version up RxAndroid*/
/*.subscribeOn(AndroidSchedulers.mainThread())*/
.flatMap(_a -> store.dispatch(new ClearNewTodoTextAction()).toMaybe())
.subscribe(_a -> {
view.clearNewTodoText();
view.showToast(R.string.toast_add_todo);
}));

subscriptions.add(clickItemSubject
compositeDisposable.add(clickItemSubject
.flatMap(id -> store.dispatch(new ToggleCompletedTodoAction(id.intValue())))
.subscribe());

subscriptions.add(longClickItemSubject
compositeDisposable.add(longClickItemSubject
.flatMap(id -> store.dispatch(new DeleteTodoAction(id)))
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe(action -> {
view.showToast(R.string.toast_delete_todo);
}));
/*TODO: Version up RxAndroid*/
/*.subscribeOn(AndroidSchedulers.mainThread())*/
.subscribe(action -> view.showToast(R.string.toast_delete_todo)));
}

void onStop() {
subscriptions.unsubscribe();
compositeDisposable.clear();
}

void onClickBtnAddTodo(String text) {
clickAddTodoSubject.onNext(text);
clickAddTodoSubject.onSuccess(text);
}

void onClickListItem(long id) {
clickItemSubject.onNext(id);
clickItemSubject.onSuccess(id);
}

void onLongClickListItem(long id) {
longClickItemSubject.onNext(id);
longClickItemSubject.onSuccess(id);
}

void clearCompletedTodo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
import info.izumin.android.droidux.example.todoswithundo.action.DeleteTodoAction;
import info.izumin.android.droidux.example.todoswithundo.action.ToggleCompletedTodoAction;
import info.izumin.android.droidux.example.todoswithundo.reducer.TodoListReducer;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.subjects.PublishSubject;
import io.reactivex.Single;
import io.reactivex.subjects.SingleSubject;

/**
* Created by izumin on 11/5/15.
Expand Down Expand Up @@ -44,8 +43,9 @@ public void onCreate() {

observeOnClickBtnAddTodo()
.filter(s -> !s.isEmpty())
.flatMap(s -> store.dispatch(new AddTodoAction(s)))
.subscribeOn(AndroidSchedulers.mainThread())
.flatMap(s -> store.dispatch(new AddTodoAction(s)).toMaybe())
/*TODO: Version up RxAndroid*/
/*.subscribeOn(AndroidSchedulers.mainThread())*/
.subscribe(action -> {
editNewTodo.setText("");
Toast.makeText(activity, R.string.toast_add_todo, Toast.LENGTH_SHORT).show();
Expand All @@ -57,7 +57,8 @@ public void onCreate() {

observeOnLongClickListItem()
.flatMap(id -> store.dispatch(new DeleteTodoAction(id)))
.subscribeOn(AndroidSchedulers.mainThread())
/*TODO: Version up RxAndroid*/
/*.subscribeOn(AndroidSchedulers.mainThread())*/
.subscribe(action -> {
Toast.makeText(activity, R.string.toast_delete_todo, Toast.LENGTH_SHORT).show();
});
Expand All @@ -81,27 +82,27 @@ public boolean onOptionItemSelected(MenuItem item) {
}
}

private Observable<String> observeOnClickBtnAddTodo() {
PublishSubject<String> subject= PublishSubject.create();
btnAddTodo.setOnClickListener(v -> subject.onNext(editNewTodo.getText().toString()));
private io.reactivex.Single<String> observeOnClickBtnAddTodo() {
SingleSubject<String> subject = SingleSubject.create();
btnAddTodo.setOnClickListener(v -> subject.onSuccess(editNewTodo.getText().toString()));
return subject;
}

private Observable<Long> observeOnClickListItem() {
PublishSubject<Long> subject = PublishSubject.create();
listTodo.setOnItemClickListener((parent, view, position, id) -> subject.onNext(id));
private io.reactivex.Single<Long> observeOnClickListItem() {
SingleSubject<Long> subject = SingleSubject.create();
listTodo.setOnItemClickListener((parent, view, position, id) -> subject.onSuccess(id));
return subject;
}

private Observable<Long> observeOnLongClickListItem() {
PublishSubject<Long> subject = PublishSubject.create();
private Single<Long> observeOnLongClickListItem() {
SingleSubject<Long> subject = SingleSubject.create();
listTodo.setOnItemLongClickListener((parent, view, position, id) -> {
new AlertDialog.Builder(activity)
.setTitle(R.string.dialog_delete_todo_title)
.setMessage(activity.getString(R.string.dialog_delete_todo_message,
store.todoList().getTodoById((int) id).getText()))
.setPositiveButton(R.string.dialog_delete_todo_btn_positive, (dialog, which) -> {
subject.onNext(id);
subject.onSuccess(id);
})
.setNeutralButton(R.string.dialog_delete_todo_btn_neutral, (dialog, which) -> {
dialog.dismiss();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import info.izumin.android.droidux.annotation.Store;
import info.izumin.android.droidux.example.todoswithundo.entity.TodoList;
import info.izumin.android.droidux.example.todoswithundo.reducer.TodoListReducer;
import rx.Observable;
import io.reactivex.Observable;

/**
* Created by izumin on 11/29/15.
Expand Down
Loading