mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-01-23 15:36:57 +00:00
Small fixes of issues with old devices support, brightness, etc
This commit is contained in:
parent
2215ce58a4
commit
883e4fcd7c
@ -102,13 +102,12 @@ import org.schabi.newpipe.util.ListHelper;
|
|||||||
import org.schabi.newpipe.util.Localization;
|
import org.schabi.newpipe.util.Localization;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
import org.schabi.newpipe.util.PermissionHelper;
|
import org.schabi.newpipe.util.PermissionHelper;
|
||||||
|
import org.schabi.newpipe.util.SerializedCache;
|
||||||
import org.schabi.newpipe.util.ShareUtils;
|
import org.schabi.newpipe.util.ShareUtils;
|
||||||
import org.schabi.newpipe.util.ThemeHelper;
|
import org.schabi.newpipe.util.ThemeHelper;
|
||||||
import org.schabi.newpipe.views.AnimatedProgressBar;
|
import org.schabi.newpipe.views.AnimatedProgressBar;
|
||||||
import org.schabi.newpipe.views.LargeTextMovementMethod;
|
import org.schabi.newpipe.views.LargeTextMovementMethod;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -337,7 +336,7 @@ public class VideoDetailFragment
|
|||||||
stopPlayerListener();
|
stopPlayerListener();
|
||||||
playerService = null;
|
playerService = null;
|
||||||
player = null;
|
player = null;
|
||||||
saveCurrentAndRestoreDefaultBrightness();
|
restoreDefaultBrightness();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,7 +425,7 @@ public class VideoDetailFragment
|
|||||||
if (currentWorker != null) {
|
if (currentWorker != null) {
|
||||||
currentWorker.dispose();
|
currentWorker.dispose();
|
||||||
}
|
}
|
||||||
saveCurrentAndRestoreDefaultBrightness();
|
restoreDefaultBrightness();
|
||||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
.edit()
|
.edit()
|
||||||
.putString(getString(R.string.stream_info_selected_tab_key),
|
.putString(getString(R.string.stream_info_selected_tab_key),
|
||||||
@ -538,31 +537,51 @@ public class VideoDetailFragment
|
|||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
if (!isLoading.get() && currentInfo != null && isVisible()) {
|
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) {
|
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
|
@Override
|
||||||
protected void onRestoreInstanceState(@NonNull final Bundle savedState) {
|
protected void onRestoreInstanceState(@NonNull final Bundle savedState) {
|
||||||
super.onRestoreInstanceState(savedState);
|
super.onRestoreInstanceState(savedState);
|
||||||
|
|
||||||
Serializable serializable = savedState.getSerializable(INFO_KEY);
|
final String infoCacheKey = savedState.getString(INFO_KEY);
|
||||||
if (serializable instanceof StreamInfo) {
|
if (infoCacheKey != null) {
|
||||||
currentInfo = (StreamInfo) serializable;
|
currentInfo = SerializedCache.getInstance().take(infoCacheKey, StreamInfo.class);
|
||||||
InfoCache.getInstance().putInfo(serviceId, url, currentInfo, InfoItem.InfoType.STREAM);
|
if (currentInfo != null) {
|
||||||
|
InfoCache.getInstance()
|
||||||
|
.putInfo(serviceId, url, currentInfo, InfoItem.InfoType.STREAM);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serializable = savedState.getSerializable(STACK_KEY);
|
final String stackCacheKey = savedState.getString(STACK_KEY);
|
||||||
if (serializable instanceof Collection) {
|
if (stackCacheKey != null) {
|
||||||
//noinspection unchecked
|
final LinkedList<StackItem> cachedStack =
|
||||||
stack.addAll((Collection<? extends StackItem>) serializable);
|
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;
|
&& player.getPlayer().getPlaybackState() != Player.STATE_IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveCurrentAndRestoreDefaultBrightness() {
|
private void restoreDefaultBrightness() {
|
||||||
final WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
|
final WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
|
||||||
if (lp.screenBrightness == -1) {
|
if (lp.screenBrightness == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Save current brightness level
|
|
||||||
PlayerHelper.setScreenBrightness(activity, lp.screenBrightness);
|
|
||||||
|
|
||||||
// Restore the old brightness when fragment.onPause() called or
|
// Restore the old brightness when fragment.onPause() called or
|
||||||
// when a player is in portrait
|
// when a player is in portrait
|
||||||
@ -2052,7 +2069,7 @@ public class VideoDetailFragment
|
|||||||
|| !player.isFullscreen()
|
|| !player.isFullscreen()
|
||||||
|| bottomSheetState != BottomSheetBehavior.STATE_EXPANDED) {
|
|| bottomSheetState != BottomSheetBehavior.STATE_EXPANDED) {
|
||||||
// Apply system brightness when the player is not in fullscreen
|
// Apply system brightness when the player is not in fullscreen
|
||||||
saveCurrentAndRestoreDefaultBrightness();
|
restoreDefaultBrightness();
|
||||||
} else {
|
} else {
|
||||||
// Restore already saved brightness level
|
// Restore already saved brightness level
|
||||||
final float brightnessLevel = PlayerHelper.getScreenBrightness(activity);
|
final float brightnessLevel = PlayerHelper.getScreenBrightness(activity);
|
||||||
|
@ -171,6 +171,7 @@ public final class MainPlayer extends Service {
|
|||||||
// Android TV will handle back button in case controls will be visible
|
// Android TV will handle back button in case controls will be visible
|
||||||
// (one more additional unneeded click while the player is hidden)
|
// (one more additional unneeded click while the player is hidden)
|
||||||
playerImpl.hideControls(0, 0);
|
playerImpl.hideControls(0, 0);
|
||||||
|
playerImpl.onQueueClosed();
|
||||||
// Notification shows information about old stream but if a user selects
|
// Notification shows information about old stream but if a user selects
|
||||||
// a stream from backStack it's not actual anymore
|
// a stream from backStack it's not actual anymore
|
||||||
// So we should hide the notification at all.
|
// So we should hide the notification at all.
|
||||||
|
@ -257,6 +257,7 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||||||
} else {
|
} else {
|
||||||
getRootView().setVisibility(View.VISIBLE);
|
getRootView().setVisibility(View.VISIBLE);
|
||||||
initVideoPlayer();
|
initVideoPlayer();
|
||||||
|
onQueueClosed();
|
||||||
// Android TV: without it focus will frame the whole player
|
// Android TV: without it focus will frame the whole player
|
||||||
playPauseButton.requestFocus();
|
playPauseButton.requestFocus();
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import android.view.View;
|
|||||||
import android.view.ViewConfiguration;
|
import android.view.ViewConfiguration;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import androidx.appcompat.content.res.AppCompatResources;
|
import androidx.appcompat.content.res.AppCompatResources;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.player.BasePlayer;
|
import org.schabi.newpipe.player.BasePlayer;
|
||||||
@ -264,14 +265,19 @@ public class PlayerGestureListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Window window = parent.getWindow();
|
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 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;
|
layoutParams.screenBrightness = currentProgressPercent;
|
||||||
window.setAttributes(layoutParams);
|
window.setAttributes(layoutParams);
|
||||||
|
|
||||||
|
// Save current brightness level
|
||||||
|
PlayerHelper.setScreenBrightness(parent, currentProgressPercent);
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "onScroll().brightnessControl, "
|
Log.d(TAG, "onScroll().brightnessControl, "
|
||||||
+ "currentBrightness = " + currentProgressPercent);
|
+ "currentBrightness = " + currentProgressPercent);
|
||||||
|
@ -353,10 +353,10 @@
|
|||||||
android:id="@+id/playbackSeekBar"
|
android:id="@+id/playbackSeekBar"
|
||||||
style="@style/Widget.AppCompat.SeekBar"
|
style="@style/Widget.AppCompat.SeekBar"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:paddingBottom="4dp"
|
android:layout_marginTop="2dp"
|
||||||
android:paddingTop="8dp"
|
|
||||||
tools:progress="25"
|
tools:progress="25"
|
||||||
android:nextFocusDown="@id/screenRotationButton"
|
android:nextFocusDown="@id/screenRotationButton"
|
||||||
tools:secondaryProgress="50"/>
|
tools:secondaryProgress="50"/>
|
||||||
|
@ -352,10 +352,10 @@
|
|||||||
android:id="@+id/playbackSeekBar"
|
android:id="@+id/playbackSeekBar"
|
||||||
style="@style/Widget.AppCompat.SeekBar"
|
style="@style/Widget.AppCompat.SeekBar"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:paddingBottom="4dp"
|
android:layout_marginTop="2dp"
|
||||||
android:paddingTop="8dp"
|
|
||||||
tools:progress="25"
|
tools:progress="25"
|
||||||
tools:secondaryProgress="50"/>
|
tools:secondaryProgress="50"/>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user