diff --git a/CHANGES.md b/CHANGES.md index 52b410e2b1..47acba9f38 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -23,6 +23,7 @@ Bugfix 🐛: - Fix status bar icon contrast on API in [21,23[ - Wrong /query request (#1444) - Make Credentials.homeServer optional because it is deprecated (#1443) + - Fix issue on dark themes, after alert popup dismiss Translations 🗣: - diff --git a/vector/src/main/java/im/vector/riotx/features/popup/PopupAlertManager.kt b/vector/src/main/java/im/vector/riotx/features/popup/PopupAlertManager.kt index 1876d83617..78a0cece41 100644 --- a/vector/src/main/java/im/vector/riotx/features/popup/PopupAlertManager.kt +++ b/vector/src/main/java/im/vector/riotx/features/popup/PopupAlertManager.kt @@ -15,6 +15,7 @@ */ package im.vector.riotx.features.popup +import android.annotation.SuppressLint import android.app.Activity import android.os.Build import android.os.Handler @@ -26,6 +27,7 @@ import com.tapadoo.alerter.OnHideAlertListener import dagger.Lazy import im.vector.riotx.R import im.vector.riotx.features.home.AvatarRenderer +import im.vector.riotx.features.themes.ThemeUtils import timber.log.Timber import java.lang.ref.WeakReference import javax.inject.Inject @@ -139,24 +141,32 @@ class PopupAlertManager @Inject constructor(private val avatarRenderer: Lazy= Build.VERSION_CODES.M && view != null) { - var flags = view.systemUiVisibility - flags = flags and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() - view.systemUiVisibility = flags - } + weakCurrentActivity?.get() + ?.takeIf { Build.VERSION.SDK_INT >= Build.VERSION_CODES.M } + // Do not change anything on Dark themes + ?.takeIf { ThemeUtils.isLightTheme(it) } + ?.let { it.window?.decorView } + ?.let { view -> + var flags = view.systemUiVisibility + flags = flags and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() + view.systemUiVisibility = flags + } } + @SuppressLint("InlinedApi") private fun setLightStatusBar() { - val view = weakCurrentActivity?.get()?.window?.decorView - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && view != null) { - var flags = view.systemUiVisibility - flags = flags or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR - view.systemUiVisibility = flags - } + weakCurrentActivity?.get() + ?.takeIf { Build.VERSION.SDK_INT >= Build.VERSION_CODES.M } + // Do not change anything on Dark themes + ?.takeIf { ThemeUtils.isLightTheme(it) } + ?.let { it.window?.decorView } + ?.let { view -> + var flags = view.systemUiVisibility + flags = flags or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR + view.systemUiVisibility = flags + } } private fun showAlert(alert: VectorAlert, activity: Activity, animate: Boolean = true) { diff --git a/vector/src/main/java/im/vector/riotx/features/themes/ThemeUtils.kt b/vector/src/main/java/im/vector/riotx/features/themes/ThemeUtils.kt index 45e64465d6..4878134375 100644 --- a/vector/src/main/java/im/vector/riotx/features/themes/ThemeUtils.kt +++ b/vector/src/main/java/im/vector/riotx/features/themes/ThemeUtils.kt @@ -44,6 +44,17 @@ object ThemeUtils { private val mColorByAttr = HashMap() + /** + * @return true if current theme is Light or Status + */ + fun isLightTheme(context: Context): Boolean { + return when (getApplicationTheme(context)) { + THEME_LIGHT_VALUE, + THEME_STATUS_VALUE -> true + else -> false + } + } + /** * Provides the selected application theme *