From d220d544ff445ec52796be91b4ddcf2d854b167a Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 18 Aug 2020 08:32:36 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../res/layout-land/activity_book_info.xml | 25 +++++++++-------- .../main/res/layout/activity_book_info.xml | 28 ++++++++++--------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/app/src/main/res/layout-land/activity_book_info.xml b/app/src/main/res/layout-land/activity_book_info.xml index b42bf1bfc..d99efc484 100644 --- a/app/src/main/res/layout-land/activity_book_info.xml +++ b/app/src/main/res/layout-land/activity_book_info.xml @@ -27,7 +27,8 @@ android:layout_height="match_parent" android:background="#50000000" android:orientation="horizontal" - android:fitsSystemWindows="true"> + android:fitsSystemWindows="true" + tools:ignore="DisableBaselineAlignment"> + android:paddingBottom="3dp" + tools:ignore="UseCompoundDrawables"> + tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" + tools:text="@string/origin_format" /> + android:paddingBottom="3dp" + tools:ignore="UseCompoundDrawables"> + tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" + tools:text="@string/read_dur_progress" /> @@ -287,10 +290,10 @@ android:includeFontPadding="false" android:paddingRight="6dp" android:singleLine="true" - android:text="@string/group_s" android:textColor="@color/tv_text_summary" android:textSize="13sp" - tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" /> + tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" + tools:text="@string/group_s" /> + tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" + tools:text="@string/toc_s" /> + android:paddingBottom="3dp" + tools:ignore="UseCompoundDrawables"> + tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" + tools:text="@string/origin_format" /> @@ -210,16 +211,17 @@ android:gravity="center_vertical" android:orientation="horizontal" android:paddingTop="3dp" - android:paddingBottom="3dp"> + android:paddingBottom="3dp" + tools:ignore="UseCompoundDrawables"> + tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" + tools:text="@string/read_dur_progress" /> @@ -249,10 +251,10 @@ + tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" + tools:text="@string/group_s" /> + tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" + tools:text="@string/toc_s" /> Date: Tue, 18 Aug 2020 08:36:28 +0800 Subject: [PATCH 2/8] =?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/ImageProvider.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt index 9bc9bda12..c5407cb1b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt @@ -49,7 +49,7 @@ object ImageProvider { out.close() } } else if (!onUi) { - HttpHelper.getBytes(src, baseUrl)?.let { + HttpHelper.getBytes(src, src)?.let { FileUtils.createFileIfNotExist(vFile.absolutePath).writeBytes(it) } } From deda8c40a5fc1508c64a367f7e847bf9f114f57d Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Tue, 18 Aug 2020 09:22:51 +0800 Subject: [PATCH 3/8] Update ImageProvider.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 加入baseUrl变量申明 --- .../io/legado/app/ui/book/read/page/provider/ImageProvider.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt index c5407cb1b..0084bfc5f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt @@ -31,7 +31,7 @@ object ImageProvider { indexCache[src] = bitmap } - fun getImage(book: Book, chapterIndex: Int, src: String, onUi: Boolean = false): Bitmap? { + fun getImage(book: Book, chapterIndex: Int, src: String, baseUrl: String, onUi: Boolean = false): Bitmap? { getCache(chapterIndex, src)?.let { return it } @@ -49,7 +49,7 @@ object ImageProvider { out.close() } } else if (!onUi) { - HttpHelper.getBytes(src, src)?.let { + HttpHelper.getBytes(src, baseUrl)?.let { FileUtils.createFileIfNotExist(vFile.absolutePath).writeBytes(it) } } From f9b566cdaf0065c167140ebd612981204e13963e Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Tue, 18 Aug 2020 09:27:50 +0800 Subject: [PATCH 4/8] Update ChapterProvider.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 图片链接的referer为当前章节的链接chapter.url --- .../legado/app/ui/book/read/page/provider/ChapterProvider.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 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 ccfe10564..c1e4bdf1e 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 @@ -122,7 +122,7 @@ object ChapterProvider { imageStyle: String? ): Float { var durY = y - ImageProvider.getImage(book, chapter.index, src)?.let { + ImageProvider.getImage(book, chapter.index, src, chapter.url)?.let { if (durY > visibleHeight) { textPages.last().height = durY textPages.add(TextPage()) @@ -453,4 +453,4 @@ object ChapterProvider { val TextPaint.textHeight: Float get() = fontMetrics.descent - fontMetrics.ascent + fontMetrics.leading -} \ No newline at end of file +} From 996bf4d5589c205eb6546f256999ade54ebd78af Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Tue, 18 Aug 2020 09:32:19 +0800 Subject: [PATCH 5/8] Update ContentTextView.kt --- .../main/java/io/legado/app/ui/book/read/page/ContentTextView.kt | 1 + 1 file changed, 1 insertion(+) 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 d21988163..0c5c63aa8 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 @@ -163,6 +163,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at ReadBook.book!!, textPage.chapterIndex, textChar.charData, + textChar.charData, true )?.let { canvas.drawBitmap(it, null, rectF, null) From 9a987726eb27a3df968ed4aded98b3f7ec962562 Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Tue, 18 Aug 2020 09:33:55 +0800 Subject: [PATCH 6/8] Update PhotoDialog.kt --- app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt index 74dfe23cd..c00064222 100644 --- a/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt @@ -56,7 +56,7 @@ class PhotoDialog : BaseDialogFragment() { val src = it.getString("src") ReadBook.book?.let { book -> src?.let { - ImageProvider.getImage(book, chapterIndex, src)?.let { bitmap -> + ImageProvider.getImage(book, chapterIndex, src, src)?.let { bitmap -> photo_view.setImageBitmap(bitmap) } } From c300f6b9e157cd4eae16f5fa40e2889c7ad2d304 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 18 Aug 2020 11:02:25 +0800 Subject: [PATCH 7/8] =?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/App.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 3275be677..d14951cb1 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -63,7 +63,8 @@ class App : MultiDexApplication() { override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) when (newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK) { - Configuration.UI_MODE_NIGHT_YES, Configuration.UI_MODE_NIGHT_NO -> applyDayNight() + Configuration.UI_MODE_NIGHT_YES, + Configuration.UI_MODE_NIGHT_NO -> applyDayNight() } } From 4b66d33e35e66d2c3b6cb00ff8576d12d9b1a3ba Mon Sep 17 00:00:00 2001 From: Knock Date: Tue, 18 Aug 2020 11:51:24 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=AD=97?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/model/webBook/BookInfo.kt | 3 ++- .../io/legado/app/model/webBook/BookList.kt | 5 ++-- .../java/io/legado/app/utils/StringUtils.kt | 24 ++++++++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt index 226e301af..ce588c5cd 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt @@ -9,6 +9,7 @@ import io.legado.app.help.BookHelp import io.legado.app.model.Debug import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.utils.NetworkUtils +import io.legado.app.utils.StringUtils.wordCountFormat import io.legado.app.utils.htmlFormat object BookInfo { @@ -51,7 +52,7 @@ object BookInfo { } Debug.log(bookSource.bookSourceUrl, "└${book.kind}") Debug.log(bookSource.bookSourceUrl, "┌获取字数") - analyzeRule.getString(infoRule.wordCount).let { + wordCountFormat(analyzeRule.getString(infoRule.wordCount)).let { if (it.isNotEmpty()) book.wordCount = it } Debug.log(bookSource.bookSourceUrl, "└${book.wordCount}") diff --git a/app/src/main/java/io/legado/app/model/webBook/BookList.kt b/app/src/main/java/io/legado/app/model/webBook/BookList.kt index bb90d5f5e..474ed653c 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookList.kt @@ -10,6 +10,7 @@ import io.legado.app.model.Debug import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.NetworkUtils +import io.legado.app.utils.StringUtils.wordCountFormat import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.isActive @@ -152,7 +153,7 @@ object BookList { Debug.log(bookSource.bookSourceUrl, "└${searchBook.kind}") if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取字数") - searchBook.wordCount = analyzeRule.getString(wordCount) + searchBook.wordCount = wordCountFormat(analyzeRule.getString(wordCount)) Debug.log(bookSource.bookSourceUrl, "└${searchBook.wordCount}") if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取最新章节") @@ -212,7 +213,7 @@ object BookList { Debug.log(bookSource.bookSourceUrl, "└${searchBook.kind}", log) if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取字数", log) - searchBook.wordCount = analyzeRule.getString(ruleWordCount) + searchBook.wordCount = wordCountFormat(analyzeRule.getString(ruleWordCount)) Debug.log(bookSource.bookSourceUrl, "└${searchBook.wordCount}", log) if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取最新章节", log) diff --git a/app/src/main/java/io/legado/app/utils/StringUtils.kt b/app/src/main/java/io/legado/app/utils/StringUtils.kt index 76f076af3..e5b658c21 100644 --- a/app/src/main/java/io/legado/app/utils/StringUtils.kt +++ b/app/src/main/java/io/legado/app/utils/StringUtils.kt @@ -214,7 +214,7 @@ object StringUtils { fun stringToInt(str: String?): Int { if (str != null) { - val num = fullToHalf(str).replace("\\s".toRegex(), "") + val num = fullToHalf(str).replace("\\s+".toRegex(), "") return try { Integer.parseInt(num) } catch (e: Exception) { @@ -226,17 +226,35 @@ object StringUtils { } fun isContainNumber(company: String): Boolean { - val p = Pattern.compile("[0-9]") + val p = Pattern.compile("[0-9]+") val m = p.matcher(company) return m.find() } fun isNumeric(str: String): Boolean { - val pattern = Pattern.compile("[0-9]*") + val pattern = Pattern.compile("[0-9]+") val isNum = pattern.matcher(str) return isNum.matches() } + fun wordCountFormat(wc: String?): String { + if (wc == null) return "" + var wordsS = "" + if (isNumeric(wc)) { + val words: Int = wc.toInt() + if (words > 0) { + wordsS = words.toString() + "字" + if (words > 10000) { + val df = DecimalFormat("#.#") + wordsS = df.format(words * 1.0f / 10000f.toDouble()) + "万字" + } + } + } else { + wordsS = wc + } + return wordsS + } + // 移除字符串首尾空字符的高效方法(利用ASCII值判断,包括全角空格) fun trim(s: String): String { if (isEmpty(s)) return ""