fix create file view to open file view

This commit is contained in:
Finnley Somdahl 2024-02-02 09:12:02 -06:00
parent 10ae66d1d0
commit 7e51e067cd

View file

@ -70,7 +70,6 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
lateinit var binding: ActivitySettingsBinding lateinit var binding: ActivitySettingsBinding
private val extensionInstaller = Injekt.get<BasePreferences>().extensionInstaller() private val extensionInstaller = Injekt.get<BasePreferences>().extensionInstaller()
private var cursedCounter = 0 private var cursedCounter = 0
private lateinit var openDocumentLauncher: ActivityResultLauncher<String>
@OptIn(UnstableApi::class) @OptIn(UnstableApi::class)
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
@ -83,11 +82,11 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
initActivity(this) initActivity(this)
var selectedImpExp = "" var selectedImpExp = ""
openDocumentLauncher = registerForActivityResult(CreateDocument("*/*")) { uri -> val openDocumentLauncher = registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
if (uri != null) { if (uri != null) {
try { try {
val jsonString = contentResolver.openInputStream(uri)?.bufferedReader() val jsonString = contentResolver.openInputStream(uri)?.bufferedReader()
.use { it?.readText() } .use { it?.readText()}
val location: Location = val location: Location =
Location.entries.find { it.name.lowercase() == selectedImpExp.lowercase() } Location.entries.find { it.name.lowercase() == selectedImpExp.lowercase() }
?: return@registerForActivityResult ?: return@registerForActivityResult
@ -273,7 +272,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
i = which i = which
} }
.setPositiveButton("Import...") { dialog, _ -> .setPositiveButton("Import...") { dialog, _ ->
openDocumentLauncher.launch("Select a file") openDocumentLauncher.launch(arrayOf("*/*"))
dialog.dismiss() dialog.dismiss()
} }
.setNegativeButton("Export...") { dialog, _ -> .setNegativeButton("Export...") { dialog, _ ->