pull/68/head^2
kunfei 5 years ago
parent a6275b5af9
commit 65bdc5541c
  1. 10
      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() { private fun copyBackup() {
for (fileName in backupFileNames) { try {
FileHelp.getFile(backupPath + File.separator + "bookshelf.json") for (fileName in backupFileNames) {
.copyTo(FileHelp.getFile(legadoPath + File.separator + "bookshelf.json"), true) 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 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)

Loading…
Cancel
Save