From ac9852f71ab68ab25090ea6df30367219bf1e61a Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 15 Sep 2019 19:36:14 +0800 Subject: [PATCH] up --- .../java/io/legado/app/help/storage/Backup.kt | 37 ++++++++++++++++--- .../java/io/legado/app/utils/FileUtils.kt | 1 + 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 90a07e0b7..fe89fb3e1 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.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) diff --git a/app/src/main/java/io/legado/app/utils/FileUtils.kt b/app/src/main/java/io/legado/app/utils/FileUtils.kt index e2ecef64e..861d7e88e 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -28,6 +28,7 @@ object FileUtils { try { sdCardDirectory = File(sdCardDirectory).canonicalPath } catch (ioe: IOException) { + ioe.printStackTrace() } return sdCardDirectory