From 1cd696cc9c7798dc71488854f600393d3f6fb79a Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 3 Nov 2020 14:26:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/ImageLoader.kt | 6 +++--- .../main/java/io/legado/app/help/storage/Backup.kt | 2 +- .../java/io/legado/app/help/storage/ImportOldData.kt | 4 ++-- .../main/java/io/legado/app/help/storage/Restore.kt | 2 +- .../io/legado/app/model/localBook/AnalyzeTxtFile.kt | 2 +- .../java/io/legado/app/model/localBook/EPUBFile.kt | 2 +- .../java/io/legado/app/model/localBook/LocalBook.kt | 4 ++-- .../app/ui/association/ImportBookSourceViewModel.kt | 2 +- .../app/ui/association/ImportReplaceRuleViewModel.kt | 4 ++-- .../app/ui/association/ImportRssSourceViewModel.kt | 2 +- .../io/legado/app/ui/book/cache/CacheActivity.kt | 2 +- .../io/legado/app/ui/book/cache/CacheViewModel.kt | 2 +- .../app/ui/book/info/edit/BookInfoEditActivity.kt | 2 +- .../legado/app/ui/book/local/ImportBookActivity.kt | 6 +++--- .../io/legado/app/ui/book/local/ImportBookAdapter.kt | 3 ++- .../legado/app/ui/book/local/ImportBookViewModel.kt | 4 ++-- .../app/ui/book/read/config/BgTextConfigDialog.kt | 4 ++-- .../ui/book/read/page/provider/ChapterProvider.kt | 4 ++-- .../app/ui/book/source/manage/BookSourceActivity.kt | 2 +- .../java/io/legado/app/ui/config/BackupRestoreUi.kt | 12 ++++++------ .../io/legado/app/ui/config/OtherConfigFragment.kt | 2 +- .../io/legado/app/ui/replace/ReplaceRuleActivity.kt | 2 +- .../io/legado/app/ui/rss/read/ReadRssViewModel.kt | 6 +++--- .../app/ui/rss/source/manage/RssSourceActivity.kt | 2 +- .../io/legado/app/ui/widget/font/FontSelectDialog.kt | 4 ++-- .../main/java/io/legado/app/utils/DocumentUtils.kt | 2 +- .../java/io/legado/app/utils/StringExtensions.kt | 4 ++-- .../main/java/io/legado/app/utils/UriExtensions.kt | 6 +++--- 28 files changed, 50 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ImageLoader.kt b/app/src/main/java/io/legado/app/help/ImageLoader.kt index 9a58f45bf..2184d03d3 100644 --- a/app/src/main/java/io/legado/app/help/ImageLoader.kt +++ b/app/src/main/java/io/legado/app/help/ImageLoader.kt @@ -7,9 +7,9 @@ import android.net.Uri import androidx.annotation.DrawableRes import com.bumptech.glide.Glide import com.bumptech.glide.RequestBuilder -import io.legado.app.utils.isAbsUrl -import io.legado.app.utils.isContentPath import io.legado.app.model.analyzeRule.AnalyzeUrl +import io.legado.app.utils.isAbsUrl +import io.legado.app.utils.isContentScheme import java.io.File object ImageLoader { @@ -21,7 +21,7 @@ object ImageLoader { return when { path.isNullOrEmpty() -> Glide.with(context).load(path) path.isAbsUrl() -> Glide.with(context).load(AnalyzeUrl(path).getGlideUrl()) - path.isContentPath() -> Glide.with(context).load(Uri.parse(path)) + path.isContentScheme() -> Glide.with(context).load(Uri.parse(path)) else -> try { Glide.with(context).load(File(path)) } catch (e: Exception) { 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 d0ecac945..85686887d 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 @@ -92,7 +92,7 @@ object Backup { edit.commit() } WebDavHelp.backUpWebDav(backupPath) - if (path.isContentPath()) { + if (path.isContentScheme()) { copyBackup(context, Uri.parse(path), isAuto) } else { if (path.isEmpty()) { 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 8400f3250..1b1a79c15 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,14 +7,14 @@ 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 io.legado.app.utils.isContentScheme import org.jetbrains.anko.toast import java.io.File object ImportOldData { fun importUri(context: Context, uri: Uri) { - if (uri.isContentPath()) { + if (uri.isContentScheme()) { DocumentFile.fromTreeUri(context, uri)?.listFiles()?.forEach { when (it.name) { "myBookShelf.json" -> diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 4820be0e3..e5a4d002c 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -73,7 +73,7 @@ object Restore { suspend fun restore(context: Context, path: String) { withContext(IO) { - if (path.isContentPath()) { + if (path.isContentScheme()) { DocumentFile.fromTreeUri(context, Uri.parse(path))?.listFiles()?.forEach { doc -> for (fileName in Backup.backupFileNames) { if (doc.name == fileName) { diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 76776b090..e3c46ed43 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -261,7 +261,7 @@ class AnalyzeTxtFile { } private fun getBookFile(book: Book): File { - if (book.bookUrl.isContentPath()) { + if (book.bookUrl.isContentScheme()) { val uri = Uri.parse(book.bookUrl) val bookFile = FileUtils.getFile(LocalBook.cacheFolder, book.originName) if (!bookFile.exists()) { diff --git a/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt b/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt index 067837f17..2cc0b4340 100644 --- a/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt @@ -57,7 +57,7 @@ class EPUBFile(val book: io.legado.app.data.entities.Book) { init { try { val epubReader = EpubReader() - val inputStream = if (book.bookUrl.isContentPath()) { + val inputStream = if (book.bookUrl.isContentScheme()) { val uri = Uri.parse(book.bookUrl) App.INSTANCE.contentResolver.openInputStream(uri) } else { diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index 5d01504ef..4d52a86cf 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -37,7 +37,7 @@ object LocalBook { fun importFile(uri: Uri): Book { val path: String - val fileName = if (uri.isContentPath()) { + val fileName = if (uri.isContentScheme()) { path = uri.toString() val doc = DocumentFile.fromSingleUri(App.INSTANCE, uri) doc?.let { @@ -94,7 +94,7 @@ object LocalBook { } if (deleteOriginal) { - if (book.bookUrl.isContentPath()) { + if (book.bookUrl.isContentScheme()) { val uri = Uri.parse(book.bookUrl) DocumentFile.fromSingleUri(App.INSTANCE, uri)?.delete() } else { diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt index 3fbad78f2..6131d7bf4 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt @@ -26,7 +26,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { fun importSourceFromFilePath(path: String) { execute { - val content = if (path.isContentPath()) { + val content = if (path.isContentScheme()) { //在前面被解码了,如果不进行编码,中文会无法识别 val newPath = Uri.encode(path, ":/.") DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt index 960bafa9b..bbd2cea78 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt @@ -10,7 +10,7 @@ import io.legado.app.data.entities.ReplaceRule import io.legado.app.help.http.HttpHelper import io.legado.app.help.storage.OldReplace import io.legado.app.utils.isAbsUrl -import io.legado.app.utils.isContentPath +import io.legado.app.utils.isContentScheme import io.legado.app.utils.readText import java.io.File @@ -22,7 +22,7 @@ class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) { fun importFromFilePath(path: String) { execute { - val content = if (path.isContentPath()) { + val content = if (path.isContentScheme()) { //在前面被解码了,如果不进行编码,中文会无法识别 val newPath = Uri.encode(path, ":/.") DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt index 13b752a79..f187a3195 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt @@ -26,7 +26,7 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) { fun importSourceFromFilePath(path: String) { execute { - val content = if (path.isContentPath()) { + val content = if (path.isContentScheme()) { //在前面被解码了,如果不进行编码,中文会无法识别 val newPath = Uri.encode(path, ":/.") DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context) 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 3504b55a4..d9cf476c1 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 @@ -207,7 +207,7 @@ class CacheActivity : VMBaseActivity(R.layout.activity_download) when (requestCode) { exportRequestCode -> if (resultCode == Activity.RESULT_OK) { data?.data?.let { uri -> - if (uri.isContentPath()) { + if (uri.isContentScheme()) { contentResolver.takePersistableUriPermission( uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index 52e26862c..5604f4599 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -20,7 +20,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { fun export(path: String, book: Book, finally: (msg: String) -> Unit) { execute { - if (path.isContentPath()) { + if (path.isContentScheme()) { val uri = Uri.parse(path) DocumentFile.fromTreeUri(context, uri)?.let { export(it, book) diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index 211c56cb3..2bd082ffc 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -107,7 +107,7 @@ class BookInfoEditActivity : } private fun coverChangeTo(uri: Uri) { - if (uri.toString().isContentPath()) { + if (uri.isContentScheme()) { val doc = DocumentFile.fromSingleUri(this, uri) doc?.name?.let { var file = this.externalFilesDir 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 b5615344e..dfb6046e0 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 @@ -128,7 +128,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity tv_empty_msg.visible() FilePicker.selectFolder(this, requestCodeSelectFolder) } - lastPath.isContentPath() -> { + lastPath.isContentScheme() -> { val rootUri = Uri.parse(lastPath) rootDoc = DocumentFile.fromTreeUri(this, rootUri) if (rootDoc == null) { @@ -276,7 +276,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity when (requestCode) { requestCodeSelectFolder -> if (resultCode == Activity.RESULT_OK) { data?.data?.let { uri -> - if (uri.isContentPath()) { + if (uri.isContentScheme()) { contentResolver.takePersistableUriPermission( uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION @@ -296,7 +296,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity @Synchronized override fun nextDoc(uri: Uri) { - if (uri.toString().isContentPath()) { + if (uri.toString().isContentScheme()) { subDocs.add(DocumentFile.fromSingleUri(this, uri)!!) } else { path = uri.path.toString() diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt index f19855e6c..0a83e9641 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt @@ -84,7 +84,8 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : ll_brief.gone() cb_select.isChecked = false } else { - val path = if (item.uri.isContentPath()) item.uri.toString() else item.uri.path + val path = + if (item.uri.isContentScheme()) item.uri.toString() else item.uri.path if (bookPaths.contains(path)) { iv_icon.setImageResource(R.drawable.ic_book_has) iv_icon.visible() diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt index aa5b7848f..b7f1243c7 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt @@ -7,7 +7,7 @@ import io.legado.app.base.BaseViewModel import io.legado.app.model.localBook.LocalBook import io.legado.app.utils.DocItem import io.legado.app.utils.DocumentUtils -import io.legado.app.utils.isContentPath +import io.legado.app.utils.isContentScheme import java.io.File import java.util.* @@ -28,7 +28,7 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application) execute { uriList.forEach { val uri = Uri.parse(it) - if (uri.isContentPath()) { + if (uri.isContentScheme()) { DocumentFile.fromSingleUri(context, uri)?.delete() } else { uri.path?.let { path -> 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 e67b06d92..3e99b8b08 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 @@ -248,7 +248,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { } val configZipPath = FileUtils.getPath(requireContext().eCacheDir, configFileName) if (ZipUtils.zipFiles(exportFiles, File(configZipPath))) { - if (uri.isContentPath()) { + if (uri.isContentScheme()) { DocumentFile.fromTreeUri(requireContext(), uri)?.let { treeDoc -> treeDoc.findFile(configFileName)?.delete() treeDoc.createFile("", configFileName) @@ -391,7 +391,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { } private fun setBgFromUri(uri: Uri) { - if (uri.toString().isContentPath()) { + if (uri.toString().isContentScheme()) { val doc = DocumentFile.fromSingleUri(requireContext(), uri) doc?.name?.let { val file = diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 4c59a4202..d1d40d6fc 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -381,13 +381,13 @@ object ChapterProvider { typeface = try { val fontPath = ReadBookConfig.textFont when { - fontPath.isContentPath() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> { + fontPath.isContentScheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> { val fd = App.INSTANCE.contentResolver .openFileDescriptor(Uri.parse(fontPath), "r")!! .fileDescriptor Typeface.Builder(fd).build() } - fontPath.isContentPath() -> { + fontPath.isContentScheme() -> { Typeface.createFromFile(RealPathUtil.getPath(App.INSTANCE, Uri.parse(fontPath))) } fontPath.isNotEmpty() -> Typeface.createFromFile(fontPath) 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 0b4bc9c1c..3b9bfbe2a 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 @@ -477,7 +477,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } exportRequestCode -> { data?.data?.let { uri -> - if (uri.toString().isContentPath()) { + if (uri.isContentScheme()) { DocumentFile.fromTreeUri(this, uri)?.let { viewModel.exportSelection(adapter.getSelection(), it) } 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 3a6174460..87e63f7d7 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 @@ -18,7 +18,7 @@ import io.legado.app.help.storage.Restore import io.legado.app.help.storage.WebDavHelp import io.legado.app.ui.filepicker.FilePicker import io.legado.app.utils.getPrefString -import io.legado.app.utils.isContentPath +import io.legado.app.utils.isContentScheme import io.legado.app.utils.longToast import io.legado.app.utils.toast import kotlinx.coroutines.Dispatchers.Main @@ -35,7 +35,7 @@ object BackupRestoreUi { if (backupPath.isNullOrEmpty()) { selectBackupFolder(fragment, backupSelectRequestCode) } else { - if (backupPath.isContentPath()) { + if (backupPath.isContentScheme()) { val uri = Uri.parse(backupPath) val doc = DocumentFile.fromTreeUri(fragment.requireContext(), uri) if (doc?.canWrite() == true) { @@ -82,7 +82,7 @@ object BackupRestoreUi { fragment.longToast("WebDavError:${it.localizedMessage}\n将从本地备份恢复。") val backupPath = fragment.getPrefString(PreferKey.backupPath) if (backupPath?.isNotEmpty() == true) { - if (backupPath.isContentPath()) { + if (backupPath.isContentScheme()) { val uri = Uri.parse(backupPath) val doc = DocumentFile.fromTreeUri(fragment.requireContext(), uri) if (doc?.canWrite() == true) { @@ -125,7 +125,7 @@ object BackupRestoreUi { when (requestCode) { backupSelectRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { uri -> - if (uri.isContentPath()) { + if (uri.isContentScheme()) { App.INSTANCE.contentResolver.takePersistableUriPermission( uri, Intent.FLAG_GRANT_READ_URI_PERMISSION @@ -151,7 +151,7 @@ object BackupRestoreUi { } restoreSelectRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { uri -> - if (uri.isContentPath()) { + if (uri.isContentScheme()) { App.INSTANCE.contentResolver.takePersistableUriPermission( uri, Intent.FLAG_GRANT_READ_URI_PERMISSION @@ -173,7 +173,7 @@ object BackupRestoreUi { } selectFolderRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { uri -> - if (uri.isContentPath()) { + if (uri.isContentScheme()) { App.INSTANCE.contentResolver.takePersistableUriPermission( uri, Intent.FLAG_GRANT_READ_URI_PERMISSION diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index c6b7e9fde..1a30c9267 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -186,7 +186,7 @@ class OtherConfigFragment : BasePreferenceFragment(), } private fun setCoverFromUri(uri: Uri) { - if (uri.toString().isContentPath()) { + if (uri.isContentScheme()) { val doc = DocumentFile.fromSingleUri(requireContext(), uri) doc?.name?.let { var file = requireContext().externalFilesDir 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 6d86a80de..e81b2dd4e 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 @@ -262,7 +262,7 @@ class ReplaceRuleActivity : } exportRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { uri -> - if (uri.toString().isContentPath()) { + if (uri.isContentScheme()) { DocumentFile.fromTreeUri(this, uri)?.let { viewModel.exportSelection(adapter.getSelection(), it) } diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index 11b4ba940..923d94358 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -17,11 +17,11 @@ import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssStar import io.legado.app.help.http.HttpHelper -import io.legado.app.model.rss.Rss import io.legado.app.model.analyzeRule.AnalyzeUrl +import io.legado.app.model.rss.Rss import io.legado.app.utils.DocumentUtils import io.legado.app.utils.FileUtils -import io.legado.app.utils.isContentPath +import io.legado.app.utils.isContentScheme import io.legado.app.utils.writeBytes import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch @@ -111,7 +111,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), execute { val fileName = "${AppConst.fileNameFormat.format(Date(System.currentTimeMillis()))}.jpg" webData2bitmap(webPic)?.let { biteArray -> - if (path.isContentPath()) { + if (path.isContentScheme()) { val uri = Uri.parse(path) DocumentFile.fromTreeUri(context, uri)?.let { doc -> DocumentUtils.createFileIfNotExist(doc, fileName) 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 332c79b0e..72241a105 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 @@ -268,7 +268,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r } exportRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { uri -> - if (uri.toString().isContentPath()) { + if (uri.isContentScheme()) { DocumentFile.fromTreeUri(this, uri)?.let { viewModel.exportSelection(adapter.getSelection(), it) } 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 d72c7f9e8..5a8134c43 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 @@ -68,7 +68,7 @@ class FontSelectDialog : BaseDialogFragment(), if (fontPath.isNullOrEmpty()) { openFolder() } else { - if (fontPath.isContentPath()) { + if (fontPath.isContentScheme()) { val doc = DocumentFile.fromTreeUri(requireContext(), Uri.parse(fontPath)) if (doc?.canRead() == true) { loadFontFiles(doc) @@ -209,7 +209,7 @@ class FontSelectDialog : BaseDialogFragment(), when (requestCode) { fontFolderRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { uri -> - if (uri.toString().isContentPath()) { + if (uri.toString().isContentScheme()) { putPrefString(PreferKey.fontFolder, uri.toString()) val doc = DocumentFile.fromTreeUri(requireContext(), uri) if (doc != null) { diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt index faa4a7532..860c25f18 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -139,7 +139,7 @@ data class DocItem( DocumentsContract.Document.MIME_TYPE_DIR == attr } - val isContentPath get() = uri.toString().isContentPath() + val isContentPath get() = uri.isContentScheme() } @Throws(Exception::class) diff --git a/app/src/main/java/io/legado/app/utils/StringExtensions.kt b/app/src/main/java/io/legado/app/utils/StringExtensions.kt index a5c0d365d..f00c332d5 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -11,10 +11,10 @@ val notImgHtmlRegex = "]*>".toRegex() fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim() -fun String?.isContentPath(): Boolean = this?.startsWith("content://") == true +fun String?.isContentScheme(): Boolean = this?.startsWith("content://") == true fun String.parseToUri(): Uri { - return if (isContentPath()) { + return if (isContentScheme()) { Uri.parse(this) } else { Uri.fromFile(File(this)) diff --git a/app/src/main/java/io/legado/app/utils/UriExtensions.kt b/app/src/main/java/io/legado/app/utils/UriExtensions.kt index 77c0fcaee..509271fb2 100644 --- a/app/src/main/java/io/legado/app/utils/UriExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/UriExtensions.kt @@ -4,11 +4,11 @@ import android.content.Context import android.net.Uri import java.io.File -fun Uri.isContentPath() = this.toString().isContentPath() +fun Uri.isContentScheme() = this.scheme == "content" @Throws(Exception::class) fun Uri.readBytes(context: Context): ByteArray? { - if (this.toString().isContentPath()) { + if (this.toString().isContentScheme()) { return DocumentUtils.readBytes(context, this) } else { val path = RealPathUtil.getPath(context, this) @@ -32,7 +32,7 @@ fun Uri.writeBytes( context: Context, byteArray: ByteArray ): Boolean { - if (this.toString().isContentPath()) { + if (this.toString().isContentScheme()) { return DocumentUtils.writeBytes(context, byteArray, this) } else { val path = RealPathUtil.getPath(context, this)