From 8b584f3922d16b1962ab843f2d18bd588aa898a0 Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 29 May 2019 16:22:01 +0200 Subject: [PATCH 01/13] Make long-press menu consistent across views: fix #2354 Also made the code that creates the menus consistent across files. --- .../fragments/list/BaseListFragment.java | 16 +++++++---- .../list/channel/ChannelFragment.java | 10 ++----- .../list/playlist/PlaylistFragment.java | 15 ++++++---- .../history/StatisticsPlaylistFragment.java | 18 +++++++----- .../local/playlist/LocalPlaylistFragment.java | 28 ++++++++++--------- 5 files changed, 49 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index dbc3dd8a2..f031ad278 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -256,9 +256,10 @@ public abstract class BaseListFragment extends BaseStateFragment implem if (context == null || context.getResources() == null || getActivity() == null) return; final String[] commands = new String[]{ - context.getResources().getString(R.string.direct_on_background), context.getResources().getString(R.string.enqueue_on_background), context.getResources().getString(R.string.enqueue_on_popup), + context.getResources().getString(R.string.start_here_on_background), + context.getResources().getString(R.string.start_here_on_popup), context.getResources().getString(R.string.append_playlist), context.getResources().getString(R.string.share) }; @@ -266,21 +267,24 @@ public abstract class BaseListFragment extends BaseStateFragment implem final DialogInterface.OnClickListener actions = (dialogInterface, i) -> { switch (i) { case 0: - NavigationHelper.playOnBackgroundPlayer(context, new SinglePlayQueue(item)); - break; - case 1: NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item)); break; - case 2: + case 1: NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item)); break; + case 2: + NavigationHelper.playOnBackgroundPlayer(context, new SinglePlayQueue(item)); + break; case 3: + NavigationHelper.playOnPopupPlayer(activity, new SinglePlayQueue(item)); + break; + case 4: if (getFragmentManager() != null) { PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) .show(getFragmentManager(), TAG); } break; - case 4: + case 5: ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl()); break; default: diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 71865b04d..2cb4d2c5f 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -159,7 +159,6 @@ public class ChannelFragment extends BaseListInfoFragment { final String[] commands = new String[]{ context.getResources().getString(R.string.enqueue_on_background), context.getResources().getString(R.string.enqueue_on_popup), - context.getResources().getString(R.string.start_here_on_main), context.getResources().getString(R.string.start_here_on_background), context.getResources().getString(R.string.start_here_on_popup), context.getResources().getString(R.string.append_playlist), @@ -176,21 +175,18 @@ public class ChannelFragment extends BaseListInfoFragment { NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item)); break; case 2: - NavigationHelper.playOnMainPlayer(context, getPlayQueue(index)); - break; - case 3: NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index)); break; - case 4: + case 3: NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index)); break; - case 5: + case 4: if (getFragmentManager() != null) { PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) .show(getFragmentManager(), TAG); } break; - case 6: + case 5: ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl()); break; default: diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index 2a775fe8f..f16bf0be4 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -31,6 +31,7 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.info_list.InfoItemDialog; +import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.local.playlist.RemotePlaylistManager; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue; @@ -44,6 +45,7 @@ import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.ThemeHelper; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -144,9 +146,9 @@ public class PlaylistFragment extends BaseListInfoFragment { final String[] commands = new String[]{ context.getResources().getString(R.string.enqueue_on_background), context.getResources().getString(R.string.enqueue_on_popup), - context.getResources().getString(R.string.start_here_on_main), context.getResources().getString(R.string.start_here_on_background), context.getResources().getString(R.string.start_here_on_popup), + context.getResources().getString(R.string.append_playlist), context.getResources().getString(R.string.share) }; @@ -160,14 +162,17 @@ public class PlaylistFragment extends BaseListInfoFragment { NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item)); break; case 2: - NavigationHelper.playOnMainPlayer(context, getPlayQueue(index)); - break; - case 3: NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index)); break; - case 4: + case 3: NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index)); break; + case 4: + if (getFragmentManager() != null) { + PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) + .show(getFragmentManager(), TAG); + } + break; case 5: ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl()); break; diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 5a62a3969..841193fd0 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -27,6 +27,7 @@ import org.schabi.newpipe.database.stream.StreamStatisticsEntry; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.local.BaseLocalListFragment; +import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.ErrorActivity; @@ -366,10 +367,10 @@ public class StatisticsPlaylistFragment final String[] commands = new String[]{ context.getResources().getString(R.string.enqueue_on_background), context.getResources().getString(R.string.enqueue_on_popup), - context.getResources().getString(R.string.start_here_on_main), context.getResources().getString(R.string.start_here_on_background), context.getResources().getString(R.string.start_here_on_popup), context.getResources().getString(R.string.delete), + context.getResources().getString(R.string.append_playlist), context.getResources().getString(R.string.share) }; @@ -383,19 +384,22 @@ public class StatisticsPlaylistFragment NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(infoItem)); break; case 2: - NavigationHelper.playOnMainPlayer(context, getPlayQueue(index)); - break; - case 3: NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index)); break; - case 4: + case 3: NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index)); break; - case 5: + case 4: deleteEntry(index); break; + case 5: + if (getFragmentManager() != null) { + PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(infoItem)) + .show(getFragmentManager(), TAG); + } + break; case 6: - ShareUtils.shareUrl(this.getContext(), item.toStreamInfoItem().getName(), item.toStreamInfoItem().getUrl()); + ShareUtils.shareUrl(this.getContext(), infoItem.getName(), infoItem.getUrl()); break; default: break; diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index dc101fade..233ddbbdf 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -28,6 +28,7 @@ import org.schabi.newpipe.database.playlist.PlaylistStreamEntry; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.local.BaseLocalListFragment; import org.schabi.newpipe.info_list.InfoItemDialog; +import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.UserAction; @@ -521,42 +522,43 @@ public class LocalPlaylistFragment extends BaseLocalListFragment { final int index = Math.max(itemListAdapter.getItemsList().indexOf(item), 0); switch (i) { case 0: - NavigationHelper.enqueueOnBackgroundPlayer(context, - new SinglePlayQueue(infoItem)); + NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(infoItem)); break; case 1: - NavigationHelper.enqueueOnPopupPlayer(activity, new - SinglePlayQueue(infoItem)); + NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(infoItem)); break; case 2: - NavigationHelper.playOnMainPlayer(context, getPlayQueue(index)); - break; - case 3: NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index)); break; - case 4: + case 3: NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index)); break; - case 5: + case 4: changeThumbnailUrl(item.thumbnailUrl); break; - case 6: + case 5: deleteItem(item); break; + case 6: + if (getFragmentManager() != null) { + PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(infoItem)) + .show(getFragmentManager(), TAG); + } + break; case 7: - ShareUtils.shareUrl(this.getContext(), item.toStreamInfoItem().getName(), item.toStreamInfoItem().getUrl()); + ShareUtils.shareUrl(this.getContext(), infoItem.getName(), infoItem.getUrl()); break; default: break; From 30eeef46c29e29953f1b0bc8a19f9bf4c03de256 Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 29 May 2019 16:25:23 +0200 Subject: [PATCH 02/13] Removed unused showStreamDialog from VideoDetailFragment VideoDetailFragment already borrows a consistant menu from the stream list it holds. --- .../fragments/detail/VideoDetailFragment.java | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index bbd1a315d..ab35ec3da 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -522,42 +522,6 @@ public class VideoDetailFragment detailControlsPopup.setOnTouchListener(getOnControlsTouchListener()); } - private void showStreamDialog(final StreamInfoItem item) { - final Context context = getContext(); - if (context == null || context.getResources() == null || getActivity() == null) return; - - final String[] commands = new String[]{ - context.getResources().getString(R.string.enqueue_on_background), - context.getResources().getString(R.string.enqueue_on_popup), - context.getResources().getString(R.string.append_playlist), - context.getResources().getString(R.string.share) - }; - - final DialogInterface.OnClickListener actions = (DialogInterface dialogInterface, int i) -> { - switch (i) { - case 0: - NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item)); - break; - case 1: - NavigationHelper.enqueueOnPopupPlayer(getActivity(), new SinglePlayQueue(item)); - break; - case 2: - if (getFragmentManager() != null) { - PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) - .show(getFragmentManager(), TAG); - } - break; - case 3: - ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl()); - break; - default: - break; - } - }; - - new InfoItemDialog(getActivity(), item, commands, actions).show(); - } - private View.OnTouchListener getOnControlsTouchListener() { return (View view, MotionEvent motionEvent) -> { if (!PreferenceManager.getDefaultSharedPreferences(activity) From bdb1be9967101c61689fff63c35842c7744c5890 Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 29 May 2019 20:25:44 +0200 Subject: [PATCH 03/13] Remove useless overrides of showStreamDialog They were exactly the same as the base class function --- .../list/channel/ChannelFragment.java | 46 ------------------ .../list/playlist/PlaylistFragment.java | 47 ------------------- 2 files changed, 93 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 2cb4d2c5f..302adc610 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -150,52 +150,6 @@ public class ChannelFragment extends BaseListInfoFragment { return headerRootLayout; } - @Override - protected void showStreamDialog(final StreamInfoItem item) { - final Activity activity = getActivity(); - final Context context = getContext(); - if (context == null || context.getResources() == null || getActivity() == null) return; - - final String[] commands = new String[]{ - context.getResources().getString(R.string.enqueue_on_background), - context.getResources().getString(R.string.enqueue_on_popup), - context.getResources().getString(R.string.start_here_on_background), - context.getResources().getString(R.string.start_here_on_popup), - context.getResources().getString(R.string.append_playlist), - context.getResources().getString(R.string.share) - }; - - final DialogInterface.OnClickListener actions = (DialogInterface dialogInterface, int i) -> { - final int index = Math.max(infoListAdapter.getItemsList().indexOf(item), 0); - switch (i) { - case 0: - NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item)); - break; - case 1: - NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item)); - break; - case 2: - NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index)); - break; - case 3: - NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index)); - break; - case 4: - if (getFragmentManager() != null) { - PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) - .show(getFragmentManager(), TAG); - } - break; - case 5: - ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl()); - break; - default: - break; - } - }; - - new InfoItemDialog(getActivity(), item, commands, actions).show(); - } /*////////////////////////////////////////////////////////////////////////// // Menu //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index f16bf0be4..c582d3ca2 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -137,53 +137,6 @@ public class PlaylistFragment extends BaseListInfoFragment { infoListAdapter.useMiniItemVariants(true); } - @Override - protected void showStreamDialog(final StreamInfoItem item) { - 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.enqueue_on_background), - context.getResources().getString(R.string.enqueue_on_popup), - context.getResources().getString(R.string.start_here_on_background), - context.getResources().getString(R.string.start_here_on_popup), - context.getResources().getString(R.string.append_playlist), - context.getResources().getString(R.string.share) - }; - - final DialogInterface.OnClickListener actions = (dialogInterface, i) -> { - final int index = Math.max(infoListAdapter.getItemsList().indexOf(item), 0); - switch (i) { - case 0: - NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item)); - break; - case 1: - NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item)); - break; - case 2: - NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index)); - break; - case 3: - NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index)); - break; - case 4: - if (getFragmentManager() != null) { - PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) - .show(getFragmentManager(), TAG); - } - break; - case 5: - ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl()); - break; - default: - break; - } - }; - - new InfoItemDialog(getActivity(), item, commands, actions).show(); - } - @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + From 86954666907e04f8153631fda9bbe84c5509be3a Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 29 May 2019 20:39:17 +0200 Subject: [PATCH 04/13] Make subscription long-press menu consistant in local sub list Inverted unsubscribe with share, since share has always been put after content-specific actions. --- .../newpipe/local/subscription/SubscriptionFragment.java | 8 ++++---- 1 file changed, 4 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 7d0fc3e61..d33fae67b 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 @@ -391,17 +391,17 @@ public class SubscriptionFragment extends BaseStateFragment { switch (i) { case 0: - shareChannel(selectedItem); + deleteChannel(selectedItem); break; case 1: - deleteChannel(selectedItem); + shareChannel(selectedItem); break; default: break; From 6f028ecb19c1e0ea08cfc702967ce750cd271df9 Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 29 May 2019 20:45:05 +0200 Subject: [PATCH 05/13] Remove unused imports from modified files --- .../newpipe/fragments/list/channel/ChannelFragment.java | 4 ---- .../newpipe/fragments/list/playlist/PlaylistFragment.java | 7 ------- 2 files changed, 11 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 302adc610..dd55870b2 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -34,12 +34,9 @@ import org.schabi.newpipe.extractor.channel.ChannelInfo; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; -import org.schabi.newpipe.info_list.InfoItemDialog; -import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.local.subscription.SubscriptionService; import org.schabi.newpipe.player.playqueue.ChannelPlayQueue; import org.schabi.newpipe.player.playqueue.PlayQueue; -import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.AnimationUtils; import org.schabi.newpipe.util.ExtractorHelper; @@ -49,7 +46,6 @@ import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ShareUtils; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index c582d3ca2..8ff03f064 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -1,8 +1,5 @@ package org.schabi.newpipe.fragments.list.playlist; -import android.app.Activity; -import android.content.Context; -import android.content.DialogInterface; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -30,12 +27,9 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; -import org.schabi.newpipe.info_list.InfoItemDialog; -import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.local.playlist.RemotePlaylistManager; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue; -import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.ExtractorHelper; @@ -45,7 +39,6 @@ import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.ThemeHelper; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; From b6cfb8a3dcd6e1f89bf4ab28b2269853e2b50bfa Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 30 May 2019 15:30:13 +0200 Subject: [PATCH 06/13] Remove dupliacte direct_on_background string start_here_on_background has the same meaning start_here_on_main is now unused, but I left it there so that if it ever becomes useful again, it is ready to be used. --- app/src/main/res/values/strings.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 90554a04f..d81923cf1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -419,7 +419,6 @@ Details Audio Settings Hold To enqueue - Play directly in background Enqueue in the background Enqueue in a new popup Start playing here From bb5028364bcc4ffffda561b342f5ceb3c2258466 Mon Sep 17 00:00:00 2001 From: Stypox Date: Mon, 22 Jul 2019 10:28:53 +0200 Subject: [PATCH 07/13] Complete merge after #2288: add resumePlayback to player calls. `resumePlayback`'s value is `false` when the video is enqueued, `true` otherwise. Also make the use of getContext() and getActivity() more consistant. --- .../newpipe/fragments/list/BaseListFragment.java | 14 +++++++------- .../local/history/StatisticsPlaylistFragment.java | 12 ++++++------ .../local/playlist/LocalPlaylistFragment.java | 14 +++++++------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index 4e8fa49e6..6a304dc1f 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -261,7 +261,7 @@ public abstract class BaseListFragment extends BaseStateFragment implem protected void showStreamDialog(final StreamInfoItem item) { final Context context = getContext(); final Activity activity = getActivity(); - if (context == null || context.getResources() == null || getActivity() == null) return; + if (context == null || context.getResources() == null || activity == null) return; final String[] commands = new String[]{ context.getResources().getString(R.string.enqueue_on_background), @@ -275,16 +275,16 @@ public abstract class BaseListFragment extends BaseStateFragment implem final DialogInterface.OnClickListener actions = (dialogInterface, i) -> { switch (i) { case 0: - NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item)); + NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item), false); break; case 1: - NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item)); + NavigationHelper.enqueueOnPopupPlayer(context, new SinglePlayQueue(item), false); break; case 2: - NavigationHelper.playOnBackgroundPlayer(context, new SinglePlayQueue(item)); + NavigationHelper.playOnBackgroundPlayer(context, new SinglePlayQueue(item), true); break; case 3: - NavigationHelper.playOnPopupPlayer(activity, new SinglePlayQueue(item)); + NavigationHelper.playOnPopupPlayer(context, new SinglePlayQueue(item), true); break; case 4: if (getFragmentManager() != null) { @@ -293,14 +293,14 @@ public abstract class BaseListFragment extends BaseStateFragment implem } break; case 5: - ShareUtils.shareUrl(this.getContext(), item.getName(), item.getUrl()); + ShareUtils.shareUrl(context, item.getName(), item.getUrl()); break; default: break; } }; - new InfoItemDialog(getActivity(), item, commands, actions).show(); + new InfoItemDialog(activity, item, commands, actions).show(); } /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 9b655b376..9a815461d 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -361,7 +361,7 @@ public class StatisticsPlaylistFragment private void showStreamDialog(final StreamStatisticsEntry item) { final Context context = getContext(); final Activity activity = getActivity(); - if (context == null || context.getResources() == null || getActivity() == null) return; + if (context == null || context.getResources() == null || activity == null) return; final StreamInfoItem infoItem = item.toStreamInfoItem(); final String[] commands = new String[]{ @@ -381,13 +381,13 @@ public class StatisticsPlaylistFragment NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(infoItem), false); break; case 1: - NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(infoItem), false); + NavigationHelper.enqueueOnPopupPlayer(context, new SinglePlayQueue(infoItem), false); break; case 2: - NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index)); + NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index), true); break; case 3: - NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index)); + NavigationHelper.playOnPopupPlayer(context, getPlayQueue(index), true); break; case 4: deleteEntry(index); @@ -399,14 +399,14 @@ public class StatisticsPlaylistFragment } break; case 6: - ShareUtils.shareUrl(this.getContext(), infoItem.getName(), infoItem.getUrl()); + ShareUtils.shareUrl(context, infoItem.getName(), infoItem.getUrl()); break; default: break; } }; - new InfoItemDialog(getActivity(), infoItem, commands, actions).show(); + new InfoItemDialog(activity, infoItem, commands, actions).show(); } private void deleteEntry(final int index) { diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 5aa506192..0de97033e 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -515,7 +515,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment Date: Mon, 22 Jul 2019 11:58:01 +0200 Subject: [PATCH 08/13] Fix showing popup options with audio-only streams --- .../fragments/list/BaseListFragment.java | 74 ++++++++------- .../history/StatisticsPlaylistFragment.java | 87 +++++++++-------- .../local/playlist/LocalPlaylistFragment.java | 93 +++++++++++-------- 3 files changed, 145 insertions(+), 109 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index 6a304dc1f..de4c17c3d 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -25,6 +25,7 @@ import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.comments.CommentsInfoItem; import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.fragments.BaseStateFragment; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; import org.schabi.newpipe.info_list.InfoItemDialog; @@ -263,40 +264,49 @@ public abstract class BaseListFragment extends BaseStateFragment implem final Activity activity = getActivity(); if (context == null || context.getResources() == null || activity == null) return; - final String[] commands = new String[]{ - context.getResources().getString(R.string.enqueue_on_background), - context.getResources().getString(R.string.enqueue_on_popup), - context.getResources().getString(R.string.start_here_on_background), - context.getResources().getString(R.string.start_here_on_popup), - context.getResources().getString(R.string.append_playlist), - context.getResources().getString(R.string.share) - }; + boolean isAudioStream = (item.getStreamType() == StreamType.AUDIO_STREAM); + + final String[] commands; + if (isAudioStream) { + commands = new String[]{ + context.getResources().getString(R.string.enqueue_on_background), + context.getResources().getString(R.string.start_here_on_background), + context.getResources().getString(R.string.append_playlist), + context.getResources().getString(R.string.share) + }; + } else { + commands = new String[]{ + context.getResources().getString(R.string.enqueue_on_background), + context.getResources().getString(R.string.enqueue_on_popup), + context.getResources().getString(R.string.start_here_on_background), + context.getResources().getString(R.string.start_here_on_popup), + context.getResources().getString(R.string.append_playlist), + context.getResources().getString(R.string.share) + }; + } final DialogInterface.OnClickListener actions = (dialogInterface, i) -> { - switch (i) { - case 0: - NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item), false); - break; - case 1: - NavigationHelper.enqueueOnPopupPlayer(context, new SinglePlayQueue(item), false); - break; - case 2: - NavigationHelper.playOnBackgroundPlayer(context, new SinglePlayQueue(item), true); - break; - case 3: - NavigationHelper.playOnPopupPlayer(context, new SinglePlayQueue(item), true); - break; - case 4: - if (getFragmentManager() != null) { - PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) - .show(getFragmentManager(), TAG); - } - break; - case 5: - ShareUtils.shareUrl(context, item.getName(), item.getUrl()); - break; - default: - break; + if (i == 0) { + NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item), false); + + } else if (i == (isAudioStream ? -1 : 1)) { // disabled with audio streams + NavigationHelper.enqueueOnPopupPlayer(context, new SinglePlayQueue(item), false); + + } else if (i == (isAudioStream ? 1 : 2)) { + NavigationHelper.playOnBackgroundPlayer(context, new SinglePlayQueue(item), true); + + } else if (i == (isAudioStream ? -1 : 3)) { // disabled with audio streams + NavigationHelper.playOnPopupPlayer(context, new SinglePlayQueue(item), true); + + } else if (i == (isAudioStream ? 2 : 4)) { + if (getFragmentManager() != null) { + PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) + .show(getFragmentManager(), TAG); + } + + } else if (i == (isAudioStream ? 3 : 5)) { + ShareUtils.shareUrl(context, item.getName(), item.getUrl()); + } }; diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 9a815461d..67d00a3b1 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -25,6 +25,7 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.database.LocalItem; import org.schabi.newpipe.database.stream.StreamStatisticsEntry; import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.local.BaseLocalListFragment; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; @@ -362,47 +363,59 @@ public class StatisticsPlaylistFragment final Context context = getContext(); final Activity activity = getActivity(); if (context == null || context.getResources() == null || activity == null) return; - final StreamInfoItem infoItem = item.toStreamInfoItem(); - final String[] commands = new String[]{ - context.getResources().getString(R.string.enqueue_on_background), - context.getResources().getString(R.string.enqueue_on_popup), - context.getResources().getString(R.string.start_here_on_background), - context.getResources().getString(R.string.start_here_on_popup), - context.getResources().getString(R.string.delete), - context.getResources().getString(R.string.append_playlist), - context.getResources().getString(R.string.share) - }; + final StreamInfoItem infoItem = item.toStreamInfoItem(); + boolean isAudioStream = (infoItem.getStreamType() == StreamType.AUDIO_STREAM); + + final String[] commands; + if (isAudioStream) { + commands = new String[]{ + context.getResources().getString(R.string.enqueue_on_background), + context.getResources().getString(R.string.start_here_on_background), + context.getResources().getString(R.string.delete), + context.getResources().getString(R.string.append_playlist), + context.getResources().getString(R.string.share) + }; + } else { + commands = new String[]{ + context.getResources().getString(R.string.enqueue_on_background), + context.getResources().getString(R.string.enqueue_on_popup), + context.getResources().getString(R.string.start_here_on_background), + context.getResources().getString(R.string.start_here_on_popup), + context.getResources().getString(R.string.delete), + context.getResources().getString(R.string.append_playlist), + context.getResources().getString(R.string.share) + }; + } + final DialogInterface.OnClickListener actions = (dialogInterface, i) -> { final int index = Math.max(itemListAdapter.getItemsList().indexOf(item), 0); - switch (i) { - case 0: - NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(infoItem), false); - break; - case 1: - NavigationHelper.enqueueOnPopupPlayer(context, new SinglePlayQueue(infoItem), false); - break; - case 2: - NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index), true); - break; - case 3: - NavigationHelper.playOnPopupPlayer(context, getPlayQueue(index), true); - break; - case 4: - deleteEntry(index); - break; - case 5: - if (getFragmentManager() != null) { - PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(infoItem)) - .show(getFragmentManager(), TAG); - } - break; - case 6: - ShareUtils.shareUrl(context, infoItem.getName(), infoItem.getUrl()); - break; - default: - break; + + if (i == 0) { + NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(infoItem), false); + + } else if (i == (isAudioStream ? -1 : 1)) { // disabled with audio streams + NavigationHelper.enqueueOnPopupPlayer(context, new SinglePlayQueue(infoItem), false); + + } else if (i == (isAudioStream ? 1 : 2)) { + NavigationHelper.playOnBackgroundPlayer(context, new SinglePlayQueue(infoItem), true); + + } else if (i == (isAudioStream ? -1 : 3)) { // disabled with audio streams + NavigationHelper.playOnPopupPlayer(context, new SinglePlayQueue(infoItem), true); + + } else if (i == (isAudioStream ? 2 : 4)) { + deleteEntry(index); + + } else if (i == (isAudioStream ? 3 : 5)) { + if (getFragmentManager() != null) { + PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(infoItem)) + .show(getFragmentManager(), TAG); + } + + } else if (i == (isAudioStream ? 4 : 6)) { + ShareUtils.shareUrl(context, infoItem.getName(), infoItem.getUrl()); + } }; diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 0de97033e..ef2a0d8d5 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -26,6 +26,7 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.database.LocalItem; import org.schabi.newpipe.database.playlist.PlaylistStreamEntry; import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.local.BaseLocalListFragment; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; @@ -518,50 +519,62 @@ public class LocalPlaylistFragment extends BaseLocalListFragment { final int index = Math.max(itemListAdapter.getItemsList().indexOf(item), 0); - switch (i) { - case 0: - NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(infoItem), false); - break; - case 1: - NavigationHelper.enqueueOnPopupPlayer(context, new SinglePlayQueue(infoItem), false); - break; - case 2: - NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index), true); - break; - case 3: - NavigationHelper.playOnPopupPlayer(context, getPlayQueue(index), true); - break; - case 4: - changeThumbnailUrl(item.thumbnailUrl); - break; - case 5: - deleteItem(item); - break; - case 6: - if (getFragmentManager() != null) { - PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(infoItem)) - .show(getFragmentManager(), TAG); - } - break; - case 7: - ShareUtils.shareUrl(context, infoItem.getName(), infoItem.getUrl()); - break; - default: - break; + + if (i == 0) { + NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(infoItem), false); + + } else if (i == (isAudioStream ? -1 : 1)) { // disabled with audio streams + NavigationHelper.enqueueOnPopupPlayer(context, new SinglePlayQueue(infoItem), false); + + } else if (i == (isAudioStream ? 1 : 2)) { + NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index), true); + + } else if (i == (isAudioStream ? -1 : 3)) { // disabled with audio streams + NavigationHelper.playOnPopupPlayer(context, getPlayQueue(index), true); + + } else if (i == (isAudioStream ? 2 : 4)) { + changeThumbnailUrl(item.thumbnailUrl); + + } else if (i == (isAudioStream ? 3 : 5)) { + deleteItem(item); + + } else if (i == (isAudioStream ? 4 : 6)) { + if (getFragmentManager() != null) { + PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(infoItem)) + .show(getFragmentManager(), TAG); + } + + } else if (i == (isAudioStream ? 5 : 7)) { + ShareUtils.shareUrl(context, infoItem.getName(), infoItem.getUrl()); + } }; From 759e9846ad1a46b87a7f7e0307ac516c3210fd36 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 25 Jul 2019 00:44:12 +0200 Subject: [PATCH 09/13] Remove ugly if-else-cascade in Common actions and labels are now in a unique enum: StreamDialogEntry If an action is not common to every long-press menu (e.g. delete) a custom action has to be provided using e.g. delete.setAction(...) --- .../fragments/list/BaseListFragment.java | 67 +++++--------- .../history/StatisticsPlaylistFragment.java | 71 ++++---------- .../local/playlist/LocalPlaylistFragment.java | 80 +++++----------- .../newpipe/util/StreamDialogEntry.java | 92 +++++++++++++++++++ 4 files changed, 159 insertions(+), 151 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index de4c17c3d..2291528c3 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -9,6 +9,7 @@ import android.content.res.Resources; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.annotation.NonNull; +import android.support.v4.app.Fragment; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.GridLayoutManager; @@ -37,10 +38,14 @@ import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.StateSaver; +import org.schabi.newpipe.util.StreamDialogEntry; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Queue; +import java.util.function.DoubleBinaryOperator; import static org.schabi.newpipe.util.AnimationUtils.animateView; @@ -259,58 +264,32 @@ public abstract class BaseListFragment extends BaseStateFragment implem } } + + + protected void showStreamDialog(final StreamInfoItem item) { final Context context = getContext(); final Activity activity = getActivity(); if (context == null || context.getResources() == null || activity == null) return; - boolean isAudioStream = (item.getStreamType() == StreamType.AUDIO_STREAM); - - final String[] commands; - if (isAudioStream) { - commands = new String[]{ - context.getResources().getString(R.string.enqueue_on_background), - context.getResources().getString(R.string.start_here_on_background), - context.getResources().getString(R.string.append_playlist), - context.getResources().getString(R.string.share) - }; + if (item.getStreamType() == StreamType.AUDIO_STREAM) { + StreamDialogEntry.setEnabledEntries( + StreamDialogEntry.enqueue_on_background, + StreamDialogEntry.start_here_on_background, + StreamDialogEntry.append_playlist, + StreamDialogEntry.share); } else { - commands = new String[]{ - context.getResources().getString(R.string.enqueue_on_background), - context.getResources().getString(R.string.enqueue_on_popup), - context.getResources().getString(R.string.start_here_on_background), - context.getResources().getString(R.string.start_here_on_popup), - context.getResources().getString(R.string.append_playlist), - context.getResources().getString(R.string.share) - }; + StreamDialogEntry.setEnabledEntries( + StreamDialogEntry.enqueue_on_background, + StreamDialogEntry.enqueue_on_popup, + StreamDialogEntry.start_here_on_background, + StreamDialogEntry.start_here_on_popup, + StreamDialogEntry.append_playlist, + StreamDialogEntry.share); } - final DialogInterface.OnClickListener actions = (dialogInterface, i) -> { - if (i == 0) { - NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item), false); - - } else if (i == (isAudioStream ? -1 : 1)) { // disabled with audio streams - NavigationHelper.enqueueOnPopupPlayer(context, new SinglePlayQueue(item), false); - - } else if (i == (isAudioStream ? 1 : 2)) { - NavigationHelper.playOnBackgroundPlayer(context, new SinglePlayQueue(item), true); - - } else if (i == (isAudioStream ? -1 : 3)) { // disabled with audio streams - NavigationHelper.playOnPopupPlayer(context, new SinglePlayQueue(item), true); - - } else if (i == (isAudioStream ? 2 : 4)) { - if (getFragmentManager() != null) { - PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) - .show(getFragmentManager(), TAG); - } - - } else if (i == (isAudioStream ? 3 : 5)) { - ShareUtils.shareUrl(context, item.getName(), item.getUrl()); - - } - }; - - new InfoItemDialog(activity, item, commands, actions).show(); + new InfoItemDialog(activity, item, StreamDialogEntry.getCommands(context), (dialog, which) -> + StreamDialogEntry.clickOn(which, this, item)).show(); } /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 67d00a3b1..7ebe2bbfc 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -37,6 +37,7 @@ import org.schabi.newpipe.settings.SettingsActivity; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; import org.schabi.newpipe.util.ShareUtils; +import org.schabi.newpipe.util.StreamDialogEntry; import org.schabi.newpipe.util.ThemeHelper; import java.util.ArrayList; @@ -363,63 +364,31 @@ public class StatisticsPlaylistFragment final Context context = getContext(); final Activity activity = getActivity(); if (context == null || context.getResources() == null || activity == null) return; - final StreamInfoItem infoItem = item.toStreamInfoItem(); - boolean isAudioStream = (infoItem.getStreamType() == StreamType.AUDIO_STREAM); - final String[] commands; - if (isAudioStream) { - commands = new String[]{ - context.getResources().getString(R.string.enqueue_on_background), - context.getResources().getString(R.string.start_here_on_background), - context.getResources().getString(R.string.delete), - context.getResources().getString(R.string.append_playlist), - context.getResources().getString(R.string.share) - }; + if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) { + StreamDialogEntry.setEnabledEntries( + StreamDialogEntry.enqueue_on_background, + StreamDialogEntry.start_here_on_background, + StreamDialogEntry.delete, + StreamDialogEntry.append_playlist, + StreamDialogEntry.share); } else { - commands = new String[]{ - context.getResources().getString(R.string.enqueue_on_background), - context.getResources().getString(R.string.enqueue_on_popup), - context.getResources().getString(R.string.start_here_on_background), - context.getResources().getString(R.string.start_here_on_popup), - context.getResources().getString(R.string.delete), - context.getResources().getString(R.string.append_playlist), - context.getResources().getString(R.string.share) - }; + StreamDialogEntry.setEnabledEntries( + StreamDialogEntry.enqueue_on_background, + StreamDialogEntry.enqueue_on_popup, + StreamDialogEntry.start_here_on_background, + StreamDialogEntry.start_here_on_popup, + StreamDialogEntry.delete, + StreamDialogEntry.append_playlist, + StreamDialogEntry.share); } + StreamDialogEntry.delete.setAction((fragment, infoItemDuplicate) -> + deleteEntry(Math.max(itemListAdapter.getItemsList().indexOf(item), 0))); - final DialogInterface.OnClickListener actions = (dialogInterface, i) -> { - final int index = Math.max(itemListAdapter.getItemsList().indexOf(item), 0); - - if (i == 0) { - NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(infoItem), false); - - } else if (i == (isAudioStream ? -1 : 1)) { // disabled with audio streams - NavigationHelper.enqueueOnPopupPlayer(context, new SinglePlayQueue(infoItem), false); - - } else if (i == (isAudioStream ? 1 : 2)) { - NavigationHelper.playOnBackgroundPlayer(context, new SinglePlayQueue(infoItem), true); - - } else if (i == (isAudioStream ? -1 : 3)) { // disabled with audio streams - NavigationHelper.playOnPopupPlayer(context, new SinglePlayQueue(infoItem), true); - - } else if (i == (isAudioStream ? 2 : 4)) { - deleteEntry(index); - - } else if (i == (isAudioStream ? 3 : 5)) { - if (getFragmentManager() != null) { - PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(infoItem)) - .show(getFragmentManager(), TAG); - } - - } else if (i == (isAudioStream ? 4 : 6)) { - ShareUtils.shareUrl(context, infoItem.getName(), infoItem.getUrl()); - - } - }; - - new InfoItemDialog(activity, infoItem, commands, actions).show(); + new InfoItemDialog(activity, infoItem, StreamDialogEntry.getCommands(context), (dialog, which) -> + StreamDialogEntry.clickOn(which, this, infoItem)).show(); } private void deleteEntry(final int index) { diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index ef2a0d8d5..db802272b 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -37,6 +37,7 @@ import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; import org.schabi.newpipe.util.ShareUtils; +import org.schabi.newpipe.util.StreamDialogEntry; import java.util.ArrayList; import java.util.Collections; @@ -517,68 +518,35 @@ public class LocalPlaylistFragment extends BaseLocalListFragment changeThumbnailUrl(item.thumbnailUrl)); + StreamDialogEntry.delete.setAction( + (fragment, infoItemDuplicate) -> deleteItem(item)); - final DialogInterface.OnClickListener actions = (dialogInterface, i) -> { - final int index = Math.max(itemListAdapter.getItemsList().indexOf(item), 0); - - if (i == 0) { - NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(infoItem), false); - - } else if (i == (isAudioStream ? -1 : 1)) { // disabled with audio streams - NavigationHelper.enqueueOnPopupPlayer(context, new SinglePlayQueue(infoItem), false); - - } else if (i == (isAudioStream ? 1 : 2)) { - NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index), true); - - } else if (i == (isAudioStream ? -1 : 3)) { // disabled with audio streams - NavigationHelper.playOnPopupPlayer(context, getPlayQueue(index), true); - - } else if (i == (isAudioStream ? 2 : 4)) { - changeThumbnailUrl(item.thumbnailUrl); - - } else if (i == (isAudioStream ? 3 : 5)) { - deleteItem(item); - - } else if (i == (isAudioStream ? 4 : 6)) { - if (getFragmentManager() != null) { - PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(infoItem)) - .show(getFragmentManager(), TAG); - } - - } else if (i == (isAudioStream ? 5 : 7)) { - ShareUtils.shareUrl(context, infoItem.getName(), infoItem.getUrl()); - - } - }; - - new InfoItemDialog(activity, infoItem, commands, actions).show(); + new InfoItemDialog(activity, infoItem, StreamDialogEntry.getCommands(context), (dialog, which) -> + StreamDialogEntry.clickOn(which, this, infoItem)).show(); } private void setInitialData(long playlistId, String name) { diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java new file mode 100644 index 000000000..aed112983 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -0,0 +1,92 @@ +package org.schabi.newpipe.util; + +import android.content.Context; +import android.support.v4.app.Fragment; + +import org.schabi.newpipe.R; +import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; +import org.schabi.newpipe.player.playqueue.SinglePlayQueue; + +import java.util.Collections; + +public enum StreamDialogEntry { + ////////////////////////////// + // enum values with actions // + ////////////////////////////// + + enqueue_on_background(R.string.enqueue_on_background, (fragment, item) -> + NavigationHelper.enqueueOnBackgroundPlayer(fragment.getContext(), new SinglePlayQueue(item), false)), + + enqueue_on_popup(R.string.enqueue_on_popup, (fragment, item) -> + NavigationHelper.enqueueOnPopupPlayer(fragment.getContext(), new SinglePlayQueue(item), false)), + + start_here_on_background(R.string.start_here_on_background, (fragment, item) -> + NavigationHelper.playOnBackgroundPlayer(fragment.getContext(), new SinglePlayQueue(item), true)), + + start_here_on_popup(R.string.start_here_on_popup, (fragment, item) -> + NavigationHelper.playOnPopupPlayer(fragment.getContext(), new SinglePlayQueue(item), true)), + + set_as_playlist_thumbnail(R.string.set_as_playlist_thumbnail, (fragment, item) -> {}), // has to be set manually + + delete(R.string.delete, (fragment, item) -> {}), // has to be set manually + + append_playlist(R.string.append_playlist, (fragment, item) -> { + if (fragment.getFragmentManager() != null) { + PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) + .show(fragment.getFragmentManager(), "StreamDialogEntry@append_playlist"); + }}), + + share(R.string.share, (fragment, item) -> + ShareUtils.shareUrl(fragment.getContext(), item.getName(), item.getUrl())); + + + /////////////// + // variables // + /////////////// + + public interface StreamDialogEntryAction { + void onClick(Fragment fragment, final StreamInfoItem infoItem); + } + + private final int resource; + private StreamDialogEntryAction action; + + private static StreamDialogEntry[] enabledEntries; + + + /////////////////////////////////////////////////////// + // non-static methods to initialize and edit entries // + /////////////////////////////////////////////////////// + + StreamDialogEntry(final int resource, StreamDialogEntryAction action) { + this.resource = resource; + this.action = action; + } + + public void setAction(StreamDialogEntryAction action) { + this.action = action; + } + + + //////////////////////////////////////////////// + // static methods that act on enabled entries // + //////////////////////////////////////////////// + + public static void setEnabledEntries(StreamDialogEntry... entries) { + enabledEntries = entries; + } + + public static String[] getCommands(Context context) { + String[] commands = new String[enabledEntries.length]; + for (int i = 0; i != enabledEntries.length; ++i) { + commands[i] = context.getResources().getString(enabledEntries[i].resource); + } + + return commands; + } + + public static void clickOn(int which, Fragment fragment, StreamInfoItem infoItem) { + enabledEntries[which].action.onClick(fragment, infoItem); + } +} From 9df27f43de590bf1dcd6e2081925d991b2aa0477 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 25 Jul 2019 00:53:13 +0200 Subject: [PATCH 10/13] Ensure default actions cannot be overwritten permanently in StreamDialogEntry --- .../history/StatisticsPlaylistFragment.java | 5 +-- .../local/playlist/LocalPlaylistFragment.java | 7 ++--- .../newpipe/util/StreamDialogEntry.java | 31 ++++++++++++++----- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 7ebe2bbfc..61f1c6418 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -2,7 +2,6 @@ package org.schabi.newpipe.local.history; import android.app.Activity; import android.content.Context; -import android.content.DialogInterface; import android.os.Bundle; import android.os.Parcelable; import android.support.annotation.NonNull; @@ -28,7 +27,6 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.local.BaseLocalListFragment; -import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.ErrorActivity; @@ -36,7 +34,6 @@ import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.settings.SettingsActivity; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; -import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.StreamDialogEntry; import org.schabi.newpipe.util.ThemeHelper; @@ -384,7 +381,7 @@ public class StatisticsPlaylistFragment StreamDialogEntry.share); } - StreamDialogEntry.delete.setAction((fragment, infoItemDuplicate) -> + StreamDialogEntry.delete.setCustomAction((fragment, infoItemDuplicate) -> deleteEntry(Math.max(itemListAdapter.getItemsList().indexOf(item), 0))); new InfoItemDialog(activity, infoItem, StreamDialogEntry.getCommands(context), (dialog, which) -> diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index db802272b..c0d8654b6 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -2,7 +2,6 @@ package org.schabi.newpipe.local.playlist; import android.app.Activity; import android.content.Context; -import android.content.DialogInterface; import android.os.Bundle; import android.os.Parcelable; import android.support.annotation.NonNull; @@ -29,14 +28,12 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.local.BaseLocalListFragment; import org.schabi.newpipe.info_list.InfoItemDialog; -import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; -import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.StreamDialogEntry; import java.util.ArrayList; @@ -540,9 +537,9 @@ public class LocalPlaylistFragment extends BaseLocalListFragment changeThumbnailUrl(item.thumbnailUrl)); - StreamDialogEntry.delete.setAction( + StreamDialogEntry.delete.setCustomAction( (fragment, infoItemDuplicate) -> deleteItem(item)); new InfoItemDialog(activity, infoItem, StreamDialogEntry.getCommands(context), (dialog, which) -> diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index aed112983..1b503dbbb 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -11,9 +11,9 @@ import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import java.util.Collections; public enum StreamDialogEntry { - ////////////////////////////// - // enum values with actions // - ////////////////////////////// + ////////////////////////////////////// + // enum values with DEFAULT actions // + ////////////////////////////////////// enqueue_on_background(R.string.enqueue_on_background, (fragment, item) -> NavigationHelper.enqueueOnBackgroundPlayer(fragment.getContext(), new SinglePlayQueue(item), false)), @@ -50,7 +50,8 @@ public enum StreamDialogEntry { } private final int resource; - private StreamDialogEntryAction action; + private final StreamDialogEntryAction action; + private StreamDialogEntryAction customAction; private static StreamDialogEntry[] enabledEntries; @@ -62,10 +63,14 @@ public enum StreamDialogEntry { StreamDialogEntry(final int resource, StreamDialogEntryAction action) { this.resource = resource; this.action = action; + this.customAction = null; } - public void setAction(StreamDialogEntryAction action) { - this.action = action; + /** + * Can be used after {@link #setEnabledEntries(StreamDialogEntry...)} has been called + */ + public void setCustomAction(StreamDialogEntryAction action) { + this.customAction = action; } @@ -73,7 +78,15 @@ public enum StreamDialogEntry { // static methods that act on enabled entries // //////////////////////////////////////////////// + /** + * To be called before using {@link #setCustomAction(StreamDialogEntryAction)} + */ public static void setEnabledEntries(StreamDialogEntry... entries) { + // cleanup from last time StreamDialogEntry was used + for (StreamDialogEntry streamDialogEntry : values()) { + streamDialogEntry.customAction = null; + } + enabledEntries = entries; } @@ -87,6 +100,10 @@ public enum StreamDialogEntry { } public static void clickOn(int which, Fragment fragment, StreamInfoItem infoItem) { - enabledEntries[which].action.onClick(fragment, infoItem); + if (enabledEntries[which].customAction == null) { + enabledEntries[which].action.onClick(fragment, infoItem); + } else { + enabledEntries[which].customAction.onClick(fragment, infoItem); + } } } From 25fbbfaf9448e7b5943a227439ba0a4720e21f60 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 25 Jul 2019 01:07:51 +0200 Subject: [PATCH 11/13] Rename action to defaultAction in StreamDialogEntry To improve readability --- .../java/org/schabi/newpipe/util/StreamDialogEntry.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index 1b503dbbb..4ccd66f0d 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -50,7 +50,7 @@ public enum StreamDialogEntry { } private final int resource; - private final StreamDialogEntryAction action; + private final StreamDialogEntryAction defaultAction; private StreamDialogEntryAction customAction; private static StreamDialogEntry[] enabledEntries; @@ -60,9 +60,9 @@ public enum StreamDialogEntry { // non-static methods to initialize and edit entries // /////////////////////////////////////////////////////// - StreamDialogEntry(final int resource, StreamDialogEntryAction action) { + StreamDialogEntry(final int resource, StreamDialogEntryAction defaultAction) { this.resource = resource; - this.action = action; + this.defaultAction = defaultAction; this.customAction = null; } @@ -101,7 +101,7 @@ public enum StreamDialogEntry { public static void clickOn(int which, Fragment fragment, StreamInfoItem infoItem) { if (enabledEntries[which].customAction == null) { - enabledEntries[which].action.onClick(fragment, infoItem); + enabledEntries[which].defaultAction.onClick(fragment, infoItem); } else { enabledEntries[which].customAction.onClick(fragment, infoItem); } From d076fe72cdce90e4a3a1ffd663a23529f384f762 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 25 Jul 2019 11:47:38 +0200 Subject: [PATCH 12/13] Optimize imports in edited files --- .../newpipe/fragments/detail/VideoDetailFragment.java | 3 --- .../schabi/newpipe/fragments/list/BaseListFragment.java | 9 --------- .../newpipe/fragments/list/channel/ChannelFragment.java | 2 -- .../newpipe/local/playlist/LocalPlaylistFragment.java | 2 +- 4 files changed, 1 insertion(+), 15 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 3719264c1..f62cda2dd 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -60,7 +60,6 @@ import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExt import org.schabi.newpipe.extractor.stream.AudioStream; import org.schabi.newpipe.extractor.stream.Stream; import org.schabi.newpipe.extractor.stream.StreamInfo; -import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.fragments.BackPressable; @@ -68,7 +67,6 @@ import org.schabi.newpipe.fragments.BaseStateFragment; import org.schabi.newpipe.fragments.EmptyFragment; import org.schabi.newpipe.fragments.list.comments.CommentsFragment; import org.schabi.newpipe.fragments.list.videos.RelatedVideosFragment; -import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.local.history.HistoryRecordManager; import org.schabi.newpipe.player.MainVideoPlayer; @@ -93,7 +91,6 @@ import org.schabi.newpipe.views.AnimatedProgressBar; import java.io.Serializable; import java.util.Collection; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.concurrent.TimeUnit; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index 2291528c3..279b396df 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -2,14 +2,12 @@ package org.schabi.newpipe.fragments.list; import android.app.Activity; import android.content.Context; -import android.content.DialogInterface; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.GridLayoutManager; @@ -31,21 +29,14 @@ import org.schabi.newpipe.fragments.BaseStateFragment; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.info_list.InfoListAdapter; -import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; -import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; -import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.StateSaver; import org.schabi.newpipe.util.StreamDialogEntry; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Queue; -import java.util.function.DoubleBinaryOperator; import static org.schabi.newpipe.util.AnimationUtils.animateView; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index ac491ee9b..dd7916314 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -1,8 +1,6 @@ package org.schabi.newpipe.fragments.list.channel; -import android.app.Activity; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index c0d8654b6..640174ab7 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -26,8 +26,8 @@ import org.schabi.newpipe.database.LocalItem; import org.schabi.newpipe.database.playlist.PlaylistStreamEntry; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamType; -import org.schabi.newpipe.local.BaseLocalListFragment; import org.schabi.newpipe.info_list.InfoItemDialog; +import org.schabi.newpipe.local.BaseLocalListFragment; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.report.UserAction; From 7c9ef58acd0971ef47c78f4d3247d388991044bc Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 25 Jul 2019 12:32:56 +0200 Subject: [PATCH 13/13] Fix crash when closing a not-yet-loaded popup. --- .../main/java/org/schabi/newpipe/player/BasePlayer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index 11434b29d..46e7c1fdc 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -288,8 +288,11 @@ public abstract class BasePlayer implements if (item != null && item.getRecoveryPosition() == PlayQueueItem.RECOVERY_UNSET && isPlaybackResumeEnabled()) { final Disposable stateLoader = recordManager.loadStreamState(item) .observeOn(AndroidSchedulers.mainThread()) - .doFinally(() -> initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, - /*playOnInit=*/true)) + .doFinally(() -> { + if (simpleExoPlayer == null) return; // doFinally called while closing + initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, + /*playOnInit=*/true); + }) .subscribe( state -> queue.setRecovery(queue.getIndex(), state.getProgressTime()), error -> { @@ -331,6 +334,7 @@ public abstract class BasePlayer implements simpleExoPlayer.removeListener(this); simpleExoPlayer.stop(); simpleExoPlayer.release(); + simpleExoPlayer = null; } if (isProgressLoopRunning()) stopProgressLoop(); if (playQueue != null) playQueue.dispose();