Fix issue on dark themes, after alert popup dismiss

This commit is contained in:
Benoit Marty 2020-06-15 23:22:09 +02:00
parent 905fa7dd86
commit 29fd4c4bd2
3 changed files with 36 additions and 14 deletions

View File

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

View File

@ -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<Ava
}
}
@SuppressLint("InlinedApi")
private fun clearLightStatusBar() {
val view = weakCurrentActivity?.get()?.window?.decorView
if (Build.VERSION.SDK_INT >= 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) {

View File

@ -44,6 +44,17 @@ object ThemeUtils {
private val mColorByAttr = HashMap<Int, Int>()
/**
* @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
*