1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 16:40:32 +00:00

Merge pull request #2310 from christophehenry/add-kodi-share-player

Add send to Kodi button to player next to share button
This commit is contained in:
Tobias Groza 2020-01-27 10:46:59 +01:00 committed by GitHub
commit be92921034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 86 additions and 13 deletions

View File

@ -79,6 +79,7 @@ import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.ImageDisplayConstants; import org.schabi.newpipe.util.ImageDisplayConstants;
import org.schabi.newpipe.util.InfoCache; import org.schabi.newpipe.util.InfoCache;
import org.schabi.newpipe.util.KoreUtil;
import org.schabi.newpipe.util.ListHelper; import org.schabi.newpipe.util.ListHelper;
import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.NavigationHelper;
@ -624,7 +625,7 @@ public class VideoDetailFragment
url.replace("https", "http"))); url.replace("https", "http")));
} 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); KoreUtil.showInstallKoreDialog(activity);
} }
return true; return true;
default: default:
@ -632,16 +633,6 @@ public class VideoDetailFragment
} }
} }
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, (DialogInterface dialog, int which) ->
NavigationHelper.installKore(context))
.setNegativeButton(R.string.cancel, (DialogInterface dialog, int which) -> {
});
builder.create().show();
}
private void setupActionBarOnError(final String url) { private void setupActionBarOnError(final String url) {
if (DEBUG) Log.d(TAG, "setupActionBarHandlerOnError() called with: url = [" + url + "]"); if (DEBUG) Log.d(TAG, "setupActionBarHandlerOnError() called with: url = [" + url + "]");
Log.e("-----", "missing code"); Log.e("-----", "missing code");

View File

@ -28,6 +28,7 @@ import android.database.ContentObserver;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@ -75,6 +76,7 @@ import org.schabi.newpipe.player.playqueue.PlayQueueItemTouchCallback;
import org.schabi.newpipe.player.resolver.MediaSourceTag; import org.schabi.newpipe.player.resolver.MediaSourceTag;
import org.schabi.newpipe.player.resolver.VideoPlaybackResolver; import org.schabi.newpipe.player.resolver.VideoPlaybackResolver;
import org.schabi.newpipe.util.AnimationUtils; import org.schabi.newpipe.util.AnimationUtils;
import org.schabi.newpipe.util.KoreUtil;
import org.schabi.newpipe.util.ListHelper; import org.schabi.newpipe.util.ListHelper;
import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper; import org.schabi.newpipe.util.PermissionHelper;
@ -435,6 +437,7 @@ public final class MainVideoPlayer extends AppCompatActivity
private boolean queueVisible; private boolean queueVisible;
private ImageButton moreOptionsButton; private ImageButton moreOptionsButton;
private ImageButton kodiButton;
private ImageButton shareButton; private ImageButton shareButton;
private ImageButton toggleOrientationButton; private ImageButton toggleOrientationButton;
private ImageButton switchPopupButton; private ImageButton switchPopupButton;
@ -471,6 +474,7 @@ public final class MainVideoPlayer extends AppCompatActivity
this.moreOptionsButton = rootView.findViewById(R.id.moreOptionsButton); this.moreOptionsButton = rootView.findViewById(R.id.moreOptionsButton);
this.secondaryControls = rootView.findViewById(R.id.secondaryControls); this.secondaryControls = rootView.findViewById(R.id.secondaryControls);
this.kodiButton = rootView.findViewById(R.id.kodi);
this.shareButton = rootView.findViewById(R.id.share); this.shareButton = rootView.findViewById(R.id.share);
this.toggleOrientationButton = rootView.findViewById(R.id.toggleOrientation); this.toggleOrientationButton = rootView.findViewById(R.id.toggleOrientation);
this.switchBackgroundButton = rootView.findViewById(R.id.switchBackground); this.switchBackgroundButton = rootView.findViewById(R.id.switchBackground);
@ -482,6 +486,9 @@ public final class MainVideoPlayer extends AppCompatActivity
titleTextView.setSelected(true); titleTextView.setSelected(true);
channelTextView.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); getRootView().setKeepScreenOn(true);
} }
@ -518,6 +525,7 @@ public final class MainVideoPlayer extends AppCompatActivity
closeButton.setOnClickListener(this); closeButton.setOnClickListener(this);
moreOptionsButton.setOnClickListener(this); moreOptionsButton.setOnClickListener(this);
kodiButton.setOnClickListener(this);
shareButton.setOnClickListener(this); shareButton.setOnClickListener(this);
toggleOrientationButton.setOnClickListener(this); toggleOrientationButton.setOnClickListener(this);
switchBackgroundButton.setOnClickListener(this); switchBackgroundButton.setOnClickListener(this);
@ -588,6 +596,17 @@ public final class MainVideoPlayer extends AppCompatActivity
finish(); finish();
} }
public void onKodiShare() {
onPause();
try {
NavigationHelper.playWithKore(this.context, Uri.parse(
playerImpl.getVideoUrl().replace("https", "http")));
} catch (Exception e) {
if (DEBUG) Log.i(TAG, "Failed to start kore", e);
KoreUtil.showInstallKoreDialog(this.context);
}
}
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Player Overrides // Player Overrides
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
@ -688,6 +707,8 @@ public final class MainVideoPlayer extends AppCompatActivity
} else if (v.getId() == closeButton.getId()) { } else if (v.getId() == closeButton.getId()) {
onPlaybackShutdown(); onPlaybackShutdown();
return; return;
} else if (v.getId() == kodiButton.getId()) {
onKodiShare();
} }
if (getCurrentState() != STATE_COMPLETED) { if (getCurrentState() != STATE_COMPLETED) {

View File

@ -0,0 +1,23 @@
package org.schabi.newpipe.util;
import android.content.Context;
import android.content.DialogInterface;
import androidx.appcompat.app.AlertDialog;
import org.schabi.newpipe.R;
public class KoreUtil {
private KoreUtil() { }
public 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,
(DialogInterface dialog, int which) -> NavigationHelper.installKore(context))
.setNegativeButton(R.string.cancel, (DialogInterface dialog, int which) -> {
});
builder.create().show();
}
}

