优化
This commit is contained in:
@@ -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
|
tvHeaderLeft.isGone = tipHeaderLeft == none
|
||||||
bvHeaderLeft.isInvisible =
|
|
||||||
tipHeaderLeft == none || !tvHeaderLeft.isInvisible
|
|
||||||
tvHeaderRight.isGone = tipHeaderRight == none
|
tvHeaderRight.isGone = tipHeaderRight == none
|
||||||
tvHeaderMiddle.isGone = tipHeaderMiddle == none
|
tvHeaderMiddle.isGone = tipHeaderMiddle == none
|
||||||
tvFooterLeft.isInvisible = tipFooterLeft != chapterTitle
|
tvFooterLeft.isInvisible = tipFooterLeft == none
|
||||||
bvFooterLeft.isInvisible =
|
|
||||||
tipFooterLeft == none || !tvFooterLeft.isInvisible
|
|
||||||
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 = getTipView(ReadTipConfig.chapterTitle)?.apply {
|
||||||
tvTitle?.apply {
|
tag = ReadTipConfig.chapterTitle
|
||||||
isBattery = false
|
isBattery = false
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
}
|
}
|
||||||
tvTime = getTipView(ReadTipConfig.time)
|
tvTime = getTipView(ReadTipConfig.time)?.apply {
|
||||||
tvTime?.apply {
|
tag = ReadTipConfig.time
|
||||||
isBattery = false
|
isBattery = false
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
}
|
}
|
||||||
tvBattery = getTipView(ReadTipConfig.battery)
|
tvBattery = getTipView(ReadTipConfig.battery)?.apply {
|
||||||
tvBattery?.apply {
|
tag = ReadTipConfig.battery
|
||||||
isBattery = true
|
isBattery = true
|
||||||
textSize = 10f
|
textSize = 11f
|
||||||
}
|
}
|
||||||
tvPage = getTipView(ReadTipConfig.page)
|
tvPage = getTipView(ReadTipConfig.page)?.apply {
|
||||||
tvPage?.apply {
|
tag = ReadTipConfig.page
|
||||||
isBattery = false
|
isBattery = false
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
}
|
}
|
||||||
tvTotalProgress = getTipView(ReadTipConfig.totalProgress)
|
tvTotalProgress = getTipView(ReadTipConfig.totalProgress)?.apply {
|
||||||
tvTotalProgress?.apply {
|
tag = ReadTipConfig.totalProgress
|
||||||
isBattery = false
|
isBattery = false
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
}
|
}
|
||||||
tvPageAndTotal = getTipView(ReadTipConfig.pageAndTotal)
|
tvPageAndTotal = getTipView(ReadTipConfig.pageAndTotal)?.apply {
|
||||||
tvPageAndTotal?.apply {
|
tag = ReadTipConfig.pageAndTotal
|
||||||
isBattery = false
|
isBattery = false
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
}
|
}
|
||||||
tvBookName = getTipView(ReadTipConfig.bookName)
|
tvBookName = getTipView(ReadTipConfig.bookName)?.apply {
|
||||||
tvBookName?.apply {
|
tag = ReadTipConfig.bookName
|
||||||
isBattery = false
|
isBattery = false
|
||||||
typeface = ChapterProvider.typeface
|
typeface = ChapterProvider.typeface
|
||||||
textSize = 12f
|
textSize = 12f
|
||||||
}
|
}
|
||||||
tvTimeBattery = getTipView(ReadTipConfig.timeBattery)
|
tvTimeBattery = getTipView(ReadTipConfig.timeBattery)?.apply {
|
||||||
tvTimeBattery?.apply {
|
tag = ReadTipConfig.timeBattery
|
||||||
isBattery = false
|
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 ->
|
ReadTipConfig.tipHeaderLeft -> tvHeaderLeft
|
||||||
if (tip == ReadTipConfig.chapterTitle) tvHeaderLeft else bvHeaderLeft
|
|
||||||
ReadTipConfig.tipHeaderMiddle -> tvHeaderMiddle
|
ReadTipConfig.tipHeaderMiddle -> tvHeaderMiddle
|
||||||
ReadTipConfig.tipHeaderRight -> tvHeaderRight
|
ReadTipConfig.tipHeaderRight -> tvHeaderRight
|
||||||
ReadTipConfig.tipFooterLeft ->
|
ReadTipConfig.tipFooterLeft -> tvFooterLeft
|
||||||
if (tip == ReadTipConfig.chapterTitle) tvFooterLeft else bvFooterLeft
|
|
||||||
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()))
|
||||||
val time = timeFormat.format(Date(System.currentTimeMillis()))
|
tvTimeBattery?.setTextAndBattery(time, battery)
|
||||||
it.text = "$time $battery%"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) {
|
fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) {
|
||||||
|
|||||||
@@ -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) {
|
fun setTextAndBattery(text: String = "", battery: Int = 0) {
|
||||||
text = "$battery"
|
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
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
Reference in New Issue
Block a user