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

Remove "Detail Page" open action from share dialog under certain circumstances

With the new application workflow and unified player, video detail page and video player are the same activity. So show only one of these options based on whether autoplay is enabled or not, and show both if using external player
This commit is contained in:
TobiGr 2020-09-09 20:45:42 +02:00 committed by Stypox
parent ad3364671d
commit 0e5f85db95
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
4 changed files with 75 additions and 35 deletions

View File

@ -39,6 +39,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
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;
import org.schabi.newpipe.player.helper.PlayerHelper;
import org.schabi.newpipe.player.playqueue.ChannelPlayQueue; import org.schabi.newpipe.player.playqueue.ChannelPlayQueue;
import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlayQueue;
import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue; import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue;
@ -278,6 +279,7 @@ public class RouterActivity extends AppCompatActivity {
handleChoice(choice.key); handleChoice(choice.key);
// open future streams always like this one, because "always" button was used by user
if (which == DialogInterface.BUTTON_POSITIVE) { if (which == DialogInterface.BUTTON_POSITIVE) {
preferences.edit() preferences.edit()
.putString(getString(R.string.preferred_open_action_key), choice.key) .putString(getString(R.string.preferred_open_action_key), choice.key)
@ -377,23 +379,50 @@ public class RouterActivity extends AppCompatActivity {
final boolean isExtAudioEnabled = preferences.getBoolean( final boolean isExtAudioEnabled = preferences.getBoolean(
getString(R.string.use_external_audio_player_key), false); getString(R.string.use_external_audio_player_key), false);
returnList.add(new AdapterChoiceItem(getString(R.string.show_info_key), final AdapterChoiceItem videoPlayer = new AdapterChoiceItem(
getString(R.string.show_info), getString(R.string.video_player_key), getString(R.string.video_player),
resolveResourceIdFromAttr(context, R.attr.ic_info_outline))); resolveResourceIdFromAttr(context, R.attr.ic_play_arrow));
final AdapterChoiceItem showInfo = new AdapterChoiceItem(
getString(R.string.show_info_key), getString(R.string.show_info),
resolveResourceIdFromAttr(context, R.attr.ic_info_outline));
final AdapterChoiceItem popupPlayer = new AdapterChoiceItem(
getString(R.string.popup_player_key), getString(R.string.popup_player),
resolveResourceIdFromAttr(context, R.attr.ic_popup));
final AdapterChoiceItem backgroundPlayer = new AdapterChoiceItem(
getString(R.string.background_player_key), getString(R.string.background_player),
resolveResourceIdFromAttr(context, R.attr.ic_headset));
if (capabilities.contains(VIDEO) && !(isExtVideoEnabled && linkType != LinkType.STREAM)) { if (linkType == LinkType.STREAM) {
returnList.add(new AdapterChoiceItem(getString(R.string.video_player_key), if (isExtVideoEnabled) {
getString(R.string.video_player), // show both "show info" and "video player", they are two different activities
resolveResourceIdFromAttr(context, R.attr.ic_play_arrow))); returnList.add(showInfo);
returnList.add(new AdapterChoiceItem(getString(R.string.popup_player_key), returnList.add(videoPlayer);
getString(R.string.popup_player), } else if (capabilities.contains(VIDEO)
resolveResourceIdFromAttr(context, R.attr.ic_popup))); && PlayerHelper.isAutoplayAllowedByUser(context)) {
// show only "video player" since the details activity will be opened and the video
// will be autoplayed there and "show info" would do the exact same thing
returnList.add(videoPlayer);
} else {
// show only "show info" if video player is not applicable or autoplay is disabled
returnList.add(showInfo);
} }
if (capabilities.contains(AUDIO) && !(isExtAudioEnabled && linkType != LinkType.STREAM)) { if (capabilities.contains(VIDEO)) {
returnList.add(new AdapterChoiceItem(getString(R.string.background_player_key), returnList.add(popupPlayer);
getString(R.string.background_player), }
resolveResourceIdFromAttr(context, R.attr.ic_headset))); if (capabilities.contains(AUDIO)) {
returnList.add(backgroundPlayer);
}
} else {
returnList.add(showInfo);
if (capabilities.contains(VIDEO) && !isExtVideoEnabled) {
returnList.add(videoPlayer);
returnList.add(popupPlayer);
}
if (capabilities.contains(AUDIO) && !isExtAudioEnabled) {
returnList.add(backgroundPlayer);
}
} }
returnList.add(new AdapterChoiceItem(getString(R.string.download_key), returnList.add(new AdapterChoiceItem(getString(R.string.download_key),

View File

@ -1236,7 +1236,7 @@ public class VideoDetailFragment
} }
private boolean isExternalPlayerEnabled() { private boolean isExternalPlayerEnabled() {
return PreferenceManager.getDefaultSharedPreferences(getContext()) return PreferenceManager.getDefaultSharedPreferences(requireContext())
.getBoolean(getString(R.string.use_external_video_player_key), false); .getBoolean(getString(R.string.use_external_video_player_key), false);
} }
@ -1247,23 +1247,7 @@ public class VideoDetailFragment
&& !isExternalPlayerEnabled() && !isExternalPlayerEnabled()
&& (player == null || player.videoPlayerSelected()) && (player == null || player.videoPlayerSelected())
&& bottomSheetState != BottomSheetBehavior.STATE_HIDDEN && bottomSheetState != BottomSheetBehavior.STATE_HIDDEN
&& isAutoplayAllowedByUser(); && PlayerHelper.isAutoplayAllowedByUser(requireContext());
}
private boolean isAutoplayAllowedByUser() {
if (activity == null) {
return false;
}
switch (PlayerHelper.getAutoplayType(activity)) {
case PlayerHelper.AutoplayType.AUTOPLAY_TYPE_NEVER:
return false;
case PlayerHelper.AutoplayType.AUTOPLAY_TYPE_WIFI:
return !ListHelper.isMeteredNetwork(activity);
case PlayerHelper.AutoplayType.AUTOPLAY_TYPE_ALWAYS:
default:
return true;
}
} }
private void addVideoPlayerView() { private void addVideoPlayerView() {

View File

@ -28,6 +28,7 @@ import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlayQueue;
import org.schabi.newpipe.player.playqueue.PlayQueueItem; import org.schabi.newpipe.player.playqueue.PlayQueueItem;
import org.schabi.newpipe.player.playqueue.SinglePlayQueue; import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
import org.schabi.newpipe.util.ListHelper;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.text.DecimalFormat; import java.text.DecimalFormat;
@ -248,6 +249,18 @@ public final class PlayerHelper {
} }
} }
public static boolean isAutoplayAllowedByUser(@NonNull final Context context) {
switch (PlayerHelper.getAutoplayType(context)) {
case PlayerHelper.AutoplayType.AUTOPLAY_TYPE_NEVER:
return false;
case PlayerHelper.AutoplayType.AUTOPLAY_TYPE_WIFI:
return !ListHelper.isMeteredNetwork(context);
case PlayerHelper.AutoplayType.AUTOPLAY_TYPE_ALWAYS:
default:
return true;
}
}
@NonNull @NonNull
public static SeekParameters getSeekParameters(@NonNull final Context context) { public static SeekParameters getSeekParameters(@NonNull final Context context) {
return isUsingInexactSeek(context) ? SeekParameters.CLOSEST_SYNC : SeekParameters.EXACT; return isUsingInexactSeek(context) ? SeekParameters.CLOSEST_SYNC : SeekParameters.EXACT;

View File

@ -18,9 +18,23 @@ public final class SettingMigrations {
/** /**
* Version number for preferences. Must be incremented every time a migration is necessary. * Version number for preferences. Must be incremented every time a migration is necessary.
*/ */
public static final int VERSION = 0; public static final int VERSION = 1;
private static SharedPreferences sp; private static SharedPreferences sp;
public static final Migration MIGRATION_0_1 = new Migration(0, 1) {
@Override
public void migrate(final Context context) {
// We changed the content of the dialog which opens when sharing a link to NewPipe
// by removing the "open detail page" option.
// Therefore, show the dialog once again to ensure users need to choose again and are
// aware of the changed dialog.
final SharedPreferences.Editor editor = sp.edit();
editor.putString(context.getString(R.string.preferred_open_action_key),
context.getString(R.string.always_ask_open_action_key));
editor.apply();
}
};
/** /**
* List of all implemented migrations. * List of all implemented migrations.
* <p> * <p>
@ -28,7 +42,7 @@ public final class SettingMigrations {
* If not sorted correctly, migrations which depend on each other, may fail. * If not sorted correctly, migrations which depend on each other, may fail.
*/ */
private static final Migration[] SETTING_MIGRATIONS = { private static final Migration[] SETTING_MIGRATIONS = {
MIGRATION_0_1
}; };