pull/34/head
kunfei 5 years ago
parent 3798d8b573
commit ac9852f71a
  1. 37
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  2. 1
      app/src/main/java/io/legado/app/utils/FileUtils.kt

@ -1,18 +1,45 @@
package io.legado.app.help.storage
import androidx.appcompat.app.AppCompatActivity
import io.legado.app.App
import io.legado.app.R
import io.legado.app.help.FileHelp
import io.legado.app.help.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.utils.FileUtils
import io.legado.app.utils.GSON
import java.io.File
object Backup {
fun backup() {
fun backup(activity: AppCompatActivity) {
PermissionsCompat.Builder(activity)
.addPermissions(*Permissions.Group.STORAGE)
.rationale(R.string.tip_perm_request_storage)
.onGranted {
val path =
FileUtils.getSdCardPath() + File.separator + "YueDu" + File.separator + "legadoBackUp"
backupBookshelf(path)
backupBookSource(path)
backupRssSource(path)
backupReplaceRule(path)
}
.request()
}
fun autoBackup() {
fun autoBackup(activity: AppCompatActivity) {
PermissionsCompat.Builder(activity)
.addPermissions(*Permissions.Group.STORAGE)
.rationale(R.string.tip_perm_request_storage)
.onGranted {
val path =
FileUtils.getSdCardPath() + File.separator + "YueDu" + File.separator + "legadoBackUp"
backupBookshelf(path)
backupBookSource(path)
backupRssSource(path)
backupReplaceRule(path)
}
.request()
}
private fun backupBookshelf(path: String) {
@ -27,7 +54,7 @@ object Backup {
file.writeText(json)
}
private fun backupCssSource(path: String) {
private fun backupRssSource(path: String) {
val json = GSON.toJson(App.db.rssSourceDao().all)
val file = FileHelp.getFile(path + File.separator + "cssSource.json")
file.writeText(json)

@ -28,6 +28,7 @@ object FileUtils {
try {
sdCardDirectory = File(sdCardDirectory).canonicalPath
} catch (ioe: IOException) {
ioe.printStackTrace()
}
return sdCardDirectory

Loading…
Cancel
Save