From 510591ef0f33bad0d72a0901c64bee33f29f58c8 Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Thu, 16 Aug 2018 00:45:37 +0200 Subject: [PATCH] Removed use of blockingFirst() and scheduleDirect() --- .../subscription/SubscriptionFragment.java | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java index a8603960b..c0a96da32 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java @@ -21,7 +21,6 @@ import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -44,9 +43,9 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.fragments.BaseStateFragment; import org.schabi.newpipe.info_list.InfoListAdapter; -import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.local.subscription.services.SubscriptionsExportService; import org.schabi.newpipe.local.subscription.services.SubscriptionsImportService; +import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.FilePickerActivityHelper; @@ -66,7 +65,6 @@ import java.util.Locale; import icepick.State; import io.reactivex.Observer; -import io.reactivex.Scheduler; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; @@ -413,13 +411,12 @@ public class SubscriptionFragment extends BaseStateFragment toDelete = subscriptionService.subscriptionTable() + final io.reactivex.Observable> observable = subscriptionService.subscriptionTable() .getSubscription(info.getServiceId(), info.getUrl()) - .blockingFirst(); - Log.d(TAG, "onNext: test"); + .toObservable(); - Scheduler io = Schedulers.io(); - io.scheduleDirect(() -> subscriptionService.subscriptionTable().delete(toDelete)); + observable.observeOn(Schedulers.io()) + .subscribe(getDeleteObserver()); } @Override @@ -434,6 +431,28 @@ public class SubscriptionFragment extends BaseStateFragment> getDeleteObserver(){ + return new Observer>() { + @Override + public void onSubscribe(Disposable d) { + disposables.add(d); + } + + @Override + public void onNext(List subscriptionEntities) { + subscriptionService.subscriptionTable().delete(subscriptionEntities); + } + + @Override + public void onError(Throwable exception) { + SubscriptionFragment.this.onError(exception); + } + + @Override + public void onComplete() { } + }; + } + private void resetFragment() { if (disposables != null) disposables.clear(); if (infoListAdapter != null) infoListAdapter.clearStreamItemList();