Skip to content

Commit c24ad9a

Browse files
Add setting to configure popup player mode.
1 parent 079f7e8 commit c24ad9a

File tree

4 files changed

+2186
-21
lines changed

4 files changed

+2186
-21
lines changed

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import android.provider.Settings;
3434
import android.util.DisplayMetrics;
3535
import android.util.Log;
36-
import android.util.Rational;
3736
import android.util.TypedValue;
3837
import android.view.LayoutInflater;
3938
import android.view.MotionEvent;
@@ -439,20 +438,13 @@ public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
439438

440439
@Override
441440
public void onPictureInPictureModeChanged(final boolean isInPictureInPictureMode) {
442-
if (isInPictureInPictureMode) {
443-
binding.overlayLayout.setVisibility(View.GONE);
444-
binding.tabLayout.setVisibility(View.GONE);
445-
binding.detailContentRootLayout.setVisibility(View.GONE);
446-
if (binding.relatedItemsLayout != null) {
447-
binding.relatedItemsLayout.setVisibility(View.GONE);
448-
}
449-
} else {
450-
binding.overlayLayout.setVisibility(View.VISIBLE);
451-
binding.tabLayout.setVisibility(View.VISIBLE);
452-
binding.detailContentRootLayout.setVisibility(View.VISIBLE);
453-
if (binding.relatedItemsLayout != null) {
454-
binding.relatedItemsLayout.setVisibility(View.VISIBLE);
455-
}
441+
final int visibility = isInPictureInPictureMode ? View.GONE : View.VISIBLE;
442+
binding.overlayLayout.setVisibility(visibility);
443+
binding.tabLayout.setVisibility(visibility);
444+
binding.detailContentRootLayout.setVisibility(visibility);
445+
binding.viewPager.setVisibility(visibility);
446+
if (binding.relatedItemsLayout != null) {
447+
binding.relatedItemsLayout.setVisibility(visibility);
456448
}
457449
}
458450

@@ -1150,16 +1142,16 @@ private void openBackgroundPlayer(final boolean append) {
11501142
}
11511143

11521144
private void openPopupPlayer(final boolean append) {
1145+
final var popupMode = PreferenceManager.getDefaultSharedPreferences(activity)
1146+
.getString(getString(R.string.popup_configuration_key),
1147+
getString(R.string.popup_mode_legacy));
11531148
final var isPipAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
11541149
&& requireContext().getPackageManager()
1155-
.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);
1150+
.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
1151+
&& popupMode.equals(getString(R.string.popup_mode_pip));
1152+
11561153
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isPipAvailable) {
1157-
final var videoPlayerUi = player.UIs().get(VideoPlayerUi.class).orElse(null);
11581154
final var pipParams = new PictureInPictureParams.Builder();
1159-
if (videoPlayerUi != null) {
1160-
final var videoView = videoPlayerUi.getBinding().getRoot();
1161-
pipParams.setAspectRatio(new Rational(videoView.getWidth(), videoView.getHeight()));
1162-
}
11631155
requireActivity().enterPictureInPictureMode(pipParams.build());
11641156
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isPipAvailable) {
11651157
requireActivity().enterPictureInPictureMode();

0 commit comments

Comments
 (0)