From f41549ccf17fb12e8c38de5a5d049291159ceead Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Sat, 19 Sep 2020 17:21:01 +0300 Subject: [PATCH] Added a comment and excluded automatic switch of orientation on tablets and Android TVs --- .../java/org/schabi/newpipe/player/VideoPlayer.java | 10 +++++----- .../org/schabi/newpipe/player/VideoPlayerImpl.java | 2 ++ .../newpipe/views/CustomCollapsingToolbarLayout.java | 7 +++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java index 46ab57786..67ea673c3 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -360,11 +360,11 @@ public abstract class VideoPlayer extends BasePlayer return true; }); // apply caption language from previous user preference - if (userPreferredLanguage != null && (captionLanguage.equals(userPreferredLanguage) - || searchForAutogenerated && captionLanguage.startsWith(userPreferredLanguage) - || userPreferredLanguage.contains("(") && captionLanguage.startsWith( - userPreferredLanguage - .substring(0, userPreferredLanguage.indexOf('('))))) { + if (userPreferredLanguage != null + && (captionLanguage.equals(userPreferredLanguage) + || (searchForAutogenerated && captionLanguage.startsWith(userPreferredLanguage)) + || (userPreferredLanguage.contains("(") && captionLanguage.startsWith( + userPreferredLanguage.substring(0, userPreferredLanguage.indexOf('(')))))) { final int textRendererIndex = getRendererIndex(C.TRACK_TYPE_TEXT); if (textRendererIndex != RENDERER_UNAVAILABLE) { trackSelector.setPreferredTextLanguage(captionLanguage); diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java index 7a258a4b8..481def60e 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -956,6 +956,8 @@ public class VideoPlayerImpl extends VideoPlayer if (orientationLocked && isFullscreen() && service.isLandscape() == isVerticalVideo + && !DeviceUtils.isTv(service) + && !DeviceUtils.isTablet(service) && fragmentListener != null) { fragmentListener.onScreenRotationButtonClicked(); } diff --git a/app/src/main/java/org/schabi/newpipe/views/CustomCollapsingToolbarLayout.java b/app/src/main/java/org/schabi/newpipe/views/CustomCollapsingToolbarLayout.java index fcbdabc8b..23e16ff58 100644 --- a/app/src/main/java/org/schabi/newpipe/views/CustomCollapsingToolbarLayout.java +++ b/app/src/main/java/org/schabi/newpipe/views/CustomCollapsingToolbarLayout.java @@ -5,6 +5,7 @@ import android.util.AttributeSet; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; import com.google.android.material.appbar.CollapsingToolbarLayout; public class CustomCollapsingToolbarLayout extends CollapsingToolbarLayout { @@ -27,8 +28,10 @@ public class CustomCollapsingToolbarLayout extends CollapsingToolbarLayout { } /** - * CollapsingToolbarLayout overrides our logic with fitsSystemWindows and ruins the layout. - * Override Google's method + * CollapsingToolbarLayout sets it's own setOnApplyInsetsListener which consumes + * system insets {@link CollapsingToolbarLayout#onWindowInsetChanged(WindowInsetsCompat)} + * so we will not receive them in subviews with fitsSystemWindows = true. + * Override Google's behavior * */ public void overrideListener() { ViewCompat.setOnApplyWindowInsetsListener(this, (v, insets) -> insets);