Skip to content

Commit

Permalink
feat: Reduce motion player setting (#121)
Browse files Browse the repository at this point in the history
* Added a reduce animation setting for player control to disable slide out

* Modified text and put into values.xml

* lint

---------

Co-authored-by: AbdallahMehiz <[email protected]>
  • Loading branch information
Anthonyy232 and abdallahmehiz authored Oct 20, 2024
1 parent 280ead0 commit 8a6b3f0
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
148 changes: 108 additions & 40 deletions app/src/main/java/live/mehiz/mpvkt/ui/player/controls/PlayerControls.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
},
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
<string name="privacy_policy_url" translatable="false">https://abdallahmehiz.github.io/mpvKt/privacy_policy.html</string>
<string name="control_player_with_media_buttons">Control player with media buttons</string>
<string name="swap_the_volume_and_brightness_slider">Swap volume and brightness slider</string>
<string name="reduce_player_animation">Reduce player animation</string>
<string name="hide_player_control_time">Hide player control time</string>

<plurals name="plural_items">
Expand Down

0 comments on commit 8a6b3f0

Please sign in to comment.