From f37c24e550a88788d6aa25ac738d8d0ddf73612b Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 13:10:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/storage/WebDavHelp.kt | 8 +++++--- .../java/io/legado/app/ui/config/BackupConfigFragment.kt | 4 +++- app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt | 4 +++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index fb2e09a15..abd7a8a8a 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -54,12 +54,12 @@ object WebDavHelp { return names } - suspend fun showRestoreDialog(context: Context): Boolean { + suspend fun showRestoreDialog(context: Context, restoreSuccess: () -> Unit): Boolean { val names = withContext(IO) { getWebDavFileNames() } return if (names.isNotEmpty()) { context.selector(title = "选择恢复文件", items = names) { _, index -> if (index in 0 until names.size) { - restoreWebDav(names[index]) + restoreWebDav(names[index], restoreSuccess) } } true @@ -68,7 +68,7 @@ object WebDavHelp { } } - private fun restoreWebDav(name: String) { + private fun restoreWebDav(name: String, success: () -> Unit) { Coroutine.async { getWebDavUrl()?.let { val file = WebDav(it + "legado/" + name) @@ -77,6 +77,8 @@ object WebDavHelp { ZipUtils.unzipFile(zipFilePath, unzipFilesPath) Restore.restore(unzipFilesPath) } + }.onSuccess { + success.invoke() } } diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 39c711974..2f153da3f 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -158,7 +158,9 @@ class BackupConfigFragment : PreferenceFragmentCompat(), fun restore() { launch { - if (!WebDavHelp.showRestoreDialog(requireContext())) { + if (!WebDavHelp.showRestoreDialog(requireContext()) { + toast(R.string.restore_success) + }) { val backupPath = getPrefString(PreferKey.backupPath) if (backupPath?.isNotEmpty() == true) { val uri = Uri.parse(backupPath) diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index fdae803bf..2c515dbb7 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -100,7 +100,9 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { fun restore() { launch { - if (!WebDavHelp.showRestoreDialog(requireContext())) { + if (!WebDavHelp.showRestoreDialog(requireContext()) { + toast(R.string.restore_success) + }) { val backupPath = getPrefString(PreferKey.backupPath) if (backupPath?.isNotEmpty() == true) { val uri = Uri.parse(backupPath)