Use modern OpenDocument for backup file selection (#3948)
This might also fix the underlying problem of #3947. I don't have any nonstandard devices available, but this works fine in an A17 Pixel emulator & on my A14 Xiaomi device. Looks like the GetContent approach was merely carried over from older code without being updated to the more modern OpenDocument contract.
This commit is contained in:
+11
-10
@@ -1,7 +1,6 @@
|
|||||||
package eu.kanade.presentation.more.settings.screen
|
package eu.kanade.presentation.more.settings.screen
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException
|
import android.content.ActivityNotFoundException
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.activity.compose.ManagedActivityResultLauncher
|
import androidx.activity.compose.ManagedActivityResultLauncher
|
||||||
@@ -186,18 +185,22 @@ object SettingsDataScreen : SearchableSettings {
|
|||||||
val lastAutoBackup by backupPreferences.lastAutoBackupTimestamp.collectAsState()
|
val lastAutoBackup by backupPreferences.lastAutoBackupTimestamp.collectAsState()
|
||||||
|
|
||||||
val chooseBackup = rememberLauncherForActivityResult(
|
val chooseBackup = rememberLauncherForActivityResult(
|
||||||
object : ActivityResultContracts.GetContent() {
|
ActivityResultContracts.OpenDocument(),
|
||||||
override fun createIntent(context: Context, input: String): Intent {
|
|
||||||
val intent = super.createIntent(context, input)
|
|
||||||
return Intent.createChooser(intent, context.stringResource(MR.strings.file_select_backup))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
) {
|
) {
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
context.toast(MR.strings.file_null_uri_error)
|
context.toast(MR.strings.file_null_uri_error)
|
||||||
return@rememberLauncherForActivityResult
|
return@rememberLauncherForActivityResult
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
context.contentResolver.takePersistableUriPermission(
|
||||||
|
it,
|
||||||
|
Intent.FLAG_GRANT_READ_URI_PERMISSION,
|
||||||
|
)
|
||||||
|
} catch (e: SecurityException) {
|
||||||
|
logcat(LogPriority.ERROR, e)
|
||||||
|
}
|
||||||
|
|
||||||
navigator.push(RestoreBackupScreen(it.toString()))
|
navigator.push(RestoreBackupScreen(it.toString()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,9 +235,7 @@ object SettingsDataScreen : SearchableSettings {
|
|||||||
if (DeviceUtil.isMiui && DeviceUtil.isMiuiOptimizationDisabled()) {
|
if (DeviceUtil.isMiui && DeviceUtil.isMiuiOptimizationDisabled()) {
|
||||||
context.toast(MR.strings.restore_miui_warning)
|
context.toast(MR.strings.restore_miui_warning)
|
||||||
}
|
}
|
||||||
|
chooseBackup.launch(arrayOf("*/*"))
|
||||||
// no need to catch because it's wrapped with a chooser
|
|
||||||
chooseBackup.launch("*/*")
|
|
||||||
} else {
|
} else {
|
||||||
context.toast(MR.strings.restore_in_progress)
|
context.toast(MR.strings.restore_in_progress)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user