From 810e48b8c3965cca050698a451c06473717d28df Mon Sep 17 00:00:00 2001 From: ag2s20150909 Date: Wed, 7 Apr 2021 00:25:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DfixPic=E4=B8=80=E6=AE=B5?= =?UTF-8?q?=E9=87=8C=E6=9C=89=E5=A4=9A=E4=B8=AAimg=E5=8F=AA=E4=BC=9A?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E7=AC=AC=E4=B8=80=E4=B8=AAimg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/cache/CacheViewModel.kt | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) 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 bd8471efc..7c6f2b37e 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 @@ -127,10 +127,10 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter -> BookHelp.getContent(book, chapter)?.let { content -> content.split("\n").forEachIndexed { index, text -> - val matcher = AppPattern.imgPattern.matcher(text) - if (matcher.find()) { - matcher.group(1)?.let { - val src = NetworkUtils.getAbsoluteURL(chapter.url, it) + val matches = AppPattern.imgPattern.toRegex().findAll(input = text) + matches.forEach { matchResult -> + matchResult.groupValues[1].let { + val src=NetworkUtils.getAbsoluteURL(chapter.url, it) srcList.add(Triple(chapter.title, index, src)) } } @@ -272,14 +272,16 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { val data = StringBuilder("") content.split("\n").forEach { text -> var text1 = text - val matcher = AppPattern.imgPattern.matcher(text) - if (matcher.find()) { - matcher.group(1)?.let { - val src = NetworkUtils.getAbsoluteURL(chapter.url, it) + val matches = AppPattern.imgPattern.toRegex().findAll(input = text) + matches.forEach { matchResult -> + matchResult.groupValues[1].let { + val src=NetworkUtils.getAbsoluteURL(chapter.url, it) 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") } return data.toString()