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() } } 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/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) 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 +} 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..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 } 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) } } 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 "" 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" />