Quality selector for external playback and better fullscreen mode for old devices

This commit is contained in:
Avently 2020-07-24 00:43:09 +03:00
parent 91a0257c8f
commit 7c79d421e8
2 changed files with 30 additions and 15 deletions

View File

@ -1142,11 +1142,7 @@ public class VideoDetailFragment
private void openVideoPlayer() { private void openVideoPlayer() {
if (PreferenceManager.getDefaultSharedPreferences(activity) if (PreferenceManager.getDefaultSharedPreferences(activity)
.getBoolean(this.getString(R.string.use_external_video_player_key), false)) { .getBoolean(this.getString(R.string.use_external_video_player_key), false)) {
final VideoStream selectedVideoStream = getSelectedVideoStream(); showExternalPlaybackDialog();
if (selectedVideoStream == null) {
return;
}
startOnExternalPlayer(activity, currentInfo, selectedVideoStream);
} else { } else {
replaceQueueIfUserConfirms(this::openMainPlayer); replaceQueueIfUserConfirms(this::openMainPlayer);
} }
@ -1302,12 +1298,6 @@ public class VideoDetailFragment
viewHolder.requestLayout(); viewHolder.requestLayout();
} }
@Nullable
private VideoStream getSelectedVideoStream() {
return sortedVideoStreams != null ? sortedVideoStreams.get(selectedVideoStreamIndex) : null;
}
private void prepareDescription(final Description description) { private void prepareDescription(final Description description) {
if (description == null || TextUtils.isEmpty(description.getContent()) if (description == null || TextUtils.isEmpty(description.getContent())
|| description == Description.emptyDescription) { || description == Description.emptyDescription) {
@ -2113,8 +2103,7 @@ public class VideoDetailFragment
private void showClearingQueueConfirmation(final Runnable onAllow) { private void showClearingQueueConfirmation(final Runnable onAllow) {
new AlertDialog.Builder(activity) new AlertDialog.Builder(activity)
.setTitle(R.string.confirm_prompt) .setTitle(R.string.clear_queue_confirmation_description)
.setMessage(R.string.clear_queue_confirmation_description)
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.yes, (dialog, which) -> { .setPositiveButton(android.R.string.yes, (dialog, which) -> {
onAllow.run(); onAllow.run();
@ -2122,6 +2111,30 @@ public class VideoDetailFragment
}).show(); }).show();
} }
private void showExternalPlaybackDialog() {
if (sortedVideoStreams == null) {
return;
}
CharSequence[] resolutions = new CharSequence[sortedVideoStreams.size()];
for (int i = 0; i < sortedVideoStreams.size(); i++) {
resolutions[i] = sortedVideoStreams.get(i).getResolution();
}
AlertDialog.Builder builder = new AlertDialog.Builder(activity)
.setNegativeButton(android.R.string.cancel, null)
.setNeutralButton(R.string.open_in_browser, (dialog, i) ->
ShareUtils.openUrlInBrowser(requireActivity(), url)
);
// Maybe there are no video streams available, show just `open in browser` button
if (resolutions.length > 0) {
builder.setSingleChoiceItems(resolutions, selectedVideoStreamIndex, (dialog, i) -> {
dialog.dismiss();
startOnExternalPlayer(activity, currentInfo, sortedVideoStreams.get(i));
}
);
}
builder.show();
}
/* /*
* Remove unneeded information while waiting for a next task * Remove unneeded information while waiting for a next task
* */ * */

View File

@ -1463,7 +1463,9 @@ public class VideoPlayerImpl extends VideoPlayer
private void showSystemUIPartially() { private void showSystemUIPartially() {
if (isFullscreen() && getParentActivity() != null) { if (isFullscreen() && getParentActivity() != null) {
final int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE; final int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
getParentActivity().getWindow().getDecorView().setSystemUiVisibility(visibility); getParentActivity().getWindow().getDecorView().setSystemUiVisibility(visibility);
} }
} }