1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 19:12:45 +01:00

Small fixes of issues with old devices support, brightness, etc

This commit is contained in:
Avently 2020-09-11 20:52:38 +03:00
parent 2215ce58a4
commit 883e4fcd7c
6 changed files with 55 additions and 30 deletions

View File

@ -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<? extends StackItem>) serializable);
final String stackCacheKey = savedState.getString(STACK_KEY);
if (stackCacheKey != null) {
final LinkedList<StackItem> 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);

View File

@ -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.

View File

@ -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();
}

View File

@ -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);

View File

@ -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"/>

View File

@ -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"/>