From 8a6b3f085c65fe849298c892cde2a1db963cbc5d Mon Sep 17 00:00:00 2001 From: Anthony La Date: Sun, 20 Oct 2024 05:58:12 -0700 Subject: [PATCH] feat: Reduce motion player setting (#121) * Added a reduce animation setting for player control to disable slide out * Modified text and put into values.xml * lint --------- Co-authored-by: AbdallahMehiz --- .../mpvkt/preferences/PlayerPreferences.kt | 1 + .../ui/player/controls/PlayerControls.kt | 148 +++++++++++++----- .../ui/preferences/PlayerPreferencesScreen.kt | 6 + app/src/main/res/values/strings.xml | 1 + 4 files changed, 116 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/live/mehiz/mpvkt/preferences/PlayerPreferences.kt b/app/src/main/java/live/mehiz/mpvkt/preferences/PlayerPreferences.kt index cd4f2b2..8480b89 100644 --- a/app/src/main/java/live/mehiz/mpvkt/preferences/PlayerPreferences.kt +++ b/app/src/main/java/live/mehiz/mpvkt/preferences/PlayerPreferences.kt @@ -45,6 +45,7 @@ class PlayerPreferences( val allowGesturesInPanels = preferenceStore.getBoolean("allow_gestures_in_panels") val showSystemStatusBar = preferenceStore.getBoolean("show_system_status_bar") + val reduceMotion = preferenceStore.getBoolean("reduce_motion") val playerTimeToDisappear = preferenceStore.getInt("player_time_to_disappear", 4000) val allowHeadsetControl = preferenceStore.getBoolean("allow_headset_control", true) } diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/PlayerControls.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/PlayerControls.kt index 02f4d3a..fae4134 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/PlayerControls.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/PlayerControls.kt @@ -1,5 +1,8 @@ package live.mehiz.mpvkt.ui.player.controls +import android.R.attr.bottom +import android.R.attr.end +import android.R.attr.top import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.core.FastOutSlowInEasing import androidx.compose.animation.core.FiniteAnimationSpec @@ -153,6 +156,7 @@ fun PlayerControls( val volume by viewModel.currentVolume.collectAsState() val mpvVolume by viewModel.currentMPVVolume.collectAsState() val swapVolumeAndBrightness by playerPreferences.swapVolumeAndBrightness.collectAsState() + val reduceMotion by playerPreferences.reduceMotion.collectAsState() LaunchedEffect(volume, mpvVolume, isVolumeSliderShown) { delay(2000) @@ -164,16 +168,28 @@ fun PlayerControls( } AnimatedVisibility( isBrightnessSliderShown, - enter = slideInHorizontally(playerControlsEnterAnimationSpec()) { - if (swapVolumeAndBrightness) -it else it - } + fadeIn( - playerControlsEnterAnimationSpec(), - ), - exit = slideOutHorizontally(playerControlsExitAnimationSpec()) { - if (swapVolumeAndBrightness) -it else it - } + fadeOut( - playerControlsExitAnimationSpec(), - ), + enter = + if (!reduceMotion) { + slideInHorizontally(playerControlsEnterAnimationSpec()) { + if (swapVolumeAndBrightness) -it else it + } + + fadeIn( + playerControlsEnterAnimationSpec(), + ) + } else { + fadeIn(playerControlsEnterAnimationSpec()) + }, + exit = + if (!reduceMotion) { + slideOutHorizontally(playerControlsExitAnimationSpec()) { + if (swapVolumeAndBrightness) -it else it + } + + fadeOut( + playerControlsExitAnimationSpec(), + ) + } else { + fadeOut(playerControlsExitAnimationSpec()) + }, modifier = Modifier.constrainAs(brightnessSlider) { if (swapVolumeAndBrightness) { start.linkTo(parent.start, spacing.medium) @@ -187,16 +203,28 @@ fun PlayerControls( AnimatedVisibility( isVolumeSliderShown, - enter = slideInHorizontally(playerControlsEnterAnimationSpec()) { - if (swapVolumeAndBrightness) it else -it - } + fadeIn( - playerControlsEnterAnimationSpec(), - ), - exit = slideOutHorizontally(playerControlsExitAnimationSpec()) { - if (swapVolumeAndBrightness) it else -it - } + fadeOut( - playerControlsExitAnimationSpec(), - ), + enter = + if (!reduceMotion) { + slideInHorizontally(playerControlsEnterAnimationSpec()) { + if (swapVolumeAndBrightness) it else -it + } + + fadeIn( + playerControlsEnterAnimationSpec(), + ) + } else { + fadeIn(playerControlsEnterAnimationSpec()) + }, + exit = + if (!reduceMotion) { + slideOutHorizontally(playerControlsExitAnimationSpec()) { + if (swapVolumeAndBrightness) it else -it + } + + fadeOut( + playerControlsExitAnimationSpec(), + ) + } else { + fadeOut(playerControlsExitAnimationSpec()) + }, modifier = Modifier.constrainAs(volumeSlider) { if (swapVolumeAndBrightness) { end.linkTo(parent.end, spacing.medium) @@ -305,10 +333,18 @@ fun PlayerControls( } AnimatedVisibility( visible = (controlsShown || seekBarShown) && !areControlsLocked, - enter = slideInVertically(playerControlsEnterAnimationSpec()) { it } + - fadeIn(playerControlsEnterAnimationSpec()), - exit = slideOutVertically(playerControlsExitAnimationSpec()) { it } + - fadeOut(playerControlsExitAnimationSpec()), + enter = if (!reduceMotion) { + slideInVertically(playerControlsEnterAnimationSpec()) { it } + + fadeIn(playerControlsEnterAnimationSpec()) + } else { + fadeIn(playerControlsEnterAnimationSpec()) + }, + exit = if (!reduceMotion) { + slideOutVertically(playerControlsExitAnimationSpec()) { it } + + fadeOut(playerControlsExitAnimationSpec()) + } else { + fadeOut(playerControlsExitAnimationSpec()) + }, modifier = Modifier.constrainAs(seekbar) { bottom.linkTo(parent.bottom, spacing.medium) }, @@ -334,10 +370,18 @@ fun PlayerControls( } AnimatedVisibility( controlsShown && !areControlsLocked, - enter = slideInHorizontally(playerControlsEnterAnimationSpec()) { -it } + - fadeIn(playerControlsEnterAnimationSpec()), - exit = slideOutHorizontally(playerControlsExitAnimationSpec()) { -it } + - fadeOut(playerControlsExitAnimationSpec()), + enter = if (!reduceMotion) { + slideInHorizontally(playerControlsEnterAnimationSpec()) { -it } + + fadeIn(playerControlsEnterAnimationSpec()) + } else { + fadeIn(playerControlsEnterAnimationSpec()) + }, + exit = if (!reduceMotion) { + slideOutHorizontally(playerControlsExitAnimationSpec()) { -it } + + fadeOut(playerControlsExitAnimationSpec()) + } else { + fadeOut(playerControlsExitAnimationSpec()) + }, modifier = Modifier.constrainAs(topLeftControls) { top.linkTo(parent.top, spacing.medium) start.linkTo(parent.start) @@ -348,10 +392,18 @@ fun PlayerControls( // Top right controls AnimatedVisibility( controlsShown && !areControlsLocked, - enter = slideInHorizontally(playerControlsEnterAnimationSpec()) { it } + - fadeIn(playerControlsEnterAnimationSpec()), - exit = slideOutHorizontally(playerControlsExitAnimationSpec()) { it } + - fadeOut(playerControlsExitAnimationSpec()), + enter = if (!reduceMotion) { + slideInHorizontally(playerControlsEnterAnimationSpec()) { it } + + fadeIn(playerControlsEnterAnimationSpec()) + } else { + fadeIn(playerControlsEnterAnimationSpec()) + }, + exit = if (!reduceMotion) { + slideOutHorizontally(playerControlsExitAnimationSpec()) { it } + + fadeOut(playerControlsExitAnimationSpec()) + } else { + fadeOut(playerControlsExitAnimationSpec()) + }, modifier = Modifier.constrainAs(topRightControls) { top.linkTo(parent.top, spacing.medium) end.linkTo(parent.end) @@ -360,10 +412,18 @@ fun PlayerControls( // Bottom right controls AnimatedVisibility( controlsShown && !areControlsLocked, - enter = slideInHorizontally(playerControlsEnterAnimationSpec()) { it } + - fadeIn(playerControlsEnterAnimationSpec()), - exit = slideOutHorizontally(playerControlsExitAnimationSpec()) { it } + - fadeOut(playerControlsExitAnimationSpec()), + enter = if (!reduceMotion) { + slideInHorizontally(playerControlsEnterAnimationSpec()) { it } + + fadeIn(playerControlsEnterAnimationSpec()) + } else { + fadeIn(playerControlsEnterAnimationSpec()) + }, + exit = if (!reduceMotion) { + slideOutHorizontally(playerControlsExitAnimationSpec()) { it } + + fadeOut(playerControlsExitAnimationSpec()) + } else { + fadeOut(playerControlsExitAnimationSpec()) + }, modifier = Modifier.constrainAs(bottomRightControls) { bottom.linkTo(seekbar.top) end.linkTo(seekbar.end) @@ -372,10 +432,18 @@ fun PlayerControls( // Bottom left controls AnimatedVisibility( controlsShown && !areControlsLocked, - enter = slideInHorizontally(playerControlsEnterAnimationSpec()) { -it } + - fadeIn(playerControlsEnterAnimationSpec()), - exit = slideOutHorizontally(playerControlsExitAnimationSpec()) { -it } + - fadeOut(playerControlsExitAnimationSpec()), + enter = if (!reduceMotion) { + slideInHorizontally(playerControlsEnterAnimationSpec()) { -it } + + fadeIn(playerControlsEnterAnimationSpec()) + } else { + fadeIn(playerControlsEnterAnimationSpec()) + }, + exit = if (!reduceMotion) { + slideOutHorizontally(playerControlsExitAnimationSpec()) { -it } + + fadeOut(playerControlsExitAnimationSpec()) + } else { + fadeOut(playerControlsExitAnimationSpec()) + }, modifier = Modifier.constrainAs(bottomLeftControls) { bottom.linkTo(seekbar.top) start.linkTo(seekbar.start) diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/preferences/PlayerPreferencesScreen.kt b/app/src/main/java/live/mehiz/mpvkt/ui/preferences/PlayerPreferencesScreen.kt index 8657967..02b46cf 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/preferences/PlayerPreferencesScreen.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/preferences/PlayerPreferencesScreen.kt @@ -212,6 +212,12 @@ object PlayerPreferencesScreen : Screen() { onValueChange = preferences.showSystemStatusBar::set, title = { Text(stringResource(R.string.pref_player_controls_show_status_bar)) }, ) + val reduceMotion by preferences.reduceMotion.collectAsState() + SwitchPreference( + value = reduceMotion, + onValueChange = preferences.reduceMotion::set, + title = { Text(stringResource(R.string.reduce_player_animation)) }, + ) val playerTimeToDisappear by preferences.playerTimeToDisappear.collectAsState() ListPreference( value = playerTimeToDisappear, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ae2c2fa..25d68f0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -212,6 +212,7 @@ https://abdallahmehiz.github.io/mpvKt/privacy_policy.html Control player with media buttons Swap volume and brightness slider + Reduce player animation Hide player control time