diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/TimeUnitObject.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/TimeUnitObject.kt index 8bf226f..5ab81bc 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/TimeUnitObject.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/TimeUnitObject.kt @@ -1184,8 +1184,8 @@ fun EditSourceCompose( onSave = { scope.launch { try { - saveLauncher.launch(fileName) - + val initialDir = solfaScreenModel.fileRepository.getAppPublicFolder().absolutePath + saveLauncher.launch(fileName, initialDir) } catch (e: Exception) { e.printStackTrace() } diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/DrawerUI.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/DrawerUI.kt index 7672c4f..1f8b5b2 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/DrawerUI.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/DrawerUI.kt @@ -9,6 +9,7 @@ import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.InsertDriveFile import androidx.compose.material.icons.automirrored.filled.Undo import androidx.compose.material.icons.filled.* import androidx.compose.material3.* @@ -284,7 +285,14 @@ fun MainScreenWithDrawer( ) { FloatingActionButton( onClick = { - saveLauncher.launch(fileName) + scope.launch { + try { + val initialDir = solfaScreenModel.fileRepository.getAppPublicFolder().absolutePath + saveLauncher.launch(fileName, initialDir) + } catch (e: Exception) { + e.printStackTrace() + } + } }, modifier = Modifier.alpha(0.45f) ) { Icon( @@ -483,16 +491,28 @@ fun MainScreenWithDrawer( ) ) { if (filteredSongs.isNotEmpty()) { + val sortedSongs = remember(filteredSongs) { + filteredSongs.sortedBy { item -> + item.path.startsWith("assets://") + } + } LazyColumn(Modifier.fillMaxSize()) { - itemsIndexed(filteredSongs, key = {_, item -> item.path}) { index, item -> + itemsIndexed(sortedSongs, key = {_, item -> item.path}) { index, item -> val isFavorite = favoritePaths.contains(item) ListItem( + leadingContent = { + Icon( + imageVector = if(item.path.startsWith("assets://")) Icons.Default.ArrowDropDownCircle else Icons.Default.Folder, + contentDescription = null, + modifier = Modifier.size(30.dp) + ) + }, headlineContent = { Text(item.title) }, supportingContent = { Text(item.contentTitle, maxLines = 1) }, trailingContent = { IconButton( onClick = { sharedScreenModel.toggleFavorite(item.path) }, - modifier = Modifier.size(30.dp) + modifier = Modifier.size(25.dp) ) { Icon( imageVector = Icons.Default.Star, diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/FileSaveLauncher.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/FileSaveLauncher.kt index 28ebf28..a79eda4 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/FileSaveLauncher.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/ui/FileSaveLauncher.kt @@ -3,7 +3,7 @@ package mg.dot.feufaro.ui import androidx.compose.runtime.Composable interface FileSaveLauncher { - fun launch(defaultName: String) + fun launch(defaultName: String, initialDir: String?) } @Composable diff --git a/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/ui/FileSaveLauncher.kt b/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/ui/FileSaveLauncher.kt index 242ddb4..d8823f5 100644 --- a/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/ui/FileSaveLauncher.kt +++ b/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/ui/FileSaveLauncher.kt @@ -2,6 +2,7 @@ package mg.dot.feufaro.ui import androidx.compose.runtime.Composable import androidx.compose.runtime.remember +import androidx.compose.ui.graphics.Color import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -16,10 +17,10 @@ actual fun rememberFileSaveLauncher( ): FileSaveLauncher { return remember { object : FileSaveLauncher { - override fun launch(defaultName: String) { + override fun launch(defaultName: String, initialDir: String?) { CoroutineScope(Dispatchers.IO).launch { val dialog = FileDialog(null as Frame?, "Sauvegarder la source", FileDialog.SAVE) - dialog.directory = System.getProperty("user.home") + dialog.directory = initialDir dialog.file = defaultName dialog.isVisible = true