pull/68/head^2
kunfei 5 years ago
parent a6275b5af9
commit 65bdc5541c
  1. 4
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  2. 20
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -120,9 +120,13 @@ object Backup {
}
private fun copyBackup() {
try {
for (fileName in backupFileNames) {
FileHelp.getFile(backupPath + File.separator + "bookshelf.json")
.copyTo(FileHelp.getFile(legadoPath + File.separator + "bookshelf.json"), true)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}

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

Loading…
Cancel
Save