Merge branch 'master' into master

pull/193/head
kunfei 5 years ago committed by GitHub
commit 1e2c48e00c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      app/src/main/java/io/legado/app/help/ReadTipConfig.kt
  2. 1
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 23
      app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt
  4. 148
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  5. 6
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  6. 2
      app/src/main/java/io/legado/app/ui/widget/BatteryView.kt
  7. 14
      app/src/main/res/layout/dialog_tip_config.xml
  8. 41
      app/src/main/res/layout/view_book_page.xml
  9. 5
      app/src/main/res/values/strings.xml

@ -2,24 +2,25 @@ package io.legado.app.help
import io.legado.app.App
import io.legado.app.R
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.putPrefBoolean
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 +47,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)
}
@ -56,4 +57,16 @@ object ReadTipConfig {
set(value) {
App.INSTANCE.putPrefInt("tipFooterRight", value)
}
var hideHeader: Boolean
get() = App.INSTANCE.getPrefBoolean("hideHeader", true)
set(value) {
App.INSTANCE.putPrefBoolean("hideHeader", value)
}
var hideFooter: Boolean
get() = App.INSTANCE.getPrefBoolean("hideFooter", false)
set(value) {
App.INSTANCE.putPrefBoolean("hideFooter", value)
}
}

@ -710,6 +710,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
observeEvent<Boolean>(EventBus.UP_CONFIG) {
upSystemUiVisibility()
page_view.upBg()
page_view.upTipStyle()
page_view.upStyle()
if (it) {
ReadBook.loadContent(resetPageOffset = false)

@ -7,10 +7,13 @@ import android.view.View
import android.view.ViewGroup
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.constant.EventBus
import io.legado.app.help.ReadTipConfig
import io.legado.app.lib.dialogs.selector
import io.legado.app.ui.book.read.Help
import io.legado.app.utils.postEvent
import kotlinx.android.synthetic.main.dialog_tip_config.*
import org.jetbrains.anko.sdk27.listeners.onCheckedChange
import org.jetbrains.anko.sdk27.listeners.onClick
class TipConfigDialog : BaseDialogFragment() {
@ -50,6 +53,8 @@ class TipConfigDialog : BaseDialogFragment() {
tv_footer_left.text = ReadTipConfig.tipFooterLeftStr
tv_footer_middle.text = ReadTipConfig.tipFooterMiddleStr
tv_footer_right.text = ReadTipConfig.tipFooterRightStr
sw_hide_header.isChecked = ReadTipConfig.hideHeader
sw_hide_footer.isChecked = ReadTipConfig.hideFooter
}
private fun initEvent() {
@ -57,36 +62,54 @@ class TipConfigDialog : BaseDialogFragment() {
selector(items = ReadTipConfig.tipArray.toList()) { _, i ->
ReadTipConfig.tipHeaderLeft = i
tv_header_left.text = ReadTipConfig.tipArray[i]
postEvent(EventBus.UP_CONFIG, true)
}
}
tv_header_middle.onClick {
selector(items = ReadTipConfig.tipArray.toList()) { _, i ->
ReadTipConfig.tipHeaderMiddle = i
tv_header_middle.text = ReadTipConfig.tipArray[i]
postEvent(EventBus.UP_CONFIG, true)
}
}
tv_header_right.onClick {
selector(items = ReadTipConfig.tipArray.toList()) { _, i ->
ReadTipConfig.tipHeaderRight = i
tv_header_right.text = ReadTipConfig.tipArray[i]
postEvent(EventBus.UP_CONFIG, true)
}
}
tv_footer_left.onClick {
selector(items = ReadTipConfig.tipArray.toList()) { _, i ->
ReadTipConfig.tipFooterLeft = i
tv_footer_left.text = ReadTipConfig.tipArray[i]
postEvent(EventBus.UP_CONFIG, true)
}
}
tv_footer_middle.onClick {
selector(items = ReadTipConfig.tipArray.toList()) { _, i ->
ReadTipConfig.tipFooterMiddle = i
tv_footer_middle.text = ReadTipConfig.tipArray[i]
postEvent(EventBus.UP_CONFIG, true)
}
}
tv_footer_right.onClick {
selector(items = ReadTipConfig.tipArray.toList()) { _, i ->
ReadTipConfig.tipFooterRight = i
tv_footer_right.text = ReadTipConfig.tipArray[i]
postEvent(EventBus.UP_CONFIG, true)
}
}
sw_hide_header.onCheckedChange { buttonView, isChecked ->
if (buttonView?.isPressed == true) {
ReadTipConfig.hideHeader = isChecked
postEvent(EventBus.UP_CONFIG, true)
}
}
sw_hide_footer.onCheckedChange { buttonView, isChecked ->
if (buttonView?.isPressed == true) {
ReadTipConfig.hideFooter = isChecked
postEvent(EventBus.UP_CONFIG, true)
}
}
}

@ -5,13 +5,19 @@ 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 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 java.util.*
@ -20,13 +26,15 @@ class ContentView(context: Context) : FrameLayout(context) {
private var battery = 100
val headerHeight: Int
get() = if (ReadBookConfig.hideStatusBar) ll_header.height else context.statusBarHeight
init {
//设置背景防止切换背景时文字重叠
setBackgroundColor(context.getCompatColor(R.color.background))
inflate(context, R.layout.view_book_page, this)
upTipStyle()
upStyle()
upTime()
content_text_view.upView = {
setProgress(it)
}
@ -34,25 +42,27 @@ 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(
headerPaddingLeft.dp,
headerPaddingTop.dp,
headerPaddingRight.dp,
headerPaddingBottom.dp
)
ll_header.visible()
page_panel.setPadding(0, 0, 0, 0)
} else {
ll_header.gone()
page_panel.setPadding(0, context.statusBarHeight, 0, 0)
}
vw_status_bar.setPadding(0, context.statusBarHeight, 0, 0)
vw_status_bar.isGone = hideStatusBar
ll_header.setPadding(
headerPaddingLeft.dp,
headerPaddingTop.dp,
headerPaddingRight.dp,
headerPaddingBottom.dp
)
ll_footer.setPadding(
footerPaddingLeft.dp,
footerPaddingTop.dp,
@ -62,47 +72,61 @@ 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()
}
}
}
val headerHeight: Int
get() {
return if (ReadBookConfig.hideStatusBar) {
ll_header.height
} else {
context.statusBarHeight
}
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
ll_header.isGone = hideHeader
ll_footer.isGone = hideFooter
}
}
fun setBg(bg: Drawable?) {
page_panel.background = bg
}
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 +147,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) {

@ -110,6 +110,12 @@ class PageView(context: Context, attrs: AttributeSet) :
callBack.screenOffTimerStart()
}
fun upTipStyle() {
curPage.upTipStyle()
prevPage.upTipStyle()
nextPage.upTipStyle()
}
fun upStyle() {
ChapterProvider.upStyle()
curPage.upStyle()

@ -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,

@ -108,4 +108,18 @@
</LinearLayout>
<Switch
android:id="@+id/sw_hide_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="@string/hideHeader" />
<Switch
android:id="@+id/sw_hide_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="@string/hideFooter" />
</LinearLayout>

@ -6,6 +6,11 @@
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="@+id/vw_status_bar"
android:layout_width="match_parent"
android:layout_height="0dp" />
<LinearLayout
android:id="@+id/ll_header"
android:layout_width="match_parent"
@ -13,8 +18,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 +27,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 +76,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 +85,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" />

@ -671,7 +671,9 @@
<string name="click_to_apply">点击加入</string>
<string name="middle"></string>
<string name="information">信息</string>
<string name="hideHeader">隐藏页眉</string>
<string name="hideFooter">隐藏页脚</string>
<!--color-->
<string name="primary">主色调</string>
<string name="accent">强调色</string>
@ -687,4 +689,5 @@
<string name="night_accent">夜间,强调色</string>
<string name="night_background_color">夜间,背景色</string>
<string name="night_navbar_color">夜间,底栏色</string>
</resources>

Loading…
Cancel
Save