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 6648363df..8400f3250 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 @@ -7,76 +7,80 @@ import io.legado.app.App import io.legado.app.data.entities.BookSource import io.legado.app.utils.DocumentUtils import io.legado.app.utils.FileUtils +import io.legado.app.utils.isContentPath import org.jetbrains.anko.toast import java.io.File object ImportOldData { - fun import(context: Context, file: File) { - try {// 导入书架 - val shelfFile = - FileUtils.createFileIfNotExist(file, "myBookShelf.json") - val json = shelfFile.readText() - val importCount = importOldBookshelf(json) - context.toast("成功导入书籍${importCount}") - } catch (e: Exception) { - context.toast("导入书籍失败\n${e.localizedMessage}") - } - - try {// Book source - val sourceFile = - FileUtils.getFile(file, "myBookSource.json") - val json = sourceFile.readText() - val importCount = importOldSource(json) - context.toast("成功导入书源${importCount}") - } catch (e: Exception) { - context.toast("导入源失败\n${e.localizedMessage}") - } - - try {// Replace rules - val ruleFile = FileUtils.getFile(file, "myBookReplaceRule.json") - if (ruleFile.exists()) { - val json = ruleFile.readText() - val importCount = importOldReplaceRule(json) - context.toast("成功导入替换规则${importCount}") - } else { - context.toast("未找到替换规则") - } - } catch (e: Exception) { - context.toast("导入替换规则失败\n${e.localizedMessage}") - } - } - - fun importUri(uri: Uri) { - DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach { - when (it.name) { - "myBookShelf.json" -> - try { - DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json -> - val importCount = importOldBookshelf(json) - App.INSTANCE.toast("成功导入书籍${importCount}") + fun importUri(context: Context, uri: Uri) { + if (uri.isContentPath()) { + DocumentFile.fromTreeUri(context, uri)?.listFiles()?.forEach { + when (it.name) { + "myBookShelf.json" -> + try { + DocumentUtils.readText(context, it.uri)?.let { json -> + val importCount = importOldBookshelf(json) + context.toast("成功导入书籍${importCount}") + } + } catch (e: java.lang.Exception) { + context.toast("导入书籍失败\n${e.localizedMessage}") } - } catch (e: java.lang.Exception) { - App.INSTANCE.toast("导入书籍失败\n${e.localizedMessage}") - } - "myBookSource.json" -> - try { - DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json -> - val importCount = importOldSource(json) - App.INSTANCE.toast("成功导入书源${importCount}") + "myBookSource.json" -> + try { + DocumentUtils.readText(context, it.uri)?.let { json -> + val importCount = importOldSource(json) + context.toast("成功导入书源${importCount}") + } + } catch (e: Exception) { + context.toast("导入源失败\n${e.localizedMessage}") } - } catch (e: Exception) { - App.INSTANCE.toast("导入源失败\n${e.localizedMessage}") - } - "myBookReplaceRule.json" -> - try { - DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json -> - val importCount = importOldReplaceRule(json) - App.INSTANCE.toast("成功导入替换规则${importCount}") + "myBookReplaceRule.json" -> + try { + DocumentUtils.readText(context, it.uri)?.let { json -> + val importCount = importOldReplaceRule(json) + context.toast("成功导入替换规则${importCount}") + } + } catch (e: Exception) { + context.toast("导入替换规则失败\n${e.localizedMessage}") } - } catch (e: Exception) { - App.INSTANCE.toast("导入替换规则失败\n${e.localizedMessage}") + } + } + } else { + uri.path?.let { + val file = File(it) + try {// 导入书架 + val shelfFile = + FileUtils.createFileIfNotExist(file, "myBookShelf.json") + val json = shelfFile.readText() + val importCount = importOldBookshelf(json) + context.toast("成功导入书籍${importCount}") + } catch (e: Exception) { + context.toast("导入书籍失败\n${e.localizedMessage}") + } + + try {// Book source + val sourceFile = + FileUtils.getFile(file, "myBookSource.json") + val json = sourceFile.readText() + val importCount = importOldSource(json) + context.toast("成功导入书源${importCount}") + } catch (e: Exception) { + context.toast("导入源失败\n${e.localizedMessage}") + } + + try {// Replace rules + val ruleFile = FileUtils.getFile(file, "myBookReplaceRule.json") + if (ruleFile.exists()) { + val json = ruleFile.readText() + val importCount = importOldReplaceRule(json) + context.toast("成功导入替换规则${importCount}") + } else { + context.toast("未找到替换规则") } + } catch (e: Exception) { + context.toast("导入替换规则失败\n${e.localizedMessage}") + } } } } diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 6a377b542..3504b55a4 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -202,26 +202,24 @@ class CacheActivity : VMBaseActivity(R.layout.activity_download) } } - override fun onFilePicked(requestCode: Int, currentPath: String) { - when (requestCode) { - exportRequestCode -> { - ACache.get(this@CacheActivity).put(exportBookPathKey, currentPath) - startExport(currentPath) - } - } - } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { exportRequestCode -> if (resultCode == Activity.RESULT_OK) { data?.data?.let { uri -> - contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) - ACache.get(this@CacheActivity).put(exportBookPathKey, uri.toString()) - startExport(uri.toString()) + if (uri.isContentPath()) { + contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + ACache.get(this@CacheActivity).put(exportBookPathKey, uri.toString()) + startExport(uri.toString()) + } else { + uri.path?.let { path -> + ACache.get(this@CacheActivity).put(exportBookPathKey, path) + startExport(path) + } + } } } diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index d7ae4055e..1bbd5275b 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -62,6 +62,24 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity return super.onCompatCreateOptionsMenu(menu) } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.menu_select_folder -> FilePicker.selectFolder(this, requestCodeSelectFolder) + R.id.menu_scan_folder -> scanFolder() + } + return super.onCompatOptionsItemSelected(item) + } + + override fun onMenuItemClick(item: MenuItem?): Boolean { + when (item?.itemId) { + R.id.menu_del_selection -> + viewModel.deleteDoc(adapter.selectedUris) { + upPath() + } + } + return false + } + private fun initView() { lay_top.setBackgroundColor(backgroundColor) recycler_view.layoutManager = LinearLayoutManager(this) @@ -94,23 +112,6 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } } - override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { - when (item.itemId) { - R.id.menu_select_folder -> FilePicker.selectFolder(this, requestCodeSelectFolder) - } - return super.onCompatOptionsItemSelected(item) - } - - override fun onMenuItemClick(item: MenuItem?): Boolean { - when (item?.itemId) { - R.id.menu_del_selection -> - viewModel.deleteDoc(adapter.selectedUris) { - upPath() - } - } - return false - } - private fun initData() { localUriLiveData?.removeObservers(this) localUriLiveData = App.db.bookDao().observeLocalUri() @@ -229,12 +230,12 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity adapter.setData(docList) } - override fun onFilePicked(requestCode: Int, currentPath: String) { - when (requestCode) { - requestCodeSelectFolder -> { - AppConfig.importBookPath = currentPath - initRootDoc() - } + /** + * 扫描当前文件夹 + */ + private fun scanFolder() { + rootDoc?.let { + } } @@ -243,12 +244,19 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity when (requestCode) { requestCodeSelectFolder -> if (resultCode == Activity.RESULT_OK) { data?.data?.let { uri -> - contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) - AppConfig.importBookPath = uri.toString() - initRootDoc() + if (uri.isContentPath()) { + contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + AppConfig.importBookPath = uri.toString() + initRootDoc() + } else { + uri.path?.let { path -> + AppConfig.importBookPath = path + initRootDoc() + } + } } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index edf960ee4..e67b06d92 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -369,13 +369,6 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { } } - override fun onFilePicked(requestCode: Int, currentPath: String) { - when (requestCode) { - requestCodeImport -> importConfig(Uri.fromFile(File(currentPath))) - requestCodeExport -> exportConfig(Uri.fromFile(File(currentPath))) - } - } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index e9788dd83..024b8a811 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -457,18 +457,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity viewModel.bottomSource(bookSource) } - override fun onFilePicked(requestCode: Int, currentPath: String) { - when (requestCode) { - exportRequestCode -> viewModel.exportSelection( - adapter.getSelection(), - File(currentPath) - ) - importRequestCode -> { - startActivity(Pair("filePath", currentPath)) - } - } - } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index d5f3815a1..097148736 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -133,10 +133,6 @@ class BackupConfigFragment : BasePreferenceFragment(), } } - override fun onFilePicked(requestCode: Int, currentPath: String) { - BackupRestoreUi.onFilePicked(requestCode, currentPath) - } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) BackupRestoreUi.onActivityResult(requestCode, resultCode, data) 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 05a5e8bbf..3a6174460 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 @@ -23,7 +23,6 @@ import io.legado.app.utils.longToast 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 @@ -122,74 +121,73 @@ object BackupRestoreUi { FilePicker.selectFolder(fragment, oldDataRequestCode) } - fun onFilePicked(requestCode: Int, currentPath: String) { - when (requestCode) { - backupSelectRequestCode -> { - AppConfig.backupPath = currentPath - Coroutine.async { - Backup.backup(App.INSTANCE, currentPath) - }.onSuccess { - App.INSTANCE.toast(R.string.backup_success) - } - } - restoreSelectRequestCode -> { - AppConfig.backupPath = currentPath - Coroutine.async { - Restore.restore(App.INSTANCE, currentPath) - } - } - selectFolderRequestCode -> { - AppConfig.backupPath = currentPath - } - oldDataRequestCode -> { - ImportOldData.import(App.INSTANCE, File(currentPath)) - } - } - } - fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { when (requestCode) { backupSelectRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { uri -> - App.INSTANCE.contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION - or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) - AppConfig.backupPath = uri.toString() - Coroutine.async { - Backup.backup(App.INSTANCE, uri.toString()) - }.onSuccess { - App.INSTANCE.toast(R.string.backup_success) + if (uri.isContentPath()) { + App.INSTANCE.contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION + or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + AppConfig.backupPath = uri.toString() + Coroutine.async { + Backup.backup(App.INSTANCE, uri.toString()) + }.onSuccess { + App.INSTANCE.toast(R.string.backup_success) + } + } else { + uri.path?.let { path -> + AppConfig.backupPath = path + Coroutine.async { + Backup.backup(App.INSTANCE, path) + }.onSuccess { + App.INSTANCE.toast(R.string.backup_success) + } + } } } } restoreSelectRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { uri -> - App.INSTANCE.contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION - or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) - AppConfig.backupPath = uri.toString() - Coroutine.async { - Restore.restore(App.INSTANCE, uri.toString()) + if (uri.isContentPath()) { + App.INSTANCE.contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION + or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + AppConfig.backupPath = uri.toString() + Coroutine.async { + Restore.restore(App.INSTANCE, uri.toString()) + } + } else { + uri.path?.let { path -> + AppConfig.backupPath = path + Coroutine.async { + Restore.restore(App.INSTANCE, path) + } + } } } } selectFolderRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { uri -> - App.INSTANCE.contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION - or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) - AppConfig.backupPath = uri.toString() + if (uri.isContentPath()) { + App.INSTANCE.contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION + or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + AppConfig.backupPath = uri.toString() + } else { + AppConfig.backupPath = uri.path + } } } oldDataRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { uri -> - ImportOldData.importUri(uri) + ImportOldData.importUri(App.INSTANCE, uri) } } } diff --git a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt index b3c9d3831..3c26b4402 100644 --- a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt +++ b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt @@ -1,5 +1,8 @@ package io.legado.app.ui.filepicker +import android.app.Activity +import android.content.Intent +import android.net.Uri import android.os.Bundle import android.view.LayoutInflater import android.view.MenuItem @@ -17,6 +20,7 @@ import io.legado.app.ui.filepicker.adapter.PathAdapter import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import kotlinx.android.synthetic.main.dialog_file_chooser.* +import java.io.File class FilePickerDialog : DialogFragment(), @@ -145,8 +149,11 @@ class FilePickerDialog : DialogFragment(), override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_ok -> fileAdapter.currentPath?.let { - (parentFragment as? CallBack)?.onFilePicked(requestCode, it) - (activity as? CallBack)?.onFilePicked(requestCode, it) + val data = Intent().setData(Uri.fromFile(File(it))) + (parentFragment as? CallBack) + ?.onActivityResult(requestCode, Activity.RESULT_OK, data) + (activity as? CallBack) + ?.onActivityResult(requestCode, Activity.RESULT_OK, data) dismiss() } else -> item?.title?.let { @@ -169,8 +176,11 @@ class FilePickerDialog : DialogFragment(), } else if (allowExtensions == null || allowExtensions?.contains(FileUtils.getExtension(path)) == true ) { - (parentFragment as? CallBack)?.onFilePicked(requestCode, path) - (activity as? CallBack)?.onFilePicked(requestCode, path) + val data = Intent().setData(Uri.fromFile(File(path))) + (parentFragment as? CallBack) + ?.onActivityResult(requestCode, Activity.RESULT_OK, data) + (activity as? CallBack) + ?.onActivityResult(requestCode, Activity.RESULT_OK, data) dismiss() } else { toast("不能打开此文件") @@ -206,7 +216,7 @@ class FilePickerDialog : DialogFragment(), } interface CallBack { - fun onFilePicked(requestCode: Int, currentPath: String) + fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) fun onMenuClick(menu: String) {} } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 09207b12a..967490d6a 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -56,10 +56,6 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FilePickerDialog.C } } - override fun onFilePicked(requestCode: Int, currentPath: String) { - BackupRestoreUi.onFilePicked(requestCode, currentPath) - } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) BackupRestoreUi.onActivityResult(requestCode, resultCode, data) diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index 0863281ae..c73c4fce8 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -244,18 +244,6 @@ class ReplaceRuleActivity : return false } - override fun onFilePicked(requestCode: Int, currentPath: String) { - when (requestCode) { - importRequestCode -> { - startActivity("filePath" to currentPath) - } - exportRequestCode -> viewModel.exportSelection( - adapter.getSelection(), - File(currentPath) - ) - } - } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index cf734f229..6d723ce40 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -294,20 +294,12 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } } - override fun onFilePicked(requestCode: Int, currentPath: String) { - when (requestCode) { - savePathRequestCode -> { - ACache.get(this).put(imagePathKey, currentPath) - viewModel.saveImage(webPic, currentPath) - } - } - } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { savePathRequestCode -> data?.data?.let { - onFilePicked(requestCode, it.toString()) + ACache.get(this).put(imagePathKey, it.toString()) + viewModel.saveImage(webPic, it.toString()) } } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 097e682e5..56e5aa63b 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -245,18 +245,6 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r }.show().applyTint() } - override fun onFilePicked(requestCode: Int, currentPath: String) { - when (requestCode) { - importRequestCode -> { - startActivity("filePath" to currentPath) - } - exportRequestCode -> viewModel.exportSelection( - adapter.getSelection(), - File(currentPath) - ) - } - } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index c7515a679..d72c7f9e8 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -204,34 +204,29 @@ class FontSelectDialog : BaseDialogFragment(), } } - /** - * 字体文件夹 - */ - override fun onFilePicked(requestCode: Int, currentPath: String) { - when (requestCode) { - fontFolderRequestCode -> { - putPrefString(PreferKey.fontFolder, currentPath) - loadFontFilesByPermission(currentPath) - } - } - } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { fontFolderRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { uri -> - putPrefString(PreferKey.fontFolder, uri.toString()) - val doc = DocumentFile.fromTreeUri(requireContext(), uri) - if (doc != null) { - context?.contentResolver?.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION - ) - loadFontFiles(doc) + if (uri.toString().isContentPath()) { + putPrefString(PreferKey.fontFolder, uri.toString()) + val doc = DocumentFile.fromTreeUri(requireContext(), uri) + if (doc != null) { + context?.contentResolver?.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION + ) + loadFontFiles(doc) + } else { + RealPathUtil.getPath(requireContext(), uri)?.let { + loadFontFilesByPermission(it) + } + } } else { - RealPathUtil.getPath(requireContext(), uri)?.let { - loadFontFilesByPermission(it) + uri.path?.let { path -> + putPrefString(PreferKey.fontFolder, path) + loadFontFilesByPermission(path) } } } diff --git a/app/src/main/res/menu/import_book.xml b/app/src/main/res/menu/import_book.xml index 8ace963eb..49ab4ec96 100644 --- a/app/src/main/res/menu/import_book.xml +++ b/app/src/main/res/menu/import_book.xml @@ -8,4 +8,9 @@ android:icon="@drawable/ic_folder_open" app:showAsAction="ifRoom" /> + + \ No newline at end of file diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index b849e2f2b..f4155b11b 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -777,5 +777,6 @@ 重新分段 样式名称: 点击右上角文件夹图标,选择文件夹 + 智能扫描 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 985e7a4df..66ea10f0e 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -777,5 +777,6 @@ 重新分段 样式名称: 点击右上角文件夹图标,选择文件夹 + 智能扫描 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index f09556f04..48d82a087 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -780,5 +780,6 @@ 重新分段 样式名称: 点击右上角文件夹图标,选择文件夹 + 智能扫描 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 95856897c..6f7a6bbea 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -783,5 +783,6 @@ 重新分段 样式名称: 点击右上角文件夹图标,选择文件夹 + 智能扫描