mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 08:29:20 +01:00
Fix restore in Android 11
This commit is contained in:
parent
2be9871d05
commit
c0e4863229
@ -11,6 +11,7 @@ import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.preference.PreferenceScreen
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.list.listItemsMultiChoice
|
||||
@ -81,7 +82,18 @@ class SettingsBackupController : SettingsController() {
|
||||
titleRes = R.string.pref_restore_backup
|
||||
summaryRes = R.string.pref_restore_backup_summ
|
||||
|
||||
onClick { restore(context) }
|
||||
onClick {
|
||||
if (!BackupRestoreService.isRunning(context)) {
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
intent.type = "application/*"
|
||||
val title = resources?.getString(R.string.file_select_backup)
|
||||
val chooser = Intent.createChooser(intent, title)
|
||||
startActivityForResult(chooser, CODE_BACKUP_RESTORE)
|
||||
} else {
|
||||
context.toast(R.string.restore_in_progress)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
preferenceCategory {
|
||||
@ -193,33 +205,40 @@ class SettingsBackupController : SettingsController() {
|
||||
)
|
||||
}
|
||||
CODE_BACKUP_RESTORE -> {
|
||||
if (uri?.path != null) {
|
||||
if (uri.path!!.endsWith(".proto.gz")) {
|
||||
val options = arrayOf(
|
||||
R.string.full_restore_offline,
|
||||
R.string.full_restore_online
|
||||
)
|
||||
.map { activity.getString(it) }
|
||||
MaterialDialog(activity)
|
||||
.title(R.string.full_restore_mode)
|
||||
.listItemsSingleChoice(
|
||||
items = options,
|
||||
initialSelection = 0
|
||||
) { _, index, _ ->
|
||||
RestoreBackupDialog(
|
||||
uri,
|
||||
BackupConst.BACKUP_TYPE_FULL,
|
||||
isOnline = index != 0
|
||||
).showDialog(router)
|
||||
}
|
||||
.positiveButton(R.string.action_restore)
|
||||
.show()
|
||||
} else if (uri.path!!.endsWith(".json")) {
|
||||
RestoreBackupDialog(
|
||||
uri,
|
||||
BackupConst.BACKUP_TYPE_LEGACY,
|
||||
isOnline = true
|
||||
).showDialog(router)
|
||||
uri?.path?.let { path ->
|
||||
val fileName = DocumentFile.fromSingleUri(activity, uri)!!.name!!
|
||||
when {
|
||||
fileName.endsWith(".proto.gz") -> {
|
||||
val options = arrayOf(
|
||||
R.string.full_restore_offline,
|
||||
R.string.full_restore_online
|
||||
)
|
||||
.map { activity.getString(it) }
|
||||
MaterialDialog(activity)
|
||||
.title(R.string.full_restore_mode)
|
||||
.listItemsSingleChoice(
|
||||
items = options,
|
||||
initialSelection = 0
|
||||
) { _, index, _ ->
|
||||
RestoreBackupDialog(
|
||||
uri,
|
||||
BackupConst.BACKUP_TYPE_FULL,
|
||||
isOnline = index != 0
|
||||
).showDialog(router)
|
||||
}
|
||||
.positiveButton(R.string.action_restore)
|
||||
.show()
|
||||
}
|
||||
fileName.endsWith(".json") -> {
|
||||
RestoreBackupDialog(
|
||||
uri,
|
||||
BackupConst.BACKUP_TYPE_LEGACY,
|
||||
isOnline = true
|
||||
).showDialog(router)
|
||||
}
|
||||
else -> {
|
||||
activity.toast(activity.getString(R.string.invalid_backup_file_type, fileName))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -237,19 +256,6 @@ class SettingsBackupController : SettingsController() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun restore(context: Context) {
|
||||
if (!BackupRestoreService.isRunning(context)) {
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
intent.type = "application/*"
|
||||
val title = resources?.getString(R.string.file_select_backup)
|
||||
val chooser = Intent.createChooser(intent, title)
|
||||
startActivityForResult(chooser, CODE_BACKUP_RESTORE)
|
||||
} else {
|
||||
context.toast(R.string.restore_in_progress)
|
||||
}
|
||||
}
|
||||
|
||||
fun createBackup(flags: Int, type: Int) {
|
||||
backupFlags = flags
|
||||
val currentDir = preferences.backupsDirectory().get()
|
||||
|
@ -365,6 +365,7 @@
|
||||
<string name="tracker_not_logged_in">Not logged in: %1$s</string>
|
||||
<string name="backup_created">Backup created</string>
|
||||
<string name="invalid_backup_file">Invalid backup file</string>
|
||||
<string name="invalid_backup_file_type">Invalid backup file: %1$s</string>
|
||||
<string name="invalid_backup_file_missing_data">File is missing data.</string>
|
||||
<string name="invalid_backup_file_missing_manga">Backup does not contain any manga.</string>
|
||||
<string name="backup_restore_missing_sources">Missing sources:</string>
|
||||
|
Loading…
Reference in New Issue
Block a user