pull/70/head
kunfei 5 years ago
parent f5873c6070
commit d7a9de736c
  1. 12
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -16,6 +16,7 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Backup
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
@ -27,7 +28,6 @@ import io.legado.app.ui.main.my.MyFragment
import io.legado.app.ui.main.rss.RssFragment import io.legado.app.ui.main.rss.RssFragment
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.launch
class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main), class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
BottomNavigationView.OnNavigationItemSelectedListener, BottomNavigationView.OnNavigationItemSelectedListener,
@ -116,20 +116,17 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
override fun finish() { override fun finish() {
if (!BuildConfig.DEBUG) { if (!BuildConfig.DEBUG) {
launch {
backup() backup()
super.finish()
} }
} else {
super.finish() super.finish()
} }
}
private suspend fun backup() { private fun backup() {
Coroutine.async {
val backupPath = getPrefString(PreferKey.backupPath) val backupPath = getPrefString(PreferKey.backupPath)
if (backupPath?.isNotEmpty() == true) { if (backupPath?.isNotEmpty() == true) {
val uri = Uri.parse(backupPath) val uri = Uri.parse(backupPath)
val doc = DocumentFile.fromTreeUri(this, uri) val doc = DocumentFile.fromTreeUri(this@MainActivity, uri)
if (doc?.canWrite() == true) { if (doc?.canWrite() == true) {
Backup.backup(this@MainActivity, uri) Backup.backup(this@MainActivity, uri)
} }
@ -137,6 +134,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
Backup.backup(this@MainActivity, null) Backup.backup(this@MainActivity, null)
} }
} }
}
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()

Loading…
Cancel
Save