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)