Fix playlist swipe bug and disable drawer gestures when no playlist is active

This commit is contained in:
Hasinjato 2026-11-30 17:24:03 +03:00
parent 0fc75bd50b
commit 8d6aaa131e
5 changed files with 104 additions and 73 deletions

View file

@ -103,9 +103,20 @@ object ScreenSolfa : Screen {
val hasSongBorder by sharedScreenModel.hasSongBorder.collectAsState()
val playlistActive by sharedScreenModel.playlistActive.collectAsState()
LaunchedEffect(playlistStanzas, activeFilePath) {
if (playlistStanzas.isNotEmpty() && stanza !in playlistStanzas) {
sharedScreenModel.setStanza(playlistStanzas.first())
val nbStanzas by sharedScreenModel.nbStanzas.collectAsState()
val isParsing by sharedScreenModel.isParsing.collectAsState()
LaunchedEffect(activeFilePath, nbStanzas, playlistStanzas, isParsing, stanza) {
if (isParsing || activeFilePath.isBlank() || nbStanzas <= 0) return@LaunchedEffect
val effectiveAllowed = if (playlistStanzas.isEmpty()) {
(1..nbStanzas).toList()
} else {
playlistStanzas.filter { it in 1..nbStanzas }
}
if (effectiveAllowed.isNotEmpty() && stanza !in effectiveAllowed) {
sharedScreenModel.setStanza(effectiveAllowed.first())
scrollState.scrollTo(0)
}
}
@ -311,7 +322,7 @@ object ScreenSolfa : Screen {
if (dragPressed.isEmpty()) {
val totalDragX = currentX - startPos.x
val threshold = screenWidthPx * 0.30f
val threshold = screenWidthPx * 0.10f
// println("DEBUG END DRAG -> totalDragX: ${totalDragX}f, threshold requis: ${threshold}f")

View file

@ -279,6 +279,8 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
//println("37: lFL bien reçu $sourceFile")
currentJob?.cancel()
currentJob = solfaScope.launch {
sharedScreenModel.setParsing(true)
try {
val lines = try {
fileRepository.readFileLines(sourceFile)
} catch (e: Exception) {
@ -350,6 +352,9 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
} else if (currentStz == 0) {
sharedScreenModel.setStanza(1)
}
} finally {
sharedScreenModel.setParsing(false)
}
}
}

View file

@ -232,7 +232,8 @@ fun MainScreenWithDrawer(
scope.launch { drawerState.close() }
}
ModalNavigationDrawer(drawerState = drawerState, drawerContent = {
val playlistActive by sharedScreenModel.playlistActive.collectAsState()
ModalNavigationDrawer(drawerState = drawerState, gesturesEnabled = playlistActive == null, drawerContent = {
SimpleDrawerContent(
items,
solfaScreenModel,

View file

@ -214,6 +214,7 @@ fun SimpleDrawerContent(
onClick = {
scope.launch { drawerState.close() }
sharedScreenModel.reset()
sharedScreenModel.setPlaylistActive(null)
solfaScreenModel.loadFromFile(item.path)
onSongSelected(midi)
},
@ -269,6 +270,7 @@ fun SimpleDrawerContent(
onClick = {
scope.launch { drawerState.close() }
sharedScreenModel.reset()
sharedScreenModel.setPlaylistActive(null)
solfaScreenModel.loadFromFile(item.path)
onSongSelected(midi)
},
@ -404,6 +406,7 @@ fun SimpleDrawerContent(
onClick = {
scope.launch { drawerState.close() }
sharedScreenModel.reset()
sharedScreenModel.setPlaylistActive(null)
solfaScreenModel.loadFromFile(item.path)
onSongSelected(midi)
},

View file

@ -783,15 +783,19 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
val activeFilePath: State<String> = _activeFilePath
fun setFileContent(content: String?, path: String) {
val isNewSong = !samePath(_activeFilePathFlow.value, path)
_fileContent.value = content
_activeFilePath.value = path
_activeFilePathFlow.value = path
val active = _activePlaylist.value
val entry = active.find { samePath(it.path, path) }
if (isNewSong) {
_nbStanzas.value = 0
}
if (entry != null && entry.stanzas.isNotEmpty()) {
_stanza.value = entry.stanzas.sorted().first()
} else if (_stanza.value == 0) {
} else if (isNewSong || _stanza.value <= 0) {
_stanza.value = 1
}
@ -1287,6 +1291,7 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
_showSearchMenu.value = false
_sourceModeState.value = false
_harmonyView.value = false
_stanza.value = 0
setTranspositionInterval(0)
setTranspToC(0)
setSilentDurBefr(0)
@ -1321,6 +1326,12 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
_songTitle.value = theTitle
}
private val _isParsing = MutableStateFlow(false)
val isParsing: StateFlow<Boolean> = _isParsing.asStateFlow()
fun setParsing(parsing: Boolean) {
_isParsing.value = parsing
}
fun setStanza(theStanza: Int) {
try {
_stanza.value = theStanza