From 883e4fcd7c2827ea5fc778447bed966842aa1a0e Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Fri, 11 Sep 2020 20:52:38 +0300 Subject: [PATCH 01/16] Small fixes of issues with old devices support, brightness, etc --- .../fragments/detail/VideoDetailFragment.java | 57 ++++++++++++------- .../org/schabi/newpipe/player/MainPlayer.java | 1 + .../newpipe/player/VideoPlayerImpl.java | 1 + .../player/event/PlayerGestureListener.java | 14 +++-- app/src/main/res/layout-large-land/player.xml | 6 +- app/src/main/res/layout/player.xml | 6 +- 6 files changed, 55 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index b731d0270..319523ab7 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -102,13 +102,12 @@ import org.schabi.newpipe.util.ListHelper; import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.PermissionHelper; +import org.schabi.newpipe.util.SerializedCache; import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.views.AnimatedProgressBar; import org.schabi.newpipe.views.LargeTextMovementMethod; -import java.io.Serializable; -import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -337,7 +336,7 @@ public class VideoDetailFragment stopPlayerListener(); playerService = null; player = null; - saveCurrentAndRestoreDefaultBrightness(); + restoreDefaultBrightness(); } } @@ -426,7 +425,7 @@ public class VideoDetailFragment if (currentWorker != null) { currentWorker.dispose(); } - saveCurrentAndRestoreDefaultBrightness(); + restoreDefaultBrightness(); PreferenceManager.getDefaultSharedPreferences(requireContext()) .edit() .putString(getString(R.string.stream_info_selected_tab_key), @@ -538,31 +537,51 @@ public class VideoDetailFragment super.onSaveInstanceState(outState); if (!isLoading.get() && currentInfo != null && isVisible()) { - outState.putSerializable(INFO_KEY, currentInfo); + final String infoCacheKey = SerializedCache.getInstance() + .put(currentInfo, StreamInfo.class); + if (infoCacheKey != null) { + outState.putString(INFO_KEY, infoCacheKey); + } } if (playQueue != null) { - outState.putSerializable(VideoPlayer.PLAY_QUEUE_KEY, playQueue); + final String queueCacheKey = SerializedCache.getInstance() + .put(playQueue, PlayQueue.class); + if (queueCacheKey != null) { + outState.putString(VideoPlayer.PLAY_QUEUE_KEY, queueCacheKey); + } + } + final String stackCacheKey = SerializedCache.getInstance().put(stack, LinkedList.class); + if (stackCacheKey != null) { + outState.putString(STACK_KEY, stackCacheKey); } - outState.putSerializable(STACK_KEY, stack); } @Override protected void onRestoreInstanceState(@NonNull final Bundle savedState) { super.onRestoreInstanceState(savedState); - Serializable serializable = savedState.getSerializable(INFO_KEY); - if (serializable instanceof StreamInfo) { - currentInfo = (StreamInfo) serializable; - InfoCache.getInstance().putInfo(serviceId, url, currentInfo, InfoItem.InfoType.STREAM); + final String infoCacheKey = savedState.getString(INFO_KEY); + if (infoCacheKey != null) { + currentInfo = SerializedCache.getInstance().take(infoCacheKey, StreamInfo.class); + if (currentInfo != null) { + InfoCache.getInstance() + .putInfo(serviceId, url, currentInfo, InfoItem.InfoType.STREAM); + } } - serializable = savedState.getSerializable(STACK_KEY); - if (serializable instanceof Collection) { - //noinspection unchecked - stack.addAll((Collection) serializable); + final String stackCacheKey = savedState.getString(STACK_KEY); + if (stackCacheKey != null) { + final LinkedList cachedStack = + SerializedCache.getInstance().take(stackCacheKey, LinkedList.class); + if (cachedStack != null) { + stack.addAll(cachedStack); + } + } + final String queueCacheKey = savedState.getString(VideoPlayer.PLAY_QUEUE_KEY); + if (queueCacheKey != null) { + playQueue = SerializedCache.getInstance().take(queueCacheKey, PlayQueue.class); } - playQueue = (PlayQueue) savedState.getSerializable(VideoPlayer.PLAY_QUEUE_KEY); } /*////////////////////////////////////////////////////////////////////////// @@ -2027,13 +2046,11 @@ public class VideoDetailFragment && player.getPlayer().getPlaybackState() != Player.STATE_IDLE; } - private void saveCurrentAndRestoreDefaultBrightness() { + private void restoreDefaultBrightness() { final WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); if (lp.screenBrightness == -1) { return; } - // Save current brightness level - PlayerHelper.setScreenBrightness(activity, lp.screenBrightness); // Restore the old brightness when fragment.onPause() called or // when a player is in portrait @@ -2052,7 +2069,7 @@ public class VideoDetailFragment || !player.isFullscreen() || bottomSheetState != BottomSheetBehavior.STATE_EXPANDED) { // Apply system brightness when the player is not in fullscreen - saveCurrentAndRestoreDefaultBrightness(); + restoreDefaultBrightness(); } else { // Restore already saved brightness level final float brightnessLevel = PlayerHelper.getScreenBrightness(activity); diff --git a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java index 273f37cc8..c78ddf036 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java @@ -171,6 +171,7 @@ public final class MainPlayer extends Service { // Android TV will handle back button in case controls will be visible // (one more additional unneeded click while the player is hidden) playerImpl.hideControls(0, 0); + playerImpl.onQueueClosed(); // Notification shows information about old stream but if a user selects // a stream from backStack it's not actual anymore // So we should hide the notification at all. 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 a5758301c..52df3d956 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -257,6 +257,7 @@ public class VideoPlayerImpl extends VideoPlayer } else { getRootView().setVisibility(View.VISIBLE); initVideoPlayer(); + onQueueClosed(); // Android TV: without it focus will frame the whole player playPauseButton.requestFocus(); } diff --git a/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java b/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java index 4aa6070eb..a2def2a64 100644 --- a/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java +++ b/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java @@ -9,6 +9,7 @@ import android.view.View; import android.view.ViewConfiguration; import android.view.Window; import android.view.WindowManager; +import android.widget.ProgressBar; import androidx.appcompat.content.res.AppCompatResources; import org.schabi.newpipe.R; import org.schabi.newpipe.player.BasePlayer; @@ -264,14 +265,19 @@ public class PlayerGestureListener } final Window window = parent.getWindow(); - - playerImpl.getBrightnessProgressBar().incrementProgressBy((int) distanceY); - final float currentProgressPercent = (float) playerImpl.getBrightnessProgressBar() - .getProgress() / playerImpl.getMaxGestureLength(); final WindowManager.LayoutParams layoutParams = window.getAttributes(); + final ProgressBar bar = playerImpl.getBrightnessProgressBar(); + final float oldBrightness = layoutParams.screenBrightness; + bar.setProgress((int) (bar.getMax() * Math.max(0, Math.min(1, oldBrightness)))); + bar.incrementProgressBy((int) distanceY); + + final float currentProgressPercent = (float) bar.getProgress() / bar.getMax(); layoutParams.screenBrightness = currentProgressPercent; window.setAttributes(layoutParams); + // Save current brightness level + PlayerHelper.setScreenBrightness(parent, currentProgressPercent); + if (DEBUG) { Log.d(TAG, "onScroll().brightnessControl, " + "currentBrightness = " + currentProgressPercent); diff --git a/app/src/main/res/layout-large-land/player.xml b/app/src/main/res/layout-large-land/player.xml index 46edda8b7..3c410801e 100644 --- a/app/src/main/res/layout-large-land/player.xml +++ b/app/src/main/res/layout-large-land/player.xml @@ -353,10 +353,10 @@ android:id="@+id/playbackSeekBar" style="@style/Widget.AppCompat.SeekBar" android:layout_width="0dp" - android:layout_height="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center" android:layout_weight="1" - android:paddingBottom="4dp" - android:paddingTop="8dp" + android:layout_marginTop="2dp" tools:progress="25" android:nextFocusDown="@id/screenRotationButton" tools:secondaryProgress="50"/> diff --git a/app/src/main/res/layout/player.xml b/app/src/main/res/layout/player.xml index 88489d8d5..ec95bd8c3 100644 --- a/app/src/main/res/layout/player.xml +++ b/app/src/main/res/layout/player.xml @@ -352,10 +352,10 @@ android:id="@+id/playbackSeekBar" style="@style/Widget.AppCompat.SeekBar" android:layout_width="0dp" - android:layout_height="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center" android:layout_weight="1" - android:paddingBottom="4dp" - android:paddingTop="8dp" + android:layout_marginTop="2dp" tools:progress="25" tools:secondaryProgress="50"/> From 011cc7d3376f14d4f92e3bac9ef5bf2c8483b789 Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Mon, 14 Sep 2020 02:46:00 +0300 Subject: [PATCH 02/16] Android 11 initial support --- app/src/main/res/layout-large-land/fragment_video_detail.xml | 1 - app/src/main/res/layout-large-land/player.xml | 3 +-- app/src/main/res/layout/activity_main.xml | 3 +-- app/src/main/res/layout/fragment_video_detail.xml | 1 - app/src/main/res/layout/player.xml | 3 +-- 5 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/src/main/res/layout-large-land/fragment_video_detail.xml b/app/src/main/res/layout-large-land/fragment_video_detail.xml index f69832b81..3c64be3b5 100644 --- a/app/src/main/res/layout-large-land/fragment_video_detail.xml +++ b/app/src/main/res/layout-large-land/fragment_video_detail.xml @@ -28,7 +28,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/transparent" - android:fitsSystemWindows="true" android:touchscreenBlocksFocus="false" app:elevation="0dp" app:layout_behavior="com.google.android.material.appbar.FlingBehavior"> diff --git a/app/src/main/res/layout-large-land/player.xml b/app/src/main/res/layout-large-land/player.xml index 3c410801e..7163964fc 100644 --- a/app/src/main/res/layout-large-land/player.xml +++ b/app/src/main/res/layout-large-land/player.xml @@ -62,8 +62,7 @@ + android:layout_height="match_parent"> + android:layout_height="match_parent"> diff --git a/app/src/main/res/layout/player.xml b/app/src/main/res/layout/player.xml index ec95bd8c3..ae445bbb2 100644 --- a/app/src/main/res/layout/player.xml +++ b/app/src/main/res/layout/player.xml @@ -62,8 +62,7 @@ + android:layout_height="match_parent"> Date: Mon, 14 Sep 2020 11:30:41 +0300 Subject: [PATCH 03/16] Android 11: transparent navigation and status bars --- .../fragments/detail/VideoDetailFragment.java | 4 ++++ .../newpipe/player/VideoPlayerImpl.java | 4 ++++ app/src/main/res/values-v29/themes.xml | 20 +++++++++++++++++++ app/src/main/res/values/styles.xml | 4 ++-- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/values-v29/themes.xml diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 319523ab7..eddefaa8c 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -2003,6 +2003,10 @@ public class VideoDetailFragment } activity.getWindow().getDecorView().setSystemUiVisibility(0); activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + if (Build.VERSION.SDK_INT >= 30 /*Android 11*/) { + activity.getWindow().setStatusBarColor(ThemeHelper.resolveColorFromAttr( + requireContext(), android.R.attr.colorPrimary)); + } } private void hideSystemUi() { 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 52df3d956..ede476653 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -27,6 +27,7 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.database.ContentObserver; import android.graphics.Bitmap; +import android.graphics.Color; import android.graphics.PixelFormat; import android.graphics.Point; import android.net.Uri; @@ -1475,6 +1476,9 @@ public class VideoPlayerImpl extends VideoPlayer | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; getParentActivity().getWindow().getDecorView().setSystemUiVisibility(visibility); + if (Build.VERSION.SDK_INT >= 30 /*Android 11*/) { + getParentActivity().getWindow().setStatusBarColor(Color.TRANSPARENT); + } } } diff --git a/app/src/main/res/values-v29/themes.xml b/app/src/main/res/values-v29/themes.xml new file mode 100644 index 000000000..63494d0ae --- /dev/null +++ b/app/src/main/res/values-v29/themes.xml @@ -0,0 +1,20 @@ + + + + + + - -