Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/src/main/java/mba/vm/onhit/ui/FragmentNdefFilePicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ class FragmentNdefFilePicker : Fragment() {
private var _binding: FragmentNdefFilePickerBinding? = null
private val binding get() = _binding!!

private var isDirLauncherOpened: Boolean = false

private val openDirLauncher =
registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri: Uri? ->
isDirLauncherOpened = false
uri ?: return@registerForActivityResult
val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_WRITE_URI_PERMISSION
Expand Down Expand Up @@ -80,7 +83,7 @@ class FragmentNdefFilePicker : Fragment() {
refreshFileList()
} ?: run {
Toast.makeText(requireContext(), R.string.toast_select_folder_saving_ndef_files, Toast.LENGTH_SHORT).show()
openDirLauncher.launch(null)
launchOpenDirOnce()
}
}

Expand All @@ -105,7 +108,7 @@ class FragmentNdefFilePicker : Fragment() {
R.string.toast_selected_folder_unavailable,
Toast.LENGTH_SHORT
).show()
openDirLauncher.launch(null)
launchOpenDirOnce()
return
}
val fileList: List<DocumentFile> = dir.listFiles()
Expand Down Expand Up @@ -199,6 +202,12 @@ class FragmentNdefFilePicker : Fragment() {
}
}

private fun launchOpenDirOnce() {
if (isDirLauncherOpened) return
isDirLauncherOpened = true
openDirLauncher.launch(null)
}

override fun onResume() {
super.onResume()
getChosenFolderUri(requireContext())?.let {
Expand Down