备份失败时及时提醒

pull/1188/head
NineWorlds 3 years ago
parent 1468a398cf
commit 6e40b28880
  1. 3
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  2. 8
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt
  3. 1
      app/src/main/res/values-zh/strings.xml
  4. 1
      app/src/main/res/values/strings.xml

@ -3,6 +3,7 @@ package io.legado.app.help.storage
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import io.legado.app.R
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.help.DefaultData import io.legado.app.help.DefaultData
@ -49,6 +50,8 @@ object Backup {
if (lastBackup + TimeUnit.DAYS.toMillis(1) < System.currentTimeMillis()) { if (lastBackup + TimeUnit.DAYS.toMillis(1) < System.currentTimeMillis()) {
Coroutine.async { Coroutine.async {
backup(context, context.getPrefString(PreferKey.backupPath) ?: "", true) backup(context, context.getPrefString(PreferKey.backupPath) ?: "", true)
}.onError {
appCtx.toastOnUi(R.string.autobackup_fail)
} }
} }
} }

@ -52,6 +52,8 @@ class BackupConfigFragment : BasePreferenceFragment(),
Backup.backup(appCtx, uri.toString()) Backup.backup(appCtx, uri.toString())
}.onSuccess { }.onSuccess {
appCtx.toastOnUi(R.string.backup_success) appCtx.toastOnUi(R.string.backup_success)
}.onError {
appCtx.toastOnUi(R.string.backup_fail)
} }
} else { } else {
uri.path?.let { path -> uri.path?.let { path ->
@ -60,6 +62,8 @@ class BackupConfigFragment : BasePreferenceFragment(),
Backup.backup(appCtx, path) Backup.backup(appCtx, path)
}.onSuccess { }.onSuccess {
appCtx.toastOnUi(R.string.backup_success) appCtx.toastOnUi(R.string.backup_success)
}.onError {
appCtx.toastOnUi(R.string.backup_fail)
} }
} }
} }
@ -231,6 +235,8 @@ class BackupConfigFragment : BasePreferenceFragment(),
Backup.backup(requireContext(), backupPath) Backup.backup(requireContext(), backupPath)
}.onSuccess { }.onSuccess {
toastOnUi(R.string.backup_success) toastOnUi(R.string.backup_success)
}.onError {
toastOnUi(R.string.backup_fail)
} }
} else { } else {
backupDir.launch(null) backupDir.launch(null)
@ -251,6 +257,8 @@ class BackupConfigFragment : BasePreferenceFragment(),
Backup.backup(requireContext(), path) Backup.backup(requireContext(), path)
}.onSuccess { }.onSuccess {
toastOnUi(R.string.backup_success) toastOnUi(R.string.backup_success)
}.onError {
toastOnUi(R.string.backup_fail)
} }
} }
.request() .request()

@ -846,5 +846,6 @@
<string name="null_url">url为空</string> <string name="null_url">url为空</string>
<string name="dict">字典</string> <string name="dict">字典</string>
<string name="unknown_error">未知错误</string> <string name="unknown_error">未知错误</string>
<string name="autobackup_fail">自动备份失败</string>
</resources> </resources>

@ -848,5 +848,6 @@
<string name="null_url">Null url</string> <string name="null_url">Null url</string>
<string name="dict">字典</string> <string name="dict">字典</string>
<string name="unknown_error">未知错误</string> <string name="unknown_error">未知错误</string>
<string name="autobackup_fail">Autobackup failed</string>
</resources> </resources>

Loading…
Cancel
Save