kunfei 4 лет назад
Родитель
Сommit
fd2200ac06

+ 9 - 1
app/src/main/java/io/legado/app/help/ReadTipConfig.kt

@@ -5,16 +5,24 @@ import io.legado.app.R
 import splitties.init.appCtx
 
 object ReadTipConfig {
-    val tips get() = appCtx.resources.getStringArray(R.array.read_tip).toList()
+
     const val none = 0
     const val chapterTitle = 1
     const val time = 2
     const val battery = 3
+    const val batteryPercentage = 10
     const val page = 4
     const val totalProgress = 5
     const val pageAndTotal = 6
     const val bookName = 7
     const val timeBattery = 8
+    const val timeBatteryPercentage = 9
+
+    val tipValues = arrayOf(
+        none, bookName, chapterTitle, time, battery, batteryPercentage, page,
+        totalProgress, pageAndTotal, timeBattery, timeBatteryPercentage
+    )
+    val tipNames get() = appCtx.resources.getStringArray(R.array.read_tip).toList()
 
     var tipHeaderLeft: Int
         get() = ReadBookConfig.config.tipHeaderLeft

+ 48 - 45
app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt

@@ -36,30 +36,33 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) {
         }
     }
 
-    private fun initView() = binding.run {
-        rgTitleMode.checkByIndex(ReadBookConfig.titleMode)
-        dsbTitleSize.progress = ReadBookConfig.titleSize
-        dsbTitleTop.progress = ReadBookConfig.titleTopSpacing
-        dsbTitleBottom.progress = ReadBookConfig.titleBottomSpacing
+    private fun initView() {
+        binding.rgTitleMode.checkByIndex(ReadBookConfig.titleMode)
+        binding.dsbTitleSize.progress = ReadBookConfig.titleSize
+        binding.dsbTitleTop.progress = ReadBookConfig.titleTopSpacing
+        binding.dsbTitleBottom.progress = ReadBookConfig.titleBottomSpacing
 
-        tvHeaderShow.text = ReadTipConfig.getHeaderModes(requireContext())[ReadTipConfig.headerMode]
-        tvFooterShow.text = ReadTipConfig.getFooterModes(requireContext())[ReadTipConfig.footerMode]
+        binding.tvHeaderShow.text =
+            ReadTipConfig.getHeaderModes(requireContext())[ReadTipConfig.headerMode]
+        binding.tvFooterShow.text =
+            ReadTipConfig.getFooterModes(requireContext())[ReadTipConfig.footerMode]
 
-        ReadTipConfig.tips.let { tips ->
-            tvHeaderLeft.text =
-                tips.getOrElse(ReadTipConfig.tipHeaderLeft) { tips[ReadTipConfig.none] }
-            tvHeaderMiddle.text =
-                tips.getOrElse(ReadTipConfig.tipHeaderMiddle) { tips[ReadTipConfig.none] }
-            tvHeaderRight.text =
-                tips.getOrElse(ReadTipConfig.tipHeaderRight) { tips[ReadTipConfig.none] }
-            tvFooterLeft.text =
-                tips.getOrElse(ReadTipConfig.tipFooterLeft) { tips[ReadTipConfig.none] }
-            tvFooterMiddle.text =
-                tips.getOrElse(ReadTipConfig.tipFooterMiddle) { tips[ReadTipConfig.none] }
-            tvFooterRight.text =
-                tips.getOrElse(ReadTipConfig.tipFooterRight) { tips[ReadTipConfig.none] }
+        ReadTipConfig.run {
+            tipNames.let { tipNames ->
+                binding.tvHeaderLeft.text =
+                    tipNames.getOrElse(tipValues.indexOf(tipHeaderLeft)) { tipNames[none] }
+                binding.tvHeaderMiddle.text =
+                    tipNames.getOrElse(tipValues.indexOf(tipHeaderMiddle)) { tipNames[none] }
+                binding.tvHeaderRight.text =
+                    tipNames.getOrElse(tipValues.indexOf(tipHeaderRight)) { tipNames[none] }
+                binding.tvFooterLeft.text =
+                    tipNames.getOrElse(tipValues.indexOf(tipFooterLeft)) { tipNames[none] }
+                binding.tvFooterMiddle.text =
+                    tipNames.getOrElse(tipValues.indexOf(tipFooterMiddle)) { tipNames[none] }
+                binding.tvFooterRight.text =
+                    tipNames.getOrElse(tipValues.indexOf(tipFooterRight)) { tipNames[none] }
+            }
         }
-
         upTvTipColor()
     }
 
@@ -106,50 +109,50 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) {
             }
         }
         llHeaderLeft.setOnClickListener {
-            context?.selector(items = ReadTipConfig.tips) { _, i ->
+            context?.selector(items = ReadTipConfig.tipNames) { _, i ->
                 clearRepeat(i)
-                ReadTipConfig.tipHeaderLeft = i
-                tvHeaderLeft.text = ReadTipConfig.tips[i]
+                ReadTipConfig.tipHeaderLeft = ReadTipConfig.tipValues[i]
+                tvHeaderLeft.text = ReadTipConfig.tipNames[i]
                 postEvent(EventBus.UP_CONFIG, true)
             }
         }
         llHeaderMiddle.setOnClickListener {
-            context?.selector(items = ReadTipConfig.tips) { _, i ->
+            context?.selector(items = ReadTipConfig.tipNames) { _, i ->
                 clearRepeat(i)
-                ReadTipConfig.tipHeaderMiddle = i
-                tvHeaderMiddle.text = ReadTipConfig.tips[i]
+                ReadTipConfig.tipHeaderMiddle = ReadTipConfig.tipValues[i]
+                tvHeaderMiddle.text = ReadTipConfig.tipNames[i]
                 postEvent(EventBus.UP_CONFIG, true)
             }
         }
         llHeaderRight.setOnClickListener {
-            context?.selector(items = ReadTipConfig.tips) { _, i ->
+            context?.selector(items = ReadTipConfig.tipNames) { _, i ->
                 clearRepeat(i)
-                ReadTipConfig.tipHeaderRight = i
-                tvHeaderRight.text = ReadTipConfig.tips[i]
+                ReadTipConfig.tipHeaderRight = ReadTipConfig.tipValues[i]
+                tvHeaderRight.text = ReadTipConfig.tipNames[i]
                 postEvent(EventBus.UP_CONFIG, true)
             }
         }
         llFooterLeft.setOnClickListener {
-            context?.selector(items = ReadTipConfig.tips) { _, i ->
+            context?.selector(items = ReadTipConfig.tipNames) { _, i ->
                 clearRepeat(i)
-                ReadTipConfig.tipFooterLeft = i
-                tvFooterLeft.text = ReadTipConfig.tips[i]
+                ReadTipConfig.tipFooterLeft = ReadTipConfig.tipValues[i]
+                tvFooterLeft.text = ReadTipConfig.tipNames[i]
                 postEvent(EventBus.UP_CONFIG, true)
             }
         }
         llFooterMiddle.setOnClickListener {
-            context?.selector(items = ReadTipConfig.tips) { _, i ->
+            context?.selector(items = ReadTipConfig.tipNames) { _, i ->
                 clearRepeat(i)
-                ReadTipConfig.tipFooterMiddle = i
-                tvFooterMiddle.text = ReadTipConfig.tips[i]
+                ReadTipConfig.tipFooterMiddle = ReadTipConfig.tipValues[i]
+                tvFooterMiddle.text = ReadTipConfig.tipNames[i]
                 postEvent(EventBus.UP_CONFIG, true)
             }
         }
         llFooterRight.setOnClickListener {
-            context?.selector(items = ReadTipConfig.tips) { _, i ->
+            context?.selector(items = ReadTipConfig.tipNames) { _, i ->
                 clearRepeat(i)
-                ReadTipConfig.tipFooterRight = i
-                tvFooterRight.text = ReadTipConfig.tips[i]
+                ReadTipConfig.tipFooterRight = ReadTipConfig.tipValues[i]
+                tvFooterRight.text = ReadTipConfig.tipNames[i]
                 postEvent(EventBus.UP_CONFIG, true)
             }
         }
@@ -175,27 +178,27 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) {
         if (repeat != none) {
             if (tipHeaderLeft == repeat) {
                 tipHeaderLeft = none
-                binding.tvHeaderLeft.text = tips[none]
+                binding.tvHeaderLeft.text = tipNames[none]
             }
             if (tipHeaderMiddle == repeat) {
                 tipHeaderMiddle = none
-                binding.tvHeaderMiddle.text = tips[none]
+                binding.tvHeaderMiddle.text = tipNames[none]
             }
             if (tipHeaderRight == repeat) {
                 tipHeaderRight = none
-                binding.tvHeaderRight.text = tips[none]
+                binding.tvHeaderRight.text = tipNames[none]
             }
             if (tipFooterLeft == repeat) {
                 tipFooterLeft = none
-                binding.tvFooterLeft.text = tips[none]
+                binding.tvFooterLeft.text = tipNames[none]
             }
             if (tipFooterMiddle == repeat) {
                 tipFooterMiddle = none
-                binding.tvFooterMiddle.text = tips[none]
+                binding.tvFooterMiddle.text = tipNames[none]
             }
             if (tipFooterRight == repeat) {
                 tipFooterRight = none
-                binding.tvFooterRight.text = tips[none]
+                binding.tvFooterRight.text = tipNames[none]
             }
         }
     }

+ 17 - 0
app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt

@@ -33,11 +33,13 @@ class PageView(context: Context) : FrameLayout(context) {
     private var tvTitle: BatteryView? = null
     private var tvTime: BatteryView? = null
     private var tvBattery: BatteryView? = null
+    private var tvBatteryP: BatteryView? = null
     private var tvPage: BatteryView? = null
     private var tvTotalProgress: BatteryView? = null
     private var tvPageAndTotal: BatteryView? = null
     private var tvBookName: BatteryView? = null
     private var tvTimeBattery: BatteryView? = null
+    private var tvTimeBatteryP: BatteryView? = null
 
     val headerHeight: Int
         get() {
@@ -169,6 +171,18 @@ class PageView(context: Context) : FrameLayout(context) {
             typeface = ChapterProvider.typeface
             textSize = 11f
         }
+        tvBatteryP = getTipView(ReadTipConfig.batteryPercentage)?.apply {
+            tag = ReadTipConfig.batteryPercentage
+            isBattery = false
+            typeface = ChapterProvider.typeface
+            textSize = 12f
+        }
+        tvTimeBatteryP = getTipView(ReadTipConfig.timeBatteryPercentage)?.apply {
+            tag = ReadTipConfig.timeBatteryPercentage
+            isBattery = false
+            typeface = ChapterProvider.typeface
+            textSize = 12f
+        }
     }
 
     private fun getTipView(tip: Int): BatteryView? = binding.run {
@@ -198,9 +212,11 @@ class PageView(context: Context) : FrameLayout(context) {
         upTimeBattery()
     }
 
+    @SuppressLint("SetTextI18n")
     fun upBattery(battery: Int) {
         this.battery = battery
         tvBattery?.setBattery(battery)
+        tvBatteryP?.text = "$battery%"
         upTimeBattery()
     }
 
@@ -208,6 +224,7 @@ class PageView(context: Context) : FrameLayout(context) {
     private fun upTimeBattery() {
         val time = timeFormat.format(Date(System.currentTimeMillis()))
         tvTimeBattery?.setBattery(battery, time)
+        tvTimeBatteryP?.text = "$time $battery%"
     }
 
     fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) {

+ 3 - 1
app/src/main/res/values-es-rES/arrays.xml

@@ -84,14 +84,16 @@
 
 	<string-array name="read_tip">
 		<item>En blanco</item>
+		<item>Nombre del libro</item>
 		<item>Título</item>
 		<item>Tiempo</item>
 		<item>Batería</item>
+		<item>Batería%</item>
 		<item>Páginas</item>
 		<item>Avance</item>
 		<item>Páginas y avance</item>
-		<item>Nombre del libro</item>
 		<item>Tiempo y Batería</item>
+		<item>Tiempo y Batería%</item>
 	</string-array>
 
 	<string-array name="text_font_weight">

+ 3 - 1
app/src/main/res/values-pt-rBR/arrays.xml

@@ -84,14 +84,16 @@
 
 	<string-array name="read_tip">
 		<item>Em branco</item>
+		<item>Nome do livro</item>
 		<item>Título</item>
 		<item>Tempo</item>
 		<item>Bateria</item>
+		<item>Bateria%</item>
 		<item>Páginas</item>
 		<item>Progresso</item>
 		<item>Páginas e progresso</item>
-		<item>Nome do livro</item>
 		<item>Tempo e Bateria</item>
+		<item>Tempo e Bateria%</item>
 	</string-array>
 
 	<string-array name="text_font_weight">

+ 3 - 1
app/src/main/res/values-zh-rHK/arrays.xml

@@ -48,14 +48,16 @@
 
     <string-array name="read_tip">
         <item>無</item>
+        <item>書名</item>
         <item>標題</item>
         <item>時間</item>
         <item>電量</item>
+        <item>電量%</item>
         <item>頁數</item>
         <item>進度</item>
         <item>頁數同埋進度</item>
-        <item>書名</item>
         <item>時間同埋電量</item>
+        <item>時間同埋電量%</item>
     </string-array>
 
     <string-array name="text_font_weight">

+ 3 - 1
app/src/main/res/values-zh-rTW/arrays.xml

@@ -63,14 +63,16 @@
 
     <string-array name="read_tip">
         <item>無</item>
+        <item>書名</item>
         <item>標題</item>
         <item>時間</item>
         <item>電量</item>
+        <item>電量%</item>
         <item>頁數</item>
         <item>進度</item>
         <item>頁數及進度</item>
-        <item>書名</item>
         <item>時間及電量</item>
+        <item>時間及電量%</item>
     </string-array>
 
     <string-array name="text_font_weight">

+ 3 - 1
app/src/main/res/values-zh/arrays.xml

@@ -63,14 +63,16 @@
 
     <string-array name="read_tip">
         <item>无</item>
+        <item>书名</item>
         <item>标题</item>
         <item>时间</item>
         <item>电量</item>
+        <item>电量%</item>
         <item>页数</item>
         <item>进度</item>
         <item>页数及进度</item>
-        <item>书名</item>
         <item>时间及电量</item>
+        <item>时间及电量%</item>
     </string-array>
 
     <string-array name="text_font_weight">

+ 4 - 2
app/src/main/res/values/arrays.xml

@@ -84,14 +84,16 @@
 
 	<string-array name="read_tip">
 		<item>Blank</item>
-		<item>Heading</item>
+		<item>Book name</item>
+		<item>Title</item>
 		<item>Time</item>
 		<item>Battery</item>
+		<item>Battery%</item>
 		<item>Pages</item>
 		<item>Progress</item>
 		<item>Pages and progress</item>
-		<item>Book name</item>
 		<item>Time and Battery</item>
+		<item>Time and Battery%</item>
 	</string-array>
 
 	<string-array name="text_font_weight">