pull/94/head
kunfei 5 years ago
parent 25425e7c45
commit 61c4a3f242
  1. 47
      app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt
  2. 6
      app/src/main/res/values/arrays.xml
  3. 3
      app/src/main/res/values/strings.xml

@ -67,7 +67,7 @@ object BackupRestoreUi {
fun selectBackupFolder(fragment: Fragment) { fun selectBackupFolder(fragment: Fragment) {
fragment.alert { fragment.alert {
titleResource = R.string.select_folder titleResource = R.string.select_folder
items(arrayListOf("默认路径", "系统文件夹选择器", "自带文件夹选择器")) { _, index -> items(fragment.resources.getStringArray(R.array.select_folder).toList()) { _, index ->
when (index) { when (index) {
0 -> PermissionsCompat.Builder(fragment) 0 -> PermissionsCompat.Builder(fragment)
.addPermissions(*Permissions.Group.STORAGE) .addPermissions(*Permissions.Group.STORAGE)
@ -118,23 +118,38 @@ object BackupRestoreUi {
} }
private fun selectRestoreFolder(fragment: Fragment) { private fun selectRestoreFolder(fragment: Fragment) {
try { fragment.alert {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) titleResource = R.string.select_folder
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) items(fragment.resources.getStringArray(R.array.select_folder).toList()) { _, index ->
fragment.startActivityForResult(intent, restoreSelectRequestCode) when (index) {
} catch (e: java.lang.Exception) { 0 -> PermissionsCompat.Builder(fragment)
PermissionsCompat.Builder(fragment) .addPermissions(*Permissions.Group.STORAGE)
.addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage)
.rationale(R.string.tip_perm_request_storage) .onGranted {
.onGranted { Coroutine.async {
Coroutine.async { AppConfig.backupPath = Backup.legadoPath
Restore.restore(Backup.legadoPath) Restore.restore(Backup.legadoPath)
}.onSuccess { }.onSuccess {
fragment.toast(R.string.restore_success) fragment.toast(R.string.restore_success)
}
}
.request()
1 -> {
try {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
fragment.startActivityForResult(intent, restoreSelectRequestCode)
} catch (e: java.lang.Exception) {
e.printStackTrace()
fragment.toast(e.localizedMessage ?: "ERROR")
}
}
2 -> {
} }
} }
.request() }
} }.show()
} }
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

@ -98,6 +98,12 @@
<item>-1</item> <item>-1</item>
</string-array> </string-array>
<string-array name="select_folder">
<item>@string/default_path</item>
<item>@string/sys_folder_picker</item>
<item>@string/app_folder_picker</item>
</string-array>
<string-array name="screen_direction_list_title"> <string-array name="screen_direction_list_title">
<item>@string/screen_unspecified</item> <item>@string/screen_unspecified</item>
<item>@string/screen_portrait</item> <item>@string/screen_portrait</item>

@ -599,5 +599,8 @@
<string name="show_rss">显示订阅</string> <string name="show_rss">显示订阅</string>
<string name="service_stop">服务已停止</string> <string name="service_stop">服务已停止</string>
<string name="service_start">正在启动服务\n具体信息查看通知栏</string> <string name="service_start">正在启动服务\n具体信息查看通知栏</string>
<string name="default_path">默认路径</string>
<string name="sys_folder_picker">系统文件夹选择器</string>
<string name="app_folder_picker">自带选择器(Android10以上可能会失效)</string>
</resources> </resources>

Loading…
Cancel
Save