From aaf08d21f9d304b2024a13e2a0f411782cf0b7bd Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 6 Sep 2020 19:15:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/config/BgTextConfigDialog.kt | 2 +- .../main/java/io/legado/app/utils/StringExtensions.kt | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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 4395b1954..69d196ee7 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 @@ -224,7 +224,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { val fontPath = ReadBookConfig.textFont if (fontPath.isNotEmpty()) { val fontName = FileUtils.getName(fontPath) - val fontBytes = Uri.parse(fontPath).readBytes(requireContext()) + val fontBytes = fontPath.parseToUri().readBytes(requireContext()) fontBytes?.let { val fontExportFile = FileUtils.createFileIfNotExist(configDir, fontName) fontExportFile.writeBytes(it) 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 76a8536fc..dc53b7bc8 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -1,5 +1,8 @@ package io.legado.app.utils +import android.net.Uri +import java.io.File + val removeHtmlRegex = "]*>".toRegex() val imgRegex = "]*>".toRegex() val notImgHtmlRegex = "]*>".toRegex() @@ -8,6 +11,14 @@ fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim() fun String?.isContentPath(): Boolean = this?.startsWith("content://") == true +fun String.parseToUri(): Uri { + return if (isContentPath()) { + Uri.parse(this) + } else { + Uri.fromFile(File(this)) + } +} + fun String?.isAbsUrl() = this?.let { it.startsWith("http://", true)