View File

@ -305,7 +305,7 @@
tools:text="English" /> tools:text="English" />
<ImageButton <ImageButton
android:id="@+id/share" android:id="@+id/kodi"
android:layout_width="30dp" android:layout_width="30dp"
android:layout_height="30dp" android:layout_height="30dp"
android:layout_marginLeft="4dp" android:layout_marginLeft="4dp"
@ -316,6 +316,25 @@
android:focusable="true" android:focusable="true"
android:padding="5dp" android:padding="5dp"
android:scaleType="fitXY" android:scaleType="fitXY"
android:src="@drawable/ic_cast_white_24dp"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/play_with_kodi_title"
tools:ignore="RtlHardcoded"
android:visibility="visible"/>
<ImageButton
android:id="@+id/share"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"
android:layout_toLeftOf="@id/kodi"
android:layout_alignWithParentIfMissing="true"
android:layout_centerVertical="true"
android:clickable="true"
android:focusable="true"
android:padding="5dp"
android:scaleType="fitXY"
android:src="@drawable/ic_share_white_24dp" android:src="@drawable/ic_share_white_24dp"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:contentDescription="@string/share" android:contentDescription="@string/share"

View File

@ -303,7 +303,7 @@
tools:text="English" /> tools:text="English" />
<ImageButton <ImageButton
android:id="@+id/share" android:id="@+id/kodi"
android:layout_width="30dp" android:layout_width="30dp"
android:layout_height="30dp" android:layout_height="30dp"
android:layout_marginLeft="4dp" android:layout_marginLeft="4dp"
@ -314,6 +314,25 @@
android:focusable="true" android:focusable="true"
android:padding="5dp" android:padding="5dp"
android:scaleType="fitXY" android:scaleType="fitXY"
android:src="@drawable/ic_cast_white_24dp"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/play_with_kodi_title"
tools:ignore="RtlHardcoded"
android:visibility="visible"/>
<ImageButton
android:id="@+id/share"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"
android:layout_toLeftOf="@id/kodi"
android:layout_alignWithParentIfMissing="true"
android:layout_centerVertical="true"
android:clickable="true"
android:focusable="true"
android:padding="5dp"
android:scaleType="fitXY"
android:src="@drawable/ic_share_white_24dp" android:src="@drawable/ic_share_white_24dp"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:contentDescription="@string/share" android:contentDescription="@string/share"