Add playlist song left border and dotted sliding trail
This commit is contained in:
parent
466579ba38
commit
88b7093171
3 changed files with 210 additions and 14 deletions
|
|
@ -1,12 +1,15 @@
|
||||||
package mg.dot.feufaro
|
package mg.dot.feufaro
|
||||||
|
|
||||||
import SharedScreenModel
|
import SharedScreenModel
|
||||||
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.gestures.detectTapGestures
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.automirrored.filled.PlaylistAdd
|
import androidx.compose.material.icons.automirrored.filled.PlaylistAdd
|
||||||
|
|
@ -17,8 +20,11 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.alpha
|
import androidx.compose.ui.draw.alpha
|
||||||
|
import androidx.compose.ui.draw.drawBehind
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.PathEffect
|
||||||
|
import androidx.compose.ui.graphics.StrokeCap
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.layout.onGloballyPositioned
|
import androidx.compose.ui.layout.onGloballyPositioned
|
||||||
import androidx.compose.ui.text.font.FontStyle
|
import androidx.compose.ui.text.font.FontStyle
|
||||||
|
|
@ -59,6 +65,9 @@ object ScreenSolfa : Screen {
|
||||||
var showContextualMenu = false
|
var showContextualMenu = false
|
||||||
var viewportHeight by remember { mutableStateOf(0) }
|
var viewportHeight by remember { mutableStateOf(0) }
|
||||||
|
|
||||||
|
var trailPoints by remember { mutableStateOf<List<Offset>>(emptyList()) }
|
||||||
|
val trailAlpha = remember { androidx.compose.animation.core.Animatable(1f) }
|
||||||
|
|
||||||
var qrCodeResult by remember { mutableStateOf("Aucun code scanné") }
|
var qrCodeResult by remember { mutableStateOf("Aucun code scanné") }
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
DeepLinkHandler.onSongReceived = { content, filePath ->
|
DeepLinkHandler.onSongReceived = { content, filePath ->
|
||||||
|
|
@ -90,6 +99,10 @@ object ScreenSolfa : Screen {
|
||||||
val allowedStanzas by sharedScreenModel.allowedStanzas.collectAsState()
|
val allowedStanzas by sharedScreenModel.allowedStanzas.collectAsState()
|
||||||
val playlistStanzas by sharedScreenModel.playlistStanzas.collectAsState()
|
val playlistStanzas by sharedScreenModel.playlistStanzas.collectAsState()
|
||||||
|
|
||||||
|
val songBorderColor by sharedScreenModel.songBorderColor.collectAsState()
|
||||||
|
val hasSongBorder by sharedScreenModel.hasSongBorder.collectAsState()
|
||||||
|
val playlistActive by sharedScreenModel.playlistActive.collectAsState()
|
||||||
|
|
||||||
LaunchedEffect(playlistStanzas, activeFilePath) {
|
LaunchedEffect(playlistStanzas, activeFilePath) {
|
||||||
if (playlistStanzas.isNotEmpty() && stanza !in playlistStanzas) {
|
if (playlistStanzas.isNotEmpty() && stanza !in playlistStanzas) {
|
||||||
sharedScreenModel.setStanza(playlistStanzas.first())
|
sharedScreenModel.setStanza(playlistStanzas.first())
|
||||||
|
|
@ -143,6 +156,34 @@ object ScreenSolfa : Screen {
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(paddingValues)
|
.padding(paddingValues)
|
||||||
.padding(horizontal = 16.dp)
|
.padding(horizontal = 16.dp)
|
||||||
|
.drawBehind {
|
||||||
|
if (hasSongBorder) {
|
||||||
|
val strokeWidth = 4.dp.toPx()
|
||||||
|
val cornerLength = 150.dp.toPx()
|
||||||
|
val colorToDraw = songBorderColor
|
||||||
|
|
||||||
|
drawLine(
|
||||||
|
color = colorToDraw,
|
||||||
|
start = Offset(0f, 0f),
|
||||||
|
end = Offset(cornerLength, 0f),
|
||||||
|
strokeWidth = strokeWidth
|
||||||
|
)
|
||||||
|
|
||||||
|
drawLine(
|
||||||
|
color = colorToDraw,
|
||||||
|
start = Offset(0f, 0f),
|
||||||
|
end = Offset(0f, size.height),
|
||||||
|
strokeWidth = strokeWidth
|
||||||
|
)
|
||||||
|
|
||||||
|
drawLine(
|
||||||
|
color = colorToDraw,
|
||||||
|
start = Offset(0f, size.height),
|
||||||
|
end = Offset(cornerLength, size.height),
|
||||||
|
strokeWidth = strokeWidth
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
.onGloballyPositioned { coordinates ->
|
.onGloballyPositioned { coordinates ->
|
||||||
screenWidthPx = coordinates.size.width
|
screenWidthPx = coordinates.size.width
|
||||||
}
|
}
|
||||||
|
|
@ -154,6 +195,21 @@ object ScreenSolfa : Screen {
|
||||||
if (isFullScreenEnabled) WindowInsets(0)
|
if (isFullScreenEnabled) WindowInsets(0)
|
||||||
else WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)
|
else WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)
|
||||||
)
|
)
|
||||||
|
.drawBehind {
|
||||||
|
if (playlistActive != null && trailPoints.size > 1 && trailAlpha.value > 0f) {
|
||||||
|
val baseColor = if (hasSongBorder) songBorderColor else Color.Blue
|
||||||
|
for (i in 0 until trailPoints.size - 1) {
|
||||||
|
drawLine(
|
||||||
|
color = baseColor.copy(alpha = 0.5f * trailAlpha.value),
|
||||||
|
start = trailPoints[i],
|
||||||
|
end = trailPoints[i + 1],
|
||||||
|
strokeWidth = 6.dp.toPx(),
|
||||||
|
cap = StrokeCap.Round,
|
||||||
|
pathEffect = PathEffect.dashPathEffect(floatArrayOf(15f, 15f), 0f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
.pointerInput(Unit) {
|
.pointerInput(Unit) {
|
||||||
detectTapGestures(
|
detectTapGestures(
|
||||||
onDoubleTap = { offset ->
|
onDoubleTap = { offset ->
|
||||||
|
|
@ -184,6 +240,10 @@ object ScreenSolfa : Screen {
|
||||||
var isHorizontalDrag = false
|
var isHorizontalDrag = false
|
||||||
var isVerticalDrag = false
|
var isVerticalDrag = false
|
||||||
|
|
||||||
|
coroutineScope.launch { trailAlpha.snapTo(1f) }
|
||||||
|
val gesturePoints = mutableListOf(startPos)
|
||||||
|
trailPoints = gesturePoints.toList()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
val moveEvent = awaitPointerEvent()
|
val moveEvent = awaitPointerEvent()
|
||||||
|
|
@ -194,6 +254,9 @@ object ScreenSolfa : Screen {
|
||||||
currentX = primaryMove.position.x
|
currentX = primaryMove.position.x
|
||||||
currentY = primaryMove.position.y
|
currentY = primaryMove.position.y
|
||||||
|
|
||||||
|
gesturePoints.add(Offset(currentX, currentY))
|
||||||
|
trailPoints = gesturePoints.toList()
|
||||||
|
|
||||||
val diffX = kotlin.math.abs(currentX - startPos.x)
|
val diffX = kotlin.math.abs(currentX - startPos.x)
|
||||||
val diffY = kotlin.math.abs(currentY - startPos.y)
|
val diffY = kotlin.math.abs(currentY - startPos.y)
|
||||||
|
|
||||||
|
|
@ -214,9 +277,19 @@ object ScreenSolfa : Screen {
|
||||||
// println("DEBUG GESTURE -> VERTICAL dragging : libération totale, attente de la levée du doigt...")
|
// println("DEBUG GESTURE -> VERTICAL dragging : libération totale, attente de la levée du doigt...")
|
||||||
while (true) {
|
while (true) {
|
||||||
val releaseEvent = awaitPointerEvent()
|
val releaseEvent = awaitPointerEvent()
|
||||||
if (releaseEvent.changes.all { !it.pressed }) {
|
val releasePressed = releaseEvent.changes.filter { it.pressed }
|
||||||
|
if (releasePressed.isEmpty()) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
releaseEvent.changes.firstOrNull { it.id == primaryChange.id }?.let { p ->
|
||||||
|
gesturePoints.add(p.position)
|
||||||
|
trailPoints = gesturePoints.toList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
coroutineScope.launch {
|
||||||
|
trailAlpha.animateTo(0f, animationSpec = tween(1500))
|
||||||
|
trailPoints = emptyList()
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -228,6 +301,14 @@ object ScreenSolfa : Screen {
|
||||||
while (true) {
|
while (true) {
|
||||||
val dragEvent = awaitPointerEvent()
|
val dragEvent = awaitPointerEvent()
|
||||||
val dragPressed = dragEvent.changes.filter { it.pressed }
|
val dragPressed = dragEvent.changes.filter { it.pressed }
|
||||||
|
|
||||||
|
dragPressed.firstOrNull { it.id == primaryChange.id }?.let { p ->
|
||||||
|
currentX = p.position.x
|
||||||
|
currentY = p.position.y
|
||||||
|
gesturePoints.add(Offset(currentX, currentY))
|
||||||
|
trailPoints = gesturePoints.toList()
|
||||||
|
}
|
||||||
|
|
||||||
if (dragPressed.isEmpty()) {
|
if (dragPressed.isEmpty()) {
|
||||||
val totalDragX = currentX - startPos.x
|
val totalDragX = currentX - startPos.x
|
||||||
val threshold = screenWidthPx * 0.30f
|
val threshold = screenWidthPx * 0.30f
|
||||||
|
|
@ -247,23 +328,13 @@ object ScreenSolfa : Screen {
|
||||||
solfaScreenModel.loadFromFile(path)
|
solfaScreenModel.loadFromFile(path)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// println("ACTION -> Changement de stanza (1 doigt)")
|
if (totalDragX < 0) {
|
||||||
val currentStanza = stanza.toString().toIntOrNull() ?: 1
|
sharedScreenModel.nextStanzaOrSong(solfaScreenModel, coroutineScope, scrollState)
|
||||||
val target = if (totalDragX < 0) {
|
|
||||||
sharedScreenModel.nextAllowedStanza(currentStanza)
|
|
||||||
} else {
|
} else {
|
||||||
sharedScreenModel.prevAllowedStanza(currentStanza)
|
sharedScreenModel.prevStanzaOrSong(solfaScreenModel, coroutineScope, scrollState)
|
||||||
}
|
|
||||||
if (target != null) {
|
|
||||||
sharedScreenModel.setStanza(target)
|
|
||||||
coroutineScope.launch {
|
|
||||||
scrollState.animateScrollTo(0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// println("ACTION IGNORÉE -> Le drag n'a pas atteint les 30% de l'écran.")
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -271,6 +342,16 @@ object ScreenSolfa : Screen {
|
||||||
currentX = primaryDrag.position.x
|
currentX = primaryDrag.position.x
|
||||||
primaryDrag.consume()
|
primaryDrag.consume()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
coroutineScope.launch {
|
||||||
|
trailAlpha.animateTo(0f, animationSpec = tween(1500))
|
||||||
|
trailPoints = emptyList()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
coroutineScope.launch {
|
||||||
|
trailAlpha.animateTo(0f, animationSpec = tween(300))
|
||||||
|
trailPoints = emptyList()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// println("DEBUG EXCEPTION -> ${e.message}")
|
// println("DEBUG EXCEPTION -> ${e.message}")
|
||||||
|
|
|
||||||
|
|
@ -312,10 +312,12 @@ fun SimpleDrawerContent(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onDelete = { playlistToDelete = pl.name },
|
onDelete = { playlistToDelete = pl.name },
|
||||||
|
// --- Dans DrawerPlaylistRow (lors du clic sur le bouton Play de la playlist) ---
|
||||||
onPlay = {
|
onPlay = {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
sharedScreenModel.selectPlaylist(pl.name)
|
sharedScreenModel.selectPlaylist(pl.name)
|
||||||
val firstPath = sharedScreenModel.startPlaylist(activeSongs)
|
val firstPath = sharedScreenModel.startPlaylist(activeSongs)
|
||||||
|
sharedScreenModel.setPlaylistActive(pl.name) // Activation explicite ici uniquement
|
||||||
if (firstPath != null) {
|
if (firstPath != null) {
|
||||||
scope.launch { drawerState.close() }
|
scope.launch { drawerState.close() }
|
||||||
sharedScreenModel.reset()
|
sharedScreenModel.reset()
|
||||||
|
|
@ -344,11 +346,13 @@ fun SimpleDrawerContent(
|
||||||
selected = di != null && di.path == activePath,
|
selected = di != null && di.path == activePath,
|
||||||
enabled = di != null,
|
enabled = di != null,
|
||||||
stzS = song.entry.stanzas.toSet(),
|
stzS = song.entry.stanzas.toSet(),
|
||||||
|
// --- Dans DrawerPlaylistSongRow (lors du clic sur un chant spécifique de la playlist) ---
|
||||||
onClick = {
|
onClick = {
|
||||||
if (di != null) {
|
if (di != null) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
sharedScreenModel.selectPlaylist(pl.name)
|
sharedScreenModel.selectPlaylist(pl.name)
|
||||||
sharedScreenModel.startPlaylist(activeSongs)
|
sharedScreenModel.startPlaylist(activeSongs)
|
||||||
|
sharedScreenModel.setPlaylistActive(pl.name) // Activation explicite ici uniquement
|
||||||
scope.launch { drawerState.close() }
|
scope.launch { drawerState.close() }
|
||||||
sharedScreenModel.reset()
|
sharedScreenModel.reset()
|
||||||
solfaScreenModel.loadFromFile(di.path)
|
solfaScreenModel.loadFromFile(di.path)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,17 @@
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.State
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import cafe.adriel.voyager.core.model.ScreenModel
|
import cafe.adriel.voyager.core.model.ScreenModel
|
||||||
import cafe.adriel.voyager.core.model.screenModelScope
|
import cafe.adriel.voyager.core.model.screenModelScope
|
||||||
import com.russhwolf.settings.Settings
|
import com.russhwolf.settings.Settings
|
||||||
|
|
@ -14,10 +24,13 @@ import mg.dot.feufaro.midi.FMediaPlayer
|
||||||
import mg.dot.feufaro.provideSettings
|
import mg.dot.feufaro.provideSettings
|
||||||
import mg.dot.feufaro.solfa.TUOEditState
|
import mg.dot.feufaro.solfa.TUOEditState
|
||||||
import mg.dot.feufaro.solfa.TimeUnitObject
|
import mg.dot.feufaro.solfa.TimeUnitObject
|
||||||
|
import mg.dot.feufaro.ui.ThemeDefaults
|
||||||
import mg.dot.feufaro.ui.findMatchingSong
|
import mg.dot.feufaro.ui.findMatchingSong
|
||||||
import mg.dot.feufaro.ui.parseRawTextToEntries
|
import mg.dot.feufaro.ui.parseRawTextToEntries
|
||||||
import mg.dot.feufaro.ui.parseVerses
|
import mg.dot.feufaro.ui.parseVerses
|
||||||
|
import mg.dot.feufaro.ui.toColorOrDefault
|
||||||
import mg.dot.feufaro.viewmodel.MidiMarkers
|
import mg.dot.feufaro.viewmodel.MidiMarkers
|
||||||
|
import mg.dot.feufaro.viewmodel.SolfaScreenModel
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class SharedScreenModel(private val fileRepository: FileRepository) : ScreenModel {
|
class SharedScreenModel(private val fileRepository: FileRepository) : ScreenModel {
|
||||||
|
|
@ -61,6 +74,25 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
var _hasMarker = MutableStateFlow<Boolean>(false)
|
var _hasMarker = MutableStateFlow<Boolean>(false)
|
||||||
val hasMarker: StateFlow<Boolean> = _hasMarker.asStateFlow()
|
val hasMarker: StateFlow<Boolean> = _hasMarker.asStateFlow()
|
||||||
|
|
||||||
|
private val _songBorderColor = MutableStateFlow<Color>(Color.Transparent)
|
||||||
|
val songBorderColor: StateFlow<Color> = _songBorderColor.asStateFlow()
|
||||||
|
|
||||||
|
private val _hasSongBorder = MutableStateFlow(false)
|
||||||
|
val hasSongBorder: StateFlow<Boolean> = _hasSongBorder.asStateFlow()
|
||||||
|
|
||||||
|
|
||||||
|
private val _playlistActive = MutableStateFlow<String?>(null)
|
||||||
|
val playlistActive: StateFlow<String?> = _playlistActive.asStateFlow()
|
||||||
|
|
||||||
|
fun setPlaylistActive(playlistName: String?) {
|
||||||
|
_playlistActive.value = playlistName
|
||||||
|
if (playlistName != null) {
|
||||||
|
_hasSongBorder.value = true
|
||||||
|
} else {
|
||||||
|
_hasSongBorder.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val _searchTitle = MutableStateFlow<String>("")
|
private val _searchTitle = MutableStateFlow<String>("")
|
||||||
val searchTitle: StateFlow<String> = _searchTitle.asStateFlow()
|
val searchTitle: StateFlow<String> = _searchTitle.asStateFlow()
|
||||||
|
|
||||||
|
|
@ -760,6 +792,20 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
} else if (_stanza.value == 0) {
|
} else if (_stanza.value == 0) {
|
||||||
_stanza.value = 1
|
_stanza.value = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val availableColors = ThemeDefaults.availableColors
|
||||||
|
|
||||||
|
availableColors.forEach { colorHex ->
|
||||||
|
colorHex.toColorOrDefault(Color.Gray)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_playlistActive.value != null && active.any { samePath(it.path, path) }) {
|
||||||
|
val playlistColors = ThemeDefaults.availableColors.map { hex ->
|
||||||
|
hex.toColorOrDefault(Color.Gray)
|
||||||
|
}
|
||||||
|
_songBorderColor.value = playlistColors.random().copy(alpha = 0.6f)
|
||||||
|
_hasSongBorder.value = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fun toggleSourceMode() {
|
fun toggleSourceMode() {
|
||||||
_sourceModeState.value = !_sourceModeState.value
|
_sourceModeState.value = !_sourceModeState.value
|
||||||
|
|
@ -790,8 +836,12 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
|
|
||||||
private val _showSearchMenu = MutableStateFlow<Boolean>(false)
|
private val _showSearchMenu = MutableStateFlow<Boolean>(false)
|
||||||
val showSearchMenu: StateFlow<Boolean> = _showSearchMenu.asStateFlow()
|
val showSearchMenu: StateFlow<Boolean> = _showSearchMenu.asStateFlow()
|
||||||
|
// --- Remplacer la fonction showSearchMenu ---
|
||||||
fun showSearchMenu(value: Boolean) {
|
fun showSearchMenu(value: Boolean) {
|
||||||
_showSearchMenu.value = value
|
_showSearchMenu.value = value
|
||||||
|
if (value) {
|
||||||
|
setPlaylistActive(null) // Réinitialise la playlist active et la bordure lors de l'ouverture de la recherche
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var _mediaPlayer by mutableStateOf<FMediaPlayer?>(null)
|
private var _mediaPlayer by mutableStateOf<FMediaPlayer?>(null)
|
||||||
|
|
@ -1368,4 +1418,65 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
prefs.putInt("voice_instrument", program)
|
prefs.putInt("voice_instrument", program)
|
||||||
_mediaPlayer?.changeInstru(program)
|
_mediaPlayer?.changeInstru(program)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class PlaylistPage(
|
||||||
|
val path: String,
|
||||||
|
val songTitle: String = "",
|
||||||
|
val stanzas: List<Int> = emptyList()
|
||||||
|
)
|
||||||
|
|
||||||
|
val playlistPages: StateFlow<List<PlaylistPage>> = combine(_activePlaylist, _drawerItems) { activeSongs, allItems ->
|
||||||
|
activeSongs.map { activeSong ->
|
||||||
|
val matchedItem = allItems.find { samePath(it.path, activeSong.path) }
|
||||||
|
val title = matchedItem?.title ?: activeSong.path
|
||||||
|
val stzs = if (activeSong.stanzas.isEmpty()) {
|
||||||
|
val nb = _nbStanzas.value.takeIf { it > 0 } ?: 1
|
||||||
|
(1..nb).toList()
|
||||||
|
} else {
|
||||||
|
activeSong.stanzas.sorted()
|
||||||
|
}
|
||||||
|
PlaylistPage(path = activeSong.path, songTitle = title, stanzas = stzs)
|
||||||
|
}
|
||||||
|
}.stateIn(screenModelScope, SharingStarted.Eagerly, emptyList())
|
||||||
|
|
||||||
|
private val _activePageIndex = MutableStateFlow(0)
|
||||||
|
val activePageIndex: StateFlow<Int> = _activePageIndex.asStateFlow()
|
||||||
|
|
||||||
|
fun setActivePageIndex(index: Int) {
|
||||||
|
_activePageIndex.value = index
|
||||||
|
}
|
||||||
|
|
||||||
|
fun nextStanzaOrSong(solfaScreenModel: SolfaScreenModel, coroutineScope: CoroutineScope, scrollState: androidx.compose.foundation.ScrollState?) {
|
||||||
|
val currentStanza = stanza.value
|
||||||
|
val nextStz = nextAllowedStanza(currentStanza)
|
||||||
|
if (nextStz != null) {
|
||||||
|
setStanza(nextStz)
|
||||||
|
coroutineScope.launch {
|
||||||
|
scrollState?.animateScrollTo(0)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val nextPath = getNextPlaylistItemPath()
|
||||||
|
if (!nextPath.isNullOrBlank()) {
|
||||||
|
reset()
|
||||||
|
solfaScreenModel.loadFromFile(nextPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun prevStanzaOrSong(solfaScreenModel: SolfaScreenModel, coroutineScope: CoroutineScope, scrollState: androidx.compose.foundation.ScrollState?) {
|
||||||
|
val currentStanza = stanza.value
|
||||||
|
val prevStz = prevAllowedStanza(currentStanza)
|
||||||
|
if (prevStz != null) {
|
||||||
|
setStanza(prevStz)
|
||||||
|
coroutineScope.launch {
|
||||||
|
scrollState?.animateScrollTo(0)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val prevPath = getPrevPlaylistItemPath()
|
||||||
|
if (!prevPath.isNullOrBlank()) {
|
||||||
|
reset()
|
||||||
|
solfaScreenModel.loadFromFile(prevPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue