diff --git a/composeApp/src/androidMain/kotlin/mg/dot/feufaro/LaunchFilePicker.kt b/composeApp/src/androidMain/kotlin/mg/dot/feufaro/LaunchFilePicker.kt index 84dd5f1..cf21f41 100644 --- a/composeApp/src/androidMain/kotlin/mg/dot/feufaro/LaunchFilePicker.kt +++ b/composeApp/src/androidMain/kotlin/mg/dot/feufaro/LaunchFilePicker.kt @@ -1,8 +1,60 @@ package mg.dot.feufaro + +import android.app.Activity +import android.content.Intent +import android.net.Uri +import androidx.activity.ComponentActivity +import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.contract.ActivityResultContracts +import java.io.File + +private var currentActivity: ComponentActivity? = null +private var fileSelectionCallback: ((String?) -> Unit)? = null +private var filePickerLauncher: ActivityResultLauncher? = null + + actual fun launchFilePicker( mimeTypes: Array, + initialDirectory: String?, onFileSelected: (path: String?) -> Unit -): Unit { +) { + val launcher = filePickerLauncher + if (launcher == null) { + onFileSelected(null) + // L'Activity n'a pas été initialisée (setFilePickerActivity non appelé). + return + } + // 1. Sauvegarde du callback + fileSelectionCallback = onFileSelected + + // 2. Crée l'Intent + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply { + addCategory(Intent.CATEGORY_OPENABLE) + type = if (mimeTypes.size == 1) mimeTypes[0] else "*/*" + if (mimeTypes.size > 1) { + putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes) + } + } + + // 3. Lance le sélecteur + launcher.launch(intent) +} + +fun setFilePickerActivity(activity: ComponentActivity) { + currentActivity = activity + + filePickerLauncher = activity.registerForActivityResult( + ActivityResultContracts.StartActivityForResult() + ) { result -> + if (result.resultCode == Activity.RESULT_OK) { + val uri: Uri? = result.data?.data + fileSelectionCallback?.invoke(uri?.toString()) + } else { + fileSelectionCallback?.invoke(null) + } + // Nettoyage + fileSelectionCallback = null + } } \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/mg/dot/feufaro/MainActivity.kt b/composeApp/src/androidMain/kotlin/mg/dot/feufaro/MainActivity.kt index a04c26c..fc60bc7 100644 --- a/composeApp/src/androidMain/kotlin/mg/dot/feufaro/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/mg/dot/feufaro/MainActivity.kt @@ -15,6 +15,7 @@ class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { enableEdgeToEdge() super.onCreate(savedInstanceState) + setFilePickerActivity(this) WindowCompat.setDecorFitsSystemWindows(window, false) hideSystemBar() diff --git a/composeApp/src/commonMain/composeResources/files/config.json b/composeApp/src/commonMain/composeResources/files/config.json index 9c5d2e9..f5de7a0 100644 --- a/composeApp/src/commonMain/composeResources/files/config.json +++ b/composeApp/src/commonMain/composeResources/files/config.json @@ -2,29 +2,135 @@ "themeMode": "DARK", "fontSize": 18.5, "playlist": [ - "assets://ffpm-367.txt", - "assets://ews-89.txt", - "assets://ews-14.txt", - "assets://ffpm-392.txt", - "assets://ffpm-358.txt", - "assets://ffpm-307.txt", - "assets://ffpm-97-1.txt", - "assets://ews-13.txt", - "assets://ffpm-38.txt", - "assets://ffpm-57.txt", - "assets://ffpm-191.txt", - "assets://ff-7.txt", - "assets://ffpm-33.txt", - "assets://ffpm-760.txt", - "assets://ews-456.txt", - "assets://ffpm-51.txt", - "assets://ffpm-428.txt", - "assets://ffpm-449.txt", - "assets://ffpm-489.txt", - "assets://ffpm-21.txt", - "assets://ffpm-179.txt", - "assets://ff-33.txt", - "assets://ffpm-38.txt" + "assets://ffpm-745.txt", + "assets://ffpm-722.txt", + "assets://ffpm-92.txt", + "assets://ffpm-86.txt", + "assets://ews-93.txt", + "assets://ffpm-336.txt", + "assets://ffpm-147.txt", + "assets://ffpm-119.txt", + "assets://ews-92.txt", + "assets://ffpm-120.txt", + "assets://ews-91-1.txt", + "assets://ffpm-407-old.txt", + "assets://ffpm-407.txt", + "assets://ews-91-2.txt", + "assets://ffpm-605.txt", + "assets://ews-240.txt", + "assets://ffpm-477.txt", + "assets://ffpm-604.txt", + "assets://ffpm-600.txt", + "assets://ffpm-629.txt", + "assets://ffpm-630-2.txt", + "assets://ffpm-630-1.txt", + "assets://ffpm-632.txt", + "assets://ffpm-643.txt", + "assets://ffpm-647.txt", + "assets://ffpm-652.txt", + "assets://ffpm-655.txt", + "assets://ffpm-658.txt", + "assets://ffpm-661.txt", + "assets://ffpm-663.txt", + "assets://ffpm-670.txt", + "assets://ffpm-671-2.txt", + "assets://ffpm-671-1.txt", + "assets://ews-32-2.txt", + "assets://ffpm-675.txt", + "assets://ffpm-676-1.txt", + "assets://ffpm-676-2.txt", + "assets://ffpm-679.txt", + "assets://ffpm-680.txt", + "assets://ffpm-682-2.txt", + "assets://ffpm-682-1.txt", + "assets://ffpm-687.txt", + "assets://ffpm-346.txt", + "assets://ffpm-258.txt", + "assets://ews-151.txt", + "assets://ffpm-744.txt", + "assets://ews-217.txt", + "assets://ews-90.txt", + "assets://ffpm-113.txt", + "assets://ews-88.txt", + "assets://ffpm-115.txt", + "assets://ews-87.txt", + "assets://ffpm-102.txt", + "assets://ews-86.txt", + "assets://ffpm-98.txt", + "assets://ews-41-2.txt", + "assets://ews-85.txt", + "assets://ffpm-116.txt", + "assets://ews-84.txt", + "assets://ffpm-117.txt", + "assets://ews-83-2.txt", + "assets://ews-83.txt", + "assets://ffpm-114.txt", + "assets://ews-82-2.txt", + "assets://ews-184.txt", + "assets://ffpm-309.txt", + "assets://ews-82.txt", + "assets://ews-394.txt", + "assets://ews-387-2.txt", + "assets://ews-387-1.txt", + "assets://ffpm-782.txt", + "assets://ffpm-815-2.txt", + "assets://ffpm-88-1.txt", + "assets://ffpm-88-2.txt", + "assets://ews-81.txt", + "assets://ews-237.txt", + "assets://ews-80.txt", + "assets://ffpm-122-2.txt", + "assets://ffpm-122-1.txt", + + "assets://ews-352.txt", + "assets://ews-198.txt", + "assets://ffpm-398.txt", + "assets://ffpm-329-1.txt", + "assets://ews-218.txt", + "assets://ews-121.txt", + "assets://ews-79.txt", + "assets://ffpm-331.txt", + "assets://ffpm-657-2.txt", + "assets://ews-78.txt", + "assets://ffpm-657-1.txt", + "assets://ews-77.txt", + "assets://ffpm-99-1.txt", + "assets://ffpm-99-2.txt", + "assets://ffpm-359-2.txt", + "assets://ews-76.txt", + "assets://ffpm-359-1.txt", + + "assets://ews-75.txt", + "assets://ffpm-664.txt", + "assets://ffpm-798.txt", + "assets://ffpm-112-2.txt", + "assets://ews-74.txt", + "assets://ffpm-112-1.txt", + "assets://ews-73.txt", + "assets://ffpm-108.txt", + "assets://ews-72.txt", + "assets://ffpm-242-2.txt", + "assets://ffpm-242-1.txt", + "assets://ews-71.txt", + "assets://ews-124.txt", + "assets://ews-69.txt", + "assets://ews-68.txt", + "assets://ffpm-704.txt", + "assets://ews-67.txt", + "assets://ews-234.txt", + "assets://ffpm-85.txt", + "assets://ews-65-2.txt", + "assets://ews-65-1.txt", + "assets://ews-64.txt", + "assets://ews-63.txt", + "assets://ffpm-65-2.txt", + "assets://ffpm-65-1.txt", + "assets://ffpm-64.txt", + "assets://ffpm-76.txt", + "assets://ffpm-337-1.txt", + "assets://ffpm-337-2.txt", + + "assets://ffpm-75.txt" ], "buttonContainerColorHex": "#FFFF8855", "buttonContentColorHex": "#FF000055", diff --git a/composeApp/src/commonMain/composeResources/files/ews-35.txt b/composeApp/src/commonMain/composeResources/files/ews-35.txt index 14e1b63..c833a82 100644 --- a/composeApp/src/commonMain/composeResources/files/ews-35.txt +++ b/composeApp/src/commonMain/composeResources/files/ews-35.txt @@ -1,4 +1,4 @@ -M0:|c:D|m:3/4|a:Lewis Hartsough 1828-1919|r:8787D|h:Lewis Hartsough 1828-1919|t:FFPM 413 Ry Mpamonjy Tompo soa|u:https://hymnary.org/tune/lead_me_to_the_rock_thats_high_hartsough +M0:|c:D|m:3/4|a:Lewis Hartsough 1828-1919|r:8787D|h:Lewis Hartsough 1828-1919|t:EWS 35 Lead me to the Rock that's higher|u:https://hymnary.org/tune/lead_me_to_the_rock_thats_high_hartsough U0:z8:y 6222 44/y 6222 8/y 6222 44/y 4422 8/y 6222 (22)4/y 6222 8/y 6222 44/y 4422 8 N1:drmdmfss llslsmr drmdmfss d'lslmrd mfsmlssff fmrrmfs drmdmfss d'lslmrd N2:#s, ssdsdrmm ffmfmdt ssdsdrmm ffmddtd drmdfmmrr rdttdtd ssdsdrmm ffmddtd diff --git a/composeApp/src/commonMain/composeResources/files/ffpm-745.txt b/composeApp/src/commonMain/composeResources/files/ffpm-745.txt index 94ddc8b..672aa74 100644 --- a/composeApp/src/commonMain/composeResources/files/ffpm-745.txt +++ b/composeApp/src/commonMain/composeResources/files/ffpm-745.txt @@ -3,5 +3,5 @@ U0:zC:(22) (22)4(22)4 (44)4/4(22)(22)(22)(22) ${DC}C/(22) (22)(22)(22)(22) (422) I1:ffpm-722.txt:^(M|Y|U) Y1:Henoy ry Jeso Tompo:/Ny fitarainanay,/${D:Fa amin’alahelo/No ipetrahanay;/}Ny fonay mba maniry/Hitovy aminao,/Kanefa be ny ratsy/Misakana anay. Y2:Nateraky ny nofo,/Ka nofo izahay;/${D:Nanompo tompo ratsy,/Ka very hatrizay!/}Ny razanay nanota/Ka nodimbiasanay:/Ry Tomponay Tsitoha,/Havaozy izahay! -Y3:Ny asam-pamonjena/Natolotra Anao;/${D:Tsy hisy tsy ho vita/Izay natombokao;/}Ra\hao resy avoko_a/Ny fahavalonao,/Hiposaka toko_a/Ny tena taom-baovao! -Y4:Ny tavanao malala,/Ry Jeso Tomponay,/${D:Ho tena masoandro,/I\zay hifali_anay./}Ry nosatrohan-tsilo,/Faingàna Hi_anao,/Hanangana ny maty,/Hitondra aim-baovao! +Y3:Ny asam-pamonjena/Natolotra Anao;/${D:Tsy hisy tsy ho vita/Izay natombokao;/}Ra\ha resy avoko_a/Ny fahavalonao,/Hiposaka toko_a/Ny tena taom-baovao! +Y4:Ny tavanao malala,/Ry Jeso Tomponay,/${D:Ho tena maso_andro,/I\zay hifali_anay./}Ry nosatrohan-tsilo,/Faingàna Hi_anao,/Hanangana ny maty,/Hitondra aim-baovao! diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/LauchFilePicker.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/LauchFilePicker.kt index 3370334..cdf65e9 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/LauchFilePicker.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/LauchFilePicker.kt @@ -1,8 +1,7 @@ package mg.dot.feufaro -import androidx.compose.runtime.Composable - expect fun launchFilePicker( mimeTypes: Array, + initialDirectory: String?, onFileSelected: (path: String?) -> Unit ): Unit \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt index 73c727f..c18760e 100644 --- a/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt +++ b/composeApp/src/commonMain/kotlin/mg/dot/feufaro/solfa/Solfa.kt @@ -153,9 +153,9 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository launchFilePicker( mimeTypes = arrayOf("text/plain"), + initialDirectory = initialPath, onFileSelected = { path -> if (path != null) { - println("fichier $path"); sharedScreenModel.reset() parse(path) screenModelScope.launch { diff --git a/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/LauchFilePicker.kt b/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/LauchFilePicker.kt index 9102ed7..c524f30 100644 --- a/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/LauchFilePicker.kt +++ b/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/LauchFilePicker.kt @@ -1,30 +1,47 @@ package mg.dot.feufaro +import java.awt.EventQueue +import java.io.File import javax.swing.JFileChooser import javax.swing.filechooser.FileNameExtensionFilter -import java.awt.EventQueue actual fun launchFilePicker( mimeTypes: Array, + initialDirectory: String?, onFileSelected: (path: String?) -> Unit ) { EventQueue.invokeLater { val fileChooser = JFileChooser() - if (mimeTypes.isNotEmpty()) { - val filter = FileNameExtensionFilter( - "Fichiers texte", - "txt" - ) - fileChooser.fileFilter = filter + if(initialDirectory != null) { + val initialFile = File(initialDirectory) + + fileChooser.currentDirectory = File(initialDirectory) } - fileChooser.dialogTitle = "Sélectionnez votre fichier personnalisé" + var isTxt = mimeTypes[0].equals("text/plain") + var isImages = mimeTypes[0].equals("images/jpeg") + + if (mimeTypes.isNotEmpty()) { + if (isTxt) { + val filter = FileNameExtensionFilter("Fichiers texte", "txt") + fileChooser.fileFilter = filter + } else if (isImages) { + val filter = FileNameExtensionFilter("Images", "jpg") + fileChooser.fileFilter = filter + } + } + + fileChooser.dialogTitle = "Sélectionnez votre fichier" val result = fileChooser.showOpenDialog(null) if (result == JFileChooser.APPROVE_OPTION) { - onFileSelected(fileChooser.selectedFile.absolutePath) + if(isTxt) { + onFileSelected(fileChooser.selectedFile.absolutePath) + } else if(isImages) { +// onFileSelected(fileChooser.selectedFile.absoluteFile) + } } else { onFileSelected(null) }