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 ac197d9db..13b1f29b0 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 @@ -24,8 +24,9 @@ import io.legado.app.ui.main.myconfig.MyConfigFragment import io.legado.app.utils.getCompatColor import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_main.* -import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext class MainActivity : BaseActivity(), BottomNavigationView.OnNavigationItemSelectedListener, ViewPager.OnPageChangeListener { @@ -62,14 +63,12 @@ class MainActivity : BaseActivity(), BottomNavigationView.OnNavig private fun importYueDu() { launch { - if (App.db.bookDao().allBookCount == 0) { - launch(Main) { - PermissionsCompat.Builder(this@MainActivity) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { viewModel.restore() } - .request() - } + if (withContext(IO) { App.db.bookDao().allBookCount == 0 }) { + PermissionsCompat.Builder(this@MainActivity) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { viewModel.restore() } + .request() } } }