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
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 chapterTitle = 1
const val time = 2
const val battery = 3
const val page = 4
const val totalProgress = 5
val tipHeaderLeftStr: String = tipArray[tipHeaderLeft]
val tipHeaderMiddleStr: String = tipArray[tipHeaderMiddle]
val tipHeaderRightStr: String = tipArray[tipHeaderRight]
val tipFooterLeftStr: String = tipArray[tipFooterLeft]
val tipFooterMiddleStr: String = tipArray[tipFooterMiddle]
val tipFooterRightStr: String = tipArray[tipFooterRight]
val tipHeaderLeftStr: String get() = tipArray.getOrElse(tipHeaderLeft) { tipArray[none] }
val tipHeaderMiddleStr: String get() = tipArray.getOrElse(tipHeaderMiddle) { tipArray[none] }
val tipHeaderRightStr: String get() = tipArray.getOrElse(tipHeaderRight) { tipArray[none] }
val tipFooterLeftStr: String get() = tipArray.getOrElse(tipFooterLeft) { tipArray[none] }
val tipFooterMiddleStr: String get() = tipArray.getOrElse(tipFooterMiddle) { tipArray[none] }
val tipFooterRightStr: String get() = tipArray.getOrElse(tipFooterRight) { tipArray[none] }
var tipHeaderLeft: Int
get() = App.INSTANCE.getPrefInt("tipHeaderLeft", time)
@ -46,7 +45,7 @@ object ReadTipConfig {
}
var tipFooterMiddle: Int
get() = App.INSTANCE.getPrefInt("tipFooterMiddle", totalProgress)
get() = App.INSTANCE.getPrefInt("tipFooterMiddle", none)
set(value) {
App.INSTANCE.putPrefInt("tipFooterMiddle", value)
}

@ -5,11 +5,14 @@ import android.content.Context
import android.graphics.drawable.Drawable
import android.view.MotionEvent
import android.widget.FrameLayout
import androidx.core.view.isGone
import androidx.core.view.isInvisible
import com.hankcs.hanlp.HanLP
import io.legado.app.R
import io.legado.app.constant.AppConst.timeFormat
import io.legado.app.help.AppConfig
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.utils.*
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))
inflate(context, R.layout.view_book_page, this)
upTipStyle()
upStyle()
upTime()
content_text_view.upView = {
setProgress(it)
}
@ -34,11 +36,18 @@ class ContentView(context: Context) : FrameLayout(context) {
fun upStyle() {
ReadBookConfig.apply {
tv_top_left.typeface = ChapterProvider.typeface
tv_top_right.typeface = ChapterProvider.typeface
tv_bottom_left.typeface = ChapterProvider.typeface
tv_bottom_right.typeface = ChapterProvider.typeface
battery_view.typeface = ChapterProvider.typeface
tv_header_left.typeface = ChapterProvider.typeface
tv_header_middle.typeface = ChapterProvider.typeface
tv_header_right.typeface = ChapterProvider.typeface
tv_footer_left.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
if (hideStatusBar) {
ll_header.setPadding(
@ -62,20 +71,25 @@ class ContentView(context: Context) : FrameLayout(context) {
vw_top_divider.visible(showHeaderLine)
vw_bottom_divider.visible(showFooterLine)
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) {
tv_bottom_left.text = timeFormat.format(Date(System.currentTimeMillis()))
battery_view.visible()
battery_view.setBattery(battery)
} else {
battery_view.gone()
upTime()
upBattery(battery)
}
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() {
if (ReadBookConfig.hideStatusBar) {
tv_bottom_right.text = timeFormat.format(Date(System.currentTimeMillis()))
val tvTime = when (ReadTipConfig.time) {
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) {
this.battery = battery
if (ReadBookConfig.hideStatusBar) {
battery_view.setBattery(battery)
val tvBattery = when (ReadTipConfig.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) {
@ -123,14 +153,28 @@ class ContentView(context: Context) : FrameLayout(context) {
2 -> HanLP.convertToTraditionalChinese(textPage.title)
else -> textPage.title
}
if (ReadBookConfig.hideStatusBar) {
tv_top_left.text = title
tv_top_right.text = readProgress
tv_bottom_left.text = "${index.plus(1)}/$pageSize"
} else {
tv_bottom_left.text = title
tv_bottom_right.text = "${index.plus(1)}/$pageSize $readProgress"
}
val tvTitle = when (ReadTipConfig.chapterTitle) {
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
}
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) {

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

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

Loading…
Cancel
Save