Call history listener for Kodi (closes #798)

If Kore (the Kodi App) was sucessfully started the history listener is
invoked.
This commit is contained in:
Coffeemakr 2017-10-30 21:31:59 +01:00
parent 7340bc05b4
commit 6f18dd26a2
No known key found for this signature in database
GPG Key ID: 3F35676D8FF6E743
4 changed files with 19 additions and 6 deletions

View File

@ -27,6 +27,7 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
@ -309,7 +310,7 @@ public class MainActivity extends AppCompatActivity implements HistoryListener {
} }
@Override @Override
public void onVideoPlayed(StreamInfo streamInfo, VideoStream videoStream) { public void onVideoPlayed(StreamInfo streamInfo, @Nullable VideoStream videoStream) {
addWatchHistoryEntry(streamInfo); addWatchHistoryEntry(streamInfo);
} }

View File

@ -560,7 +560,10 @@ public class VideoDetailFragment extends BaseStateFragment<StreamInfo> implement
@Override @Override
public void onActionSelected(int selectedStreamId) { public void onActionSelected(int selectedStreamId) {
try { 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) { } catch (Exception e) {
if(DEBUG) Log.i(TAG, "Failed to start kore", e); if(DEBUG) Log.i(TAG, "Failed to start kore", e);
showInstallKoreDialog(activity); showInstallKoreDialog(activity);

View File

@ -1,5 +1,7 @@
package org.schabi.newpipe.history; package org.schabi.newpipe.history;
import android.support.annotation.Nullable;
import org.schabi.newpipe.extractor.stream.AudioStream; import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.extractor.stream.VideoStream;
@ -9,9 +11,10 @@ public interface HistoryListener {
* Called when a video is played * Called when a video is played
* *
* @param streamInfo the stream info * @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 * Called when the audio is played in the background

View File

@ -342,10 +342,16 @@ public class NavigationHelper {
/** /**
* Start Kore app to show a video on Kodi * Start Kore app to show a video on Kodi
*
* For a list of supported urls see the
* <a href="https://github.com/xbmc/Kore/blob/master/app/src/main/AndroidManifest.xml">
* Kore source code
* </a>.
*
* @param context the context to use * @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 intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage(context.getString(R.string.kore_package)); intent.setPackage(context.getString(R.string.kore_package));
intent.setData(videoURL); intent.setData(videoURL);