mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Handle d-pad skipping for RTL
This commit is contained in:
parent
b08497440f
commit
513a217c1c
3 changed files with 45 additions and 26 deletions
|
|
@ -45,7 +45,9 @@ import androidx.compose.ui.input.key.KeyEventType
|
||||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||||
import androidx.compose.ui.input.key.type
|
import androidx.compose.ui.input.key.type
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||||
import androidx.media3.common.util.UnstableApi
|
import androidx.media3.common.util.UnstableApi
|
||||||
|
|
@ -106,9 +108,11 @@ fun NowPlayingPage(
|
||||||
).value.appPreferences
|
).value.appPreferences
|
||||||
val musicPrefs = preferences.musicPreferences
|
val musicPrefs = preferences.musicPreferences
|
||||||
|
|
||||||
|
val isLtr = LocalLayoutDirection.current == LayoutDirection.Ltr
|
||||||
val keyHandler =
|
val keyHandler =
|
||||||
remember(preferences) {
|
remember(isLtr, preferences) {
|
||||||
PlaybackKeyHandler(
|
PlaybackKeyHandler(
|
||||||
|
isLtr = isLtr,
|
||||||
player = player,
|
player = player,
|
||||||
controlsEnabled = true,
|
controlsEnabled = true,
|
||||||
skipWithLeftRight = false,
|
skipWithLeftRight = false,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import kotlin.time.Duration
|
||||||
* Handles [KeyEvent]s during playback on [PlaybackPage]
|
* Handles [KeyEvent]s during playback on [PlaybackPage]
|
||||||
*/
|
*/
|
||||||
class PlaybackKeyHandler(
|
class PlaybackKeyHandler(
|
||||||
|
private val isLtr: Boolean,
|
||||||
private val player: Player,
|
private val player: Player,
|
||||||
private val controlsEnabled: Boolean,
|
private val controlsEnabled: Boolean,
|
||||||
private val skipWithLeftRight: Boolean,
|
private val skipWithLeftRight: Boolean,
|
||||||
|
|
@ -47,11 +48,21 @@ class PlaybackKeyHandler(
|
||||||
if (isDirectionalDpad(it) || isEnterKey(it) || isControllerMedia(it)) {
|
if (isDirectionalDpad(it) || isEnterKey(it) || isControllerMedia(it)) {
|
||||||
if (!controllerViewState.controlsVisible) {
|
if (!controllerViewState.controlsVisible) {
|
||||||
if (skipWithLeftRight && isSkipBack(it)) {
|
if (skipWithLeftRight && isSkipBack(it)) {
|
||||||
updateSkipIndicator(-seekBack.inWholeMilliseconds)
|
if (isLtr) {
|
||||||
player.seekBack(seekBack)
|
updateSkipIndicator(-seekBack.inWholeMilliseconds)
|
||||||
|
player.seekBack(seekBack)
|
||||||
|
} else {
|
||||||
|
updateSkipIndicator(seekForward.inWholeMilliseconds)
|
||||||
|
player.seekForward(seekForward)
|
||||||
|
}
|
||||||
} else if (skipWithLeftRight && isSkipForward(it)) {
|
} else if (skipWithLeftRight && isSkipForward(it)) {
|
||||||
player.seekForward(seekForward)
|
if (isLtr) {
|
||||||
updateSkipIndicator(seekForward.inWholeMilliseconds)
|
player.seekForward(seekForward)
|
||||||
|
updateSkipIndicator(seekForward.inWholeMilliseconds)
|
||||||
|
} else {
|
||||||
|
player.seekBack(seekBack)
|
||||||
|
updateSkipIndicator(seekBack.inWholeMilliseconds)
|
||||||
|
}
|
||||||
} else if (oneClickPause && isEnterKey(it)) {
|
} else if (oneClickPause && isEnterKey(it)) {
|
||||||
val wasPlaying = player.isPlaying
|
val wasPlaying = player.isPlaying
|
||||||
Util.handlePlayPauseButtonAction(player)
|
Util.handlePlayPauseButtonAction(player)
|
||||||
|
|
@ -127,7 +138,7 @@ class PlaybackKeyHandler(
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
val isBack = isSkipBack(event)
|
val isBack = if (isLtr) isSkipBack(event) else isSkipForward(event)
|
||||||
return when (event.type) {
|
return when (event.type) {
|
||||||
KeyEventType.KeyDown -> {
|
KeyEventType.KeyDown -> {
|
||||||
val repeatCount = event.nativeKeyEvent.repeatCount
|
val repeatCount = event.nativeKeyEvent.repeatCount
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.github.damontecres.wholphin.ui.playback
|
package com.github.damontecres.wholphin.ui.playback
|
||||||
|
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
|
|
@ -48,8 +47,10 @@ import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.layout.onSizeChanged
|
import androidx.compose.ui.layout.onSizeChanged
|
||||||
import androidx.compose.ui.platform.LocalConfiguration
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||||
import androidx.compose.ui.text.intl.Locale
|
import androidx.compose.ui.text.intl.Locale
|
||||||
import androidx.compose.ui.unit.IntSize
|
import androidx.compose.ui.unit.IntSize
|
||||||
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
|
|
@ -240,26 +241,29 @@ fun PlaybackPageContent(
|
||||||
skipIndicatorDuration += delta
|
skipIndicatorDuration += delta
|
||||||
skipPosition = player.currentPosition
|
skipPosition = player.currentPosition
|
||||||
}
|
}
|
||||||
|
val isLtr = LocalLayoutDirection.current == LayoutDirection.Ltr
|
||||||
val keyHandler =
|
val keyHandler =
|
||||||
PlaybackKeyHandler(
|
remember(isLtr, preferences) {
|
||||||
player = player,
|
PlaybackKeyHandler(
|
||||||
controlsEnabled = nextUp == null,
|
isLtr = isLtr,
|
||||||
skipWithLeftRight = true,
|
player = player,
|
||||||
seekForward = preferences.appPreferences.playbackPreferences.skipForwardMs.milliseconds,
|
controlsEnabled = nextUp == null,
|
||||||
seekBack = preferences.appPreferences.playbackPreferences.skipBackMs.milliseconds,
|
skipWithLeftRight = true,
|
||||||
getDurationMs = { player.duration.coerceAtLeast(0L) },
|
seekForward = preferences.appPreferences.playbackPreferences.skipForwardMs.milliseconds,
|
||||||
controllerViewState = controllerViewState,
|
seekBack = preferences.appPreferences.playbackPreferences.skipBackMs.milliseconds,
|
||||||
updateSkipIndicator = updateSkipIndicator,
|
getDurationMs = { player.duration.coerceAtLeast(0L) },
|
||||||
skipBackOnResume = preferences.appPreferences.playbackPreferences.skipBackOnResume,
|
controllerViewState = controllerViewState,
|
||||||
onInteraction = viewModel::reportInteraction,
|
updateSkipIndicator = updateSkipIndicator,
|
||||||
oneClickPause = preferences.appPreferences.playbackPreferences.oneClickPause,
|
skipBackOnResume = preferences.appPreferences.playbackPreferences.skipBackOnResume,
|
||||||
onStop = {
|
onInteraction = viewModel::reportInteraction,
|
||||||
player.stop()
|
oneClickPause = preferences.appPreferences.playbackPreferences.oneClickPause,
|
||||||
viewModel.navigationManager.goBack()
|
onStop = {
|
||||||
},
|
player.stop()
|
||||||
onPlaybackDialogTypeClick = { playbackDialog = it },
|
viewModel.navigationManager.goBack()
|
||||||
)
|
},
|
||||||
|
onPlaybackDialogTypeClick = { playbackDialog = it },
|
||||||
|
)
|
||||||
|
}
|
||||||
val onPlaybackActionClick: (PlaybackAction) -> Unit = {
|
val onPlaybackActionClick: (PlaybackAction) -> Unit = {
|
||||||
when (it) {
|
when (it) {
|
||||||
is PlaybackAction.PlaybackSpeed -> {
|
is PlaybackAction.PlaybackSpeed -> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue