Fix playlist swipe bug and disable drawer gestures when no playlist is active
This commit is contained in:
parent
0fc75bd50b
commit
8d6aaa131e
5 changed files with 104 additions and 73 deletions
|
|
@ -103,9 +103,20 @@ object ScreenSolfa : Screen {
|
||||||
val hasSongBorder by sharedScreenModel.hasSongBorder.collectAsState()
|
val hasSongBorder by sharedScreenModel.hasSongBorder.collectAsState()
|
||||||
val playlistActive by sharedScreenModel.playlistActive.collectAsState()
|
val playlistActive by sharedScreenModel.playlistActive.collectAsState()
|
||||||
|
|
||||||
LaunchedEffect(playlistStanzas, activeFilePath) {
|
val nbStanzas by sharedScreenModel.nbStanzas.collectAsState()
|
||||||
if (playlistStanzas.isNotEmpty() && stanza !in playlistStanzas) {
|
val isParsing by sharedScreenModel.isParsing.collectAsState()
|
||||||
sharedScreenModel.setStanza(playlistStanzas.first())
|
|
||||||
|
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)
|
scrollState.scrollTo(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -311,7 +322,7 @@ object ScreenSolfa : Screen {
|
||||||
|
|
||||||
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.10f
|
||||||
|
|
||||||
// println("DEBUG END DRAG -> totalDragX: ${totalDragX}f, threshold requis: ${threshold}f")
|
// println("DEBUG END DRAG -> totalDragX: ${totalDragX}f, threshold requis: ${threshold}f")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -279,6 +279,8 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
//println("37: lFL bien reçu $sourceFile")
|
//println("37: lFL bien reçu $sourceFile")
|
||||||
currentJob?.cancel()
|
currentJob?.cancel()
|
||||||
currentJob = solfaScope.launch {
|
currentJob = solfaScope.launch {
|
||||||
|
sharedScreenModel.setParsing(true)
|
||||||
|
try {
|
||||||
val lines = try {
|
val lines = try {
|
||||||
fileRepository.readFileLines(sourceFile)
|
fileRepository.readFileLines(sourceFile)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|
@ -350,6 +352,9 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
} else if (currentStz == 0) {
|
} else if (currentStz == 0) {
|
||||||
sharedScreenModel.setStanza(1)
|
sharedScreenModel.setStanza(1)
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
sharedScreenModel.setParsing(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -232,7 +232,8 @@ fun MainScreenWithDrawer(
|
||||||
scope.launch { drawerState.close() }
|
scope.launch { drawerState.close() }
|
||||||
}
|
}
|
||||||
|
|
||||||
ModalNavigationDrawer(drawerState = drawerState, drawerContent = {
|
val playlistActive by sharedScreenModel.playlistActive.collectAsState()
|
||||||
|
ModalNavigationDrawer(drawerState = drawerState, gesturesEnabled = playlistActive == null, drawerContent = {
|
||||||
SimpleDrawerContent(
|
SimpleDrawerContent(
|
||||||
items,
|
items,
|
||||||
solfaScreenModel,
|
solfaScreenModel,
|
||||||
|
|
|
||||||
|
|
@ -214,6 +214,7 @@ fun SimpleDrawerContent(
|
||||||
onClick = {
|
onClick = {
|
||||||
scope.launch { drawerState.close() }
|
scope.launch { drawerState.close() }
|
||||||
sharedScreenModel.reset()
|
sharedScreenModel.reset()
|
||||||
|
sharedScreenModel.setPlaylistActive(null)
|
||||||
solfaScreenModel.loadFromFile(item.path)
|
solfaScreenModel.loadFromFile(item.path)
|
||||||
onSongSelected(midi)
|
onSongSelected(midi)
|
||||||
},
|
},
|
||||||
|
|
@ -269,6 +270,7 @@ fun SimpleDrawerContent(
|
||||||
onClick = {
|
onClick = {
|
||||||
scope.launch { drawerState.close() }
|
scope.launch { drawerState.close() }
|
||||||
sharedScreenModel.reset()
|
sharedScreenModel.reset()
|
||||||
|
sharedScreenModel.setPlaylistActive(null)
|
||||||
solfaScreenModel.loadFromFile(item.path)
|
solfaScreenModel.loadFromFile(item.path)
|
||||||
onSongSelected(midi)
|
onSongSelected(midi)
|
||||||
},
|
},
|
||||||
|
|
@ -404,6 +406,7 @@ fun SimpleDrawerContent(
|
||||||
onClick = {
|
onClick = {
|
||||||
scope.launch { drawerState.close() }
|
scope.launch { drawerState.close() }
|
||||||
sharedScreenModel.reset()
|
sharedScreenModel.reset()
|
||||||
|
sharedScreenModel.setPlaylistActive(null)
|
||||||
solfaScreenModel.loadFromFile(item.path)
|
solfaScreenModel.loadFromFile(item.path)
|
||||||
onSongSelected(midi)
|
onSongSelected(midi)
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -783,15 +783,19 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
val activeFilePath: State<String> = _activeFilePath
|
val activeFilePath: State<String> = _activeFilePath
|
||||||
|
|
||||||
fun setFileContent(content: String?, path: String) {
|
fun setFileContent(content: String?, path: String) {
|
||||||
|
val isNewSong = !samePath(_activeFilePathFlow.value, path)
|
||||||
_fileContent.value = content
|
_fileContent.value = content
|
||||||
_activeFilePath.value = path
|
_activeFilePath.value = path
|
||||||
_activeFilePathFlow.value = path
|
_activeFilePathFlow.value = path
|
||||||
|
|
||||||
val active = _activePlaylist.value
|
val active = _activePlaylist.value
|
||||||
val entry = active.find { samePath(it.path, path) }
|
val entry = active.find { samePath(it.path, path) }
|
||||||
|
if (isNewSong) {
|
||||||
|
_nbStanzas.value = 0
|
||||||
|
}
|
||||||
if (entry != null && entry.stanzas.isNotEmpty()) {
|
if (entry != null && entry.stanzas.isNotEmpty()) {
|
||||||
_stanza.value = entry.stanzas.sorted().first()
|
_stanza.value = entry.stanzas.sorted().first()
|
||||||
} else if (_stanza.value == 0) {
|
} else if (isNewSong || _stanza.value <= 0) {
|
||||||
_stanza.value = 1
|
_stanza.value = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1287,6 +1291,7 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
_showSearchMenu.value = false
|
_showSearchMenu.value = false
|
||||||
_sourceModeState.value = false
|
_sourceModeState.value = false
|
||||||
_harmonyView.value = false
|
_harmonyView.value = false
|
||||||
|
_stanza.value = 0
|
||||||
setTranspositionInterval(0)
|
setTranspositionInterval(0)
|
||||||
setTranspToC(0)
|
setTranspToC(0)
|
||||||
setSilentDurBefr(0)
|
setSilentDurBefr(0)
|
||||||
|
|
@ -1321,6 +1326,12 @@ class SharedScreenModel(private val fileRepository: FileRepository) : ScreenMode
|
||||||
_songTitle.value = theTitle
|
_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) {
|
fun setStanza(theStanza: Int) {
|
||||||
try {
|
try {
|
||||||
_stanza.value = theStanza
|
_stanza.value = theStanza
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue