diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsThemeActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsThemeActivity.kt index 4d72254b..f53fe5ec 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsThemeActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsThemeActivity.kt @@ -25,6 +25,8 @@ import android.view.WindowManager import androidx.annotation.ColorInt import androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode import androidx.core.os.ConfigurationCompat +import androidx.core.view.WindowInsetsCompat +import androidx.core.view.WindowInsetsControllerCompat import code.name.monkey.appthemehelper.ATH import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.common.ATHToolbarActivity @@ -192,16 +194,20 @@ abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable { } private fun setImmersiveFullscreen() { - val flags = - (View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) - if (PreferenceUtil.isFullScreenMode) { - window.decorView.systemUiVisibility = flags + WindowInsetsControllerCompat(window, window.decorView).apply { + systemBarsBehavior = + WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + hide(WindowInsetsCompat.Type.systemBars()) + } } } private fun exitFullscreen() { - window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE + WindowInsetsControllerCompat(window, window.decorView).apply { + systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + show(WindowInsetsCompat.Type.systemBars()) + } } override fun run() { diff --git a/appthemehelper/src/main/java/code/name/monkey/appthemehelper/ATH.kt b/appthemehelper/src/main/java/code/name/monkey/appthemehelper/ATH.kt index 0397779a..3b5409dc 100755 --- a/appthemehelper/src/main/java/code/name/monkey/appthemehelper/ATH.kt +++ b/appthemehelper/src/main/java/code/name/monkey/appthemehelper/ATH.kt @@ -6,9 +6,9 @@ import android.app.ActivityManager import android.content.Context import android.os.Build import android.view.View -import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR import androidx.annotation.ColorInt import androidx.appcompat.widget.Toolbar +import androidx.core.view.WindowInsetsControllerCompat import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper @@ -27,29 +27,20 @@ object ATH { } fun setLightStatusbar(activity: Activity, enabled: Boolean) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - val decorView = activity.window.decorView - val systemUiVisibility = decorView.systemUiVisibility - if (enabled) { - decorView.systemUiVisibility = - systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR - } else { - decorView.systemUiVisibility = - systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() - } + activity.window.apply { + WindowInsetsControllerCompat( + this, + decorView + ).isAppearanceLightStatusBars = enabled } } fun setLightNavigationbar(activity: Activity, enabled: Boolean) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val decorView = activity.window.decorView - var systemUiVisibility = decorView.systemUiVisibility - systemUiVisibility = if (enabled) { - systemUiVisibility or SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR - } else { - systemUiVisibility and SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv() - } - decorView.systemUiVisibility = systemUiVisibility + activity.window?.apply { + WindowInsetsControllerCompat( + this, + decorView + ).isAppearanceLightNavigationBars = enabled } }