diff --git a/app/src/main/java/io/legado/app/help/ReadTipConfig.kt b/app/src/main/java/io/legado/app/help/ReadTipConfig.kt index a1210dbae..8515fa07e 100644 --- a/app/src/main/java/io/legado/app/help/ReadTipConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadTipConfig.kt @@ -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 = 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) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 2db36940d..43d03c332 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -710,6 +710,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo observeEvent(EventBus.UP_CONFIG) { upSystemUiVisibility() page_view.upBg() + page_view.upTipStyle() page_view.upStyle() if (it) { ReadBook.loadContent(resetPageOffset = false) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt index 4bcb355f3..cb9cfa594 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt @@ -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) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index d38a924b4..ad8b706ac 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -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) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index dd19fdc0e..3a996bfe9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/ui/widget/BatteryView.kt b/app/src/main/java/io/legado/app/ui/widget/BatteryView.kt index f11db64e8..eabfad602 100644 --- a/app/src/main/java/io/legado/app/ui/widget/BatteryView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/BatteryView.kt @@ -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, diff --git a/app/src/main/res/layout/dialog_tip_config.xml b/app/src/main/res/layout/dialog_tip_config.xml index f17910c20..9ef889a05 100644 --- a/app/src/main/res/layout/dialog_tip_config.xml +++ b/app/src/main/res/layout/dialog_tip_config.xml @@ -108,4 +108,18 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_book_page.xml b/app/src/main/res/layout/view_book_page.xml index 3f09664a3..c15680c91 100644 --- a/app/src/main/res/layout/view_book_page.xml +++ b/app/src/main/res/layout/view_book_page.xml @@ -6,6 +6,11 @@ android:layout_height="match_parent" android:orientation="vertical"> + + - - + + - - + android:visibility="gone" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a1a1642bd..edf2698e6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -671,7 +671,9 @@ 点击加入 信息 - + 隐藏页眉 + 隐藏页脚 + 主色调 强调色 @@ -687,4 +689,5 @@ 夜间,强调色 夜间,背景色 夜间,底栏色 +