修复fixPic一段里有多个img只会替换第一个img

pull/935/head
ag2s20150909 4 years ago
parent cc4fa964d4
commit 810e48b8c3
  1. 16
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt

@ -127,9 +127,9 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter -> appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter ->
BookHelp.getContent(book, chapter)?.let { content -> BookHelp.getContent(book, chapter)?.let { content ->
content.split("\n").forEachIndexed { index, text -> content.split("\n").forEachIndexed { index, text ->
val matcher = AppPattern.imgPattern.matcher(text) val matches = AppPattern.imgPattern.toRegex().findAll(input = text)
if (matcher.find()) { matches.forEach { matchResult ->
matcher.group(1)?.let { matchResult.groupValues[1].let {
val src=NetworkUtils.getAbsoluteURL(chapter.url, it) val src=NetworkUtils.getAbsoluteURL(chapter.url, it)
srcList.add(Triple(chapter.title, index, src)) srcList.add(Triple(chapter.title, index, src))
} }
@ -272,14 +272,16 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
val data = StringBuilder("") val data = StringBuilder("")
content.split("\n").forEach { text -> content.split("\n").forEach { text ->
var text1 = text var text1 = text
val matcher = AppPattern.imgPattern.matcher(text) val matches = AppPattern.imgPattern.toRegex().findAll(input = text)
if (matcher.find()) { matches.forEach { matchResult ->
matcher.group(1)?.let { matchResult.groupValues[1].let {
val src=NetworkUtils.getAbsoluteURL(chapter.url, it) val src=NetworkUtils.getAbsoluteURL(chapter.url, it)
setPic(src, book, epubBook) setPic(src, book, epubBook)
text1 = text.replace(src, MD5Utils.md5Encode16(src) + ".jpg") text1 = text1.replace(src, MD5Utils.md5Encode16(src) + ".jpg")
} }
} }
data.append(text1).append("\n") data.append(text1).append("\n")
} }
return data.toString() return data.toString()

Loading…
Cancel
Save