From 83faf119a90ac1adb02d62fee2ec31d54f18e669 Mon Sep 17 00:00:00 2001 From: khimaros Date: Tue, 29 Dec 2020 18:17:36 -0800 Subject: [PATCH] add list item to play video on kodi closes: #5157 --- .../newpipe/fragments/list/BaseListFragment.java | 7 +++++++ .../fragments/list/playlist/PlaylistFragment.java | 8 ++++++++ .../local/history/StatisticsPlaylistFragment.java | 8 ++++++++ .../newpipe/local/playlist/LocalPlaylistFragment.java | 8 ++++++++ .../org/schabi/newpipe/util/StreamDialogEntry.java | 10 ++++++++++ 5 files changed, 41 insertions(+) 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 5252024c2..ecfaaf80e 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 @@ -31,6 +31,7 @@ import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.info_list.InfoListAdapter; import org.schabi.newpipe.player.helper.PlayerHolder; import org.schabi.newpipe.report.ErrorActivity; +import org.schabi.newpipe.util.KoreUtil; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; import org.schabi.newpipe.util.StateSaver; @@ -359,6 +360,12 @@ public abstract class BaseListFragment extends BaseStateFragment StreamDialogEntry.share )); } + final boolean enableKodiEntry = KoreUtil.isServiceSupportedByKore(item.getServiceId()) + && PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(context.getString(R.string.show_play_with_kodi_key), false); + if (enableKodiEntry) { + entries.add(StreamDialogEntry.play_on_kodi); + } StreamDialogEntry.setEnabledEntries(entries); new InfoItemDialog(activity, item, StreamDialogEntry.getCommands(context), 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 6fa7eb700..a4ccd9c78 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 @@ -17,6 +17,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.content.res.AppCompatResources; +import androidx.preference.PreferenceManager; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -42,6 +43,7 @@ import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.ImageDisplayConstants; +import org.schabi.newpipe.util.KoreUtil; import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ShareUtils; @@ -174,6 +176,12 @@ public class PlaylistFragment extends BaseListInfoFragment { StreamDialogEntry.share )); } + final boolean enableKodiEntry = KoreUtil.isServiceSupportedByKore(item.getServiceId()) + && PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(context.getString(R.string.show_play_with_kodi_key), false); + if (enableKodiEntry) { + entries.add(StreamDialogEntry.play_on_kodi); + } StreamDialogEntry.setEnabledEntries(entries); StreamDialogEntry.start_here_on_background.setCustomAction((fragment, infoItem) -> 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 9750d9820..59537f1a8 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 @@ -17,6 +17,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; +import androidx.preference.PreferenceManager; import com.google.android.material.snackbar.Snackbar; @@ -37,6 +38,7 @@ import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.ErrorInfo; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.settings.SettingsActivity; +import org.schabi.newpipe.util.KoreUtil; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; import org.schabi.newpipe.util.StreamDialogEntry; @@ -413,6 +415,12 @@ public class StatisticsPlaylistFragment StreamDialogEntry.share )); } + final boolean enableKodiEntry = KoreUtil.isServiceSupportedByKore(infoItem.getServiceId()) + && PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(context.getString(R.string.show_play_with_kodi_key), false); + if (enableKodiEntry) { + entries.add(StreamDialogEntry.play_on_kodi); + } StreamDialogEntry.setEnabledEntries(entries); StreamDialogEntry.start_here_on_background.setCustomAction((fragment, infoItemDuplicate) -> 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 a8974e018..c6314f557 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 @@ -20,6 +20,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; @@ -41,6 +42,7 @@ import org.schabi.newpipe.player.helper.PlayerHolder; 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.KoreUtil; import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; @@ -781,6 +783,12 @@ public class LocalPlaylistFragment extends BaseLocalListFragment 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 34ff637ad..d85f5ae57 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.util; import android.content.Context; +import android.net.Uri; import androidx.fragment.app.Fragment; @@ -70,6 +71,15 @@ public enum StreamDialogEntry { } }), + play_on_kodi(R.string.play_with_kodi_title, (fragment, item) -> { + final Uri videoUrl = Uri.parse(item.getUrl()); + try { + NavigationHelper.playWithKore(fragment.getContext(), videoUrl); + } catch (final Exception e) { + KoreUtil.showInstallKoreDialog(fragment.getActivity()); + } + }), + share(R.string.share, (fragment, item) -> ShareUtils.shareUrl(fragment.getContext(), item.getName(), item.getUrl()));