|
|
@ -1,8 +1,10 @@ |
|
|
|
package io.legado.app.ui.main |
|
|
|
package io.legado.app.ui.main |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.net.Uri |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import android.view.KeyEvent |
|
|
|
import android.view.KeyEvent |
|
|
|
import android.view.MenuItem |
|
|
|
import android.view.MenuItem |
|
|
|
|
|
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
import androidx.fragment.app.FragmentManager |
|
|
|
import androidx.fragment.app.FragmentManager |
|
|
|
import androidx.fragment.app.FragmentStatePagerAdapter |
|
|
|
import androidx.fragment.app.FragmentStatePagerAdapter |
|
|
@ -13,6 +15,8 @@ import io.legado.app.BuildConfig |
|
|
|
import io.legado.app.R |
|
|
|
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.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 |
|
|
|
import io.legado.app.service.help.ReadAloud |
|
|
|
import io.legado.app.service.help.ReadAloud |
|
|
@ -28,8 +32,6 @@ import kotlinx.coroutines.launch |
|
|
|
class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main), |
|
|
|
class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main), |
|
|
|
BottomNavigationView.OnNavigationItemSelectedListener, |
|
|
|
BottomNavigationView.OnNavigationItemSelectedListener, |
|
|
|
ViewPager.OnPageChangeListener by ViewPager.SimpleOnPageChangeListener() { |
|
|
|
ViewPager.OnPageChangeListener by ViewPager.SimpleOnPageChangeListener() { |
|
|
|
private val backupSelectRequestCode = 11 |
|
|
|
|
|
|
|
private val restoreSelectRequestCode = 22 |
|
|
|
|
|
|
|
override val viewModel: MainViewModel |
|
|
|
override val viewModel: MainViewModel |
|
|
|
get() = getViewModel(MainViewModel::class.java) |
|
|
|
get() = getViewModel(MainViewModel::class.java) |
|
|
|
|
|
|
|
|
|
|
@ -115,6 +117,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main), |
|
|
|
override fun finish() { |
|
|
|
override fun finish() { |
|
|
|
if (!BuildConfig.DEBUG) { |
|
|
|
if (!BuildConfig.DEBUG) { |
|
|
|
launch { |
|
|
|
launch { |
|
|
|
|
|
|
|
backup() |
|
|
|
super.finish() |
|
|
|
super.finish() |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -122,6 +125,19 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Backup.backup(this@MainActivity, null) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onDestroy() { |
|
|
|
override fun onDestroy() { |
|
|
|
super.onDestroy() |
|
|
|
super.onDestroy() |
|
|
|
ReadAloud.stop(this) |
|
|
|
ReadAloud.stop(this) |
|
|
|