feat: 优化代码

pull/117/head
kunfei 5 years ago
parent b13d4cccd8
commit acd2108f47
  1. 2
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  2. 9
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  3. 9
      app/src/main/java/io/legado/app/ui/book/read/Help.kt
  4. 7
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  5. 11
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt
  7. 5
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  8. 1
      app/src/main/res/layout/dialog_read_padding.xml

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

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

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

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

@ -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))
}

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

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

@ -8,6 +8,7 @@
android:orientation="vertical">
<io.legado.app.ui.widget.text.AccentTextView
android:id="@+id/tv_header_padding"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"

Loading…
Cancel
Save