From b48c251b36860f59f6e6da7dd5e12b8c159bea0d Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Sat, 30 Jun 2018 02:42:47 +0200 Subject: [PATCH] Added unsubscription toast Added error handling Corrected threads --- .../subscription/SubscriptionFragment.java | 63 +++++++++++-------- 1 file changed, 36 insertions(+), 27 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 c0e24b53f..5a9f34cd9 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 @@ -6,15 +6,10 @@ import android.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; -import android.content.Entity; import android.content.Intent; import android.content.IntentFilter; -import android.content.pm.ResolveInfo; -import android.content.res.Resources; import android.graphics.Color; import android.graphics.PorterDuff; -import android.graphics.drawable.Drawable; -import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; import android.os.Parcelable; @@ -26,7 +21,6 @@ import android.support.v7.app.ActionBar; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; -import android.util.TypedValue; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -40,24 +34,20 @@ import com.nononsenseapps.filepicker.Utils; import org.schabi.newpipe.R; import org.schabi.newpipe.database.subscription.SubscriptionEntity; -import org.schabi.newpipe.download.DownloadDialog; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.channel.ChannelInfo; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.stream.StreamInfo; -import org.schabi.newpipe.extractor.stream.VideoStream; 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.UserAction; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.FilePickerActivityHelper; -import org.schabi.newpipe.util.ListHelper; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; import org.schabi.newpipe.util.ServiceHelper; @@ -71,22 +61,15 @@ import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Locale; -import java.util.concurrent.TimeUnit; import icepick.State; -import io.reactivex.Flowable; -import io.reactivex.Observable; import io.reactivex.Observer; import io.reactivex.Scheduler; -import io.reactivex.Single; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Consumer; -import io.reactivex.functions.Function; import io.reactivex.schedulers.Schedulers; -import static android.content.ContentValues.TAG; import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.KEY_MODE; import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.KEY_VALUE; import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.PREVIOUS_EXPORT_MODE; @@ -405,16 +388,42 @@ public class SubscriptionFragment extends BaseStateFragment { - List toDelete = subscriptionService.subscriptionTable() - .getSubscription(result.getServiceId(), result.getUrl()) - .blockingFirst(); - subscriptionService.subscriptionTable().delete(toDelete); - })); + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(getUnsubscribeObserver()); + } + + + + private Observer getUnsubscribeObserver() { + return new Observer() { + @Override + public void onSubscribe(Disposable d) { + disposables.add(d); + } + + @Override + public void onNext(ChannelInfo info) { + List toDelete = subscriptionService.subscriptionTable() + .getSubscription(info.getServiceId(), info.getUrl()) + .blockingFirst(); + Log.d(TAG, "onNext: test"); + + Scheduler io = Schedulers.io(); + io.scheduleDirect(() -> subscriptionService.subscriptionTable().delete(toDelete)); + } + + @Override + public void onError(Throwable exception) { + SubscriptionFragment.this.onError(exception); + } + + @Override + public void onComplete() { + Toast.makeText(activity, getString(R.string.channel_unsubscribed), Toast.LENGTH_SHORT).show(); + } + }; } private void resetFragment() {