feat: tipConfig

pull/193/head^2
kunfei 5 years ago
parent 12278dad34
commit 52db990d1d
  1. 17
      app/src/main/java/io/legado/app/help/ReadTipConfig.kt
  2. 106
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  3. 2
      app/src/main/java/io/legado/app/ui/widget/BatteryView.kt
  4. 36
      app/src/main/res/layout/view_book_page.xml

@ -6,20 +6,19 @@ import io.legado.app.utils.getPrefInt
import io.legado.app.utils.putPrefInt import io.legado.app.utils.putPrefInt
object ReadTipConfig { object ReadTipConfig {
val tipArray = App.INSTANCE.resources.getStringArray(R.array.read_tip) val tipArray: Array<String> = App.INSTANCE.resources.getStringArray(R.array.read_tip)
const val none = 0 const val none = 0
const val chapterTitle = 1 const val chapterTitle = 1
const val time = 2 const val time = 2
const val battery = 3 const val battery = 3
const val page = 4 const val page = 4
const val totalProgress = 5
val tipHeaderLeftStr: String = tipArray[tipHeaderLeft] val tipHeaderLeftStr: String get() = tipArray.getOrElse(tipHeaderLeft) { tipArray[none] }
val tipHeaderMiddleStr: String = tipArray[tipHeaderMiddle] val tipHeaderMiddleStr: String get() = tipArray.getOrElse(tipHeaderMiddle) { tipArray[none] }
val tipHeaderRightStr: String = tipArray[tipHeaderRight] val tipHeaderRightStr: String get() = tipArray.getOrElse(tipHeaderRight) { tipArray[none] }
val tipFooterLeftStr: String = tipArray[tipFooterLeft] val tipFooterLeftStr: String get() = tipArray.getOrElse(tipFooterLeft) { tipArray[none] }
val tipFooterMiddleStr: String = tipArray[tipFooterMiddle] val tipFooterMiddleStr: String get() = tipArray.getOrElse(tipFooterMiddle) { tipArray[none] }
val tipFooterRightStr: String = tipArray[tipFooterRight] val tipFooterRightStr: String get() = tipArray.getOrElse(tipFooterRight) { tipArray[none] }
var tipHeaderLeft: Int var tipHeaderLeft: Int
get() = App.INSTANCE.getPrefInt("tipHeaderLeft", time) get() = App.INSTANCE.getPrefInt("tipHeaderLeft", time)
@ -46,7 +45,7 @@ object ReadTipConfig {
} }
var tipFooterMiddle: Int var tipFooterMiddle: Int
get() = App.INSTANCE.getPrefInt("tipFooterMiddle", totalProgress) get() = App.INSTANCE.getPrefInt("tipFooterMiddle", none)
set(value) { set(value) {
App.INSTANCE.putPrefInt("tipFooterMiddle", value) App.INSTANCE.putPrefInt("tipFooterMiddle", value)
} }

@ -5,11 +5,14 @@ import android.content.Context
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.MotionEvent import android.view.MotionEvent
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.core.view.isGone
import androidx.core.view.isInvisible
import com.hankcs.hanlp.HanLP import com.hankcs.hanlp.HanLP
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.AppConst.timeFormat import io.legado.app.constant.AppConst.timeFormat
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
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.utils.* import io.legado.app.utils.*
import kotlinx.android.synthetic.main.view_book_page.view.* import kotlinx.android.synthetic.main.view_book_page.view.*
@ -24,9 +27,8 @@ class ContentView(context: Context) : FrameLayout(context) {
//设置背景防止切换背景时文字重叠 //设置背景防止切换背景时文字重叠
setBackgroundColor(context.getCompatColor(R.color.background)) setBackgroundColor(context.getCompatColor(R.color.background))
inflate(context, R.layout.view_book_page, this) inflate(context, R.layout.view_book_page, this)
upTipStyle()
upStyle() upStyle()
upTime()
content_text_view.upView = { content_text_view.upView = {
setProgress(it) setProgress(it)
} }
@ -34,11 +36,18 @@ class ContentView(context: Context) : FrameLayout(context) {
fun upStyle() { fun upStyle() {
ReadBookConfig.apply { ReadBookConfig.apply {
tv_top_left.typeface = ChapterProvider.typeface tv_header_left.typeface = ChapterProvider.typeface
tv_top_right.typeface = ChapterProvider.typeface tv_header_middle.typeface = ChapterProvider.typeface
tv_bottom_left.typeface = ChapterProvider.typeface tv_header_right.typeface = ChapterProvider.typeface
tv_bottom_right.typeface = ChapterProvider.typeface tv_footer_left.typeface = ChapterProvider.typeface
battery_view.typeface = ChapterProvider.typeface tv_footer_middle.typeface = ChapterProvider.typeface
tv_footer_right.typeface = ChapterProvider.typeface
tv_header_left.setColor(durConfig.textColor())
tv_header_middle.setColor(durConfig.textColor())
tv_header_right.setColor(durConfig.textColor())
tv_footer_left.setColor(durConfig.textColor())
tv_footer_middle.setColor(durConfig.textColor())
tv_footer_right.setColor(durConfig.textColor())
//显示状态栏时隐藏header //显示状态栏时隐藏header
if (hideStatusBar) { if (hideStatusBar) {
ll_header.setPadding( ll_header.setPadding(
@ -62,20 +71,25 @@ class ContentView(context: Context) : FrameLayout(context) {
vw_top_divider.visible(showHeaderLine) vw_top_divider.visible(showHeaderLine)
vw_bottom_divider.visible(showFooterLine) vw_bottom_divider.visible(showFooterLine)
content_text_view.upVisibleRect() content_text_view.upVisibleRect()
durConfig.textColor().let {
tv_top_left.setTextColor(it)
tv_top_right.setTextColor(it)
tv_bottom_left.setTextColor(it)
tv_bottom_right.setTextColor(it)
battery_view.setColor(it)
} }
if (hideStatusBar) { upTime()
tv_bottom_left.text = timeFormat.format(Date(System.currentTimeMillis())) upBattery(battery)
battery_view.visible()
battery_view.setBattery(battery)
} else {
battery_view.gone()
} }
fun upTipStyle() {
ReadTipConfig.apply {
val tipHeaderLeftNone = tipHeaderLeft == none
val tipHeaderRightNone = tipHeaderRight == none
val tipHeaderMiddleNone = tipHeaderMiddle == none
val tipFooterLeftNone = tipFooterLeft == none
val tipFooterRightNone = tipFooterRight == none
val tipFooterMiddleNone = tipFooterMiddle == none
tv_header_left.isInvisible = tipHeaderLeftNone
tv_header_right.isGone = tipHeaderRightNone
tv_header_middle.isGone = tipHeaderMiddleNone
tv_footer_left.isInvisible = tipFooterLeftNone
tv_footer_right.isGone = tipFooterRightNone
tv_footer_middle.isGone = tipFooterMiddleNone
} }
} }
@ -93,16 +107,32 @@ class ContentView(context: Context) : FrameLayout(context) {
} }
fun upTime() { fun upTime() {
if (ReadBookConfig.hideStatusBar) { val tvTime = when (ReadTipConfig.time) {
tv_bottom_right.text = timeFormat.format(Date(System.currentTimeMillis())) ReadTipConfig.tipHeaderLeft -> tv_header_left
ReadTipConfig.tipHeaderMiddle -> tv_header_middle
ReadTipConfig.tipHeaderRight -> tv_header_right
ReadTipConfig.tipFooterLeft -> tv_footer_left
ReadTipConfig.tipFooterMiddle -> tv_footer_middle
ReadTipConfig.tipFooterRight -> tv_footer_right
else -> null
} }
tvTime?.isBattery = false
tvTime?.text = timeFormat.format(Date(System.currentTimeMillis()))
} }
fun upBattery(battery: Int) { fun upBattery(battery: Int) {
this.battery = battery this.battery = battery
if (ReadBookConfig.hideStatusBar) { val tvBattery = when (ReadTipConfig.battery) {
battery_view.setBattery(battery) ReadTipConfig.tipHeaderLeft -> tv_header_left
ReadTipConfig.tipHeaderMiddle -> tv_header_middle
ReadTipConfig.tipHeaderRight -> tv_header_right
ReadTipConfig.tipFooterLeft -> tv_footer_left
ReadTipConfig.tipFooterMiddle -> tv_footer_middle
ReadTipConfig.tipFooterRight -> tv_footer_right
else -> null
} }
tvBattery?.isBattery = true
tvBattery?.setBattery(battery)
} }
fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) { fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) {
@ -123,14 +153,28 @@ class ContentView(context: Context) : FrameLayout(context) {
2 -> HanLP.convertToTraditionalChinese(textPage.title) 2 -> HanLP.convertToTraditionalChinese(textPage.title)
else -> textPage.title else -> textPage.title
} }
if (ReadBookConfig.hideStatusBar) { val tvTitle = when (ReadTipConfig.chapterTitle) {
tv_top_left.text = title ReadTipConfig.tipHeaderLeft -> tv_header_left
tv_top_right.text = readProgress ReadTipConfig.tipHeaderMiddle -> tv_header_middle
tv_bottom_left.text = "${index.plus(1)}/$pageSize" ReadTipConfig.tipHeaderRight -> tv_header_right
} else { ReadTipConfig.tipFooterLeft -> tv_footer_left
tv_bottom_left.text = title ReadTipConfig.tipFooterMiddle -> tv_footer_middle
tv_bottom_right.text = "${index.plus(1)}/$pageSize $readProgress" ReadTipConfig.tipFooterRight -> tv_footer_right
} else -> null
}
tvTitle?.isBattery = false
tvTitle?.text = title
val tvPage = when (ReadTipConfig.page) {
ReadTipConfig.tipHeaderLeft -> tv_header_left
ReadTipConfig.tipHeaderMiddle -> tv_header_middle
ReadTipConfig.tipHeaderRight -> tv_header_right
ReadTipConfig.tipFooterLeft -> tv_footer_left
ReadTipConfig.tipFooterMiddle -> tv_footer_middle
ReadTipConfig.tipFooterRight -> tv_footer_right
else -> null
}
tvPage?.isBattery = false
tvPage?.text = "${index.plus(1)}/$pageSize $readProgress"
} }
fun onScroll(offset: Float) { fun onScroll(offset: Float) {

@ -14,6 +14,7 @@ class BatteryView(context: Context, attrs: AttributeSet?) : AppCompatTextView(co
private val batteryPaint = Paint() private val batteryPaint = Paint()
private val outFrame = Rect() private val outFrame = Rect()
private val polar = Rect() private val polar = Rect()
var isBattery = false
init { init {
setPadding(4.dp, 0, 6.dp, 0) setPadding(4.dp, 0, 6.dp, 0)
@ -35,6 +36,7 @@ class BatteryView(context: Context, attrs: AttributeSet?) : AppCompatTextView(co
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {
super.onDraw(canvas) super.onDraw(canvas)
if (!isBattery) return
outFrame.set( outFrame.set(
1.dp, 1.dp,
layout.getLineTop(0) + 2.dp, layout.getLineTop(0) + 2.dp,

@ -13,8 +13,8 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <io.legado.app.ui.widget.BatteryView
android:id="@+id/tv_top_left" android:id="@+id/tv_header_left"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
@ -22,8 +22,18 @@
android:ellipsize="end" android:ellipsize="end"
android:textSize="12sp" /> android:textSize="12sp" />
<TextView <io.legado.app.ui.widget.BatteryView
android:id="@+id/tv_top_right" android:id="@+id/tv_header_middle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1"
android:ellipsize="end"
android:textSize="12sp"
android:visibility="gone" />
<io.legado.app.ui.widget.BatteryView
android:id="@+id/tv_header_right"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="3dp" android:layout_marginLeft="3dp"
@ -61,8 +71,8 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <io.legado.app.ui.widget.BatteryView
android:id="@+id/tv_bottom_left" android:id="@+id/tv_footer_left"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
@ -70,22 +80,22 @@
android:ellipsize="end" android:ellipsize="end"
android:textSize="12sp" /> android:textSize="12sp" />
<TextView <io.legado.app.ui.widget.BatteryView
android:id="@+id/tv_bottom_right" android:id="@+id/tv_footer_middle"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="3dp" android:layout_weight="1"
android:textSize="12sp" android:textSize="12sp"
android:maxLines="1" android:maxLines="1"
android:ellipsize="end" android:ellipsize="end"
tools:ignore="RtlHardcoded,RtlSymmetry" /> android:visibility="gone" />
<io.legado.app.ui.widget.BatteryView <io.legado.app.ui.widget.BatteryView
android:id="@+id/battery_view" android:id="@+id/tv_footer_right"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="3dp" android:layout_marginLeft="3dp"
android:textSize="10sp" android:textSize="12sp"
android:maxLines="1" android:maxLines="1"
android:ellipsize="end" android:ellipsize="end"
tools:ignore="RtlHardcoded,RtlSymmetry,SmallSp" /> tools:ignore="RtlHardcoded,RtlSymmetry,SmallSp" />

Loading…
Cancel
Save