feat: 优化

pull/209/head
kunfei 5 years ago
parent b636bd23a6
commit c208d32ef3
  1. 8
      app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt
  2. 65
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  3. 4
      app/src/main/java/io/legado/app/ui/widget/BatteryView.kt
  4. 26
      app/src/main/res/layout/view_book_page.xml

@ -86,13 +86,9 @@ class TipConfigDialog : BaseDialogFragment() {
tipHeaderLeft = i tipHeaderLeft = i
tv_header_left.text = tipArray[i] tv_header_left.text = tipArray[i]
} }
if (i == ReadTipConfig.battery) {
activity?.recreate()
} else {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
} }
}
tv_header_middle.onClick { tv_header_middle.onClick {
selector(items = ReadTipConfig.tipArray.toList()) { _, i -> selector(items = ReadTipConfig.tipArray.toList()) { _, i ->
ReadTipConfig.apply { ReadTipConfig.apply {
@ -183,13 +179,9 @@ class TipConfigDialog : BaseDialogFragment() {
tipFooterLeft = i tipFooterLeft = i
tv_footer_left.text = tipArray[i] tv_footer_left.text = tipArray[i]
} }
if (i == ReadTipConfig.battery) {
activity?.recreate()
} else {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
} }
}
tv_footer_middle.onClick { tv_footer_middle.onClick {
selector(items = ReadTipConfig.tipArray.toList()) { _, i -> selector(items = ReadTipConfig.tipArray.toList()) { _, i ->
ReadTipConfig.apply { ReadTipConfig.apply {

@ -15,7 +15,10 @@ import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ReadTipConfig import io.legado.app.help.ReadTipConfig
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.ui.widget.BatteryView import io.legado.app.ui.widget.BatteryView
import io.legado.app.utils.* import io.legado.app.utils.dp
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.statusBarHeight
import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.view_book_page.view.* import kotlinx.android.synthetic.main.view_book_page.view.*
import java.util.* import java.util.*
@ -46,15 +49,19 @@ class ContentView(context: Context) : FrameLayout(context) {
fun upStyle() { fun upStyle() {
ReadBookConfig.apply { ReadBookConfig.apply {
bv_header_left.typeface = ChapterProvider.typeface
tv_header_left.typeface = ChapterProvider.typeface tv_header_left.typeface = ChapterProvider.typeface
tv_header_middle.typeface = ChapterProvider.typeface tv_header_middle.typeface = ChapterProvider.typeface
tv_header_right.typeface = ChapterProvider.typeface tv_header_right.typeface = ChapterProvider.typeface
bv_footer_left.typeface = ChapterProvider.typeface
tv_footer_left.typeface = ChapterProvider.typeface tv_footer_left.typeface = ChapterProvider.typeface
tv_footer_middle.typeface = ChapterProvider.typeface tv_footer_middle.typeface = ChapterProvider.typeface
tv_footer_right.typeface = ChapterProvider.typeface tv_footer_right.typeface = ChapterProvider.typeface
bv_header_left.setColor(durConfig.textColor())
tv_header_left.setColor(durConfig.textColor()) tv_header_left.setColor(durConfig.textColor())
tv_header_middle.setColor(durConfig.textColor()) tv_header_middle.setColor(durConfig.textColor())
tv_header_right.setColor(durConfig.textColor()) tv_header_right.setColor(durConfig.textColor())
bv_footer_left.setColor(durConfig.textColor())
tv_footer_left.setColor(durConfig.textColor()) tv_footer_left.setColor(durConfig.textColor())
tv_footer_middle.setColor(durConfig.textColor()) tv_footer_middle.setColor(durConfig.textColor())
tv_footer_right.setColor(durConfig.textColor()) tv_footer_right.setColor(durConfig.textColor())
@ -83,40 +90,22 @@ class ContentView(context: Context) : FrameLayout(context) {
fun upTipStyle() { fun upTipStyle() {
ReadTipConfig.apply { ReadTipConfig.apply {
val tipHeaderLeftNone = tipHeaderLeft == none tv_header_left.isInvisible = tipHeaderLeft != chapterTitle
val tipHeaderRightNone = tipHeaderRight == none bv_header_left.isInvisible = tipHeaderLeft == none || !tv_header_left.isInvisible
val tipHeaderMiddleNone = tipHeaderMiddle == none tv_header_right.isGone = tipHeaderRight == none
val tipFooterLeftNone = tipFooterLeft == none tv_header_middle.isGone = tipHeaderMiddle == none
val tipFooterRightNone = tipFooterRight == none tv_footer_left.isInvisible = tipFooterLeft != chapterTitle
val tipFooterMiddleNone = tipFooterMiddle == none bv_footer_left.isInvisible = tipFooterLeft == none || !tv_footer_left.isInvisible
tv_header_left.isInvisible = tipHeaderLeftNone tv_footer_right.isGone = tipFooterRight == none
tv_header_right.isGone = tipHeaderRightNone tv_footer_middle.isGone = tipFooterMiddle == none
tv_header_middle.isGone = tipHeaderMiddleNone
tv_footer_left.isInvisible = tipFooterLeftNone
tv_footer_right.isGone = tipFooterRightNone
tv_footer_middle.isGone = tipFooterMiddleNone
ll_header.isGone = hideHeader ll_header.isGone = hideHeader
ll_footer.isGone = hideFooter ll_footer.isGone = hideFooter
} }
tvTitle = when (ReadTipConfig.chapterTitle) { tvTitle = when (ReadTipConfig.chapterTitle) {
ReadTipConfig.tipHeaderLeft -> { ReadTipConfig.tipHeaderLeft -> tv_header_left
ConstraintUtil(ll_header).begin()
.rightToLeftOf(R.id.tv_header_left, R.id.tv_header_right)
.setWidth(R.id.tv_header_left, 0)
.setHorizontalWeight(R.id.tv_header_left, 1f)
.commit()
tv_header_left
}
ReadTipConfig.tipHeaderMiddle -> tv_header_middle ReadTipConfig.tipHeaderMiddle -> tv_header_middle
ReadTipConfig.tipHeaderRight -> tv_header_right ReadTipConfig.tipHeaderRight -> tv_header_right
ReadTipConfig.tipFooterLeft -> { ReadTipConfig.tipFooterLeft -> tv_footer_left
ConstraintUtil(ll_footer).begin()
.rightToLeftOf(R.id.tv_footer_left, R.id.tv_footer_right)
.setWidth(R.id.tv_footer_left, 0)
.setHorizontalWeight(R.id.tv_footer_left, 1f)
.commit()
tv_footer_left
}
ReadTipConfig.tipFooterMiddle -> tv_footer_middle ReadTipConfig.tipFooterMiddle -> tv_footer_middle
ReadTipConfig.tipFooterRight -> tv_footer_right ReadTipConfig.tipFooterRight -> tv_footer_right
else -> null else -> null
@ -139,24 +128,10 @@ class ContentView(context: Context) : FrameLayout(context) {
textSize = 12f textSize = 12f
} }
tvBattery = when (ReadTipConfig.battery) { tvBattery = when (ReadTipConfig.battery) {
ReadTipConfig.tipHeaderLeft -> { ReadTipConfig.tipHeaderLeft -> bv_header_left
ConstraintUtil(ll_header).begin()
.clear(R.id.tv_header_left, 2)
.setHorizontalWeight(R.id.tv_footer_left, 0.0F)
.setWidth(R.id.tv_header_left, LayoutParams.WRAP_CONTENT)
.commit()
tv_header_left
}
ReadTipConfig.tipHeaderMiddle -> tv_header_middle ReadTipConfig.tipHeaderMiddle -> tv_header_middle
ReadTipConfig.tipHeaderRight -> tv_header_right ReadTipConfig.tipHeaderRight -> tv_header_right
ReadTipConfig.tipFooterLeft -> { ReadTipConfig.tipFooterLeft -> bv_footer_left
ConstraintUtil(ll_header).begin()
.clear(R.id.tv_footer_left, 2)
.setHorizontalWeight(R.id.tv_footer_left, 0.0F)
.setWidth(R.id.tv_footer_left, LayoutParams.WRAP_CONTENT)
.commit()
tv_footer_left
}
ReadTipConfig.tipFooterMiddle -> tv_footer_middle ReadTipConfig.tipFooterMiddle -> tv_footer_middle
ReadTipConfig.tipFooterRight -> tv_footer_right ReadTipConfig.tipFooterRight -> tv_footer_right
else -> null else -> null

@ -39,9 +39,9 @@ class BatteryView(context: Context, attrs: AttributeSet?) : AppCompatTextView(co
if (!isBattery) return if (!isBattery) return
outFrame.set( outFrame.set(
1.dp, 1.dp,
layout.getLineTop(0) + 2.dp, layout.getLineBaseline(0) + layout.getLineAscent(0) + 2.dp,
width - 3.dp, width - 3.dp,
layout.getLineBottom(0) - 2.dp layout.getLineBaseline(0) + 2.dp
) )
val dj = (outFrame.bottom - outFrame.top) / 3 val dj = (outFrame.bottom - outFrame.top) / 3
polar.set( polar.set(

@ -20,6 +20,19 @@
<io.legado.app.ui.widget.BatteryView <io.legado.app.ui.widget.BatteryView
android:id="@+id/tv_header_left" android:id="@+id/tv_header_left"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintHorizontal_weight="1"
android:maxLines="1"
android:ellipsize="end"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toLeftOf="@+id/tv_header_right" />
<io.legado.app.ui.widget.BatteryView
android:id="@+id/bv_header_left"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:maxLines="1" android:maxLines="1"
@ -85,6 +98,19 @@
<io.legado.app.ui.widget.BatteryView <io.legado.app.ui.widget.BatteryView
android:id="@+id/tv_footer_left" android:id="@+id/tv_footer_left"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintHorizontal_weight="1"
android:maxLines="1"
android:ellipsize="end"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
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_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:maxLines="1" android:maxLines="1"

Loading…
Cancel
Save