Skip to content

Commit

Permalink
MVI sample - Updated to RxBindings 2.0 - removes RxInterop
Browse files Browse the repository at this point in the history
  • Loading branch information
sockeqwe committed Mar 11, 2017
1 parent 3e86901 commit d46f9f5
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies {
compile 'com.hannesdorfmann.mosby3:mvp:3.0.1-SNAPSHOT'
compile 'com.hannesdorfmann.mosby3:viewstate:3.0.1-SNAPSHOT'
compile 'com.hannesdorfmann.mosby3:mvp-lce:3.0.1-SNAPSHOT'
compile 'com.hannesdorfmann.mosby3:mvp-nullobject-presenter:3.0.1-SNAPSHOT'
}
Expand Down
12 changes: 5 additions & 7 deletions sample-mvi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ android {
dependencies {

def retrofitVersion = '2.1.1-SNAPSHOT'
def rxbindingVersion = '1.0.0'
def rxbindingVersion = '2.0.0'
def okHttpVersion = '3.6.0'


Expand Down Expand Up @@ -87,14 +87,12 @@ dependencies {
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.github.bumptech.glide:glide:3.7.0'

compile "com.github.akarnokd:rxjava2-interop:0.7.2"

debugCompile 'com.squareup.leakcanary:leakcanary-android:' + rootProject.ext.leakcanaryVersion
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:' + rootProject.ext.leakcanaryVersion
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:' + rootProject.ext.leakcanaryVersion

compile "com.jakewharton.rxbinding:rxbinding:$rxbindingVersion"
compile "com.jakewharton.rxbinding:rxbinding-support-v4:$rxbindingVersion"
compile "com.jakewharton.rxbinding:rxbinding-design:$rxbindingVersion"
compile "com.jakewharton.rxbinding:rxbinding-recyclerview-v7:$rxbindingVersion"
compile "com.jakewharton.rxbinding2:rxbinding:$rxbindingVersion"
compile "com.jakewharton.rxbinding2:rxbinding-support-v4:$rxbindingVersion"
compile "com.jakewharton.rxbinding2:rxbinding-design:$rxbindingVersion"
compile "com.jakewharton.rxbinding2:rxbinding-recyclerview-v7:$rxbindingVersion"
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ public class DependencyInjection {
new ShoppingCartOverviewPresenter(shoppingCart, deleteSelectionRelay, clearSelectionRelay);


// Initializer block
{
httpLogger.setLevel(HttpLoggingInterceptor.Level.BODY);
}

private SearchEngine newSearchEngine() {
return new SearchEngine(backendApiDecorator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public CheckoutButton(Context context, AttributeSet attrs) {
mviDelegate.onDetachedFromWindow();
}


@Override public Parcelable onSaveInstanceState() {
return mviDelegate.onSaveInstanceState();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@
import com.hannesdorfmann.mosby3.mvi.MviActivity;
import com.hannesdorfmann.mosby3.sample.mvi.R;
import com.hannesdorfmann.mosby3.sample.mvi.SampleApplication;
import com.hannesdorfmann.mosby3.sample.mvi.businesslogic.http.ProductBackendApi;
import com.hannesdorfmann.mosby3.sample.mvi.businesslogic.interactor.details.ProductDetailsViewState;
import com.hannesdorfmann.mosby3.sample.mvi.businesslogic.model.Product;
import com.hannesdorfmann.mosby3.sample.mvi.dependencyinjection.DependencyInjection;
import com.jakewharton.rxbinding.view.RxView;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import com.jakewharton.rxbinding2.view.RxView;
import io.reactivex.Observable;
import java.util.Locale;
import timber.log.Timber;
Expand Down Expand Up @@ -77,8 +75,7 @@ public static void start(Activity activity, Product product) {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

fabClickObservable =
RxJavaInterop.toV2Observable(RxView.clicks(fab).share().map(ignored -> true));
fabClickObservable = RxView.clicks(fab).share().map(ignored -> true);
}

@NonNull @Override public ProductDetailsPresenter createPresenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
import com.hannesdorfmann.mosby3.sample.mvi.view.detail.ProductDetailsActivity;
import com.hannesdorfmann.mosby3.sample.mvi.view.ui.GridSpacingItemDecoration;
import com.hannesdorfmann.mosby3.sample.mvi.view.ui.viewholder.ProductViewHolder;
import com.jakewharton.rxbinding.support.v4.widget.RxSwipeRefreshLayout;
import com.jakewharton.rxbinding.support.v7.widget.RxRecyclerView;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import com.jakewharton.rxbinding2.support.v4.widget.RxSwipeRefreshLayout;
import com.jakewharton.rxbinding2.support.v7.widget.RxRecyclerView;
import io.reactivex.Observable;
import timber.log.Timber;

Expand Down Expand Up @@ -112,7 +111,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
}

@Override public Observable<Boolean> loadNextPageIntent() {
return RxJavaInterop.toV2Observable(RxRecyclerView.scrollStateChanges(recyclerView))
return RxRecyclerView.scrollStateChanges(recyclerView)
.filter(event -> !adapter.isLoadingNextPage())
.filter(event -> event == RecyclerView.SCROLL_STATE_IDLE)
.filter(event -> layoutManager.findLastCompletelyVisibleItemPosition()
Expand All @@ -121,8 +120,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
}

@Override public Observable<Boolean> pullToRefreshIntent() {
return RxJavaInterop.toV2Observable(
RxSwipeRefreshLayout.refreshes(swipeRefreshLayout).map(ignored -> true));
return RxSwipeRefreshLayout.refreshes(swipeRefreshLayout).map(ignored -> true);
}

@Override public Observable<String> loadAllProductsFromCategoryIntent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import com.hannesdorfmann.mosby3.sample.mvi.view.detail.ProductDetailsActivity;
import com.hannesdorfmann.mosby3.sample.mvi.view.ui.GridSpacingItemDecoration;
import com.hannesdorfmann.mosby3.sample.mvi.view.ui.viewholder.ProductViewHolder;
import com.jakewharton.rxbinding.widget.RxSearchView;
import hu.akarnokd.rxjava.interop.RxJavaInterop;
import com.jakewharton.rxbinding2.widget.RxSearchView;
import io.reactivex.Observable;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -73,7 +72,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
}

@Override public Observable<String> searchIntent() {
return RxJavaInterop.toV2Observable(RxSearchView.queryTextChanges(searchView))
return RxSearchView.queryTextChanges(searchView)
.skip(2) // Because after screen orientation changes query Text will be resubmitted again
.filter(queryString -> queryString.length() > 3 || queryString.length() == 0)
.debounce(500, TimeUnit.MILLISECONDS)
Expand Down

0 comments on commit d46f9f5

Please sign in to comment.