pull/363/head
gedoor 4 years ago
parent f92de8797b
commit aaf08d21f9
  1. 2
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  2. 11
      app/src/main/java/io/legado/app/utils/StringExtensions.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)

@ -1,5 +1,8 @@
package io.legado.app.utils
import android.net.Uri
import java.io.File
val removeHtmlRegex = "</?(?:div|p|br|hr|h\\d|article|dd|dl)[^>]*>".toRegex()
val imgRegex = "<img[^>]*>".toRegex()
val notImgHtmlRegex = "</?(?!img)\\w+[^>]*>".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)

Loading…
Cancel
Save