diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index c47951385..5b1e88186 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -32,9 +32,7 @@ object Backup { val lastBackup = context.getPrefLong(PreferKey.lastBackup) if (lastBackup + TimeUnit.DAYS.toMillis(1) < System.currentTimeMillis()) { Coroutine.async { - context.getPrefString(PreferKey.backupPath)?.let { - backup(context, it, true) - } + backup(context, context.getPrefString(PreferKey.backupPath) ?: "", true) } } } @@ -71,7 +69,11 @@ object Backup { if (path.isContentPath()) { copyBackup(context, Uri.parse(path), isAuto) } else { - copyBackup(File(path), isAuto) + if (path.isEmpty()) { + copyBackup(context.getExternalFilesDir(null)!!, false) + } else { + copyBackup(File(path), isAuto) + } } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 93e39afad..2db36940d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -134,6 +134,10 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo timeBatteryReceiver = null } upSystemUiVisibility() + if (!BuildConfig.DEBUG) { + SyncBookProgress.uploadBookProgress() + Backup.autoBack(this) + } } /** diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 0aa49ede7..a7a2b3209 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -15,6 +15,7 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig +import io.legado.app.help.storage.Backup import io.legado.app.lib.theme.ATH import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud @@ -113,6 +114,13 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), return super.onKeyUp(keyCode, event) } + override fun onPause() { + super.onPause() + if (!BuildConfig.DEBUG) { + Backup.autoBack(this) + } + } + override fun onDestroy() { super.onDestroy() ReadAloud.stop(this)