From 8de2bd73d001c5bcd15e63337410574ccd445ff2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 1 Mar 2020 14:43:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/help/storage/ImportOldData.kt | 11 ++++------ .../legado/app/ui/config/BackupRestoreUi.kt | 22 +++++-------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt b/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt index 91618a704..9087c3e9f 100644 --- a/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt +++ b/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt @@ -17,15 +17,12 @@ import org.jetbrains.anko.toast import java.io.File object ImportOldData { - val yueDuPath by lazy { - FileUtils.getSdCardPath() + File.separator + "YueDu" - } - fun import(context: Context) { + fun import(context: Context, file: File) { GlobalScope.launch(Dispatchers.IO) { try {// 导入书架 val shelfFile = - FileUtils.createFileIfNotExist(yueDuPath + File.separator + "myBookShelf.json") + FileUtils.createFileIfNotExist(file, "myBookShelf.json") val json = shelfFile.readText() val importCount = importOldBookshelf(json) withContext(Dispatchers.Main) { @@ -39,7 +36,7 @@ object ImportOldData { try {// Book source val sourceFile = - FileUtils.createFileIfNotExist(yueDuPath + File.separator + "myBookSource.json") + FileUtils.createFileIfNotExist(file, "myBookSource.json") val json = sourceFile.readText() val importCount = importOldSource(json) withContext(Dispatchers.Main) { @@ -53,7 +50,7 @@ object ImportOldData { try {// Replace rules val ruleFile = - FileUtils.createFileIfNotExist(yueDuPath + File.separator + "myBookReplaceRule.json") + FileUtils.createFileIfNotExist(file, "myBookReplaceRule.json") val json = ruleFile.readText() val importCount = importOldReplaceRule(json) withContext(Dispatchers.Main) { diff --git a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt index 36715bcf8..1bec0a184 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt @@ -3,7 +3,6 @@ package io.legado.app.ui.config import android.app.Activity.RESULT_OK import android.content.Intent import android.net.Uri -import android.os.Build import androidx.documentfile.provider.DocumentFile import androidx.fragment.app.Fragment import io.legado.app.App @@ -23,6 +22,7 @@ import io.legado.app.utils.isContentPath import io.legado.app.utils.toast import kotlinx.coroutines.Dispatchers.Main import org.jetbrains.anko.toast +import java.io.File object BackupRestoreUi { private const val selectFolderRequestCode = 21 @@ -123,22 +123,7 @@ object BackupRestoreUi { } fun importOldData(fragment: Fragment) { - FilePicker.selectFolder(fragment, oldDataRequestCode) { - importOldUsePermission(fragment) - } - } - - private fun importOldUsePermission(fragment: Fragment) { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { - fragment.toast(R.string.a10_permission_toast) - } - PermissionsCompat.Builder(fragment) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - ImportOldData.import(fragment.requireContext()) - } - .request() + FilePicker.selectFolder(fragment, oldDataRequestCode) } fun onFilePicked(requestCode: Int, currentPath: String) { @@ -162,6 +147,9 @@ object BackupRestoreUi { selectFolderRequestCode -> { AppConfig.backupPath = currentPath } + oldDataRequestCode -> { + ImportOldData.import(App.INSTANCE, File(currentPath)) + } } }