feat: 优化代码

pull/182/head
kunfei 5 years ago
parent 9711ca0a51
commit 39d079dfc9
  1. 8
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 8
      app/src/main/java/io/legado/app/ui/main/MainActivity.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)
}
}
}
@ -70,12 +68,16 @@ object Backup {
WebDavHelp.backUpWebDav(backupPath)
if (path.isContentPath()) {
copyBackup(context, Uri.parse(path), isAuto)
} else {
if (path.isEmpty()) {
copyBackup(context.getExternalFilesDir(null)!!, false)
} else {
copyBackup(File(path), isAuto)
}
}
}
}
}
private fun writeListToJson(list: List<Any>, fileName: String, path: String) {
if (list.isNotEmpty()) {

@ -134,6 +134,10 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
timeBatteryReceiver = null
}
upSystemUiVisibility()
if (!BuildConfig.DEBUG) {
SyncBookProgress.uploadBookProgress()
Backup.autoBack(this)
}
}
/**

@ -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<MainViewModel>(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)

Loading…
Cancel
Save