适配SDK30

pull/461/head
gedoor 4 years ago
parent c1ae91d34a
commit cca8ff7318
  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)
if (toolBarTheme == Theme.Dark) {
ATH.setLightStatusBar(window, false)
ATH.setLightStatusBar(this, false)
} else if (toolBarTheme == Theme.Light) {
ATH.setLightStatusBar(window, true)
ATH.setLightStatusBar(this, true)
}
upNavigationBarColor()
}

@ -9,7 +9,7 @@ import android.graphics.drawable.GradientDrawable
import android.os.Build
import android.view.View
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.ScrollView
import androidx.annotation.ColorInt
@ -43,11 +43,8 @@ object ATH {
fun setStatusBarColorAuto(activity: Activity, fullScreen: Boolean) {
val isTransparentStatusBar = AppConfig.isTransparentStatusBar
setStatusBarColor(
activity,
ThemeStore.statusBarColor(activity, isTransparentStatusBar),
isTransparentStatusBar, fullScreen
)
val statusBarColor = ThemeStore.statusBarColor(activity, isTransparentStatusBar)
setStatusBarColor(activity, statusBarColor, isTransparentStatusBar, fullScreen)
}
fun setStatusBarColor(
@ -65,16 +62,34 @@ object ATH {
} else {
activity.window.statusBarColor = color
}
setLightStatusBarAuto(activity.window, color)
setLightStatusBarAuto(activity, color)
}
fun setLightStatusBarAuto(window: Window, bgColor: Int) {
setLightStatusBar(window, ColorUtils.isColorLight(bgColor))
fun setLightStatusBarAuto(activity: Activity, bgColor: Int) {
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) {
val decorView = window.decorView
val decorView = activity.window.decorView
val systemUiVisibility = decorView.systemUiVisibility
if (enabled) {
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) {
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) {
val decorView = activity.window.decorView
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) {
setTaskDescriptionColor(activity, ThemeStore.primaryColor(activity))
}

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

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

Loading…
Cancel
Save