From 6f18dd26a2cf5fd7d8a9fa4ae27e93906a541dde Mon Sep 17 00:00:00 2001 From: Coffeemakr Date: Mon, 30 Oct 2017 21:31:59 +0100 Subject: [PATCH] Call history listener for Kodi (closes #798) If Kore (the Kodi App) was sucessfully started the history listener is invoked. --- app/src/main/java/org/schabi/newpipe/MainActivity.java | 3 ++- .../newpipe/fragments/detail/VideoDetailFragment.java | 5 ++++- .../org/schabi/newpipe/history/HistoryListener.java | 7 +++++-- .../java/org/schabi/newpipe/util/NavigationHelper.java | 10 ++++++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 03b856d31..056db3500 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -27,6 +27,7 @@ import android.os.Handler; import android.os.Looper; import android.preference.PreferenceManager; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; @@ -309,7 +310,7 @@ public class MainActivity extends AppCompatActivity implements HistoryListener { } @Override - public void onVideoPlayed(StreamInfo streamInfo, VideoStream videoStream) { + public void onVideoPlayed(StreamInfo streamInfo, @Nullable VideoStream videoStream) { addWatchHistoryEntry(streamInfo); } 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 3e4165875..c5b743193 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 @@ -560,7 +560,10 @@ public class VideoDetailFragment extends BaseStateFragment implement @Override public void onActionSelected(int selectedStreamId) { try { - NavigationHelper.startKore(activity, Uri.parse(info.url.replace("https", "http"))); + NavigationHelper.playWithKore(activity, Uri.parse(info.url.replace("https", "http"))); + if(activity instanceof HistoryListener) { + ((HistoryListener) activity).onVideoPlayed(info, null); + } } catch (Exception e) { if(DEBUG) Log.i(TAG, "Failed to start kore", e); showInstallKoreDialog(activity); diff --git a/app/src/main/java/org/schabi/newpipe/history/HistoryListener.java b/app/src/main/java/org/schabi/newpipe/history/HistoryListener.java index 8b6c91328..5c729b022 100644 --- a/app/src/main/java/org/schabi/newpipe/history/HistoryListener.java +++ b/app/src/main/java/org/schabi/newpipe/history/HistoryListener.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.history; +import android.support.annotation.Nullable; + import org.schabi.newpipe.extractor.stream.AudioStream; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.VideoStream; @@ -9,9 +11,10 @@ public interface HistoryListener { * Called when a video is played * * @param streamInfo the stream info - * @param videoStream the video stream that is played + * @param videoStream the video stream that is played. Can be null if it's not sure what + * quality was viewed (e.g. with Kodi). */ - void onVideoPlayed(StreamInfo streamInfo, VideoStream videoStream); + void onVideoPlayed(StreamInfo streamInfo, @Nullable VideoStream videoStream); /** * Called when the audio is played in the background diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index 417c3bbdf..e58d9996a 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -342,10 +342,16 @@ public class NavigationHelper { /** * Start Kore app to show a video on Kodi + * + * For a list of supported urls see the + * + * Kore source code + * . + * * @param context the context to use - * @param videoURL the url to the video stream + * @param videoURL the url to the video */ - public static void startKore(Context context, Uri videoURL) { + public static void playWithKore(Context context, Uri videoURL) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setPackage(context.getString(R.string.kore_package)); intent.setData(videoURL);