1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-17 14:20:21 +01:00

Small refactoring for Kore and Kodi

* Improve installation procedure
This commit is contained in:
Coffeemakr 2017-10-30 21:15:06 +01:00
parent 59b3362715
commit 7340bc05b4
No known key found for this signature in database
GPG Key ID: 3F35676D8FF6E743
3 changed files with 71 additions and 25 deletions

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.fragments.detail;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
@ -94,7 +95,6 @@ public class VideoDetailFragment extends BaseStateFragment<StreamInfo> implement
// Amount of videos to show on start
private static final int INITIAL_RELATED_VIDEOS = 8;
private static final String KORE_PACKET = "org.xbmc.kore";
private ActionBarHandler actionBarHandler;
private ArrayList<VideoStream> sortedStreamVideosList;
@ -513,6 +513,24 @@ public class VideoDetailFragment extends BaseStateFragment<StreamInfo> implement
return (!isLoading.get() && actionBarHandler.onItemSelected(item)) || super.onOptionsItemSelected(item);
}
private static void showInstallKoreDialog(final Context context) {
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(R.string.kore_not_found)
.setPositiveButton(R.string.install, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
NavigationHelper.installKore(context);
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.create().show();
}
private void setupActionBarHandler(final StreamInfo info) {
if (DEBUG) Log.d(TAG, "setupActionBarHandler() called with: info = [" + info + "]");
sortedStreamVideosList = new ArrayList<>(ListHelper.getSortedStreamVideosList(activity, info.video_streams, info.video_only_streams, false));
@ -542,30 +560,10 @@ public class VideoDetailFragment extends BaseStateFragment<StreamInfo> implement
@Override
public void onActionSelected(int selectedStreamId) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage(KORE_PACKET);
intent.setData(Uri.parse(info.url.replace("https", "http")));
activity.startActivity(intent);
NavigationHelper.startKore(activity, Uri.parse(info.url.replace("https", "http")));
} catch (Exception e) {
e.printStackTrace();
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage(R.string.kore_not_found)
.setPositiveButton(R.string.install, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(activity.getString(R.string.fdroid_kore_url)));
activity.startActivity(intent);
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.create().show();
if(DEBUG) Log.i(TAG, "Failed to start kore", e);
showInstallKoreDialog(activity);
}
}
});

View File

@ -1,11 +1,14 @@
package org.schabi.newpipe.util;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import com.nostra13.universalimageloader.core.ImageLoader;
@ -303,4 +306,49 @@ public class NavigationHelper {
}
return null;
}
private static Uri openMarketUrl(String packageName) {
return Uri.parse("market://details")
.buildUpon()
.appendQueryParameter("id", packageName)
.build();
}
private static Uri getGooglePlayUrl(String packageName) {
return Uri.parse("https://play.google.com/store/apps/details")
.buildUpon()
.appendQueryParameter("id", packageName)
.build();
}
private static void installApp(Context context, String packageName) {
try {
// Try market:// scheme
context.startActivity(new Intent(Intent.ACTION_VIEW, openMarketUrl(packageName)));
} catch (ActivityNotFoundException e) {
// Fall back to google play URL (don't worry F-Droid can handle it :)
context.startActivity(new Intent(Intent.ACTION_VIEW, getGooglePlayUrl(packageName)));
}
}
/**
* Start an activity to install Kore
* @param context the context
*/
public static void installKore(Context context) {
installApp(context, context.getString(R.string.kore_package));
}
/**
* Start Kore app to show a video on Kodi
* @param context the context to use
* @param videoURL the url to the video stream
*/
public static void startKore(Context context, Uri videoURL) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage(context.getString(R.string.kore_package));
intent.setData(videoURL);
context.startActivity(intent);
}
}

View File

@ -53,7 +53,7 @@
<string name="show_higher_resolutions_summary">Only some devices support playing 2K/4K videos</string>
<string name="play_with_kodi_title">Play with Kodi</string>
<string name="kore_not_found">Kore app not found. Install it?</string>
<string name="fdroid_kore_url" translatable="false">https://f-droid.org/repository/browse/?fdfilter=Kore&amp;fdid=org.xbmc.kore</string>
<string name="kore_package" translatable="false">org.xbmc.kore</string>
<string name="show_play_with_kodi_title">Show \"Play with Kodi\" option</string>
<string name="show_play_with_kodi_summary">Display an option to play a video via Kodi media center</string>
<string name="play_audio">Audio</string>