From acd2108f47b426f82fd2ad31b60f420dddedd777 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 18:47:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/ReadBookConfig.kt | 2 ++ .../main/java/io/legado/app/help/storage/Restore.kt | 9 ++++++++- app/src/main/java/io/legado/app/ui/book/read/Help.kt | 9 +++------ .../main/java/io/legado/app/ui/book/read/ReadMenu.kt | 7 +++---- .../app/ui/book/read/config/MoreConfigDialog.kt | 11 +++++++++-- .../app/ui/book/read/config/PaddingConfigDialog.kt | 2 ++ .../io/legado/app/ui/book/read/page/ContentView.kt | 5 ++--- app/src/main/res/layout/dialog_read_padding.xml | 1 + 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 08302561f..3b05df869 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -112,6 +112,8 @@ object ReadBookConfig { } //配置写入读取 + var hideStatusBar = App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar) + var hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar) var textBold: Boolean get() = if (shareLayout) shareConfig.textBold else durConfig.textBold set(value) = if (shareLayout) shareConfig.textBold = value else durConfig.textBold = value diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 123332df6..9fd939f74 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -104,7 +104,14 @@ object Restore { else -> Unit } edit.putInt(PreferKey.versionCode, App.INSTANCE.versionCode) - edit.commit() + edit.apply() + } + ReadBookConfig.apply { + styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect) + shareLayout = App.INSTANCE.getPrefBoolean(PreferKey.shareLayout) + pageAnim = App.INSTANCE.getPrefInt(PreferKey.pageAnim) + hideStatusBar = App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar) + hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar) } } LauncherIconHelp.changeIcon(App.INSTANCE.getPrefString(PreferKey.launcherIcon)) diff --git a/app/src/main/java/io/legado/app/ui/book/read/Help.kt b/app/src/main/java/io/legado/app/ui/book/read/Help.kt index 3a3e04191..549b7b987 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/Help.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/Help.kt @@ -10,7 +10,6 @@ import android.view.View.NO_ID import android.widget.EditText import io.legado.app.App import io.legado.app.R -import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Bookmark import io.legado.app.help.AppConfig import io.legado.app.help.ReadBookConfig @@ -23,7 +22,6 @@ import io.legado.app.lib.theme.ThemeStore import io.legado.app.service.help.Download import io.legado.app.service.help.ReadBook import io.legado.app.utils.applyTint -import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.requestInputMethod import kotlinx.android.synthetic.main.dialog_download_choice.view.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* @@ -42,15 +40,14 @@ object Help { or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_IMMERSIVE or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) - val hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar) - if (hideNavigationBar) { + if (ReadBookConfig.hideNavigationBar) { flag = flag or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION } if (toolBarHide) { - if (App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar)) { + if (ReadBookConfig.hideStatusBar) { flag = flag or View.SYSTEM_UI_FLAG_FULLSCREEN } - if (hideNavigationBar) { + if (ReadBookConfig.hideNavigationBar) { flag = flag or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 076215c40..6dec43d12 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -10,8 +10,8 @@ import android.widget.SeekBar import androidx.core.view.isVisible import io.legado.app.App import io.legado.app.R -import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig +import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.buttonDisabledColor import io.legado.app.service.help.ReadBook @@ -199,9 +199,8 @@ class ReadMenu : FrameLayout { vw_menu_bg.onClick { runMenuOut() } vwNavigationBar.layoutParams = vwNavigationBar.layoutParams.apply { height = - if (context.getPrefBoolean(PreferKey.hideNavigationBar) - && Help.isNavigationBarExist(activity) - ) context.navigationBarHeight + if (ReadBookConfig.hideNavigationBar && Help.isNavigationBarExist(activity)) + context.navigationBarHeight else 0 } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index b087a1508..9b975e7e8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -14,6 +14,7 @@ import androidx.preference.PreferenceFragmentCompat import io.legado.app.R import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey +import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.read.Help import io.legado.app.utils.getPrefBoolean @@ -92,8 +93,14 @@ class MoreConfigDialog : DialogFragment() { key: String? ) { when (key) { - PreferKey.hideStatusBar -> postEvent(EventBus.UP_CONFIG, true) - PreferKey.hideNavigationBar -> postEvent(EventBus.UP_CONFIG, true) + PreferKey.hideStatusBar -> { + ReadBookConfig.hideStatusBar = getPrefBoolean(PreferKey.hideStatusBar) + postEvent(EventBus.UP_CONFIG, true) + } + PreferKey.hideNavigationBar -> { + ReadBookConfig.hideNavigationBar = getPrefBoolean(PreferKey.hideNavigationBar) + postEvent(EventBus.UP_CONFIG, true) + } PreferKey.keepLight -> postEvent(key, true) PreferKey.textSelectAble -> postEvent(key, getPrefBoolean(key)) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt index 0dd4e8a7d..c72e1a417 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt @@ -11,6 +11,7 @@ import io.legado.app.constant.EventBus import io.legado.app.help.ReadBookConfig import io.legado.app.ui.book.read.Help import io.legado.app.utils.postEvent +import io.legado.app.utils.visible import kotlinx.android.synthetic.main.dialog_read_padding.* class PaddingConfigDialog : DialogFragment() { @@ -56,6 +57,7 @@ class PaddingConfigDialog : DialogFragment() { dsb_padding_left.progress = paddingLeft dsb_padding_right.progress = paddingRight //页眉 + tv_header_padding.visible(hideStatusBar) dsb_header_padding_top.progress = headerPaddingTop dsb_header_padding_bottom.progress = headerPaddingBottom dsb_header_padding_left.progress = headerPaddingLeft 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 3613f17bd..bcf3098a8 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 @@ -7,7 +7,6 @@ import android.view.MotionEvent import android.widget.FrameLayout import io.legado.app.R import io.legado.app.constant.AppConst.TIME_FORMAT -import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.* @@ -39,7 +38,7 @@ class ContentView(context: Context) : FrameLayout(context) { tv_bottom_left.typeface = ChapterProvider.typeface tv_bottom_right.typeface = ChapterProvider.typeface //显示状态栏时隐藏header - if (context.getPrefBoolean(PreferKey.hideStatusBar, false)) { + if (hideStatusBar) { ll_header.layoutParams = ll_header.layoutParams.apply { height = context.statusBarHeight } ll_header.setPadding( @@ -77,7 +76,7 @@ class ContentView(context: Context) : FrameLayout(context) { val headerHeight: Int get() { - return if (context.getPrefBoolean(PreferKey.hideStatusBar, false)) { + return if (ReadBookConfig.hideStatusBar) { ll_header.height } else { context.statusBarHeight diff --git a/app/src/main/res/layout/dialog_read_padding.xml b/app/src/main/res/layout/dialog_read_padding.xml index 648f062a3..37e3b8cc4 100644 --- a/app/src/main/res/layout/dialog_read_padding.xml +++ b/app/src/main/res/layout/dialog_read_padding.xml @@ -8,6 +8,7 @@ android:orientation="vertical">