From a68823491c4195cd26ed73da61882ba0379ef7f0 Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Thu, 28 Jun 2018 20:37:05 +0200 Subject: [PATCH 01/10] Delete on long press --- .../holder/ChannelMiniInfoItemHolder.java | 7 ++ .../subscription/SubscriptionFragment.java | 88 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/info_list/holder/ChannelMiniInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/holder/ChannelMiniInfoItemHolder.java index 643886da8..ca783833a 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/holder/ChannelMiniInfoItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/holder/ChannelMiniInfoItemHolder.java @@ -47,6 +47,13 @@ public class ChannelMiniInfoItemHolder extends InfoItemHolder { itemBuilder.getOnChannelSelectedListener().selected(item); } }); + + itemView.setOnLongClickListener(view -> { + if (itemBuilder.getOnChannelSelectedListener() != null) { + itemBuilder.getOnChannelSelectedListener().held(item); + } + return true; + }); } protected String getDetailLine(final ChannelInfoItem item) { 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 5f6ea42ee..f31e0a7c3 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 @@ -1,8 +1,11 @@ package org.schabi.newpipe.local.subscription; +import android.annotation.SuppressLint; import android.app.Activity; +import android.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.graphics.Color; @@ -17,6 +20,7 @@ import android.support.v4.content.LocalBroadcastManager; import android.support.v7.app.ActionBar; 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; @@ -30,18 +34,24 @@ 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.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; @@ -55,12 +65,17 @@ 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.Observable; import io.reactivex.Observer; +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 org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.KEY_MODE; @@ -316,12 +331,17 @@ public class SubscriptionFragment extends BaseStateFragment() { - @Override + public void selected(ChannelInfoItem selectedItem) { // Requires the parent fragment to find holder for fragment replacement NavigationHelper.openChannelFragment(getParentFragment().getFragmentManager(), selectedItem.getServiceId(), selectedItem.getUrl(), selectedItem.getName()); } + + public void held(ChannelInfoItem selectedItem) { + showLongTapDialog(selectedItem); + } + }); //noinspection ConstantConditions @@ -330,6 +350,72 @@ public class SubscriptionFragment extends BaseStateFragment importExportOptions.switchState()); } + private void showLongTapDialog(ChannelInfoItem selectedItem) { + final Context context = getContext(); + final Activity activity = getActivity(); + if (context == null || context.getResources() == null || getActivity() == null) return; + + final String[] commands = new String[]{ + context.getResources().getString(R.string.share), + context.getResources().getString(R.string.unsubscribe) + }; + + final DialogInterface.OnClickListener actions = (dialogInterface, i) -> { + switch (i) { + case 0: + shareChannel(selectedItem); + break; + case 1: + deleteChannel(selectedItem); + break; + default: + break; + } + }; + + final View bannerView = View.inflate(activity, R.layout.dialog_title, null); + bannerView.setSelected(true); + + TextView titleView = bannerView.findViewById(R.id.itemTitleView); + titleView.setText(selectedItem.getName()); + + TextView detailsView = bannerView.findViewById(R.id.itemAdditionalDetails); + detailsView.setVisibility(View.GONE); + + new AlertDialog.Builder(activity) + .setCustomTitle(bannerView) + .setItems(commands, actions) + .create() + .show(); + + } + + private void shareChannel (ChannelInfoItem selectedItem) { + shareUrl(selectedItem.getName(), selectedItem.getUrl()); + } + + @SuppressLint("CheckResult") + private void deleteChannel (ChannelInfoItem selectedItem) { + ExtractorHelper.getChannelInfo(selectedItem.getServiceId(), selectedItem.getUrl(), true) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe((@NonNull ChannelInfo result) -> { + mapOnUnsubscribe(SubscriptionEntity.from(result)); + }, (@NonNull Throwable throwable) -> { + + }); + } + + private Function mapOnUnsubscribe(final SubscriptionEntity subscription) { + return new Function() { + @Override + public Object apply(@NonNull Object o) throws Exception { + subscriptionService.subscriptionTable().delete(subscription); + return o; + } + }; + } + private void resetFragment() { if (disposables != null) disposables.clear(); if (infoListAdapter != null) infoListAdapter.clearStreamItemList(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5ca88bd6f..2faae0175 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -27,6 +27,7 @@ RSS Subscribe Subscribed + Unsubscribe Channel unsubscribed Unable to change subscription Unable to update subscription From 0b7593ad28a1d04d67ef85e6157eca4c83579cc0 Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Thu, 28 Jun 2018 20:43:46 +0200 Subject: [PATCH 02/10] Delete on long press --- .../subscription/SubscriptionFragment.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 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 f31e0a7c3..4b311a852 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 @@ -8,8 +8,12 @@ import android.content.Context; import android.content.DialogInterface; 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; @@ -21,6 +25,7 @@ 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; @@ -78,6 +83,7 @@ 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; @@ -400,20 +406,20 @@ public class SubscriptionFragment extends BaseStateFragment { - mapOnUnsubscribe(SubscriptionEntity.from(result)); + new LongOperation().execute(SubscriptionEntity.from(result)); }, (@NonNull Throwable throwable) -> { }); } - private Function mapOnUnsubscribe(final SubscriptionEntity subscription) { - return new Function() { - @Override - public Object apply(@NonNull Object o) throws Exception { - subscriptionService.subscriptionTable().delete(subscription); - return o; - } - }; + + private class LongOperation extends AsyncTask { + + @Override + protected Void doInBackground(SubscriptionEntity... params) { + subscriptionService.subscriptionTable().delete(params[0]); + return null; + } } private void resetFragment() { From 5150c2ee62dba57e954a8ef436118218e0ff50cb Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Thu, 28 Jun 2018 23:56:39 +0200 Subject: [PATCH 03/10] This thing actually works lol --- .../local/subscription/SubscriptionFragment.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 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 4b311a852..8f02158bc 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 @@ -73,6 +73,7 @@ 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.Single; @@ -406,18 +407,20 @@ public class SubscriptionFragment extends BaseStateFragment { - new LongOperation().execute(SubscriptionEntity.from(result)); + new LongOperation().execute(result); }, (@NonNull Throwable throwable) -> { }); } - private class LongOperation extends AsyncTask { + private class LongOperation extends AsyncTask { @Override - protected Void doInBackground(SubscriptionEntity... params) { - subscriptionService.subscriptionTable().delete(params[0]); + protected Void doInBackground(ChannelInfo... params) { + ChannelInfo info = params[0]; + Flowable> subscription = subscriptionService.subscriptionTable().getSubscription(info.getServiceId(), info.getUrl()); + subscriptionService.subscriptionTable().delete(subscription.blockingFirst()); return null; } } From f2f275512d4ef276e473ffb08b24202fef340c18 Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Fri, 29 Jun 2018 00:39:16 +0200 Subject: [PATCH 04/10] It looks good now --- .../subscription/SubscriptionFragment.java | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 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 8f02158bc..16f203923 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,6 +6,7 @@ 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; @@ -76,6 +77,7 @@ 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; @@ -405,26 +407,13 @@ public class SubscriptionFragment extends BaseStateFragment { - new LongOperation().execute(result); - }, (@NonNull Throwable throwable) -> { - + List toDelete = subscriptionService.subscriptionTable().getSubscription(result.getServiceId(), result.getUrl()).blockingFirst(); + subscriptionService.subscriptionTable().delete(toDelete); }); } - - private class LongOperation extends AsyncTask { - - @Override - protected Void doInBackground(ChannelInfo... params) { - ChannelInfo info = params[0]; - Flowable> subscription = subscriptionService.subscriptionTable().getSubscription(info.getServiceId(), info.getUrl()); - subscriptionService.subscriptionTable().delete(subscription.blockingFirst()); - return null; - } - } - private void resetFragment() { if (disposables != null) disposables.clear(); if (infoListAdapter != null) infoListAdapter.clearStreamItemList(); From b9ea7ce066189b21b94268ed9ae33b9c222f4385 Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Fri, 29 Jun 2018 00:39:44 +0200 Subject: [PATCH 05/10] Code looking nicer --- .../newpipe/local/subscription/SubscriptionFragment.java | 4 +++- .../main/java/org/schabi/newpipe/util/ExtractorHelper.java | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) 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 16f203923..4c4242055 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 @@ -409,7 +409,9 @@ public class SubscriptionFragment extends BaseStateFragment { - List toDelete = subscriptionService.subscriptionTable().getSubscription(result.getServiceId(), result.getUrl()).blockingFirst(); + List toDelete = subscriptionService.subscriptionTable() + .getSubscription(result.getServiceId(), result.getUrl()) + .blockingFirst(); subscriptionService.subscriptionTable().delete(toDelete); }); } diff --git a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java index 1897589c6..e248ed993 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java @@ -32,6 +32,7 @@ import org.schabi.newpipe.extractor.Info; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelInfo; +import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; From 181a14ce5958149af308872dfc66a826caea2da1 Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Sat, 30 Jun 2018 02:20:01 +0200 Subject: [PATCH 06/10] Disposable now is cleaned properly --- .../newpipe/local/subscription/SubscriptionFragment.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 4c4242055..c0e24b53f 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 @@ -405,6 +405,7 @@ public class SubscriptionFragment extends BaseStateFragment Date: Sat, 30 Jun 2018 02:42:47 +0200 Subject: [PATCH 07/10] 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() { From 510591ef0f33bad0d72a0901c64bee33f29f58c8 Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Thu, 16 Aug 2018 00:45:37 +0200 Subject: [PATCH 08/10] 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(); From f4416fe007c90f0da6b890c30f5f5ad404e34722 Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Thu, 16 Aug 2018 01:04:37 +0200 Subject: [PATCH 09/10] Doesn't use getChannelInfo() anymore. --- .../subscription/SubscriptionFragment.java | 43 ++++--------------- 1 file changed, 8 insertions(+), 35 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 c0a96da32..e39047bd3 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 @@ -37,7 +37,6 @@ import org.schabi.newpipe.database.subscription.SubscriptionEntity; 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.subscription.SubscriptionExtractor; @@ -47,7 +46,6 @@ 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; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; @@ -394,43 +392,18 @@ public class SubscriptionFragment extends BaseStateFragment> observable = subscriptionService.subscriptionTable() + .getSubscription(selectedItem.getServiceId(), selectedItem.getUrl()) + .toObservable(); - - - private Observer getUnsubscribeObserver() { - return new Observer() { - @Override - public void onSubscribe(Disposable d) { - disposables.add(d); - } - - @Override - public void onNext(ChannelInfo info) { - final io.reactivex.Observable> observable = subscriptionService.subscriptionTable() - .getSubscription(info.getServiceId(), info.getUrl()) - .toObservable(); - - observable.observeOn(Schedulers.io()) + observable.observeOn(Schedulers.io()) .subscribe(getDeleteObserver()); - } - @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(); - } - }; + Toast.makeText(activity, getString(R.string.channel_unsubscribed), Toast.LENGTH_SHORT).show(); } + + private Observer> getDeleteObserver(){ return new Observer>() { @Override @@ -449,7 +422,7 @@ public class SubscriptionFragment extends BaseStateFragment Date: Wed, 22 Aug 2018 13:59:12 +0200 Subject: [PATCH 10/10] Code cleanup --- .../newpipe/local/subscription/SubscriptionFragment.java | 7 +++---- 1 file changed, 3 insertions(+), 4 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 e39047bd3..7b7f43047 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 @@ -392,11 +392,10 @@ public class SubscriptionFragment extends BaseStateFragment> observable = subscriptionService.subscriptionTable() + subscriptionService.subscriptionTable() .getSubscription(selectedItem.getServiceId(), selectedItem.getUrl()) - .toObservable(); - - observable.observeOn(Schedulers.io()) + .toObservable() + .observeOn(Schedulers.io()) .subscribe(getDeleteObserver()); Toast.makeText(activity, getString(R.string.channel_unsubscribed), Toast.LENGTH_SHORT).show();