From d7a9de736c78b6df74e498d49135ab5de8869ab6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 9 Jan 2020 11:42:02 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/main/MainActivity.kt | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) 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 571b32139..ddb8b3f10 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 @@ -16,6 +16,7 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus import io.legado.app.constant.PreferKey +import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.storage.Backup import io.legado.app.lib.theme.ATH 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.utils.* import kotlinx.android.synthetic.main.activity_main.* -import kotlinx.coroutines.launch class MainActivity : VMBaseActivity(R.layout.activity_main), BottomNavigationView.OnNavigationItemSelectedListener, @@ -116,25 +116,23 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), override fun finish() { if (!BuildConfig.DEBUG) { - launch { - backup() - super.finish() - } - } else { - super.finish() + backup() } + super.finish() } - private suspend fun backup() { - val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isNotEmpty() == true) { - val uri = Uri.parse(backupPath) - val doc = DocumentFile.fromTreeUri(this, uri) - if (doc?.canWrite() == true) { - Backup.backup(this@MainActivity, uri) + private fun backup() { + Coroutine.async { + val backupPath = getPrefString(PreferKey.backupPath) + if (backupPath?.isNotEmpty() == true) { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(this@MainActivity, uri) + if (doc?.canWrite() == true) { + Backup.backup(this@MainActivity, uri) + } + } else { + Backup.backup(this@MainActivity, null) } - } else { - Backup.backup(this@MainActivity, null) } }