Skip to content

Commit

Permalink
Remove RxJava1 dependencies completely
Browse files Browse the repository at this point in the history
  • Loading branch information
wakwak3125 committed Jan 2, 2018
1 parent b96dcc4 commit f0cab99
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.subjects.PublishSubject;
import io.reactivex.subjects.SingleSubject;

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

observeOnLongClickListItem()
.flatMap(id -> store.dispatch(new DeleteTodoAction(id)))
/*TODO: Version up RxAndroid*/
/*.subscribeOn(AndroidSchedulers.mainThread())*/
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe(action -> {
Toast.makeText(activity, R.string.toast_delete_todo, Toast.LENGTH_SHORT).show();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import java.util.List;

import rx.Observable;
import io.reactivex.Observable;


/**
* Created by izumin on 11/4/15.
Expand All @@ -23,8 +24,8 @@ public List<Todo> getTodoList() {
}

public Todo getTodoById(int id) {
return Observable.from(getTodoList())
.filter(todo -> id == todo.getId()).toBlocking().first();
return Observable.fromIterable(getTodoList())
.filter(todo -> id == todo.getId()).blockingFirst();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import info.izumin.android.droidux.example.todomvc.action.DeleteTodoAction;
import info.izumin.android.droidux.example.todomvc.action.ToggleCompletedTodoAction;
import info.izumin.android.droidux.example.todomvc.entity.TodoList;
import rx.Observable;
import io.reactivex.Observable;


/**
* Created by izumin on 11/4/15.
Expand All @@ -21,38 +22,40 @@ public class TodoListReducer {
@Dispatchable(AddTodoAction.class)
public TodoList onAddedTodo(TodoList state, AddTodoAction action) {
List<TodoList.Todo> list = state.getTodoList();
int id = Observable.from(list)
int id = Observable.fromIterable(list)
.reduce((todo, todo2) -> (todo.getId() < todo2.getId()) ? todo2 : todo)
.onErrorReturn(throwable -> new TodoList.Todo(0, ""))
.toBlocking().last().getId();
.toObservable()
.blockingLast()
.getId();
list.add(new TodoList.Todo(id + 1, action.getText()));
return new TodoList(list);
}

@Dispatchable(ToggleCompletedTodoAction.class)
public TodoList onCompletedTodo(TodoList state, ToggleCompletedTodoAction action) {
return new TodoList(Observable.from(state.getTodoList())
return new TodoList(Observable.fromIterable(state.getTodoList())
.map(todo -> {
if (todo.getId() == action.getId()) {
return new TodoList.Todo(todo.getId(), todo.getText(), !todo.isCompleted());
}
return todo;
})
.toList().toBlocking().single()
.toList().blockingGet()
);
}

@Dispatchable(ClearCompletedTodoAction.class)
public TodoList onClearCompletedTodo(TodoList state, ClearCompletedTodoAction action) {
return new TodoList(Observable.from(state.getTodoList())
.filter(todo -> !todo.isCompleted()).toList().toBlocking().single()
return new TodoList(Observable.fromIterable(state.getTodoList())
.filter(todo -> !todo.isCompleted()).toList().blockingGet()
);
}

@Dispatchable(DeleteTodoAction.class)
public TodoList onDeletedTodo(TodoList state, DeleteTodoAction action) {
return new TodoList(Observable.from(state.getTodoList())
.filter(todo -> todo.getId() != action.getId()).toList().toBlocking().single()
return new TodoList(Observable.fromIterable(state.getTodoList())
.filter(todo -> todo.getId() != action.getId()).toList().blockingGet()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.List;

import info.izumin.android.droidux.UndoableState;
import rx.Observable;
import io.reactivex.Observable;

/**
* Created by izumin on 11/4/15.
Expand All @@ -22,8 +22,8 @@ public TodoList(List<Todo> list) {
}

public Todo getTodoById(int id) {
return Observable.from(this)
.filter(todo -> id == todo.getId()).toBlocking().first();
return Observable.fromIterable(this)
.filter(todo -> id == todo.getId()).blockingFirst();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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 io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.subjects.PublishSubject;

Expand Down Expand Up @@ -36,8 +37,7 @@ void onStart() {
compositeDisposable.add(clickAddTodoSubject
.filter(s -> !s.isEmpty())
.flatMap(s -> store.dispatch(new AddTodoAction(s)).toObservable())
/*TODO: Version up RxAndroid*/
/*.subscribeOn(AndroidSchedulers.mainThread())*/
.subscribeOn(AndroidSchedulers.mainThread())
.flatMap(_a -> store.dispatch(new ClearNewTodoTextAction()).toObservable())
.subscribe(_a -> {
view.clearNewTodoText();
Expand All @@ -50,8 +50,7 @@ void onStart() {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import info.izumin.android.droidux.example.todoswithdagger.action.DeleteTodoAction;
import info.izumin.android.droidux.example.todoswithdagger.action.ToggleCompletedTodoAction;
import info.izumin.android.droidux.example.todoswithdagger.entity.TodoList;
import rx.Observable;
import io.reactivex.Observable;

/**
* Created by izumin on 11/4/15.
Expand All @@ -18,39 +18,41 @@ public class TodoListReducer {

@Dispatchable(AddTodoAction.class)
public TodoList add(TodoList state, AddTodoAction action) {
int id = Observable.from(state)
int id = Observable.fromIterable(state)
.reduce((todo, todo2) -> (todo.getId() < todo2.getId()) ? todo2 : todo)
.onErrorReturn(throwable -> new TodoList.Todo(0, ""))
.toBlocking().last().getId();
.toObservable()
.blockingLast()
.getId();
TodoList newState = new TodoList(state);
newState.add(new TodoList.Todo(id + 1, action.getText()));
return newState;
}

@Dispatchable(ToggleCompletedTodoAction.class)
public TodoList complete(TodoList state, ToggleCompletedTodoAction action) {
return new TodoList(Observable.from(state)
return new TodoList(Observable.fromIterable(state)
.map(todo -> {
if (todo.getId() == action.getId()) {
return new TodoList.Todo(todo.getId(), todo.getText(), !todo.isCompleted());
}
return todo;
})
.toList().toBlocking().single()
.toList().blockingGet()
);
}

@Dispatchable(ClearCompletedTodoAction.class)
public TodoList clear(TodoList state) {
return new TodoList(Observable.from(state)
.filter(todo -> !todo.isCompleted()).toList().toBlocking().single()
return new TodoList(Observable.fromIterable(state)
.filter(todo -> !todo.isCompleted()).toList().blockingGet()
);
}

@Dispatchable(DeleteTodoAction.class)
public TodoList delete(TodoList state, DeleteTodoAction action) {
return new TodoList(Observable.from(state)
.filter(todo -> todo.getId() != action.getId()).toList().toBlocking().single()
return new TodoList(Observable.fromIterable(state)
.filter(todo -> todo.getId() != action.getId()).toList().blockingGet()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.subjects.PublishSubject;
import io.reactivex.subjects.SingleSubject;

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

observeOnLongClickListItem()
.flatMap(id -> store.dispatch(new DeleteTodoAction(id)))
/*TODO: Version up RxAndroid*/
/*.subscribeOn(AndroidSchedulers.mainThread())*/
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe(action -> {
Toast.makeText(activity, R.string.toast_delete_todo, Toast.LENGTH_SHORT).show();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.List;

import info.izumin.android.droidux.UndoableState;
import rx.Observable;
import io.reactivex.Observable;

/**
* Created by izumin on 11/4/15.
Expand All @@ -22,8 +22,8 @@ public TodoList(List<Todo> list) {
}

public Todo getTodoById(int id) {
return Observable.from(this)
.filter(todo -> id == todo.getId()).toBlocking().first();
return Observable.fromIterable(this)
.filter(todo -> id == todo.getId()).blockingFirst();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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.entity.TodoList;
import rx.Observable;
import io.reactivex.Observable;

/**
* Created by izumin on 11/4/15.
Expand All @@ -20,39 +20,41 @@ public class TodoListReducer {

@Dispatchable(AddTodoAction.class)
public TodoList onAddedTodo(TodoList state, AddTodoAction action) {
int id = Observable.from(state)
int id = Observable.fromIterable(state)
.reduce((todo, todo2) -> (todo.getId() < todo2.getId()) ? todo2 : todo)
.onErrorReturn(throwable -> new TodoList.Todo(0, ""))
.toBlocking().last().getId();
.toObservable()
.blockingLast()
.getId();
TodoList newState = new TodoList(state);
newState.add(new TodoList.Todo(id + 1, action.getText()));
return newState;
}

@Dispatchable(ToggleCompletedTodoAction.class)
public TodoList onCompletedTodo(TodoList state, ToggleCompletedTodoAction action) {
return new TodoList(Observable.from(state)
return new TodoList(Observable.fromIterable(state)
.map(todo -> {
if (todo.getId() == action.getId()) {
return new TodoList.Todo(todo.getId(), todo.getText(), !todo.isCompleted());
}
return todo;
})
.toList().toBlocking().single()
.toList().blockingGet()
);
}

@Dispatchable(ClearCompletedTodoAction.class)
public TodoList onClearCompletedTodo(TodoList state, ClearCompletedTodoAction action) {
return new TodoList(Observable.from(state)
.filter(todo -> !todo.isCompleted()).toList().toBlocking().single()
return new TodoList(Observable.fromIterable(state)
.filter(todo -> !todo.isCompleted()).toList().blockingGet()
);
}

@Dispatchable(DeleteTodoAction.class)
public TodoList onDeletedTodo(TodoList state, DeleteTodoAction action) {
return new TodoList(Observable.from(state)
.filter(todo -> todo.getId() != action.getId()).toList().toBlocking().single()
return new TodoList(Observable.fromIterable(state)
.filter(todo -> todo.getId() != action.getId()).toList().blockingGet()
);
}
}

0 comments on commit f0cab99

Please sign in to comment.