Skip to content

Commit

Permalink
feat: keep screen awake on lyrics (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Dec 1, 2024
1 parent b592c48 commit 43c1a5a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .phrasey/schema.toml
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,6 @@ name = "GridColumns"

[[keys]]
name = "CaseSensitiveSorting"

[[keys]]
name = "KeepScreenAwakeOnLyrics"
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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)
}
)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,4 @@ PlayStore = "Play Store"
GaplessPlayback = "Gapless playback"
GridColumns = "Grid columns"
CaseSensitiveSorting = "Case sensitive sorting"
KeepScreenAwakeOnLyrics = "Keep screen awake on lyrics content"

0 comments on commit 43c1a5a

Please sign in to comment.