From c884340dcd42c333b46f08c5c8416466b17b4457 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 19 Oct 2021 10:59:58 +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 --- .../java/io/legado/app/help/storage/ImportOldData.kt | 6 +++--- .../main/java/io/legado/app/help/storage/Restore.kt | 2 +- .../java/io/legado/app/model/localBook/LocalBook.kt | 2 +- .../java/io/legado/app/model/localBook/TextFile.kt | 2 +- .../java/io/legado/app/ui/book/cache/CacheViewModel.kt | 10 ++++------ .../app/ui/book/read/config/BgTextConfigDialog.kt | 4 ++-- 6 files changed, 12 insertions(+), 14 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 1cf361213..0c79c280d 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 @@ -16,7 +16,7 @@ object ImportOldData { when (doc.name) { "myBookShelf.json" -> kotlin.runCatching { - DocumentUtils.readText(context, doc.uri)?.let { json -> + DocumentUtils.readText(context, doc.uri).let { json -> val importCount = importOldBookshelf(json) context.toastOnUi("成功导入书籍${importCount}") } @@ -25,7 +25,7 @@ object ImportOldData { } "myBookSource.json" -> kotlin.runCatching { - DocumentUtils.readText(context, doc.uri)?.let { json -> + DocumentUtils.readText(context, doc.uri).let { json -> val importCount = importOldSource(json) context.toastOnUi("成功导入书源${importCount}") } @@ -34,7 +34,7 @@ object ImportOldData { } "myBookReplaceRule.json" -> kotlin.runCatching { - DocumentUtils.readText(context, doc.uri)?.let { json -> + DocumentUtils.readText(context, doc.uri).let { json -> val importCount = importOldReplaceRule(json) context.toastOnUi("成功导入替换规则${importCount}") } 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 8baee57e8..46a171ab1 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 @@ -72,7 +72,7 @@ object Restore { DocumentFile.fromTreeUri(context, Uri.parse(path))?.listFiles()?.forEach { doc -> for (fileName in Backup.backupFileNames) { if (doc.name == fileName) { - DocumentUtils.readText(context, doc.uri)?.let { + DocumentUtils.readText(context, doc.uri).let { FileUtils.createFileIfNotExist("${Backup.backupPath}${File.separator}$fileName") .writeText(it) } 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 6400267c1..265e019d5 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 @@ -67,7 +67,7 @@ object LocalBook { val bookFile = cacheFolder.getFile(it.name!!) if (!bookFile.exists()) { bookFile.createNewFile() - doc.readBytes(appCtx)?.let { bytes -> + doc.readBytes(appCtx).let { bytes -> bookFile.writeBytes(bytes) } } diff --git a/app/src/main/java/io/legado/app/model/localBook/TextFile.kt b/app/src/main/java/io/legado/app/model/localBook/TextFile.kt index f00556ca9..23062ba2e 100644 --- a/app/src/main/java/io/legado/app/model/localBook/TextFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/TextFile.kt @@ -267,7 +267,7 @@ class TextFile { val bookFile = LocalBook.cacheFolder.getFile(book.originName) if (!bookFile.exists()) { bookFile.createNewFile() - DocumentUtils.readBytes(appCtx, uri)?.let { + DocumentUtils.readBytes(appCtx, uri).let { bookFile.writeBytes(it) } } 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 f0a52176c..e21157ade 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 @@ -278,11 +278,9 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { if (file.isFile) { when { //正文模板 - file.name.equals( - "chapter.html", - true - ) || file.name.equals("chapter.xhtml", true) -> { - contentModel = file.readText(context) ?: "" + file.name.equals("chapter.html", true) + || file.name.equals("chapter.xhtml", true) -> { + contentModel = file.readText(context) } //封面等其他模板 true == file.name?.endsWith("html", true) -> { @@ -296,7 +294,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { book.getDisplayIntro(), book.kind, book.wordCount, - file.readText(context) ?: "", + file.readText(context), "${folder.name}/${file.name}" ) ) 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 6ff08a850..3bee08141 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 @@ -223,7 +223,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) { if (fontPath.isNotEmpty()) { val fontName = FileUtils.getName(fontPath) val fontBytes = fontPath.parseToUri().readBytes(requireContext()) - fontBytes?.let { + fontBytes.let { val fontExportFile = FileUtils.createFileIfNotExist(configDir, fontName) fontExportFile.writeBytes(it) exportFiles.add(fontExportFile) @@ -309,7 +309,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) { private fun importConfig(uri: Uri) { execute { @Suppress("BlockingMethodInNonBlockingContext") - importConfig(uri.readBytes(requireContext())!!) + importConfig(uri.readBytes(requireContext())) }.onError { Timber.e(it) longToast("导入失败:${it.localizedMessage}")