From 43c1a5a0cd8e0481750b65fd50e40c57476162bb Mon Sep 17 00:00:00 2001 From: Zyrouge Date: Sun, 1 Dec 2024 16:53:54 +0530 Subject: [PATCH] feat: keep screen awake on lyrics (#433) --- .phrasey/schema.toml | 3 +++ .../zyrouge/symphony/services/Settings.kt | 1 + .../symphony/ui/components/KeepScreenAwake.kt | 17 +++++++++++++++++ .../github/zyrouge/symphony/ui/view/Lyrics.kt | 9 +++++++++ .../symphony/ui/view/nowPlaying/BodyCover.kt | 7 +++++++ .../ui/view/settings/NowPlayingSettingsView.kt | 15 +++++++++++++++ i18n/en.toml | 1 + 7 files changed, 53 insertions(+) create mode 100644 app/src/main/java/io/github/zyrouge/symphony/ui/components/KeepScreenAwake.kt diff --git a/.phrasey/schema.toml b/.phrasey/schema.toml index a6a3a5e7..55e218a9 100644 --- a/.phrasey/schema.toml +++ b/.phrasey/schema.toml @@ -753,3 +753,6 @@ name = "GridColumns" [[keys]] name = "CaseSensitiveSorting" + +[[keys]] +name = "KeepScreenAwakeOnLyrics" diff --git a/app/src/main/java/io/github/zyrouge/symphony/services/Settings.kt b/app/src/main/java/io/github/zyrouge/symphony/services/Settings.kt index 32267bb5..67d39b54 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/services/Settings.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/services/Settings.kt @@ -327,6 +327,7 @@ class Settings(private val symphony: Symphony) { val useMetaphony = BooleanEntry("use_metaphony", true) val gaplessPlayback = BooleanEntry("gapless_playback", true) val caseSensitiveSorting = BooleanEntry("case_sensitive_sorting", false) + val lyricsKeepScreenAwake = BooleanEntry("lyrics_keep_screen_awake", true) private fun getSharedPreferences() = symphony.applicationContext .getSharedPreferences("settings", Context.MODE_PRIVATE) diff --git a/app/src/main/java/io/github/zyrouge/symphony/ui/components/KeepScreenAwake.kt b/app/src/main/java/io/github/zyrouge/symphony/ui/components/KeepScreenAwake.kt new file mode 100644 index 00000000..4f6e9ab4 --- /dev/null +++ b/app/src/main/java/io/github/zyrouge/symphony/ui/components/KeepScreenAwake.kt @@ -0,0 +1,17 @@ +package io.github.zyrouge.symphony.ui.components + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.ui.platform.LocalView + +@Composable +fun KeepScreenAwake() { + val view = LocalView.current + + DisposableEffect(Unit) { + view.keepScreenOn = true + onDispose { + view.keepScreenOn = false + } + } +} diff --git a/app/src/main/java/io/github/zyrouge/symphony/ui/view/Lyrics.kt b/app/src/main/java/io/github/zyrouge/symphony/ui/view/Lyrics.kt index 025c7724..d2ed1434 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/ui/view/Lyrics.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/ui/view/Lyrics.kt @@ -20,11 +20,14 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import io.github.zyrouge.symphony.ui.components.IconButtonPlaceholder +import io.github.zyrouge.symphony.ui.components.KeepScreenAwake import io.github.zyrouge.symphony.ui.components.LyricsText import io.github.zyrouge.symphony.ui.components.TimedContentTextStyle import io.github.zyrouge.symphony.ui.components.TopAppBarMinimalTitle @@ -41,6 +44,12 @@ object LyricsViewRoute @OptIn(ExperimentalMaterial3Api::class) @Composable fun LyricsView(context: ViewContext) { + val keepScreenAwake by context.symphony.settings.lyricsKeepScreenAwake.flow.collectAsState() + + if (keepScreenAwake) { + KeepScreenAwake() + } + NowPlayingObserver(context) { data -> Scaffold( modifier = Modifier.fillMaxSize(), diff --git a/app/src/main/java/io/github/zyrouge/symphony/ui/view/nowPlaying/BodyCover.kt b/app/src/main/java/io/github/zyrouge/symphony/ui/view/nowPlaying/BodyCover.kt index 6ab207b2..d6ae3eaf 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/ui/view/nowPlaying/BodyCover.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/ui/view/nowPlaying/BodyCover.kt @@ -27,6 +27,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.min import coil.compose.AsyncImage import io.github.zyrouge.symphony.services.groove.Song +import io.github.zyrouge.symphony.ui.components.KeepScreenAwake import io.github.zyrouge.symphony.ui.components.LyricsText import io.github.zyrouge.symphony.ui.components.TimedContentTextStyle import io.github.zyrouge.symphony.ui.components.swipeable @@ -68,6 +69,12 @@ fun NowPlayingBodyCover( @Composable private fun NowPlayingBodyCoverLyrics(context: ViewContext, orientation: ScreenOrientation) { + val keepScreenAwake by context.symphony.settings.lyricsKeepScreenAwake.flow.collectAsState() + + if (keepScreenAwake) { + KeepScreenAwake() + } + Box( modifier = Modifier .fillMaxSize() diff --git a/app/src/main/java/io/github/zyrouge/symphony/ui/view/settings/NowPlayingSettingsView.kt b/app/src/main/java/io/github/zyrouge/symphony/ui/view/settings/NowPlayingSettingsView.kt index 8ac7fd7a..cea9a716 100644 --- a/app/src/main/java/io/github/zyrouge/symphony/ui/view/settings/NowPlayingSettingsView.kt +++ b/app/src/main/java/io/github/zyrouge/symphony/ui/view/settings/NowPlayingSettingsView.kt @@ -12,6 +12,7 @@ import androidx.compose.material.icons.automirrored.filled.Wysiwyg import androidx.compose.material.icons.automirrored.outlined.Article import androidx.compose.material.icons.filled.Dashboard import androidx.compose.material.icons.filled.Forward30 +import androidx.compose.material.icons.filled.Lyrics import androidx.compose.material3.CenterAlignedTopAppBar import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.HorizontalDivider @@ -47,6 +48,7 @@ fun NowPlayingSettingsView(context: ViewContext) { val nowPlayingAdditionalInfo by context.symphony.settings.nowPlayingAdditionalInfo.flow.collectAsState() val nowPlayingSeekControls by context.symphony.settings.nowPlayingSeekControls.flow.collectAsState() val nowPlayingLyricsLayout by context.symphony.settings.nowPlayingLyricsLayout.flow.collectAsState() + val lyricsKeepScreenAwake by context.symphony.settings.lyricsKeepScreenAwake.flow.collectAsState() Scaffold( modifier = Modifier.fillMaxSize(), @@ -138,6 +140,19 @@ fun NowPlayingSettingsView(context: ViewContext) { context.symphony.settings.nowPlayingSeekControls.setValue(value) } ) + HorizontalDivider() + SettingsSwitchTile( + icon = { + Icon(Icons.Filled.Lyrics, null) + }, + title = { + Text(context.symphony.t.KeepScreenAwakeOnLyrics) + }, + value = lyricsKeepScreenAwake, + onChange = { value -> + context.symphony.settings.lyricsKeepScreenAwake.setValue(value) + } + ) } } } diff --git a/i18n/en.toml b/i18n/en.toml index ee384dff..2fe9e4c4 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -252,3 +252,4 @@ PlayStore = "Play Store" GaplessPlayback = "Gapless playback" GridColumns = "Grid columns" CaseSensitiveSorting = "Case sensitive sorting" +KeepScreenAwakeOnLyrics = "Keep screen awake on lyrics content"