File picker
This commit is contained in:
parent
581bf42b32
commit
99314a1b4d
8 changed files with 214 additions and 39 deletions
|
|
@ -1,8 +1,60 @@
|
||||||
package mg.dot.feufaro
|
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<Intent>? = null
|
||||||
|
|
||||||
|
|
||||||
actual fun launchFilePicker(
|
actual fun launchFilePicker(
|
||||||
mimeTypes: Array<String>,
|
mimeTypes: Array<String>,
|
||||||
|
initialDirectory: String?,
|
||||||
onFileSelected: (path: String?) -> Unit
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -15,6 +15,7 @@ class MainActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
setFilePickerActivity(this)
|
||||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
hideSystemBar()
|
hideSystemBar()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,29 +2,135 @@
|
||||||
"themeMode": "DARK",
|
"themeMode": "DARK",
|
||||||
"fontSize": 18.5,
|
"fontSize": 18.5,
|
||||||
"playlist": [
|
"playlist": [
|
||||||
"assets://ffpm-367.txt",
|
"assets://ffpm-745.txt",
|
||||||
"assets://ews-89.txt",
|
"assets://ffpm-722.txt",
|
||||||
"assets://ews-14.txt",
|
"assets://ffpm-92.txt",
|
||||||
"assets://ffpm-392.txt",
|
"assets://ffpm-86.txt",
|
||||||
"assets://ffpm-358.txt",
|
"assets://ews-93.txt",
|
||||||
"assets://ffpm-307.txt",
|
"assets://ffpm-336.txt",
|
||||||
"assets://ffpm-97-1.txt",
|
"assets://ffpm-147.txt",
|
||||||
"assets://ews-13.txt",
|
"assets://ffpm-119.txt",
|
||||||
"assets://ffpm-38.txt",
|
"assets://ews-92.txt",
|
||||||
"assets://ffpm-57.txt",
|
"assets://ffpm-120.txt",
|
||||||
"assets://ffpm-191.txt",
|
"assets://ews-91-1.txt",
|
||||||
"assets://ff-7.txt",
|
"assets://ffpm-407-old.txt",
|
||||||
"assets://ffpm-33.txt",
|
"assets://ffpm-407.txt",
|
||||||
"assets://ffpm-760.txt",
|
"assets://ews-91-2.txt",
|
||||||
"assets://ews-456.txt",
|
"assets://ffpm-605.txt",
|
||||||
"assets://ffpm-51.txt",
|
"assets://ews-240.txt",
|
||||||
"assets://ffpm-428.txt",
|
"assets://ffpm-477.txt",
|
||||||
"assets://ffpm-449.txt",
|
"assets://ffpm-604.txt",
|
||||||
"assets://ffpm-489.txt",
|
"assets://ffpm-600.txt",
|
||||||
"assets://ffpm-21.txt",
|
"assets://ffpm-629.txt",
|
||||||
"assets://ffpm-179.txt",
|
"assets://ffpm-630-2.txt",
|
||||||
"assets://ff-33.txt",
|
"assets://ffpm-630-1.txt",
|
||||||
"assets://ffpm-38.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",
|
"buttonContainerColorHex": "#FFFF8855",
|
||||||
"buttonContentColorHex": "#FF000055",
|
"buttonContentColorHex": "#FF000055",
|
||||||
|
|
|
||||||
|
|
@ -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
|
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
|
N1:drmdmfss llslsmr drmdmfss d'lslmrd mfsmlssff fmrrmfs drmdmfss d'lslmrd
|
||||||
N2:#s, ssdsdrmm ffmfmdt ssdsdrmm ffmddtd drmdfmmrr rdttdtd ssdsdrmm ffmddtd
|
N2:#s, ssdsdrmm ffmfmdt ssdsdrmm ffmddtd drmdfmmrr rdttdtd ssdsdrmm ffmddtd
|
||||||
|
|
|
||||||
|
|
@ -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)
|
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.
|
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!
|
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!
|
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 masoandro,/I\zay hifali_anay./}Ry nosatrohan-tsilo,/Faingàna Hi_anao,/Hanangana ny maty,/Hitondra aim-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!
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
package mg.dot.feufaro
|
package mg.dot.feufaro
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
|
|
||||||
expect fun launchFilePicker(
|
expect fun launchFilePicker(
|
||||||
mimeTypes: Array<String>,
|
mimeTypes: Array<String>,
|
||||||
|
initialDirectory: String?,
|
||||||
onFileSelected: (path: String?) -> Unit
|
onFileSelected: (path: String?) -> Unit
|
||||||
): Unit
|
): Unit
|
||||||
|
|
@ -153,9 +153,9 @@ class Solfa(val sharedScreenModel: SharedScreenModel, private val fileRepository
|
||||||
|
|
||||||
launchFilePicker(
|
launchFilePicker(
|
||||||
mimeTypes = arrayOf("text/plain"),
|
mimeTypes = arrayOf("text/plain"),
|
||||||
|
initialDirectory = initialPath,
|
||||||
onFileSelected = { path ->
|
onFileSelected = { path ->
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
println("fichier $path");
|
|
||||||
sharedScreenModel.reset()
|
sharedScreenModel.reset()
|
||||||
parse(path)
|
parse(path)
|
||||||
screenModelScope.launch {
|
screenModelScope.launch {
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,47 @@
|
||||||
package mg.dot.feufaro
|
package mg.dot.feufaro
|
||||||
|
|
||||||
|
import java.awt.EventQueue
|
||||||
|
import java.io.File
|
||||||
import javax.swing.JFileChooser
|
import javax.swing.JFileChooser
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter
|
import javax.swing.filechooser.FileNameExtensionFilter
|
||||||
import java.awt.EventQueue
|
|
||||||
|
|
||||||
actual fun launchFilePicker(
|
actual fun launchFilePicker(
|
||||||
mimeTypes: Array<String>,
|
mimeTypes: Array<String>,
|
||||||
|
initialDirectory: String?,
|
||||||
onFileSelected: (path: String?) -> Unit
|
onFileSelected: (path: String?) -> Unit
|
||||||
) {
|
) {
|
||||||
EventQueue.invokeLater {
|
EventQueue.invokeLater {
|
||||||
val fileChooser = JFileChooser()
|
val fileChooser = JFileChooser()
|
||||||
|
|
||||||
if (mimeTypes.isNotEmpty()) {
|
if(initialDirectory != null) {
|
||||||
val filter = FileNameExtensionFilter(
|
val initialFile = File(initialDirectory)
|
||||||
"Fichiers texte",
|
|
||||||
"txt"
|
fileChooser.currentDirectory = File(initialDirectory)
|
||||||
)
|
|
||||||
fileChooser.fileFilter = filter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
val result = fileChooser.showOpenDialog(null)
|
||||||
|
|
||||||
if (result == JFileChooser.APPROVE_OPTION) {
|
if (result == JFileChooser.APPROVE_OPTION) {
|
||||||
|
if(isTxt) {
|
||||||
onFileSelected(fileChooser.selectedFile.absolutePath)
|
onFileSelected(fileChooser.selectedFile.absolutePath)
|
||||||
|
} else if(isImages) {
|
||||||
|
// onFileSelected(fileChooser.selectedFile.absoluteFile)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
onFileSelected(null)
|
onFileSelected(null)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue