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

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

@@ -63,11 +63,9 @@ class PageView(context: Context) : FrameLayout(context) {
             val tipColor = with(ReadTipConfig) {
             val tipColor = with(ReadTipConfig) {
                 if (tipColor == 0) it.textColor else tipColor
                 if (tipColor == 0) it.textColor else tipColor
             }
             }
-            bvHeaderLeft.setColor(tipColor)
             tvHeaderLeft.setColor(tipColor)
             tvHeaderLeft.setColor(tipColor)
             tvHeaderMiddle.setColor(tipColor)
             tvHeaderMiddle.setColor(tipColor)
             tvHeaderRight.setColor(tipColor)
             tvHeaderRight.setColor(tipColor)
-            bvFooterLeft.setColor(tipColor)
             tvFooterLeft.setColor(tipColor)
             tvFooterLeft.setColor(tipColor)
             tvFooterMiddle.setColor(tipColor)
             tvFooterMiddle.setColor(tipColor)
             tvFooterRight.setColor(tipColor)
             tvFooterRight.setColor(tipColor)
@@ -101,15 +99,17 @@ class PageView(context: Context) : FrameLayout(context) {
     }
     }
 
 
     private fun upTipStyle() = binding.run {
     private fun upTipStyle() = binding.run {
+        tvHeaderLeft.tag = null
+        tvHeaderMiddle.tag = null
+        tvHeaderRight.tag = null
+        tvFooterLeft.tag = null
+        tvFooterMiddle.tag = null
+        tvFooterRight.tag = null
         ReadTipConfig.apply {
         ReadTipConfig.apply {
-            tvHeaderLeft.isInvisible = tipHeaderLeft != chapterTitle
-            bvHeaderLeft.isInvisible =
-                tipHeaderLeft == none || !tvHeaderLeft.isInvisible
+            tvHeaderLeft.isGone = tipHeaderLeft == none
             tvHeaderRight.isGone = tipHeaderRight == none
             tvHeaderRight.isGone = tipHeaderRight == none
             tvHeaderMiddle.isGone = tipHeaderMiddle == none
             tvHeaderMiddle.isGone = tipHeaderMiddle == none
-            tvFooterLeft.isInvisible = tipFooterLeft != chapterTitle
-            bvFooterLeft.isInvisible =
-                tipFooterLeft == none || !tvFooterLeft.isInvisible
+            tvFooterLeft.isInvisible = tipFooterLeft == none
             tvFooterRight.isGone = tipFooterRight == none
             tvFooterRight.isGone = tipFooterRight == none
             tvFooterMiddle.isGone = tipFooterMiddle == none
             tvFooterMiddle.isGone = tipFooterMiddle == none
             llHeader.isGone = when (headerMode) {
             llHeader.isGone = when (headerMode) {
@@ -122,63 +122,61 @@ class PageView(context: Context) : FrameLayout(context) {
                 else -> false
                 else -> false
             }
             }
         }
         }
-        tvTitle = getTipView(ReadTipConfig.chapterTitle)
-        tvTitle?.apply {
+        tvTitle = getTipView(ReadTipConfig.chapterTitle)?.apply {
+            tag = ReadTipConfig.chapterTitle
             isBattery = false
             isBattery = false
             typeface = ChapterProvider.typeface
             typeface = ChapterProvider.typeface
             textSize = 12f
             textSize = 12f
         }
         }
-        tvTime = getTipView(ReadTipConfig.time)
-        tvTime?.apply {
+        tvTime = getTipView(ReadTipConfig.time)?.apply {
+            tag = ReadTipConfig.time
             isBattery = false
             isBattery = false
             typeface = ChapterProvider.typeface
             typeface = ChapterProvider.typeface
             textSize = 12f
             textSize = 12f
         }
         }
-        tvBattery = getTipView(ReadTipConfig.battery)
-        tvBattery?.apply {
+        tvBattery = getTipView(ReadTipConfig.battery)?.apply {
+            tag = ReadTipConfig.battery
             isBattery = true
             isBattery = true
-            textSize = 10f
+            textSize = 11f
         }
         }
-        tvPage = getTipView(ReadTipConfig.page)
-        tvPage?.apply {
+        tvPage = getTipView(ReadTipConfig.page)?.apply {
+            tag = ReadTipConfig.page
             isBattery = false
             isBattery = false
             typeface = ChapterProvider.typeface
             typeface = ChapterProvider.typeface
             textSize = 12f
             textSize = 12f
         }
         }
-        tvTotalProgress = getTipView(ReadTipConfig.totalProgress)
-        tvTotalProgress?.apply {
+        tvTotalProgress = getTipView(ReadTipConfig.totalProgress)?.apply {
+            tag = ReadTipConfig.totalProgress
             isBattery = false
             isBattery = false
             typeface = ChapterProvider.typeface
             typeface = ChapterProvider.typeface
             textSize = 12f
             textSize = 12f
         }
         }
-        tvPageAndTotal = getTipView(ReadTipConfig.pageAndTotal)
-        tvPageAndTotal?.apply {
+        tvPageAndTotal = getTipView(ReadTipConfig.pageAndTotal)?.apply {
+            tag = ReadTipConfig.pageAndTotal
             isBattery = false
             isBattery = false
             typeface = ChapterProvider.typeface
             typeface = ChapterProvider.typeface
             textSize = 12f
             textSize = 12f
         }
         }
-        tvBookName = getTipView(ReadTipConfig.bookName)
-        tvBookName?.apply {
+        tvBookName = getTipView(ReadTipConfig.bookName)?.apply {
+            tag = ReadTipConfig.bookName
             isBattery = false
             isBattery = false
             typeface = ChapterProvider.typeface
             typeface = ChapterProvider.typeface
             textSize = 12f
             textSize = 12f
         }
         }
-        tvTimeBattery = getTipView(ReadTipConfig.timeBattery)
-        tvTimeBattery?.apply {
-            isBattery = false
+        tvTimeBattery = getTipView(ReadTipConfig.timeBattery)?.apply {
+            tag = ReadTipConfig.timeBattery
+            isBattery = true
             typeface = ChapterProvider.typeface
             typeface = ChapterProvider.typeface
-            textSize = 12f
+            textSize = 11f
         }
         }
     }
     }
 
 
     private fun getTipView(tip: Int): BatteryView? = binding.run {
     private fun getTipView(tip: Int): BatteryView? = binding.run {
         return when (tip) {
         return when (tip) {
-            ReadTipConfig.tipHeaderLeft ->
-                if (tip == ReadTipConfig.chapterTitle) tvHeaderLeft else bvHeaderLeft
+            ReadTipConfig.tipHeaderLeft -> tvHeaderLeft
             ReadTipConfig.tipHeaderMiddle -> tvHeaderMiddle
             ReadTipConfig.tipHeaderMiddle -> tvHeaderMiddle
             ReadTipConfig.tipHeaderRight -> tvHeaderRight
             ReadTipConfig.tipHeaderRight -> tvHeaderRight
-            ReadTipConfig.tipFooterLeft ->
-                if (tip == ReadTipConfig.chapterTitle) tvFooterLeft else bvFooterLeft
+            ReadTipConfig.tipFooterLeft -> tvFooterLeft
             ReadTipConfig.tipFooterMiddle -> tvFooterMiddle
             ReadTipConfig.tipFooterMiddle -> tvFooterMiddle
             ReadTipConfig.tipFooterRight -> tvFooterRight
             ReadTipConfig.tipFooterRight -> tvFooterRight
             else -> null
             else -> null
@@ -202,16 +200,14 @@ class PageView(context: Context) : FrameLayout(context) {
 
 
     fun upBattery(battery: Int) {
     fun upBattery(battery: Int) {
         this.battery = battery
         this.battery = battery
-        tvBattery?.setBattery(battery)
+        tvBattery?.setTextAndBattery(battery = battery)
         upTimeBattery()
         upTimeBattery()
     }
     }
 
 
     @SuppressLint("SetTextI18n")
     @SuppressLint("SetTextI18n")
     private fun upTimeBattery() {
     private fun upTimeBattery() {
-        tvTimeBattery?.let {
-            val time = timeFormat.format(Date(System.currentTimeMillis()))
-            it.text = "$time $battery%"
-        }
+        val time = timeFormat.format(Date(System.currentTimeMillis()))
+        tvTimeBattery?.setTextAndBattery(time, battery)
     }
     }
 
 
     fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) {
     fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) {

+ 10 - 3
app/src/main/java/io/legado/app/ui/widget/BatteryView.kt

@@ -6,6 +6,7 @@ import android.graphics.Canvas
 import android.graphics.Paint
 import android.graphics.Paint
 import android.graphics.Rect
 import android.graphics.Rect
 import android.graphics.Typeface
 import android.graphics.Typeface
+import android.text.StaticLayout
 import android.util.AttributeSet
 import android.util.AttributeSet
 import androidx.annotation.ColorInt
 import androidx.annotation.ColorInt
 import androidx.appcompat.widget.AppCompatTextView
 import androidx.appcompat.widget.AppCompatTextView
@@ -29,6 +30,8 @@ class BatteryView @JvmOverloads constructor(
                 postInvalidate()
                 postInvalidate()
             }
             }
         }
         }
+    private var battery: Int = 0
+    private var batteryWidth = 0
 
 
     init {
     init {
         setPadding(4.dp, 2.dp, 6.dp, 2.dp)
         setPadding(4.dp, 2.dp, 6.dp, 2.dp)
@@ -50,15 +53,19 @@ class BatteryView @JvmOverloads constructor(
     }
     }
 
 
     @SuppressLint("SetTextI18n")
     @SuppressLint("SetTextI18n")
-    fun setBattery(battery: Int) {
-        text = "$battery"
+    fun setTextAndBattery(text: String = "", battery: Int = 0) {
+        this.battery = battery
+        if (isBattery) {
+            batteryWidth = StaticLayout.getDesiredWidth(battery.toString(), paint).toInt()
+        }
+        setText("$text  $battery")
     }
     }
 
 
     override fun onDraw(canvas: Canvas) {
     override fun onDraw(canvas: Canvas) {
         super.onDraw(canvas)
         super.onDraw(canvas)
         if (!isBattery) return
         if (!isBattery) return
         outFrame.set(
         outFrame.set(
-            1.dp,
+            width - 6.dp - batteryWidth,
             1.dp,
             1.dp,
             width - 3.dp,
             width - 3.dp,
             height - 1.dp
             height - 1.dp

+ 0 - 22
app/src/main/res/layout/view_book_page.xml

@@ -39,17 +39,6 @@
             app:layout_constraintRight_toLeftOf="@+id/tv_header_right"
             app:layout_constraintRight_toLeftOf="@+id/tv_header_right"
             app:layout_constraintTop_toTopOf="parent" />
             app:layout_constraintTop_toTopOf="parent" />
 
 
-        <io.legado.app.ui.widget.BatteryView
-            android:id="@+id/bv_header_left"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:ellipsize="end"
-            android:singleLine="true"
-            android:textSize="12sp"
-            app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintLeft_toLeftOf="parent"
-            app:layout_constraintTop_toTopOf="parent" />
-
         <io.legado.app.ui.widget.BatteryView
         <io.legado.app.ui.widget.BatteryView
             android:id="@+id/tv_header_middle"
             android:id="@+id/tv_header_middle"
             android:layout_width="wrap_content"
             android:layout_width="wrap_content"
@@ -122,17 +111,6 @@
             app:layout_constraintRight_toLeftOf="@+id/tv_footer_right"
             app:layout_constraintRight_toLeftOf="@+id/tv_footer_right"
             app:layout_constraintTop_toTopOf="parent" />
             app:layout_constraintTop_toTopOf="parent" />
 
 
-        <io.legado.app.ui.widget.BatteryView
-            android:id="@+id/bv_footer_left"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:ellipsize="end"
-            android:singleLine="true"
-            android:textSize="12sp"
-            app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintLeft_toLeftOf="parent"
-            app:layout_constraintTop_toTopOf="parent" />
-
         <io.legado.app.ui.widget.BatteryView
         <io.legado.app.ui.widget.BatteryView
             android:id="@+id/tv_footer_middle"
             android:id="@+id/tv_footer_middle"
             android:layout_width="wrap_content"
             android:layout_width="wrap_content"