From 2469983166a01b123d8789af24778cfba9a6e3c8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 20:46:12 +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/BookHelp.kt | 12 ++++++------ .../java/io/legado/app/utils/StringExtensions.kt | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 7071579ea..b9bf8d11c 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -38,7 +38,7 @@ object BookHelp { } fun clearCache() { - if (downloadUri.isDocumentUri(App.INSTANCE)) { + if (downloadPath.isContentPath()) { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri) ?.findFile(cacheFolderName) ?.delete() @@ -55,7 +55,7 @@ object BookHelp { @Synchronized fun saveContent(book: Book, bookChapter: BookChapter, content: String) { if (content.isEmpty()) return - if (downloadUri.isDocumentUri(App.INSTANCE)) { + if (downloadPath.isContentPath()) { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> DocumentUtils.getDirDocument( root, @@ -91,7 +91,7 @@ object BookHelp { } fun getChapterCount(book: Book): Int { - if (downloadUri.isDocumentUri(App.INSTANCE)) { + if (downloadPath.isContentPath()) { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> return DocumentUtils.createFolderIfNotExist( root, @@ -112,7 +112,7 @@ object BookHelp { book.isLocalBook() -> { return true } - downloadUri.isDocumentUri(App.INSTANCE) -> { + downloadPath.isContentPath() -> { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> return DocumentUtils.exists( root, @@ -137,7 +137,7 @@ object BookHelp { book.isLocalBook() -> { return AnalyzeTxtFile.getContent(book, bookChapter) } - downloadUri.isDocumentUri(App.INSTANCE) -> { + downloadPath.isContentPath() -> { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> return DocumentUtils.getDirDocument( root, @@ -163,7 +163,7 @@ object BookHelp { fun delContent(book: Book, bookChapter: BookChapter) { when { book.isLocalBook() -> return - downloadUri.isDocumentUri(App.INSTANCE) -> { + downloadPath.isContentPath() -> { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> DocumentUtils.getDirDocument( root, 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 19319d3ba..02faf53c3 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -4,6 +4,8 @@ package io.legado.app.utils fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim() +fun String?.isContentPath(): Boolean = this?.startsWith("content://") == true + fun String?.isAbsUrl() = this?.let { it.startsWith("http://", true) @@ -48,7 +50,4 @@ fun String.splitNotBlank(regex: Regex, limit: Int = 0): Array = run { this.split(regex, limit).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray() } -fun String.startWithIgnoreCase(start: String): Boolean { - return if (this.isBlank()) false else startsWith(start, true) -}