Skip to content

Commit

Permalink
Fix NP gradient, LPM info, begin #122
Browse files Browse the repository at this point in the history
Fix incorrect NP gradient placement on overscroll
Fix LPM info button not appearing in some cases
Begin fixing #122 (WIP)
  • Loading branch information
toasterofbread committed Sep 28, 2023
1 parent 24667ec commit f4ea234
Show file tree
Hide file tree
Showing 31 changed files with 416 additions and 414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,17 @@ class SettingsValueState<T: Any>(

updateValue()

listener = object : PlatformPreferences.Listener {
override fun onChanged(prefs: PlatformPreferences, key: String) {
if (key == this@SettingsValueState.key) {
updateValue()
listener =
object : PlatformPreferences.Listener {
override fun onChanged(prefs: PlatformPreferences, key: String) {
if (key == this@SettingsValueState.key) {
updateValue()
}
}
}
}.also {
prefs.addListener(it)
}
.also {
prefs.addListener(it)
}

return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ enum class Settings {
KEY_LYRICS_ENABLE_WORD_SYNC,
KEY_LYRICS_FONT_SIZE,
KEY_LYRICS_DEFAULT_SOURCE,
KEY_LYRICS_TOP_BAR_MAX_LINES,

KEY_LYRICS_SHOW_IN_LIBRARY,
KEY_LYRICS_SHOW_IN_RADIOBUILDER,
Expand Down Expand Up @@ -307,6 +308,7 @@ enum class Settings {
KEY_LYRICS_ENABLE_WORD_SYNC -> false
KEY_LYRICS_FONT_SIZE -> 0.5f
KEY_LYRICS_DEFAULT_SOURCE -> 0
KEY_LYRICS_TOP_BAR_MAX_LINES -> 1

KEY_LYRICS_SHOW_IN_LIBRARY -> true
KEY_LYRICS_SHOW_IN_RADIOBUILDER -> true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material3.LocalContentColor
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand All @@ -17,6 +19,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.toasterofbread.spmp.model.Settings
import com.toasterofbread.spmp.model.SongLyrics
import com.toasterofbread.utils.common.BasicFuriganaText
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -80,35 +83,31 @@ fun LyricsLineDisplay(
val enter = slideInVertically { it }
val exit = slideOutVertically { -it } + fadeOut()

Box(modifier, contentAlignment = Alignment.Center) {
val max_lines: Int by Settings.KEY_LYRICS_TOP_BAR_MAX_LINES.rememberMutableState()

Box(modifier.height(IntrinsicSize.Min), contentAlignment = Alignment.Center) {
val show_a = line_a != null && show_line_a
val show_b = line_b != null && !show_line_a

AnimatedVisibility(show_a, enter = enter, exit = exit) {
var line by remember { mutableStateOf(line_a) }
LaunchedEffect(line_a) {
if (line_a != null) {
line = line_a
@Composable
fun phase(show: Boolean, index: Int?) {
AnimatedVisibility(show, Modifier.height(IntrinsicSize.Min), enter = enter, exit = exit) {
var line by remember { mutableStateOf(index) }
LaunchedEffect(index) {
if (index != null) {
line = index
}
}
}

line?.also {
BasicFuriganaText(lyrics.lines[it], show_readings = show_furigana, text_colour = text_colour)
}
}
AnimatedVisibility(show_b, enter = enter, exit = exit) {
var line by remember { mutableStateOf(line_b) }
LaunchedEffect(line_b) {
if (line_a != null) {
line = line_b
line?.also {
BasicFuriganaText(lyrics.lines[it], show_readings = show_furigana, text_colour = text_colour, max_lines = max_lines)
}
}

line?.also {
BasicFuriganaText(lyrics.lines[it], show_readings = show_furigana, text_colour = text_colour)
}
}

phase(show_a, line_a)
phase(show_b, line_b)

Crossfade(if (show_a || show_b) null else emptyContent, Modifier.fillMaxWidth()) { content ->
if (content != null) {
Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
Expand Down Expand Up @@ -196,18 +197,19 @@ private fun MusicTopBar(

AnimatedVisibility(
show,
modifier.platformClickable(
onClick = onClick,
onAltClick = {
if (current_state is SongLyrics) {
player.openNowPlayingPlayerOverlayMenu(PlayerOverlayMenu.getLyricsMenu())
modifier
.platformClickable(
onClick = onClick,
onAltClick = {
if (current_state is SongLyrics) {
player.openNowPlayingPlayerOverlayMenu(PlayerOverlayMenu.getLyricsMenu())
}
}
}
),
),
enter = expandVertically(),
exit = shrinkVertically()
) {
Column(Modifier.height(30.dp + padding.calculateTopPadding() + padding.calculateBottomPadding())) {
Column(Modifier.heightIn(30.dp + padding.calculateTopPadding() + padding.calculateBottomPadding())) {
Box(Modifier.padding(padding)) {
innerContent?.invoke(mode_state)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.toasterofbread.spmp.model.mediaitem.artist.Artist
import com.toasterofbread.spmp.model.mediaitem.playlist.Playlist
import com.toasterofbread.spmp.model.mediaitem.song.Song
import com.toasterofbread.spmp.model.mediaitem.toInfoString
import com.toasterofbread.spmp.resources.getString
import com.toasterofbread.spmp.ui.component.longpressmenu.artist.ArtistLongPressMenuInfo
import com.toasterofbread.spmp.ui.component.longpressmenu.playlist.PlaylistLongPressMenuInfo
import com.toasterofbread.spmp.ui.component.longpressmenu.song.SongLongPressMenuInfo
import com.toasterofbread.spmp.ui.theme.Theme
import com.toasterofbread.utils.common.isDebugBuild
import com.toasterofbread.utils.composable.WidthShrinkText
Expand All @@ -38,8 +43,15 @@ internal fun ColumnScope.LongPressMenuInfoActions(
) {
val player = LocalPlayerState.current

Column(Modifier.fillMaxHeight().weight(1f), verticalArrangement = Arrangement.spacedBy(spacing)) {
data.infoContent?.invoke(this, getAccentColour)
Column(
Modifier.fillMaxHeight().weight(1f),
verticalArrangement = Arrangement.spacedBy(spacing)
) {
when (data.item) {
is Song -> SongLongPressMenuInfo(data.item, data.multiselect_key, getAccentColour)
is Artist -> ArtistLongPressMenuInfo(data.item, getAccentColour)
is Playlist -> PlaylistLongPressMenuInfo(data.item, getAccentColour)
}
}

// Share
Expand Down Expand Up @@ -103,7 +115,13 @@ internal fun ColumnScope.LongPressMenuActions(data: LongPressMenuData, getAccent
)

// Hide
LongPressMenuActionProvider.ActionButton(Icons.Filled.VisibilityOff, getString("lpm_action_hide"), getAccentColour, onClick = {
data.item.Hidden.set(true, player.database)
}, onAction = onAction)
LongPressMenuActionProvider.ActionButton(
Icons.Filled.VisibilityOff,
getString("lpm_action_hide"),
getAccentColour,
onClick = {
data.item.Hidden.set(true, player.database)
},
onAction = onAction
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import LocalPlayerState
import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -54,6 +53,7 @@ import com.toasterofbread.spmp.model.mediaitem.artist.Artist
import com.toasterofbread.spmp.model.mediaitem.db.observePinnedToHome
import com.toasterofbread.spmp.platform.composable.platformClickable
import com.toasterofbread.spmp.platform.vibrateShort
import com.toasterofbread.spmp.resources.getString
import com.toasterofbread.spmp.ui.component.MediaItemTitleEditDialog
import com.toasterofbread.spmp.ui.component.Thumbnail
import com.toasterofbread.spmp.ui.component.mediaitempreview.MediaItemPreviewLong
Expand Down Expand Up @@ -213,7 +213,7 @@ internal fun LongPressMenuContent(
contentAlignment = Alignment.CenterStart
) {
AlignableCrossfade(show_info, Modifier.requiredHeight(40.dp), contentAlignment = Alignment.CenterStart) { info ->
val text = if (info) data.info_title else data.getInitialInfoTitle?.invoke()
val text = if (info) getString("lpm_long_press_actions") else data.getTitle?.invoke()
val current = info == show_info
if (text != null) {
Text(
Expand Down Expand Up @@ -249,20 +249,14 @@ internal fun LongPressMenuContent(
}
}

if (data.infoContent != null) {
IconButton({ show_info = !show_info }, Modifier.requiredHeight(40.dp)) {
Crossfade(show_info) { info ->
Icon(if (info) Icons.Filled.Close else Icons.Filled.Info, null)
}
IconButton({ show_info = !show_info }, Modifier.requiredHeight(40.dp)) {
Crossfade(show_info) { info ->
Icon(if (info) Icons.Filled.Close else Icons.Filled.Info, null)
}
}

data.SideButton(
Modifier
.requiredHeight(40.dp)
.thenIf(data.infoContent == null) {
padding(start = 10.dp)
},
Modifier.requiredHeight(40.dp),
Theme.background
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.toasterofbread.spmp.ui.component.longpressmenu

import LocalPlayerState
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -16,9 +15,9 @@ import com.toasterofbread.spmp.model.mediaitem.artist.Artist
import com.toasterofbread.spmp.model.mediaitem.playlist.Playlist
import com.toasterofbread.spmp.model.mediaitem.song.Song
import com.toasterofbread.spmp.ui.component.LikeDislikeButton
import com.toasterofbread.spmp.ui.component.mediaitempreview.ArtistLongPressMenuActions
import com.toasterofbread.spmp.ui.component.mediaitempreview.PlaylistLongPressMenuActions
import com.toasterofbread.spmp.ui.component.mediaitempreview.SongLongPressMenuActions
import com.toasterofbread.spmp.ui.component.longpressmenu.artist.ArtistLongPressMenuActions
import com.toasterofbread.spmp.ui.component.longpressmenu.playlist.PlaylistLongPressMenuActions
import com.toasterofbread.spmp.ui.component.longpressmenu.song.SongLongPressMenuActions
import com.toasterofbread.spmp.ui.component.multiselect.MediaItemMultiSelectContext
import com.toasterofbread.spmp.ui.layout.artistpage.ArtistSubscribeButton
import com.toasterofbread.utils.common.getContrasted
Expand All @@ -29,9 +28,7 @@ import kotlinx.coroutines.launch
data class LongPressMenuData(
val item: MediaItem,
val thumb_shape: Shape? = null,
val infoContent: (@Composable ColumnScope.(accent: () -> Color) -> Unit)? = null,
val info_title: String? = null,
val getInitialInfoTitle: (@Composable () -> String?)? = null,
val getTitle: (@Composable () -> String?)? = null,
val multiselect_context: MediaItemMultiSelectContext? = null,
val multiselect_key: Int? = null,
val playlist_as_song: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.toasterofbread.spmp.ui.component.longpressmenu.artist

import LocalPlayerState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.runtime.Composable
import com.toasterofbread.spmp.model.mediaitem.MediaItem
import com.toasterofbread.spmp.model.mediaitem.artist.Artist
import com.toasterofbread.spmp.resources.getString
import com.toasterofbread.spmp.ui.component.longpressmenu.LongPressMenuActionProvider

@Composable
fun LongPressMenuActionProvider.ArtistLongPressMenuActions(artist: MediaItem) {
require(artist is Artist)
val player = LocalPlayerState.current

ActionButton(
Icons.Default.PlayArrow,
getString("lpm_action_play"),
onClick = {
player.playMediaItem(artist)
},
onLongClick = {
player.playMediaItem(artist, shuffle = true)
}
)

ActiveQueueIndexAction(
{ distance ->
getString(if (distance == 1) "lpm_action_play_after_1_song" else "lpm_action_play_after_x_songs").replace("\$x", distance.toString())
},
onClick = { active_queue_index ->
player.playMediaItem(artist, at_index = active_queue_index + 1)
},
onLongClick = { active_queue_index ->
player.playMediaItem(artist, at_index = active_queue_index + 1, shuffle = true)
}
)

ActionButton(Icons.Default.Person, getString("lpm_action_open_artist"), onClick = {
player.openMediaItem(artist,)
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.toasterofbread.spmp.ui.component.longpressmenu.artist

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.filled.SubdirectoryArrowRight
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.toasterofbread.spmp.model.mediaitem.artist.Artist
import com.toasterofbread.spmp.resources.getString
import com.toasterofbread.utils.composable.WidthShrinkText

@Composable
fun ColumnScope.ArtistLongPressMenuInfo(artist: Artist, getAccentColour: () -> Color) {
@Composable
fun Item(icon: ImageVector, text: String, modifier: Modifier = Modifier) {
Row(
modifier,
horizontalArrangement = Arrangement.spacedBy(20.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(icon, null, tint = getAccentColour())
WidthShrinkText(text, fontSize = 15.sp)
}
}

Item(Icons.Default.PlayArrow, getString("lpm_action_radio"))
Item(Icons.Default.SubdirectoryArrowRight, getString("lpm_action_radio_after_x_songs"))

Spacer(
Modifier
.fillMaxHeight()
.weight(1f)
)
}
Loading

0 comments on commit f4ea234

Please sign in to comment.