diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index bcec98b1d..3f4472f31 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -26,8 +26,7 @@ class ContentView(context: Context) : FrameLayout(context) { upStyle() upTime() content_text_view.upView = { - tv_bottom_left.text = it.title - setPageIndex(it.index, it.pageSize) + setProgress(it) } } @@ -85,20 +84,19 @@ class ContentView(context: Context) : FrameLayout(context) { } fun upTime() { - tv_top_left.text = timeFormat.format(Date(System.currentTimeMillis())) + if (ReadBookConfig.hideStatusBar) { + tv_bottom_left.text = timeFormat.format(Date(System.currentTimeMillis())) + } } fun upBattery(battery: Int) { - tv_top_right.text = context.getString(R.string.battery_show, battery) + if (ReadBookConfig.hideStatusBar) { + tv_bottom_right.text = context.getString(R.string.battery_show, battery) + } } fun setContent(textPage: TextPage) { - tv_bottom_left.text = when (AppConfig.chineseConverterType) { - 1 -> ZhConvertBootstrap.newInstance().toSimple(textPage.title) - 2 -> ZhConvertBootstrap.newInstance().toTraditional(textPage.title) - else -> textPage.title - } - setPageIndex(textPage.index, textPage.pageSize) + setProgress(textPage) content_text_view.resetPageOffset() content_text_view.setContent(textPage) } @@ -108,9 +106,19 @@ class ContentView(context: Context) : FrameLayout(context) { } @SuppressLint("SetTextI18n") - fun setPageIndex(pageIndex: Int?, pageSize: Int) { - pageIndex?.let { - tv_bottom_right.text = "${pageIndex.plus(1)}/${pageSize}" + fun setProgress(textPage: TextPage) = textPage.apply { + val title = when (AppConfig.chineseConverterType) { + 1 -> ZhConvertBootstrap.newInstance().toSimple(textPage.title) + 2 -> ZhConvertBootstrap.newInstance().toTraditional(textPage.title) + else -> textPage.title + } + val progress = "${index.plus(1)}/$pageSize $readProgress" + if (ReadBookConfig.hideStatusBar) { + tv_top_left.text = title + tv_top_right.text = progress + } else { + tv_bottom_left.text = title + tv_bottom_right.text = progress } } 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 f42fcdb5d..bfb8e822c 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 @@ -5,6 +5,7 @@ import android.text.StaticLayout import io.legado.app.App import io.legado.app.R import io.legado.app.ui.book.read.page.ChapterProvider +import java.text.DecimalFormat data class TextPage( var index: Int = 0, @@ -84,4 +85,20 @@ data class TextPage( lineStart += textLine.text.length } } + + val readProgress: String + get() { + val df = DecimalFormat("0.0%") + if (chapterSize == 0 || pageSize == 0 && chapterIndex == 0) { + return "0.0%" + } else if (pageSize == 0) { + return df.format((chapterIndex + 1.0f) / chapterSize.toDouble()) + } + var percent = + df.format(chapterIndex * 1.0f / chapterSize + 1.0f / chapterSize * (index + 1) / pageSize.toDouble()) + if (percent == "100.0%" && (chapterIndex + 1 != chapterSize || index + 1 != pageSize)) { + percent = "99.9%" + } + return percent + } }