From 491fc5e05e1edccc6f170553b5a829cd336f89b8 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 6 Mar 2021 22:39:43 +0800 Subject: [PATCH 01/22] =?UTF-8?q?=E9=98=85=E8=AF=BB=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=B7=BB=E5=8A=A0=E5=9B=BE=E7=89=87=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E9=80=89=E6=8B=A9,=E9=92=88=E5=AF=B9=E6=AF=8F?= =?UTF-8?q?=E6=9C=AC=E4=B9=A6=E7=B1=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/entities/Book.kt | 16 ++++++++-- .../app/model/webBook/BookChapterList.kt | 32 ++++--------------- .../io/legado/app/service/help/ReadBook.kt | 11 ++++--- .../app/ui/book/read/ReadBookActivity.kt | 11 +++++++ .../read/page/provider/ChapterProvider.kt | 8 +++-- app/src/main/res/menu/book_read.xml | 5 +++ app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 51 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index aba5aa977..5093c05c1 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -146,6 +146,14 @@ data class Book( config().pageAnim = pageAnim } + fun getImageStyle(): String? { + return config().imageStyle + } + + fun setImageStyle(imageStyle: String?) { + config().imageStyle = imageStyle + } + fun getDelParagraph(): Int { return config().delParagraph } @@ -228,15 +236,19 @@ data class Book( const val hTag = 2L const val rubyTag = 4L const val imgTag = 8L + const val imgStyleDefault = "DEFAULT" + const val imgStyleFull = "FULL" + const val imgStyleText = "TEXT" } @Parcelize data class ReadConfig( var pageAnim: Int = -1, var reSegment: Boolean = false, - var useReplaceRule: Boolean = AppConfig.replaceEnableDefault, // 正文使用净化替换规则 + var imageStyle: String? = null, + var useReplaceRule: Boolean = AppConfig.replaceEnableDefault,// 正文使用净化替换规则 var delParagraph: Int = 0,//去除段首 - var delTag: Long = 0L//去除标签 + var delTag: Long = 0L,//去除标签 ) : Parcelable class Converters { diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index 1fe21c3f8..4b03eb4a4 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -47,15 +47,8 @@ object BookChapterList { } var chapterData = analyzeChapterList( - scope, - book, - baseUrl, - redirectUrl, - body, - tocRule, - listRule, - bookSource, - log = true + scope, book, baseUrl, redirectUrl, body, + tocRule, listRule, bookSource, log = true ) chapterData.chapterList?.let { chapterList.addAll(it) @@ -75,14 +68,8 @@ object BookChapterList { headerMapF = bookSource.getHeaderMap() ).getStrResponse(bookSource.bookSourceUrl).body?.let { nextBody -> chapterData = analyzeChapterList( - this, - book, - nextUrl, - nextUrl, - nextBody, - tocRule, - listRule, - bookSource + this, book, nextUrl, nextUrl, + nextBody, tocRule, listRule, bookSource ) nextUrl = chapterData.nextUrl.firstOrNull() ?: "" chapterData.chapterList?.let { @@ -144,15 +131,8 @@ object BookChapterList { ).getStrResponse(bookSource.bookSourceUrl).body ?: throw Exception("${chapterData.nextUrl}, 下载失败") val nextChapterData = analyzeChapterList( - this, - book, - chapterData.nextUrl, - chapterData.nextUrl, - nextBody, - tocRule, - listRule, - bookSource, - false + this, book, chapterData.nextUrl, chapterData.nextUrl, + nextBody, tocRule, listRule, bookSource, false ) synchronized(chapterDataList) { val isFinished = addChapterListIsFinish( diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index ab07ec9f2..63d892374 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -71,6 +71,9 @@ object ReadBook { appDb.bookSourceDao.getBookSource(book.origin)?.let { bookSource = it webBook = WebBook(it) + if (book.getImageStyle().isNullOrBlank()) { + book.setImageStyle(it.getContentRule().imageStyle) + } } ?: let { bookSource = null webBook = null @@ -413,7 +416,7 @@ object ReadBook { durChapterIndex -> { curTextChapter = ChapterProvider.getTextChapter( - book, chapter, contents, chapterSize, imageStyle + book, chapter, contents, chapterSize ) if (upContent) callBack?.upContent(resetPageOffset = resetPageOffset) callBack?.upView() @@ -423,14 +426,14 @@ object ReadBook { durChapterIndex - 1 -> { prevTextChapter = ChapterProvider.getTextChapter( - book, chapter, contents, chapterSize, imageStyle + book, chapter, contents, chapterSize ) if (upContent) callBack?.upContent(-1, resetPageOffset) } durChapterIndex + 1 -> { nextTextChapter = ChapterProvider.getTextChapter( - book, chapter, contents, chapterSize, imageStyle + book, chapter, contents, chapterSize ) if (upContent) callBack?.upContent(1, resetPageOffset) } @@ -444,8 +447,6 @@ object ReadBook { } } - private val imageStyle get() = webBook?.bookSource?.ruleContent?.imageStyle - fun pageAnim(): Int { book?.let { return if (it.getPageAnim() < 0) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index d51321812..6e24e5838 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -27,6 +27,7 @@ import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadTipConfig import io.legado.app.help.storage.Backup import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.accentColor import io.legado.app.receiver.TimeBatteryReceiver import io.legado.app.service.BaseReadAloudService @@ -253,6 +254,16 @@ class ReadBookActivity : ReadBookBaseActivity(), viewModel.reverseContent(it) } R.id.menu_set_charset -> showCharsetConfig() + R.id.menu_image_style -> { + val imgStyles = + arrayListOf(Book.imgStyleDefault, Book.imgStyleFull, Book.imgStyleText) + selector( + R.string.image_style, + imgStyles + ) { _, index -> + ReadBook.book?.setImageStyle(imgStyles[index]) + } + } R.id.menu_get_progress -> ReadBook.book?.let { viewModel.syncBookProgress(it) { progress -> sureSyncProgress(progress) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index a31833111..4f8ccbe21 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -81,7 +81,6 @@ object ChapterProvider { bookChapter: BookChapter, contents: List, chapterSize: Int, - imageStyle: String?, ): TextChapter { val textPages = arrayListOf() val stringBuilder = StringBuilder() @@ -94,7 +93,7 @@ object ChapterProvider { if (!book.isEpub()) { val src = NetworkUtils.getAbsoluteURL(bookChapter.url, it) durY = setTypeImage( - book, bookChapter, src, durY, textPages, imageStyle + book, bookChapter, src, durY, textPages, book.getImageStyle() ) } } @@ -142,9 +141,12 @@ object ChapterProvider { var height = it.height var width = it.width when (imageStyle?.toUpperCase(Locale.ROOT)) { - "FULL" -> { + Book.imgStyleFull -> { width = visibleWidth height = it.height * visibleWidth / it.width + } + Book.imgStyleText -> { + } else -> { if (it.width > visibleWidth) { diff --git a/app/src/main/res/menu/book_read.xml b/app/src/main/res/menu/book_read.xml index e2cdb3f45..bb713e388 100644 --- a/app/src/main/res/menu/book_read.xml +++ b/app/src/main/res/menu/book_read.xml @@ -92,6 +92,11 @@ android:checked="false" app:showAsAction="never" /> + + 调试 崩溃日志 使用自定义中文分行 + 图片样式 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 18a974a42..ab10dc901 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -810,5 +810,6 @@ 匯出到WebDav 反转内容 调试 + 图片样式 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 9365bc626..f6bb78f34 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -812,5 +812,6 @@ 调试 崩溃日志 使用自定义中文分行 + 图片样式 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2c820a9a4..0e54cdc00 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -815,5 +815,6 @@ 调试 崩溃日志 使用自定义中文分行 + 图片样式 From 8f4bf259adf21c79654a30699344a29050594264 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 7 Mar 2021 00:07:59 +0800 Subject: [PATCH 02/22] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=A0=B7=E5=BC=8FTEXT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 44 +++++++++---------- .../ui/book/read/page/entities/TextLine.kt | 1 - .../read/page/provider/ChapterProvider.kt | 2 +- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 10a454109..3fba231a4 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -113,19 +113,15 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at val lineTop = textLine.lineTop + relativeOffset val lineBase = textLine.lineBase + relativeOffset val lineBottom = textLine.lineBottom + relativeOffset - if (textLine.isImage) { - drawImage(canvas, textLine, lineTop, lineBottom) - } else { - drawChars( - canvas, - textLine.textChars, - lineTop, - lineBase, - lineBottom, - isTitle = textLine.isTitle, - isReadAloud = textLine.isReadAloud - ) - } + drawChars( + canvas, + textLine.textChars, + lineTop, + lineBase, + lineBottom, + isTitle = textLine.isTitle, + isReadAloud = textLine.isReadAloud + ) } /** @@ -148,7 +144,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at textPaint.color = if (isReadAloud) context.accentColor else ReadBookConfig.textColor textChars.forEach { - canvas.drawText(it.charData, it.start, lineBase, textPaint) + if (it.isImage) { + drawImage(canvas, it, lineTop, lineBottom) + } else { + canvas.drawText(it.charData, it.start, lineBase, textPaint) + } if (it.selected) { canvas.drawRect(it.start, lineTop, it.end, lineBottom, selectedPaint) } @@ -160,18 +160,16 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at */ private fun drawImage( canvas: Canvas, - textLine: TextLine, + textChar: TextChar, lineTop: Float, lineBottom: Float, ) { - textLine.textChars.forEach { textChar -> - ReadBook.book?.let { book -> - val rectF = RectF(textChar.start, lineTop, textChar.end, lineBottom) - ImageProvider.getImage(book, textPage.chapterIndex, textChar.charData, true) - ?.let { - canvas.drawBitmap(it, null, rectF, null) - } - } + ReadBook.book?.let { book -> + val rectF = RectF(textChar.start, lineTop, textChar.end, lineBottom) + ImageProvider.getImage(book, textPage.chapterIndex, textChar.charData, true) + ?.let { + canvas.drawBitmap(it, null, rectF, null) + } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index 9d73757bb..fe02e4f48 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -12,7 +12,6 @@ data class TextLine( var lineBase: Float = 0f, var lineBottom: Float = 0f, val isTitle: Boolean = false, - val isImage: Boolean = false, var isReadAloud: Boolean = false ) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 4f8ccbe21..e2e963431 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -164,7 +164,7 @@ object ChapterProvider { } } } - val textLine = TextLine(isImage = true) + val textLine = TextLine() textLine.lineTop = durY durY += height textLine.lineBottom = durY From 29b5806d91b1ae776c191b14fac7f55cf1286c3c Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 7 Mar 2021 00:11:22 +0800 Subject: [PATCH 03/22] edit updateLog.md --- app/src/main/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index cff575923..992b4bcd7 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -8,6 +8,9 @@ * 添加了针对中文的断行排版处理-by hoodie13, 需要再阅读界面设置里手动开启 * 添加朗读快捷方式 * 优化Epub解析 by hoodie13 +* epub书籍增加cache by hoodie13 +* 修复切换书籍或者章节时的断言崩溃问题。看漫画容易复现。 by hoodie13 +* 修正增加书签alert的正文内容较多时,确定键溢出屏幕问题 by hoodie13 **2021/02/26** * 添加反转内容功能 From 0596ddafa8c1e37796c0843a19cb7eb433d3f920 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 7 Mar 2021 22:42:34 +0800 Subject: [PATCH 04/22] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=A0=B7=E5=BC=8FTEXT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../read/page/provider/ChapterProvider.kt | 130 +++++++++++++++--- .../io/legado/app/utils/StringExtensions.kt | 2 - 2 files changed, 109 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index e2e963431..730f79a34 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -69,6 +69,8 @@ object ChapterProvider { @JvmStatic lateinit var contentPaint: TextPaint + private const val srcReplaceChar = "🖼" + init { upStyle() } @@ -86,23 +88,68 @@ object ChapterProvider { val stringBuilder = StringBuilder() var durY = 0f textPages.add(TextPage()) - contents.forEachIndexed { index, text -> - val matcher = AppPattern.imgPattern.matcher(text) - if (matcher.find()) { - matcher.group(1)?.let { - if (!book.isEpub()) { - val src = NetworkUtils.getAbsoluteURL(bookChapter.url, it) - durY = setTypeImage( - book, bookChapter, src, durY, textPages, book.getImageStyle() - ) + contents.forEachIndexed { index, content -> + if (book.getImageStyle() == Book.imgStyleText) { + var text = content.replace(srcReplaceChar, "画") + val srcList = LinkedList() + val sb = StringBuffer() + val matcher = AppPattern.imgPattern.matcher(text) + while (matcher.find()) { + matcher.group(1)?.let { + srcList.add(it) + matcher.appendReplacement(sb, srcReplaceChar) } } - } else { + matcher.appendTail(sb) + text = sb.toString() val isTitle = index == 0 val textPaint = if (isTitle) titlePaint else contentPaint if (!(isTitle && ReadBookConfig.titleMode == 2)) { - durY = setTypeText(text, durY, textPages, stringBuilder, isTitle, textPaint) + durY = setTypeText( + text, + durY, + textPages, + stringBuilder, + isTitle, + textPaint, + srcList + ) } + } else if (book.getImageStyle() != Book.imgStyleText) { + content.replace(AppPattern.imgPattern.toRegex(), "\n\$0\n") + .split("\n").forEach { text -> + if (text.isNotBlank()) { + val matcher = AppPattern.imgPattern.matcher(text) + if (matcher.find()) { + matcher.group(1)?.let { mt -> + if (!book.isEpub()) { + val src = NetworkUtils.getAbsoluteURL(bookChapter.url, mt) + durY = setTypeImage( + book, + bookChapter, + src, + durY, + textPages, + book.getImageStyle() + ) + } + } + } else { + val isTitle = index == 0 + val textPaint = if (isTitle) titlePaint else contentPaint + if (!(isTitle && ReadBookConfig.titleMode == 2)) { + durY = setTypeText( + text, + durY, + textPages, + stringBuilder, + isTitle, + textPaint + ) + } + } + } + } } } textPages.last().height = durY + 20.dp @@ -199,7 +246,8 @@ object ChapterProvider { textPages: ArrayList, stringBuilder: StringBuilder, isTitle: Boolean, - textPaint: TextPaint + textPaint: TextPaint, + srcList: LinkedList? = null ): Float { var durY = if (isTitle) y + titleTopSpacing else y val layout = if (ReadBookConfig.useZhLayout) { @@ -216,7 +264,13 @@ object ChapterProvider { if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) { //第一行 textLine.text = words - addCharsToLineFirst(textLine, words.toStringArray(), textPaint, desiredWidth) + addCharsToLineFirst( + textLine, + words.toStringArray(), + textPaint, + desiredWidth, + srcList + ) } else if (lineIndex == layout.lineCount - 1) { //最后一行 textLine.text = "$words\n" @@ -224,11 +278,18 @@ object ChapterProvider { val x = if (isTitle && ReadBookConfig.titleMode == 1) (visibleWidth - layout.getLineWidth(lineIndex)) / 2 else 0f - addCharsToLineLast(textLine, words.toStringArray(), textPaint, x) + addCharsToLineLast(textLine, words.toStringArray(), textPaint, x, srcList) } else { //中间行 textLine.text = words - addCharsToLineMiddle(textLine, words.toStringArray(), textPaint, desiredWidth, 0f) + addCharsToLineMiddle( + textLine, + words.toStringArray(), + textPaint, + desiredWidth, + 0f, + srcList + ) } if (durY + textPaint.textHeight > visibleHeight) { //当前页面结束,设置各种值 @@ -259,21 +320,30 @@ object ChapterProvider { words: Array, textPaint: TextPaint, desiredWidth: Float, + srcList: LinkedList? ) { var x = 0f if (!ReadBookConfig.textFullJustify) { - addCharsToLineLast(textLine, words, textPaint, x) + addCharsToLineLast(textLine, words, textPaint, x, srcList) return } val bodyIndent = ReadBookConfig.paragraphIndent val icw = StaticLayout.getDesiredWidth(bodyIndent, textPaint) / bodyIndent.length bodyIndent.toStringArray().forEach { val x1 = x + icw - textLine.addTextChar(charData = it, start = paddingLeft + x, end = paddingLeft + x1) + if (srcList != null && it == srcReplaceChar) { + textLine.addTextChar( + srcList.removeFirst(), + start = paddingLeft + x, + end = paddingLeft + x1 + ) + } else { + textLine.addTextChar(it, start = paddingLeft + x, end = paddingLeft + x1) + } x = x1 } val words1 = words.copyOfRange(bodyIndent.length, words.size) - addCharsToLineMiddle(textLine, words1, textPaint, desiredWidth, x) + addCharsToLineMiddle(textLine, words1, textPaint, desiredWidth, x, srcList) } /** @@ -285,9 +355,10 @@ object ChapterProvider { textPaint: TextPaint, desiredWidth: Float, startX: Float, + srcList: LinkedList? ) { if (!ReadBookConfig.textFullJustify) { - addCharsToLineLast(textLine, words, textPaint, startX) + addCharsToLineLast(textLine, words, textPaint, startX, srcList) return } val gapCount: Int = words.lastIndex @@ -296,7 +367,15 @@ object ChapterProvider { words.forEachIndexed { index, s -> val cw = StaticLayout.getDesiredWidth(s, textPaint) val x1 = if (index != words.lastIndex) (x + cw + d) else (x + cw) - textLine.addTextChar(charData = s, start = paddingLeft + x, end = paddingLeft + x1) + if (srcList != null && s == srcReplaceChar) { + textLine.addTextChar( + srcList.removeFirst(), + start = paddingLeft + x, + end = paddingLeft + x1 + ) + } else { + textLine.addTextChar(charData = s, start = paddingLeft + x, end = paddingLeft + x1) + } x = x1 } exceed(textLine, words) @@ -310,12 +389,21 @@ object ChapterProvider { words: Array, textPaint: TextPaint, startX: Float, + srcList: LinkedList? ) { var x = startX words.forEach { val cw = StaticLayout.getDesiredWidth(it, textPaint) val x1 = x + cw - textLine.addTextChar(charData = it, start = paddingLeft + x, end = paddingLeft + x1) + if (srcList != null && it == srcReplaceChar) { + textLine.addTextChar( + srcList.removeFirst(), + start = paddingLeft + x, + end = paddingLeft + x1 + ) + } else { + textLine.addTextChar(charData = it, start = paddingLeft + x, end = paddingLeft + x1) + } x = x1 } exceed(textLine, words) 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 b6a6d23e2..0ca1950d9 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -9,7 +9,6 @@ import java.io.File import java.util.* val removeHtmlRegex = "]*>".toRegex() -val imgRegex = "]*>".toRegex() val notImgHtmlRegex = "])[^<>]*>".toRegex() fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim() @@ -54,7 +53,6 @@ fun String?.isJsonArray(): Boolean = fun String?.htmlFormat(): String { this ?: return "" return this - .replace(imgRegex, "\n$0\n") .replace(removeHtmlRegex, "\n") .replace(notImgHtmlRegex, "") .replace("\\s*\\n+\\s*".toRegex(), "\n  ") From ac5d377496b629a4f71358a454ddbd76487599ee Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 7 Mar 2021 22:47:36 +0800 Subject: [PATCH 05/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/page/provider/ZhLayout.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt index f6c027c99..9df6820db 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt @@ -18,10 +18,10 @@ class ZhLayout( textPaint: TextPaint, width: Int ) : Layout(text, textPaint, width, Alignment.ALIGN_NORMAL, 0f, 0f) { - var lineStart = IntArray(1000) - var lineEnd = IntArray(1000) - var lineWidth = FloatArray(1000) - var lineCompressMod = IntArray(1000) + var lineStart = arrayListOf() + var lineEnd = arrayListOf() + var lineWidth = arrayListOf() + var lineCompressMod = arrayListOf() private var lineCount = 0 private val curPaint = textPaint private val cnCharWitch = getDesiredWidth("我", textPaint) From 7fddbb6112c2d06fd49b04a67fb938bf3c9624d8 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 7 Mar 2021 22:48:54 +0800 Subject: [PATCH 06/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt index 9df6820db..9a6aab20f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt @@ -167,9 +167,6 @@ class ZhLayout( } } cwPre = cw - if (line >= 999) { - return@forEachIndexed - } } lineCount = line From 1c4b5a54cde2c1ad9d8b96ccf5d9e5bf04668159 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 7 Mar 2021 22:52:00 +0800 Subject: [PATCH 07/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 992b4bcd7..e772483e1 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -11,6 +11,7 @@ * epub书籍增加cache by hoodie13 * 修复切换书籍或者章节时的断言崩溃问题。看漫画容易复现。 by hoodie13 * 修正增加书签alert的正文内容较多时,确定键溢出屏幕问题 by hoodie13 +* 图片样式添加TEXT **2021/02/26** * 添加反转内容功能 From 25e3f65b9a23c6cc54e737b7294b7ddabbcb0251 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 7 Mar 2021 22:57:48 +0800 Subject: [PATCH 08/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/page/entities/TextLine.kt | 3 ++- .../legado/app/ui/book/read/page/provider/ChapterProvider.kt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index fe02e4f48..435dd8613 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -12,7 +12,8 @@ data class TextLine( var lineBase: Float = 0f, var lineBottom: Float = 0f, val isTitle: Boolean = false, - var isReadAloud: Boolean = false + var isReadAloud: Boolean = false, + var isImage: Boolean = false ) { val charSize: Int get() = textChars.size diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 730f79a34..2a40a32d4 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -211,7 +211,7 @@ object ChapterProvider { } } } - val textLine = TextLine() + val textLine = TextLine(isImage = true) textLine.lineTop = durY durY += height textLine.lineBottom = durY From 2991a5ff6c99876ebb0042c3845d33b444178cfb Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 7 Mar 2021 23:11:29 +0800 Subject: [PATCH 09/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/EpubChapterDao.kt | 2 +- app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/EpubChapterDao.kt b/app/src/main/java/io/legado/app/data/dao/EpubChapterDao.kt index 6badb81b7..cf2f66d2a 100644 --- a/app/src/main/java/io/legado/app/data/dao/EpubChapterDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/EpubChapterDao.kt @@ -12,7 +12,7 @@ interface EpubChapterDao { fun getCnt(bookUrl: String): Int @Query("select * from epubChapters Where bookUrl = :bookUrl and parentHref = :parentHref ") - fun get(bookUrl: String, parentHref: String): List? + fun get(bookUrl: String, parentHref: String): List @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg chapter: EpubChapter) diff --git a/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt b/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt index dda787ddb..77246e20b 100644 --- a/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt @@ -133,7 +133,7 @@ class EPUBFile(var book: io.legado.app.data.entities.Book) { /*获取当前章节文本*/ var string = getChildChapter(chapter, chapter.url) val childContends = appDb.epubChapterDao.get(book.bookUrl, chapter.url) - childContends?.forEach { + childContends.forEach { string += "\n" + getChildChapter(chapter, it.href) } return string From 33add6504b58a048466f4467ea947df72549d9a8 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 8 Mar 2021 08:40:34 +0800 Subject: [PATCH 10/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/read/page/provider/ZhLayout.kt | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt index 9a6aab20f..4ed32e41c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt @@ -18,10 +18,9 @@ class ZhLayout( textPaint: TextPaint, width: Int ) : Layout(text, textPaint, width, Alignment.ALIGN_NORMAL, 0f, 0f) { - var lineStart = arrayListOf() - var lineEnd = arrayListOf() - var lineWidth = arrayListOf() - var lineCompressMod = arrayListOf() + var lineStart = IntArray(100) + var lineWidth = FloatArray(100) + var lineCompressMod = IntArray(100) private var lineCount = 0 private val curPaint = textPaint private val cnCharWitch = getDesiredWidth("我", textPaint) @@ -103,37 +102,37 @@ class ZhLayout( when (breakMod) { BreakMod.NORMAL -> {//模式0 正常断行 offset = cw - lineEnd[line] = index + lineStart[line + 1] = index lineCompressMod[line] = 0 breakCharCnt = 1 } BreakMod.BREAK_ONE_CHAR -> {//模式1 当前行下移一个字 offset = cw + cwPre - lineEnd[line] = index - 1 + lineStart[line + 1] = index - 1 lineCompressMod[line] = 0 breakCharCnt = 2 } BreakMod.BREAK_MORE_CHAR -> {//模式2 当前行下移多个字 offset = cw + cwPre - lineEnd[line] = index - breakIndex + lineStart[line + 1] = index - breakIndex lineCompressMod[line] = 0 breakCharCnt = breakIndex + 1 } BreakMod.CPS_1 -> {//模式3 两个后置标点压缩 offset = 0f - lineEnd[line] = index + 1 + lineStart[line + 1] = index + 1 lineCompressMod[line] = 1 breakCharCnt = 0 } BreakMod.CPS_2 -> { //模式4 前置标点压缩+前置标点压缩+字 offset = 0f - lineEnd[line] = index + 1 + lineStart[line + 1] = index + 1 lineCompressMod[line] = 2 breakCharCnt = 0 } BreakMod.CPS_3 -> {//模式5 前置标点压缩+字+后置标点压缩 offset = 0f - lineEnd[line] = index + 1 + lineStart[line + 1] = index + 1 lineCompressMod[line] = 3 breakCharCnt = 0 } @@ -144,26 +143,26 @@ class ZhLayout( /*当前行写满情况下的断行*/ if (breakLine) { lineWidth[line] = lineW - offset - lineStart[line + 1] = lineEnd[line] lineW = offset line++ + addLineArray(line) } /*已到最后一个字符*/ if ((words.lastIndex) == index) { if (!breakLine) { offset = 0f - lineEnd[line] = index + 1 - lineStart[line + 1] = lineEnd[line] + lineStart[line + 1] = index + 1 lineWidth[line] = lineW - offset lineW = offset line++ + addLineArray(line) } /*写满断行、段落末尾、且需要下移字符,这种特殊情况下要额外多一行*/ else if (breakCharCnt > 0) { - lineEnd[line] = lineStart[line] + breakCharCnt - lineStart[line + 1] = lineEnd[line] + lineStart[line + 1] = lineStart[line] + breakCharCnt lineWidth[line] = lineW line++ + addLineArray(line) } } cwPre = cw @@ -173,6 +172,14 @@ class ZhLayout( } + private fun addLineArray(line: Int) { + if (lineStart.size <= line) { + lineStart = lineStart.copyOf(line + 100) + lineWidth = lineWidth.copyOf(line + 100) + lineCompressMod = lineCompressMod.copyOf(line + 100) + } + } + private fun isPostPanc(string: String): Boolean { val panc = arrayOf( ",", "。", ":", "?", "!", "、", "”", "’", ")", "》", "}", From cd0d7dccc76a0e3427c45aee7e4500fd29ac477d Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 8 Mar 2021 08:52:11 +0800 Subject: [PATCH 11/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/provider/ZhLayout.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt index 4ed32e41c..c35c7f730 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt @@ -18,9 +18,10 @@ class ZhLayout( textPaint: TextPaint, width: Int ) : Layout(text, textPaint, width, Alignment.ALIGN_NORMAL, 0f, 0f) { - var lineStart = IntArray(100) - var lineWidth = FloatArray(100) - var lineCompressMod = IntArray(100) + private val defaultCapacity = 10 + var lineStart = IntArray(defaultCapacity) + var lineWidth = FloatArray(defaultCapacity) + var lineCompressMod = IntArray(defaultCapacity) private var lineCount = 0 private val curPaint = textPaint private val cnCharWitch = getDesiredWidth("我", textPaint) @@ -173,10 +174,10 @@ class ZhLayout( } private fun addLineArray(line: Int) { - if (lineStart.size <= line) { - lineStart = lineStart.copyOf(line + 100) - lineWidth = lineWidth.copyOf(line + 100) - lineCompressMod = lineCompressMod.copyOf(line + 100) + if (lineStart.size <= line + 1) { + lineStart = lineStart.copyOf(line + defaultCapacity) + lineWidth = lineWidth.copyOf(line + defaultCapacity) + lineCompressMod = lineCompressMod.copyOf(line + defaultCapacity) } } From 333462661d97fabf140d8aeb246c7b53cffb0640 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 8 Mar 2021 09:06:38 +0800 Subject: [PATCH 12/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/read/page/entities/TextLine.kt | 4 -- .../read/page/provider/ChapterProvider.kt | 65 ++++++++++++------- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index 435dd8613..57006ad8f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -24,10 +24,6 @@ data class TextLine( lineBase = lineBottom - textPaint.fontMetrics.descent } - fun addTextChar(charData: String, start: Float, end: Float) { - textChars.add(TextChar(charData, start = start, end = end)) - } - fun getTextChar(index: Int): TextChar { return textChars.getOrElse(index) { textChars.last() diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 2a40a32d4..f1d2e3ffe 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -95,8 +95,9 @@ object ChapterProvider { val sb = StringBuffer() val matcher = AppPattern.imgPattern.matcher(text) while (matcher.find()) { - matcher.group(1)?.let { - srcList.add(it) + matcher.group(1)?.let { src -> + srcList.add(src) + ImageProvider.getImage(book, bookChapter.index, src) matcher.appendReplacement(sb, srcReplaceChar) } } @@ -106,13 +107,8 @@ object ChapterProvider { val textPaint = if (isTitle) titlePaint else contentPaint if (!(isTitle && ReadBookConfig.titleMode == 2)) { durY = setTypeText( - text, - durY, - textPages, - stringBuilder, - isTitle, - textPaint, - srcList + text, durY, textPages, stringBuilder, + isTitle, textPaint, srcList ) } } else if (book.getImageStyle() != Book.imgStyleText) { @@ -332,13 +328,20 @@ object ChapterProvider { bodyIndent.toStringArray().forEach { val x1 = x + icw if (srcList != null && it == srcReplaceChar) { - textLine.addTextChar( - srcList.removeFirst(), - start = paddingLeft + x, - end = paddingLeft + x1 + textLine.textChars.add( + TextChar( + srcList.removeFirst(), + start = paddingLeft + x, + end = paddingLeft + x1, + isImage = true + ) ) } else { - textLine.addTextChar(it, start = paddingLeft + x, end = paddingLeft + x1) + textLine.textChars.add( + TextChar( + it, start = paddingLeft + x, end = paddingLeft + x1 + ) + ) } x = x1 } @@ -368,13 +371,20 @@ object ChapterProvider { val cw = StaticLayout.getDesiredWidth(s, textPaint) val x1 = if (index != words.lastIndex) (x + cw + d) else (x + cw) if (srcList != null && s == srcReplaceChar) { - textLine.addTextChar( - srcList.removeFirst(), - start = paddingLeft + x, - end = paddingLeft + x1 + textLine.textChars.add( + TextChar( + srcList.removeFirst(), + start = paddingLeft + x, + end = paddingLeft + x1, + isImage = true + ) ) } else { - textLine.addTextChar(charData = s, start = paddingLeft + x, end = paddingLeft + x1) + textLine.textChars.add( + TextChar( + s, start = paddingLeft + x, end = paddingLeft + x1 + ) + ) } x = x1 } @@ -396,13 +406,20 @@ object ChapterProvider { val cw = StaticLayout.getDesiredWidth(it, textPaint) val x1 = x + cw if (srcList != null && it == srcReplaceChar) { - textLine.addTextChar( - srcList.removeFirst(), - start = paddingLeft + x, - end = paddingLeft + x1 + textLine.textChars.add( + TextChar( + srcList.removeFirst(), + start = paddingLeft + x, + end = paddingLeft + x1, + isImage = true + ) ) } else { - textLine.addTextChar(charData = it, start = paddingLeft + x, end = paddingLeft + x1) + textLine.textChars.add( + TextChar( + it, start = paddingLeft + x, end = paddingLeft + x1 + ) + ) } x = x1 } From 52ce20faa6548412681ad13dd42a414db90d5dc6 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 8 Mar 2021 09:07:33 +0800 Subject: [PATCH 13/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index e772483e1..79b7ec578 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -11,7 +11,7 @@ * epub书籍增加cache by hoodie13 * 修复切换书籍或者章节时的断言崩溃问题。看漫画容易复现。 by hoodie13 * 修正增加书签alert的正文内容较多时,确定键溢出屏幕问题 by hoodie13 -* 图片样式添加TEXT +* 图片样式添加TEXT, 阅读界面菜单里可以选择图片样式 **2021/02/26** * 添加反转内容功能 From dabb66018fe339a0a1a50057d10a813605fb4222 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 8 Mar 2021 09:09:08 +0800 Subject: [PATCH 14/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/page/entities/TextPage.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index 0c90a541e..6108710f7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -72,7 +72,11 @@ data class TextPage( val char = textLine.text[i].toString() val cw = StaticLayout.getDesiredWidth(char, ChapterProvider.contentPaint) val x1 = x + cw - textLine.addTextChar(charData = char, start = x, end = x1) + textLine.textChars.add( + TextChar( + char, start = x, end = x1 + ) + ) x = x1 } textLines.add(textLine) From 7df8206eb67b15e3ade3b37a139c18ef21b2592c Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 8 Mar 2021 09:13:29 +0800 Subject: [PATCH 15/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/provider/ZhLayout.kt | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt index c35c7f730..2e3f7d12a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt @@ -7,11 +7,10 @@ import android.text.TextPaint import io.legado.app.utils.toStringArray import kotlin.math.max -/* -* 针对中文的断行排版处理-by hoodie13 -* 因为StaticLayout对标点处理不符合国人习惯,继承Layout -* 接口封的不抽象,数组用的也琐碎,因目前语法不熟悉,后面完善。 -* */ +/** + * 针对中文的断行排版处理-by hoodie13 + * 因为StaticLayout对标点处理不符合国人习惯,继承Layout + * */ @Suppress("MemberVisibilityCanBePrivate", "unused") class ZhLayout( text: String, @@ -145,8 +144,7 @@ class ZhLayout( if (breakLine) { lineWidth[line] = lineW - offset lineW = offset - line++ - addLineArray(line) + addLineArray(++line) } /*已到最后一个字符*/ if ((words.lastIndex) == index) { @@ -155,15 +153,13 @@ class ZhLayout( lineStart[line + 1] = index + 1 lineWidth[line] = lineW - offset lineW = offset - line++ - addLineArray(line) + addLineArray(++line) } /*写满断行、段落末尾、且需要下移字符,这种特殊情况下要额外多一行*/ else if (breakCharCnt > 0) { lineStart[line + 1] = lineStart[line] + breakCharCnt lineWidth[line] = lineW - line++ - addLineArray(line) + addLineArray(++line) } } cwPre = cw From ebc5a9b055eb83e41ec8a6c69210865bc3ad2a21 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 8 Mar 2021 09:30:56 +0800 Subject: [PATCH 16/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/read/page/provider/ZhLayout.kt | 109 +----------------- 1 file changed, 3 insertions(+), 106 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt index 2e3f7d12a..1972f93ef 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt @@ -20,7 +20,6 @@ class ZhLayout( private val defaultCapacity = 10 var lineStart = IntArray(defaultCapacity) var lineWidth = FloatArray(defaultCapacity) - var lineCompressMod = IntArray(defaultCapacity) private var lineCount = 0 private val curPaint = textPaint private val cnCharWitch = getDesiredWidth("我", textPaint) @@ -103,37 +102,31 @@ class ZhLayout( BreakMod.NORMAL -> {//模式0 正常断行 offset = cw lineStart[line + 1] = index - lineCompressMod[line] = 0 breakCharCnt = 1 } BreakMod.BREAK_ONE_CHAR -> {//模式1 当前行下移一个字 offset = cw + cwPre lineStart[line + 1] = index - 1 - lineCompressMod[line] = 0 breakCharCnt = 2 } BreakMod.BREAK_MORE_CHAR -> {//模式2 当前行下移多个字 offset = cw + cwPre lineStart[line + 1] = index - breakIndex - lineCompressMod[line] = 0 breakCharCnt = breakIndex + 1 } BreakMod.CPS_1 -> {//模式3 两个后置标点压缩 offset = 0f lineStart[line + 1] = index + 1 - lineCompressMod[line] = 1 breakCharCnt = 0 } BreakMod.CPS_2 -> { //模式4 前置标点压缩+前置标点压缩+字 offset = 0f lineStart[line + 1] = index + 1 - lineCompressMod[line] = 2 breakCharCnt = 0 } BreakMod.CPS_3 -> {//模式5 前置标点压缩+字+后置标点压缩 offset = 0f lineStart[line + 1] = index + 1 - lineCompressMod[line] = 3 breakCharCnt = 0 } } @@ -173,7 +166,6 @@ class ZhLayout( if (lineStart.size <= line + 1) { lineStart = lineStart.copyOf(line + defaultCapacity) lineWidth = lineWidth.copyOf(line + defaultCapacity) - lineCompressMod = lineCompressMod.copyOf(line + defaultCapacity) } } @@ -252,7 +244,9 @@ class ZhLayout( return 0 } - override fun getLineWidth(line: Int): Float = lineWidth[line] + override fun getLineWidth(line: Int): Float { + return lineWidth[line] + } override fun getEllipsisStart(line: Int): Int { return 0 @@ -262,101 +256,4 @@ class ZhLayout( return 0 } - fun getDefaultWidth(): Float = cnCharWitch - - /* - * @fun:获取当前行的平均间隔:用于两端对齐,获取左对齐时的右边间隔:用于间隔过大时不再两端对齐 - * @in:行,当前字符串,最大显示宽度 - * @out:单个字符的平均间隔,左对齐的最大间隔 - */ - fun getInterval(line: Int, words: Array, visibleWidth: Int): Interval { - val interval = Interval() - val total: Float - val d: Float - val lastIndex = words.lastIndex - val desiredWidth = getLineWidth(line) - if (lineCompressMod[line] > 0) { - val gapCount: Int = lastIndex - 1 - val lastWordsWith = getDesiredWidth(words[lastIndex], curPaint) - total = visibleWidth - desiredWidth + lastWordsWith - d = total / gapCount - } else { - val gapCount: Int = lastIndex - total = visibleWidth - desiredWidth - d = total / gapCount - } - interval.total = total - interval.single = d - return interval - } - - /* - * @fun:获取当前行不同字符的位置 - * @in:行,当前字符对于最后一个字符的偏移值,字符,间隔,定位参数 - * @out:定位参数 - */ - fun getLocate(line: Int, idx: Int, string: String, interval: Float, locate: Locate) { - val cw = getDesiredWidth(string, curPaint) - when (lineCompressMod[line]) { - 1 -> { - when (idx) { - 1 -> { - val offset = getPostPancOffset(string) - locate.start -= offset - locate.end = locate.start + cw / 2 + offset - } - 0 -> { - locate.start -= getPostPancOffset(string) - locate.end = locate.start + cw - } - else -> { - locate.end = locate.start + cw + interval - } - } - } - 2 -> { - when (idx) { - 2 -> { - val offset = getPostPancOffset(string) - locate.start -= offset - locate.end = locate.start + cw / 2 + offset - } - 1 -> { - val offset = getPostPancOffset(string) - locate.start -= offset - locate.end = locate.start + cw / 2 + offset - } - 0 -> { - locate.end = locate.start + cw - } - else -> { - locate.end = locate.start + cw + interval - } - } - } - 3 -> { - when (idx) { - 2 -> { - val offset = getPrePancOffset(string) - locate.start -= offset - locate.end = locate.start + cw / 2 + offset - } - 1 -> { - locate.end = locate.start + cw + interval - } - 0 -> { - locate.start -= getPostPancOffset(string) - locate.end = locate.start + cw - } - else -> { - locate.end = locate.start + cw + interval - } - } - } - else -> { - locate.end = if (idx != 0) (locate.start + cw + interval) else (locate.start + cw) - } - } - } - } \ No newline at end of file From 6c8f1609b20d2714353ca0765f63aab4e82158d9 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 8 Mar 2021 10:09:02 +0800 Subject: [PATCH 17/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/defaultData/rssSources.json | 9 +++++++++ .../java/io/legado/app/ui/main/rss/RssFragment.kt | 11 ++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/assets/defaultData/rssSources.json b/app/src/main/assets/defaultData/rssSources.json index b4b2a70e0..bc1754b59 100644 --- a/app/src/main/assets/defaultData/rssSources.json +++ b/app/src/main/assets/defaultData/rssSources.json @@ -17,5 +17,14 @@ "sourceName": "阅读下载", "sourceUrl": "https:\/\/github.com\/gedoor\/legado\/releases", "style": "" + }, + { + "customOrder": 1, + "enableJs": true, + "enabled": true, + "singleUrl": true, + "sourceIcon": "http:\/\/mmbiz.qpic.cn\/mmbiz_png\/hpfMV8hEuL2eS6vnCxvTzoOiaCAibV6exBzJWq9xMic9xDg3YXAick87tsfafic0icRwkQ5ibV0bJ84JtSuxhPuEDVquA\/0?wx_fmt=png", + "sourceName": "小说拾遗", + "sourceUrl": "snssdk1128:\/\/user\/profile\/562564899806367" } ] \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 039c54f75..6441cea91 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -25,6 +25,7 @@ import io.legado.app.ui.rss.source.manage.RssSourceActivity import io.legado.app.ui.rss.source.manage.RssSourceViewModel import io.legado.app.ui.rss.subscription.RuleSubActivity import io.legado.app.utils.cnCompare +import io.legado.app.utils.openUrl import io.legado.app.utils.splitNotBlank import io.legado.app.utils.startActivity import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -143,9 +144,13 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), override fun openRss(rssSource: RssSource) { if (rssSource.singleUrl) { - startActivity { - putExtra("title", rssSource.sourceName) - putExtra("origin", rssSource.sourceUrl) + if (rssSource.sourceUrl.startsWith("http", true)) { + startActivity { + putExtra("title", rssSource.sourceName) + putExtra("origin", rssSource.sourceUrl) + } + } else { + context?.openUrl(rssSource.sourceUrl) } } else { startActivity { From 565f62cdd54fd1eaa268dd92662f074722c9d852 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 8 Mar 2021 10:09:40 +0800 Subject: [PATCH 18/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/LocalConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/LocalConfig.kt b/app/src/main/java/io/legado/app/help/LocalConfig.kt index ff86c7a47..ed0e46b2b 100644 --- a/app/src/main/java/io/legado/app/help/LocalConfig.kt +++ b/app/src/main/java/io/legado/app/help/LocalConfig.kt @@ -71,5 +71,5 @@ object LocalConfig { get() = !isLastVersion(1, "txtTocRuleVersion") val hasUpRssSources: Boolean - get() = !isLastVersion(1, "rssSourceVersion") + get() = !isLastVersion(2, "rssSourceVersion") } \ No newline at end of file From 354038d7aaa2fef8b7464f1b3cd7fbdad825f481 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 8 Mar 2021 11:24:48 +0800 Subject: [PATCH 19/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- avd11.bat | 1 + 1 file changed, 1 insertion(+) create mode 100644 avd11.bat diff --git a/avd11.bat b/avd11.bat new file mode 100644 index 000000000..fef788ee9 --- /dev/null +++ b/avd11.bat @@ -0,0 +1 @@ +emulator -avd android11 -dns-server 8.8.8.8 -no-snapshot-load \ No newline at end of file From 5a333fdf02d520fb40e54e4ca653341f993d209b Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 8 Mar 2021 12:20:30 +0800 Subject: [PATCH 20/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 79b7ec578..b83d0ac2d 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,7 +3,7 @@ * 关注合作公众号 **[小说拾遗]** 获取好看的小说。 * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 -**2021/03/01** +**2021/03/08** * 阅读页面停留10分钟之后自动备份进度 * 添加了针对中文的断行排版处理-by hoodie13, 需要再阅读界面设置里手动开启 * 添加朗读快捷方式 From d3f158e206e77e61fe3702a29e6a5ed3e7057b0b Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 9 Mar 2021 14:11:26 +0800 Subject: [PATCH 21/22] =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=9B=B8=E5=AF=B9?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E8=BD=AC=E7=BB=9D=E5=AF=B9=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../read/page/provider/ChapterProvider.kt | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index f1d2e3ffe..54fec4b6e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -95,7 +95,8 @@ object ChapterProvider { val sb = StringBuffer() val matcher = AppPattern.imgPattern.matcher(text) while (matcher.find()) { - matcher.group(1)?.let { src -> + matcher.group(1)?.let { it -> + val src = NetworkUtils.getAbsoluteURL(bookChapter.url, it) srcList.add(src) ImageProvider.getImage(book, bookChapter.index, src) matcher.appendReplacement(sb, srcReplaceChar) @@ -117,16 +118,12 @@ object ChapterProvider { if (text.isNotBlank()) { val matcher = AppPattern.imgPattern.matcher(text) if (matcher.find()) { - matcher.group(1)?.let { mt -> + matcher.group(1)?.let { it -> if (!book.isEpub()) { - val src = NetworkUtils.getAbsoluteURL(bookChapter.url, mt) + val src = NetworkUtils.getAbsoluteURL(bookChapter.url, it) durY = setTypeImage( - book, - bookChapter, - src, - durY, - textPages, - book.getImageStyle() + book, bookChapter, src, + durY, textPages, book.getImageStyle() ) } } @@ -135,12 +132,8 @@ object ChapterProvider { val textPaint = if (isTitle) titlePaint else contentPaint if (!(isTitle && ReadBookConfig.titleMode == 2)) { durY = setTypeText( - text, - durY, - textPages, - stringBuilder, - isTitle, - textPaint + text, durY, textPages, + stringBuilder, isTitle, textPaint ) } } From 8b4829996af2c125d5ba24cad6bf6634ab554d8c Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 9 Mar 2021 15:06:29 +0800 Subject: [PATCH 22/22] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/AppConfig.kt | 2 ++ .../app/receiver/MediaButtonReceiver.kt | 33 +++++++------------ .../app/receiver/SharedReceiverActivity.kt | 4 +-- app/src/main/res/xml/shortcuts.xml | 2 +- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 3b110e589..a0d2dff56 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -175,6 +175,8 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { val preDownload get() = appCtx.getPrefBoolean(PreferKey.preDownload, true) + val mediaButtonOnExit get() = appCtx.getPrefBoolean("mediaButtonOnExit", true) + private fun getPrefUserAgent(): String { val ua = appCtx.getPrefString(PreferKey.userAgent) if (ua.isNullOrBlank()) { diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index 8dbb836a9..beded7255 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -6,8 +6,8 @@ import android.content.Intent import android.view.KeyEvent import io.legado.app.constant.EventBus import io.legado.app.data.appDb -import io.legado.app.data.entities.Book import io.legado.app.help.ActivityHelp +import io.legado.app.help.AppConfig import io.legado.app.service.AudioPlayService import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.AudioPlay @@ -15,13 +15,7 @@ import io.legado.app.service.help.ReadAloud import io.legado.app.ui.audio.AudioPlayActivity import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.main.MainActivity -import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.postEvent -import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.Dispatchers.Main -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext /** @@ -61,7 +55,7 @@ class MediaButtonReceiver : BroadcastReceiver() { return true } - fun readAloud(context: Context) { + fun readAloud(context: Context, isMediaKey: Boolean = true) { when { BaseReadAloudService.isRun -> if (BaseReadAloudService.isPlay()) { ReadAloud.pause(context) @@ -79,24 +73,19 @@ class MediaButtonReceiver : BroadcastReceiver() { postEvent(EventBus.MEDIA_BUTTON, true) ActivityHelp.isExist(AudioPlayActivity::class.java) -> postEvent(EventBus.MEDIA_BUTTON, true) - else -> if (context.getPrefBoolean("mediaButtonOnExit", true)) { - GlobalScope.launch(Main) { - val lastBook: Book? = withContext(IO) { - appDb.bookDao.lastReadBook - } - lastBook?.let { - if (!ActivityHelp.isExist(MainActivity::class.java)) { - Intent(context, MainActivity::class.java).let { - it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(it) - } - } - Intent(context, ReadBookActivity::class.java).let { + else -> if (AppConfig.mediaButtonOnExit || !isMediaKey) { + appDb.bookDao.lastReadBook?.let { + if (!ActivityHelp.isExist(MainActivity::class.java)) { + Intent(context, MainActivity::class.java).let { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - it.putExtra("readAloud", true) context.startActivity(it) } } + Intent(context, ReadBookActivity::class.java).let { + it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + it.putExtra("readAloud", true) + context.startActivity(it) + } } } } diff --git a/app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt b/app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt index 1e08c3c6f..a6bb0af91 100644 --- a/app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt +++ b/app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt @@ -41,8 +41,8 @@ class SharedReceiverActivity : AppCompatActivity() { } } } - intent.getStringExtra("action") == "mediaButton" -> { - MediaButtonReceiver.readAloud(appCtx) + intent.getStringExtra("action") == "readAloud" -> { + MediaButtonReceiver.readAloud(appCtx, false) } } } diff --git a/app/src/main/res/xml/shortcuts.xml b/app/src/main/res/xml/shortcuts.xml index 6e16843c7..2e6e4f6cb 100644 --- a/app/src/main/res/xml/shortcuts.xml +++ b/app/src/main/res/xml/shortcuts.xml @@ -36,7 +36,7 @@ android:targetClass="io.legado.app.receiver.SharedReceiverActivity"> + android:value="readAloud" />