Skip to content

Commit

Permalink
fix(settings/storage): folder picker on raw path inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
aliernfrog committed Sep 14, 2024
1 parent c2aa90a commit b186816
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ private fun FolderConfiguration(
) {
val context = LocalContext.current
var activePref: PrefEditItem<String>? = remember { null }
val openFolderLauncher = rememberLauncherForActivityResult(contract = ActivityResultContracts.OpenDocumentTree(), onResult = {
if (it == null) return@rememberLauncherForActivityResult
val openFolderLauncher = rememberLauncherForActivityResult(contract = ActivityResultContracts.OpenDocumentTree(), onResult = { uri ->
if (uri == null) return@rememberLauncherForActivityResult
val pref = activePref ?: return@rememberLauncherForActivityResult
it.takePersistablePermissions(context)
pref.preference(prefs).value = it.toString()
if (!useRawPathInputs) uri.takePersistablePermissions(context)
pref.preference(prefs).value = uri.toString().let {
if (useRawPathInputs) FileUtil.getFilePath(it) else it
}
})

AnimatedContent(useRawPathInputs) { rawPathInput ->
Expand All @@ -145,6 +147,7 @@ private fun FolderConfiguration(
label = label,
pref = pref,
onPickFolderRequest = {
activePref = prefEditItem
openFolderLauncher.launch(null)
}
)
Expand Down

0 comments on commit b186816

Please sign in to comment.