pull/1630/head
kunfei 3 years ago
parent 5f61d2e178
commit 42ef4af9c0
  1. 68
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  2. 13
      app/src/main/java/io/legado/app/ui/widget/BatteryView.kt
  3. 22
      app/src/main/res/layout/view_book_page.xml

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

@ -6,6 +6,7 @@ import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.Typeface
import android.text.StaticLayout
import android.util.AttributeSet
import androidx.annotation.ColorInt
import androidx.appcompat.widget.AppCompatTextView
@ -29,6 +30,8 @@ class BatteryView @JvmOverloads constructor(
postInvalidate()
}
}
private var battery: Int = 0
private var batteryWidth = 0
init {
setPadding(4.dp, 2.dp, 6.dp, 2.dp)
@ -50,15 +53,19 @@ class BatteryView @JvmOverloads constructor(
}
@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) {
super.onDraw(canvas)
if (!isBattery) return
outFrame.set(
1.dp,
width - 6.dp - batteryWidth,
1.dp,
width - 3.dp,
height - 1.dp

@ -39,17 +39,6 @@
app:layout_constraintRight_toLeftOf="@+id/tv_header_right"
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
android:id="@+id/tv_header_middle"
android:layout_width="wrap_content"
@ -122,17 +111,6 @@
app:layout_constraintRight_toLeftOf="@+id/tv_footer_right"
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
android:id="@+id/tv_footer_middle"
android:layout_width="wrap_content"

Loading…
Cancel
Save