pull/464/head
Robot 4 years ago
commit ebfdc85acb
  1. 4
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 75
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  4. 10
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivityHelp.kt

@ -152,9 +152,9 @@ abstract class BaseActivity(
} }
ATH.setStatusBarColorAuto(this, fullScreen) ATH.setStatusBarColorAuto(this, fullScreen)
if (toolBarTheme == Theme.Dark) { if (toolBarTheme == Theme.Dark) {
ATH.setLightStatusBar(window, false) ATH.setLightStatusBar(this, false)
} else if (toolBarTheme == Theme.Light) { } else if (toolBarTheme == Theme.Light) {
ATH.setLightStatusBar(window, true) ATH.setLightStatusBar(this, true)
} }
upNavigationBarColor() upNavigationBarColor()
} }

@ -9,7 +9,7 @@ import android.graphics.drawable.GradientDrawable
import android.os.Build import android.os.Build
import android.view.View import android.view.View
import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
import android.view.Window import android.view.WindowInsetsController
import android.widget.EdgeEffect import android.widget.EdgeEffect
import android.widget.ScrollView import android.widget.ScrollView
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
@ -43,11 +43,8 @@ object ATH {
fun setStatusBarColorAuto(activity: Activity, fullScreen: Boolean) { fun setStatusBarColorAuto(activity: Activity, fullScreen: Boolean) {
val isTransparentStatusBar = AppConfig.isTransparentStatusBar val isTransparentStatusBar = AppConfig.isTransparentStatusBar
setStatusBarColor( val statusBarColor = ThemeStore.statusBarColor(activity, isTransparentStatusBar)
activity, setStatusBarColor(activity, statusBarColor, isTransparentStatusBar, fullScreen)
ThemeStore.statusBarColor(activity, isTransparentStatusBar),
isTransparentStatusBar, fullScreen
)
} }
fun setStatusBarColor( fun setStatusBarColor(
@ -65,16 +62,34 @@ object ATH {
} else { } else {
activity.window.statusBarColor = color activity.window.statusBarColor = color
} }
setLightStatusBarAuto(activity.window, color) setLightStatusBarAuto(activity, color)
} }
fun setLightStatusBarAuto(window: Window, bgColor: Int) { fun setLightStatusBarAuto(activity: Activity, bgColor: Int) {
setLightStatusBar(window, ColorUtils.isColorLight(bgColor)) setLightStatusBar(activity, ColorUtils.isColorLight(bgColor))
} }
fun setLightStatusBar(window: Window, enabled: Boolean) { fun setLightStatusBar(activity: Activity, enabled: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
activity.window.insetsController?.let {
if (enabled) {
it.setSystemBarsAppearance(
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
)
} else {
it.setSystemBarsAppearance(0, 0)
}
}
} else {
setLightStatusBarO(activity, enabled)
}
}
@Suppress("DEPRECATION")
private fun setLightStatusBarO(activity: Activity, enabled: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val decorView = window.decorView val decorView = activity.window.decorView
val systemUiVisibility = decorView.systemUiVisibility val systemUiVisibility = decorView.systemUiVisibility
if (enabled) { if (enabled) {
decorView.systemUiVisibility = decorView.systemUiVisibility =
@ -86,7 +101,35 @@ object ATH {
} }
} }
fun setNavigationBarColorAuto(
activity: Activity,
color: Int = ThemeStore.navigationBarColor(activity)
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.window.navigationBarColor = color
setLightNavigationBar(activity, ColorUtils.isColorLight(color))
}
}
fun setLightNavigationBar(activity: Activity, enabled: Boolean) { fun setLightNavigationBar(activity: Activity, enabled: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
activity.window.insetsController?.let {
if (enabled) {
it.setSystemBarsAppearance(
WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS,
WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS
)
} else {
it.setSystemBarsAppearance(0, 0)
}
}
} else {
setLightNavigationBarO(activity, enabled)
}
}
@Suppress("DEPRECATION")
private fun setLightNavigationBarO(activity: Activity, enabled: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val decorView = activity.window.decorView val decorView = activity.window.decorView
var systemUiVisibility = decorView.systemUiVisibility var systemUiVisibility = decorView.systemUiVisibility
@ -99,16 +142,6 @@ object ATH {
} }
} }
fun setNavigationBarColorAuto(
activity: Activity,
color: Int = ThemeStore.navigationBarColor(activity)
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.window.navigationBarColor = color
setLightNavigationBar(activity, ColorUtils.isColorLight(color))
}
}
fun setTaskDescriptionColorAuto(activity: Activity) { fun setTaskDescriptionColorAuto(activity: Activity) {
setTaskDescriptionColor(activity, ThemeStore.primaryColor(activity)) setTaskDescriptionColor(activity, ThemeStore.primaryColor(activity))
} }

@ -736,7 +736,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
* 更新状态栏,导航栏 * 更新状态栏,导航栏
*/ */
override fun upSystemUiVisibility() { override fun upSystemUiVisibility() {
ReadBookActivityHelp.upSystemUiVisibility(window, isInMultiWindow, !read_menu.isVisible) ReadBookActivityHelp.upSystemUiVisibility(this, isInMultiWindow, !read_menu.isVisible)
upNavigationBarColor() upNavigationBarColor()
} }

@ -38,7 +38,7 @@ object ReadBookActivityHelp {
* 更新状态栏,导航栏 * 更新状态栏,导航栏
*/ */
fun upSystemUiVisibility( fun upSystemUiVisibility(
window: Window, activity: Activity,
isInMultiWindow: Boolean, isInMultiWindow: Boolean,
toolBarHide: Boolean = true toolBarHide: Boolean = true
) { ) {
@ -59,13 +59,13 @@ object ReadBookActivityHelp {
flag = flag or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION flag = flag or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
} }
} }
window.decorView.systemUiVisibility = flag activity.window.decorView.systemUiVisibility = flag
if (toolBarHide) { if (toolBarHide) {
ATH.setLightStatusBar(window, ReadBookConfig.durConfig.curStatusIconDark()) ATH.setLightStatusBar(activity, ReadBookConfig.durConfig.curStatusIconDark())
} else { } else {
ATH.setLightStatusBarAuto( ATH.setLightStatusBarAuto(
window, activity,
ThemeStore.statusBarColor(App.INSTANCE, AppConfig.isTransparentStatusBar) ThemeStore.statusBarColor(activity, AppConfig.isTransparentStatusBar)
) )
} }
} }

Loading…
Cancel
Save