From 9ca6cfd6374159b50ccc4716bf8d3ba15891014d Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 6 May 2020 20:40:44 +0200 Subject: [PATCH 1/2] Fix Kodi button showing up in unsupported services --- .../newpipe/fragments/detail/VideoDetailFragment.java | 8 ++++---- app/src/main/java/org/schabi/newpipe/util/KoreUtil.java | 6 ++++++ 2 files changed, 10 insertions(+), 4 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 35352c013..ec1c655a0 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 @@ -632,9 +632,10 @@ public class VideoDetailFragment extends BaseStateFragment } private void updateMenuItemVisibility() { - // show kodi if set in settings + // show kodi button if it supports the current service and it is enabled in settings menu.findItem(R.id.action_play_with_kodi).setVisible( - PreferenceManager.getDefaultSharedPreferences(activity).getBoolean( + KoreUtil.isServiceSupportedByKore(serviceId) + && PreferenceManager.getDefaultSharedPreferences(activity).getBoolean( activity.getString(R.string.show_play_with_kodi_key), false)); } @@ -665,8 +666,7 @@ public class VideoDetailFragment extends BaseStateFragment return true; case R.id.action_play_with_kodi: try { - NavigationHelper.playWithKore(activity, Uri.parse( - url.replace("https", "http"))); + NavigationHelper.playWithKore(activity, Uri.parse(currentInfo.getUrl())); } catch (Exception e) { if (DEBUG) { Log.i(TAG, "Failed to start kore", e); diff --git a/app/src/main/java/org/schabi/newpipe/util/KoreUtil.java b/app/src/main/java/org/schabi/newpipe/util/KoreUtil.java index 85cf82db1..983fe689b 100644 --- a/app/src/main/java/org/schabi/newpipe/util/KoreUtil.java +++ b/app/src/main/java/org/schabi/newpipe/util/KoreUtil.java @@ -7,10 +7,16 @@ import android.content.DialogInterface; import androidx.appcompat.app.AlertDialog; import org.schabi.newpipe.R; +import org.schabi.newpipe.extractor.ServiceList; public final class KoreUtil { private KoreUtil() { } + public static boolean isServiceSupportedByKore(final int serviceId) { + return (serviceId == ServiceList.YouTube.getServiceId() + || serviceId == ServiceList.SoundCloud.getServiceId()); + } + public static void showInstallKoreDialog(final Context context) { final AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage(R.string.kore_not_found) From 5c711322d416d0c6ccda53873f82d2379fd99771 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 7 May 2020 09:08:52 +0200 Subject: [PATCH 2/2] In player hide kodi button if service unsupported --- .../schabi/newpipe/player/MainVideoPlayer.java | 15 +++++++++------ .../layout-large-land/activity_main_player.xml | 3 ++- app/src/main/res/layout/activity_main_player.xml | 3 ++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index 570819433..37a07fb20 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -593,9 +593,6 @@ public final class MainVideoPlayer extends AppCompatActivity titleTextView.setSelected(true); channelTextView.setSelected(true); - boolean showKodiButton = PreferenceManager.getDefaultSharedPreferences(this.context) - .getBoolean(this.context.getString(R.string.show_play_with_kodi_key), false); - kodiButton.setVisibility(showKodiButton ? View.VISIBLE : View.GONE); getRootView().setKeepScreenOn(true); } @@ -712,6 +709,13 @@ public final class MainVideoPlayer extends AppCompatActivity protected void onMetadataChanged(@NonNull final MediaSourceTag tag) { super.onMetadataChanged(tag); + // show kodi button if it supports the current service and it is enabled in settings + final boolean showKodiButton = + KoreUtil.isServiceSupportedByKore(tag.getMetadata().getServiceId()) + && PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(context.getString(R.string.show_play_with_kodi_key), false); + kodiButton.setVisibility(showKodiButton ? View.VISIBLE : View.GONE); + titleTextView.setText(tag.getMetadata().getName()); channelTextView.setText(tag.getMetadata().getUploaderName()); } @@ -725,13 +729,12 @@ public final class MainVideoPlayer extends AppCompatActivity public void onKodiShare() { onPause(); try { - NavigationHelper.playWithKore(this.context, - Uri.parse(playerImpl.getVideoUrl().replace("https", "http"))); + NavigationHelper.playWithKore(context, Uri.parse(playerImpl.getVideoUrl())); } catch (Exception e) { if (DEBUG) { Log.i(TAG, "Failed to start kore", e); } - KoreUtil.showInstallKoreDialog(this.context); + KoreUtil.showInstallKoreDialog(context); } } diff --git a/app/src/main/res/layout-large-land/activity_main_player.xml b/app/src/main/res/layout-large-land/activity_main_player.xml index 8dab200e8..13ca79da1 100644 --- a/app/src/main/res/layout-large-land/activity_main_player.xml +++ b/app/src/main/res/layout-large-land/activity_main_player.xml @@ -325,8 +325,9 @@ android:src="@drawable/ic_cast_white_24dp" android:background="?attr/selectableItemBackground" android:contentDescription="@string/play_with_kodi_title" + android:visibility="gone" tools:ignore="RtlHardcoded" - android:visibility="visible"/> + tools:visibility="visible"/> + tools:visibility="visible"/>