From 73ed40bc6ba5e25198b34b57b9c257c19273f9a0 Mon Sep 17 00:00:00 2001 From: AbdallahMehiz Date: Sat, 17 Aug 2024 09:40:35 +0100 Subject: [PATCH] feat: rotation button --- .../mehiz/mpvkt/ui/player/PlayerViewModel.kt | 20 ++++++++++++++++++- .../controls/BottomLeftPlayerControls.kt | 5 +++++ .../controls/components/ControlsButton.kt | 3 +-- .../controls/components/CurrentChapter.kt | 2 +- .../controls/components/PlayerUpdates.kt | 4 +++- .../components/panels/AudioDelayPanel.kt | 3 ++- .../components/panels/SubtitleDelayPanel.kt | 9 +++++---- .../panels/SubtitleSettingsColorsCard.kt | 9 +++++---- .../panels/SubtitleSettingsPanel.kt | 5 +++-- .../panels/SubtitleSettingsTypographyCard.kt | 12 ++++++----- 10 files changed, 51 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt index f7adb1c..face8d8 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt @@ -1,5 +1,6 @@ package live.mehiz.mpvkt.ui.player +import android.content.pm.ActivityInfo import android.media.AudioManager import android.net.Uri import android.os.Build @@ -67,7 +68,7 @@ class PlayerViewModel( val isVolumeSliderShown = MutableStateFlow(false) val currentBrightness = MutableStateFlow( Settings.System.getFloat(activity.contentResolver, Settings.System.SCREEN_BRIGHTNESS) - .normalize(0f, 255f, 0f, 1f) + .normalize(0f, 255f, 0f, 1f), ) val currentVolume = MutableStateFlow(activity.audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)) @@ -351,6 +352,23 @@ class PlayerViewModel( } } } + + fun cycleScreenRotations() { + activity.requestedOrientation = when (activity.requestedOrientation) { + ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, + ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE, + ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, + -> { + playerPreferences.orientation.set(PlayerOrientation.SensorPortrait) + ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT + } + + else -> { + playerPreferences.orientation.set(PlayerOrientation.SensorLandscape) + ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE + } + } + } } data class Track( diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/BottomLeftPlayerControls.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/BottomLeftPlayerControls.kt index 626a7bf..6308c3c 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/BottomLeftPlayerControls.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/BottomLeftPlayerControls.kt @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Lock +import androidx.compose.material.icons.filled.ScreenRotation import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue @@ -37,6 +38,10 @@ fun BottomLeftPlayerControls(modifier: Modifier = Modifier) { Icons.Default.Lock, onClick = { viewModel.lockControls() }, ) + ControlsButton( + icon = Icons.Default.ScreenRotation, + onClick = { viewModel.cycleScreenRotations() } + ) val defaultSpeed by playerPreferences.defaultSpeed.collectAsState() ControlsButton( text = stringResource(R.string.player_speed, defaultSpeed), diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/ControlsButton.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/ControlsButton.kt index e9ffca6..54b4505 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/ControlsButton.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/ControlsButton.kt @@ -19,7 +19,6 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp import live.mehiz.mpvkt.ui.player.controls.LocalPlayerButtonsClickEvent import live.mehiz.mpvkt.ui.theme.spacing @@ -82,7 +81,7 @@ fun ControlsButton( interactionSource = interactionSource, indication = rememberRipple(), ) - .padding(16.dp), + .padding(MaterialTheme.spacing.medium), ) { Text( text, diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/CurrentChapter.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/CurrentChapter.kt index dc6059b..07e2ef8 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/CurrentChapter.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/CurrentChapter.kt @@ -66,7 +66,7 @@ fun CurrentChapter( imageVector = Icons.Default.Bookmarks, contentDescription = null, modifier = Modifier - .padding(end = 8.dp) + .padding(end = MaterialTheme.spacing.smaller) .size(16.dp), tint = MaterialTheme.colorScheme.onBackground ) diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/PlayerUpdates.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/PlayerUpdates.kt index 677e305..5ede5e2 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/PlayerUpdates.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/PlayerUpdates.kt @@ -9,6 +9,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.DoubleArrow import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -19,6 +20,7 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import live.mehiz.mpvkt.ui.theme.spacing @Composable fun PlayerUpdate( @@ -29,7 +31,7 @@ fun PlayerUpdate( modifier = modifier .clip(RoundedCornerShape(16.dp)) .background(Color.Black.copy(0.4f)) - .padding(vertical = 8.dp, horizontal = 16.dp) + .padding(vertical = MaterialTheme.spacing.smaller, horizontal = MaterialTheme.spacing.medium) .animateContentSize(), contentAlignment = Alignment.Center, ) { content() } diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/AudioDelayPanel.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/AudioDelayPanel.kt index 6144e7b..bd7a18f 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/AudioDelayPanel.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/AudioDelayPanel.kt @@ -26,6 +26,7 @@ import androidx.constraintlayout.compose.ConstraintLayout import `is`.xyz.mpv.MPVLib import live.mehiz.mpvkt.R import live.mehiz.mpvkt.preferences.AudioPreferences +import live.mehiz.mpvkt.ui.theme.spacing import org.koin.compose.koinInject @Composable @@ -38,7 +39,7 @@ fun AudioDelayPanel( ConstraintLayout( modifier = modifier .fillMaxSize() - .padding(16.dp), + .padding(MaterialTheme.spacing.medium), ) { val delayControlCard = createRef() diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleDelayPanel.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleDelayPanel.kt index cba516b..cd5fa27 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleDelayPanel.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleDelayPanel.kt @@ -43,6 +43,7 @@ import `is`.xyz.mpv.MPVLib import live.mehiz.mpvkt.R import live.mehiz.mpvkt.preferences.SubtitlesPreferences import live.mehiz.mpvkt.presentation.components.OutlinedNumericChooser +import live.mehiz.mpvkt.ui.theme.spacing import org.koin.compose.koinInject import kotlin.math.round @@ -172,8 +173,8 @@ fun DelayCard( colors = SubtitleSettingsCardColors(), ) { Column( - Modifier.padding(horizontal = 16.dp, vertical = 8.dp), - verticalArrangement = Arrangement.spacedBy(8.dp), + Modifier.padding(horizontal = MaterialTheme.spacing.medium, vertical = MaterialTheme.spacing.smaller), + verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.smaller), ) { title() OutlinedNumericChooser( @@ -189,7 +190,7 @@ fun DelayCard( modifier = Modifier.animateContentSize() ) { extraSettings() } Row( - horizontalArrangement = Arrangement.spacedBy(8.dp), + horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.smaller), ) { Button( onClick = onApply, @@ -214,7 +215,7 @@ fun SubtitleDelayTitle( ) { Row( verticalAlignment = Alignment.Bottom, - horizontalArrangement = Arrangement.spacedBy(4.dp), + horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.extraSmall), modifier = modifier.fillMaxWidth(), ) { Text( diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleSettingsColorsCard.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleSettingsColorsCard.kt index 66c99ac..fccb6c7 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleSettingsColorsCard.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleSettingsColorsCard.kt @@ -18,6 +18,7 @@ import androidx.compose.material.icons.filled.FormatColorText import androidx.compose.material.icons.filled.Palette import androidx.compose.material3.Icon import androidx.compose.material3.IconToggleButton +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable @@ -31,7 +32,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp import androidx.core.graphics.alpha import androidx.core.graphics.blue import androidx.core.graphics.green @@ -44,6 +44,7 @@ import live.mehiz.mpvkt.preferences.preference.collectAsState import live.mehiz.mpvkt.preferences.preference.deleteAndGet import live.mehiz.mpvkt.presentation.components.ExpandableCard import live.mehiz.mpvkt.presentation.components.TintedSliderItem +import live.mehiz.mpvkt.ui.theme.spacing import org.koin.compose.koinInject @Composable @@ -57,7 +58,7 @@ fun SubtitleSettingsColorsCard( onExpand = { isExpanded = !isExpanded }, title = { Row( - horizontalArrangement = Arrangement.spacedBy(16.dp), + horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.medium), ) { Icon(Icons.Default.Palette, null) Text(stringResource(R.string.player_sheets_sub_colors_card_title)) @@ -75,7 +76,7 @@ fun SubtitleSettingsColorsCard( modifier = Modifier .fillMaxWidth() .horizontalScroll(rememberScrollState()) - .padding(start = 4.dp, end = 16.dp), + .padding(start = MaterialTheme.spacing.extraSmall, end = MaterialTheme.spacing.medium), ) { SubColorType.entries.forEach { type -> IconToggleButton( @@ -102,7 +103,7 @@ fun SubtitleSettingsColorsCard( Text(stringResource(currentColorType.titleRes)) Spacer(Modifier.weight(1f)) TextButton(onClick = { resetColors(preferences) }) { - Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) { + Row(horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.extraSmall)) { Icon(Icons.Default.FormatColorReset, null) Text(stringResource(R.string.generic_reset)) } diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleSettingsPanel.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleSettingsPanel.kt index d583b53..a1a14b0 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleSettingsPanel.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleSettingsPanel.kt @@ -37,6 +37,7 @@ import androidx.compose.ui.graphics.Shadow import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.unit.dp import androidx.constraintlayout.compose.ConstraintLayout +import live.mehiz.mpvkt.ui.theme.spacing @OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class) @Composable @@ -65,7 +66,7 @@ fun SubtitleSettingsPanel( top.linkTo(parent.top, 32.dp) start.linkTo(parent.start) }, - verticalArrangement = Arrangement.spacedBy(4.dp) + verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.extraSmall) ) { TopAppBar( title = { @@ -95,7 +96,7 @@ fun SubtitleSettingsPanel( } else { Column( horizontalAlignment = Alignment.Start, - verticalArrangement = Arrangement.spacedBy(8.dp), + verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.smaller), modifier = Modifier .constrainAs(subSettingsCards) { top.linkTo(parent.top) diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleSettingsTypographyCard.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleSettingsTypographyCard.kt index acea16c..e896a1f 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleSettingsTypographyCard.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/panels/SubtitleSettingsTypographyCard.kt @@ -22,6 +22,7 @@ import androidx.compose.material.icons.filled.FormatSize import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.Icon import androidx.compose.material3.IconToggleButton +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable @@ -49,6 +50,7 @@ import live.mehiz.mpvkt.preferences.preference.deleteAndGet import live.mehiz.mpvkt.presentation.components.ExpandableCard import live.mehiz.mpvkt.presentation.components.ExposedTextDropDownMenu import live.mehiz.mpvkt.presentation.components.SliderItem +import live.mehiz.mpvkt.ui.theme.spacing import org.koin.compose.koinInject @SuppressLint("MutableCollectionMutableState") @@ -88,7 +90,7 @@ fun SubtitleSettingsTypographyCard( onExpand = { isExpanded = !isExpanded }, title = { Row( - horizontalArrangement = Arrangement.spacedBy(16.dp), + horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.medium), ) { Icon(Icons.Default.FormatColorText, null) Text(stringResource(R.string.player_sheets_sub_typography_card_title)) @@ -105,7 +107,7 @@ fun SubtitleSettingsTypographyCard( Modifier .fillMaxWidth() .horizontalScroll(rememberScrollState()) - .padding(start = 4.dp, end = 16.dp), + .padding(start = MaterialTheme.spacing.extraSmall, end = MaterialTheme.spacing.medium), verticalAlignment = Alignment.CenterVertically, ) { IconToggleButton( @@ -152,7 +154,7 @@ fun SubtitleSettingsTypographyCard( } Spacer(Modifier.weight(1f)) TextButton(onClick = { resetTypography(preferences) }) { - Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) { + Row(horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.extraSmall)) { Icon(Icons.Default.FormatClear, null) Text(stringResource(R.string.generic_reset)) } @@ -160,8 +162,8 @@ fun SubtitleSettingsTypographyCard( } val font by preferences.font.collectAsState() Row( - modifier = Modifier.padding(horizontal = 16.dp), - horizontalArrangement = Arrangement.spacedBy(16.dp), + modifier = Modifier.padding(horizontal = MaterialTheme.spacing.medium), + horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.medium), verticalAlignment = Alignment.CenterVertically, ) { Icon(