Skip to content

Commit

Permalink
refactor: mini player text marquee setting (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Dec 28, 2023
1 parent 0675ab2 commit 5594687
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .phrasey/schema.toml
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,5 @@ parameters = ["x"]
name = "CopiedXToClipboard"
parameters = ["x"]

[[keys]]
name = "MiniPlayerTextMarquee"
16 changes: 16 additions & 0 deletions app/src/main/java/io/github/zyrouge/symphony/services/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ object SettingsKeys {
const val nowPlayingLyricsLayout = "now_playing_lyrics_layout"
const val artistTagSeparators = "artist_tag_separators"
const val genreTagSeparators = "genre_tag_separators"
const val miniPlayerTextMarquee = "mini_player_text_marquee"
}

object SettingsDefaults {
Expand Down Expand Up @@ -135,6 +136,7 @@ object SettingsDefaults {
val nowPlayingLyricsLayout = NowPlayingLyricsLayout.ReplaceArtwork
val artistTagSeparators = setOf(";", "/", ",", "+")
val genreTagSeparators = setOf(";", "/", ",", "+", " ")
const val miniPlayerTextMarquee = true
}

@Suppress("MemberVisibilityCanBePrivate")
Expand Down Expand Up @@ -252,6 +254,8 @@ class SettingsManager(private val symphony: Symphony) {
val artistTagSeparators = _artistTagSeparators.asStateFlow()
private val _genreTagSeparators = MutableStateFlow(getGenreTagSeparators())
val genreTagSeparators = _genreTagSeparators.asStateFlow()
private val _miniPlayerTextMarquee = MutableStateFlow(getMiniPlayerTextMarquee())
val miniPlayerTextMarquee = _miniPlayerTextMarquee.asStateFlow()

fun getThemeMode() = getSharedPreferences().getString(SettingsKeys.themeMode, null)
?.let { ThemeMode.valueOf(it) }
Expand Down Expand Up @@ -876,6 +880,18 @@ class SettingsManager(private val symphony: Symphony) {
_genreTagSeparators.updateUsingValue(getGenreTagSeparators())
}

fun getMiniPlayerTextMarquee() = getSharedPreferences().getBoolean(
SettingsKeys.miniPlayerTextMarquee,
SettingsDefaults.miniPlayerTextMarquee,
)

fun setMiniPlayerTextMarquee(value: Boolean) {
getSharedPreferences().edit {
putBoolean(SettingsKeys.miniPlayerTextMarquee, value)
}
_miniPlayerTextMarquee.updateUsingValue(getMiniPlayerTextMarquee())
}

private fun getSharedPreferences() = symphony.applicationContext.getSharedPreferences(
SettingsKeys.identifier,
Context.MODE_PRIVATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.boundsInParent
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
Expand All @@ -71,6 +72,7 @@ import io.github.zyrouge.symphony.ui.helpers.Routes
import io.github.zyrouge.symphony.ui.helpers.TransitionDurations
import io.github.zyrouge.symphony.ui.helpers.ViewContext
import io.github.zyrouge.symphony.ui.helpers.navigate
import io.github.zyrouge.symphony.utils.runIfOrThis
import kotlin.math.absoluteValue

@OptIn(ExperimentalMaterial3Api::class)
Expand Down Expand Up @@ -289,11 +291,13 @@ private fun NowPlayingBottomBarContent(context: ViewContext, song: Song) {
) {
Column(modifier = Modifier.fillMaxWidth()) {
NowPlayingBottomBarContentText(
context,
song.title,
style = MaterialTheme.typography.bodyMedium,
)
if (song.artists.isNotEmpty()) {
NowPlayingBottomBarContentText(
context,
song.artists.joinToString(),
style = MaterialTheme.typography.bodySmall,
)
Expand All @@ -306,18 +310,26 @@ private fun NowPlayingBottomBarContent(context: ViewContext, song: Song) {
@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun NowPlayingBottomBarContentText(
context: ViewContext,
text: String,
style: TextStyle,
) {
val textMarquee by context.symphony.settings.miniPlayerTextMarquee.collectAsState()
var showOverlay by remember { mutableStateOf(false) }

Box {
Text(
text,
style = style,
maxLines = 1,
overflow = when {
textMarquee -> TextOverflow.Clip
else -> TextOverflow.Ellipsis
},
modifier = Modifier
.basicMarquee(iterations = Int.MAX_VALUE)
.runIfOrThis<Modifier>(textMarquee) {
basicMarquee(iterations = Int.MAX_VALUE)
}
.onGloballyPositioned {
val offsetX = it.boundsInParent().centerLeft.x
showOverlay = offsetX.absoluteValue != 0f
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/io/github/zyrouge/symphony/ui/view/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.material.icons.filled.GraphicEq
import androidx.compose.material.icons.filled.Headset
import androidx.compose.material.icons.filled.HeadsetOff
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.KeyboardDoubleArrowRight
import androidx.compose.material.icons.filled.Language
import androidx.compose.material.icons.filled.MusicNote
import androidx.compose.material.icons.filled.Palette
Expand Down Expand Up @@ -125,6 +126,7 @@ fun SettingsView(context: ViewContext) {
val seekForwardDuration by context.symphony.settings.seekForwardDuration.collectAsState()
val miniPlayerTrackControls by context.symphony.settings.miniPlayerTrackControls.collectAsState()
val miniPlayerSeekControls by context.symphony.settings.miniPlayerSeekControls.collectAsState()
val miniPlayerTextMarquee by context.symphony.settings.miniPlayerTextMarquee.collectAsState()
val nowPlayingControlsLayout by context.symphony.settings.nowPlayingControlsLayout.collectAsState()
val nowPlayingAdditionalInfo by context.symphony.settings.nowPlayingAdditionalInfo.collectAsState()
val nowPlayingSeekControls by context.symphony.settings.nowPlayingSeekControls.collectAsState()
Expand Down Expand Up @@ -576,6 +578,18 @@ fun SettingsView(context: ViewContext) {
context.symphony.settings.setMiniPlayerSeekControls(value)
}
)
SettingsSwitchTile(
icon = {
Icon(Icons.Filled.KeyboardDoubleArrowRight, null)
},
title = {
Text(context.symphony.t.MiniPlayerTextMarquee)
},
value = miniPlayerTextMarquee,
onChange = { value ->
context.symphony.settings.setMiniPlayerTextMarquee(value)
}
)
HorizontalDivider()
SettingsSideHeading(context.symphony.t.NowPlaying)
SettingsOptionTile(
Expand Down
1 change: 1 addition & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,4 @@ ReplaceArtwork = "Replace artwork"
SeparatePage = "Separate page"
UnknownAlbumX = "Unknown album ({x})"
CopiedXToClipboard = "Copied '{x}' to clipboard"
MiniPlayerTextMarquee = "Mini-player text marquee"

0 comments on commit 5594687

Please sign in to comment.