From c043b16fa6fd49b2e9e2f58342ae87c1d818bd7a Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 21:21:05 +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 --- .../main/java/io/legado/app/help/BookHelp.kt | 66 +++++++++++-------- 1 file changed, 37 insertions(+), 29 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 0cdb7e1e8..7071579ea 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -133,44 +133,52 @@ object BookHelp { } fun getContent(book: Book, bookChapter: BookChapter): String? { - if (book.isLocalBook()) { - return AnalyzeTxtFile.getContent(book, bookChapter) - } else if (downloadUri.isDocumentUri(App.INSTANCE)) { - DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> - return DocumentUtils.getDirDocument( - root, - subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - )?.findFile("${bookChapterName(bookChapter)}.nb") - ?.uri?.readText(App.INSTANCE) + when { + book.isLocalBook() -> { + return AnalyzeTxtFile.getContent(book, bookChapter) } - } else { - val file = FileUtils.getFile( - File(downloadPath), - "${bookChapterName(bookChapter)}.nb", - subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - ) - if (file.exists()) { - return file.readText() + downloadUri.isDocumentUri(App.INSTANCE) -> { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> + return DocumentUtils.getDirDocument( + root, + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + )?.findFile("${bookChapterName(bookChapter)}.nb") + ?.uri?.readText(App.INSTANCE) + } + } + else -> { + val file = FileUtils.getFile( + File(downloadPath), + "${bookChapterName(bookChapter)}.nb", + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + ) + if (file.exists()) { + return file.readText() + } } } return null } fun delContent(book: Book, bookChapter: BookChapter) { - if (downloadUri.isDocumentUri(App.INSTANCE)) { - DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> - DocumentUtils.getDirDocument( - root, + when { + book.isLocalBook() -> return + downloadUri.isDocumentUri(App.INSTANCE) -> { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> + DocumentUtils.getDirDocument( + root, + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + )?.findFile("${bookChapterName(bookChapter)}.nb") + ?.delete() + } + } + else -> { + FileUtils.createFileIfNotExist( + File(downloadPath), + "${bookChapterName(bookChapter)}.nb", subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - )?.findFile("${bookChapterName(bookChapter)}.nb") - ?.delete() + ).delete() } - } else { - FileUtils.createFileIfNotExist( - File(downloadPath), - "${bookChapterName(bookChapter)}.nb", - subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - ).delete() } }