Merge pull request #4223 from avently/small-fixes

Small fixes of issues with brightness, background playback, gestures
This commit is contained in:
Stypox 2020-09-05 20:51:37 +02:00 committed by GitHub
commit a801d0994f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 15 deletions

View File

@ -337,6 +337,7 @@ public class VideoDetailFragment
stopPlayerListener(); stopPlayerListener();
playerService = null; playerService = null;
player = null; player = null;
saveCurrentAndRestoreDefaultBrightness();
} }
} }
@ -425,7 +426,7 @@ public class VideoDetailFragment
if (currentWorker != null) { if (currentWorker != null) {
currentWorker.dispose(); currentWorker.dispose();
} }
setupBrightness(true); saveCurrentAndRestoreDefaultBrightness();
PreferenceManager.getDefaultSharedPreferences(getContext()) PreferenceManager.getDefaultSharedPreferences(getContext())
.edit() .edit()
.putString(getString(R.string.stream_info_selected_tab_key), .putString(getString(R.string.stream_info_selected_tab_key),
@ -439,7 +440,7 @@ public class VideoDetailFragment
activity.sendBroadcast(new Intent(ACTION_VIDEO_FRAGMENT_RESUMED)); activity.sendBroadcast(new Intent(ACTION_VIDEO_FRAGMENT_RESUMED));
setupBrightness(false); setupBrightness();
if (updateFlags != 0) { if (updateFlags != 0) {
if (!isLoading.get() && currentInfo != null) { if (!isLoading.get() && currentInfo != null) {
@ -1908,6 +1909,7 @@ public class VideoDetailFragment
@Override @Override
public void onFullscreenStateChanged(final boolean fullscreen) { public void onFullscreenStateChanged(final boolean fullscreen) {
setupBrightness();
if (playerService.getView() == null || player.getParentActivity() == null) { if (playerService.getView() == null || player.getParentActivity() == null) {
return; return;
} }
@ -2022,29 +2024,41 @@ public class VideoDetailFragment
&& player.getPlayer().getPlaybackState() != Player.STATE_IDLE; && player.getPlayer().getPlaybackState() != Player.STATE_IDLE;
} }
private void setupBrightness(final boolean save) { private void saveCurrentAndRestoreDefaultBrightness() {
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
lp.screenBrightness = -1;
activity.getWindow().setAttributes(lp);
}
private void setupBrightness() {
if (activity == null) { if (activity == null) {
return; return;
} }
final WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); final WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
if (save) { if (player == null
// Save current brightness level || !player.videoPlayerSelected()
PlayerHelper.setScreenBrightness(activity, lp.screenBrightness); || !player.isFullscreen()
|| bottomSheetState != BottomSheetBehavior.STATE_EXPANDED) {
// Restore the old brightness when fragment.onPause() called. // Apply system brightness when the player is not in fullscreen
// It means when user leaves this fragment brightness will be set to system brightness saveCurrentAndRestoreDefaultBrightness();
lp.screenBrightness = -1;
} else { } else {
// Restore already saved brightness level // Restore already saved brightness level
final float brightnessLevel = PlayerHelper.getScreenBrightness(activity); final float brightnessLevel = PlayerHelper.getScreenBrightness(activity);
if (brightnessLevel <= 0.0f && brightnessLevel > 1.0f) { if (brightnessLevel == lp.screenBrightness) {
return; return;
} }
lp.screenBrightness = brightnessLevel; lp.screenBrightness = brightnessLevel;
activity.getWindow().setAttributes(lp);
} }
activity.getWindow().setAttributes(lp);
} }
private void checkLandscape() { private void checkLandscape() {
@ -2167,6 +2181,7 @@ public class VideoDetailFragment
* @param toMain if true than the main fragment will be focused or the player otherwise * @param toMain if true than the main fragment will be focused or the player otherwise
*/ */
private void moveFocusToMainFragment(final boolean toMain) { private void moveFocusToMainFragment(final boolean toMain) {
setupBrightness();
final ViewGroup mainFragment = requireActivity().findViewById(R.id.fragment_holder); final ViewGroup mainFragment = requireActivity().findViewById(R.id.fragment_holder);
// Hamburger button steels a focus even under bottomSheet // Hamburger button steels a focus even under bottomSheet
final Toolbar toolbar = requireActivity().findViewById(R.id.toolbar); final Toolbar toolbar = requireActivity().findViewById(R.id.toolbar);
@ -2190,7 +2205,7 @@ public class VideoDetailFragment
* Bottom padding should be equal to the mini player's height in this case * Bottom padding should be equal to the mini player's height in this case
* *
* @param showMore whether main fragment should be expanded or not * @param showMore whether main fragment should be expanded or not
* */ */
private void manageSpaceAtTheBottom(final boolean showMore) { private void manageSpaceAtTheBottom(final boolean showMore) {
final int peekHeight = getResources().getDimensionPixelSize(R.dimen.mini_player_height); final int peekHeight = getResources().getDimensionPixelSize(R.dimen.mini_player_height);
final ViewGroup holder = requireActivity().findViewById(R.id.fragment_holder); final ViewGroup holder = requireActivity().findViewById(R.id.fragment_holder);

View File

@ -1339,6 +1339,11 @@ public abstract class BasePlayer implements
return; return;
} }
final StreamInfo currentInfo = currentMetadata.getMetadata(); final StreamInfo currentInfo = currentMetadata.getMetadata();
if (playQueue != null) {
// Save current position. It will help to restore this position once a user
// wants to play prev or next stream from the queue
playQueue.setRecovery(playQueue.getIndex(), simpleExoPlayer.getContentPosition());
}
savePlaybackState(currentInfo, simpleExoPlayer.getCurrentPosition()); savePlaybackState(currentInfo, simpleExoPlayer.getCurrentPosition());
} }

View File

@ -184,6 +184,9 @@ public final class MainPlayer extends Service {
@Override @Override
public void onTaskRemoved(final Intent rootIntent) { public void onTaskRemoved(final Intent rootIntent) {
super.onTaskRemoved(rootIntent); super.onTaskRemoved(rootIntent);
if (!playerImpl.videoPlayerSelected()) {
return;
}
onDestroy(); onDestroy();
// Unload from memory completely // Unload from memory completely
Runtime.getRuntime().halt(0); Runtime.getRuntime().halt(0);

View File

@ -202,7 +202,8 @@ public class PlayerGestureListener
private boolean onScrollInMain(final MotionEvent initialEvent, final MotionEvent movingEvent, private boolean onScrollInMain(final MotionEvent initialEvent, final MotionEvent movingEvent,
final float distanceX, final float distanceY) { final float distanceX, final float distanceY) {
if (!isVolumeGestureEnabled && !isBrightnessGestureEnabled) { if ((!isVolumeGestureEnabled && !isBrightnessGestureEnabled)
|| !playerImpl.isFullscreen()) {
return false; return false;
} }