Skip to content

Commit

Permalink
Fixed day/night UI issue (#2074)
Browse files Browse the repository at this point in the history
* Fixed NPE in GmailApiHelper.generateGmailApiService().| #2072

* Modified WebView.setupDayNight(). Step 2.| #2026

* Modified WebView.setupDayNight(). Step 3.| #2026
  • Loading branch information
DenBond7 authored Nov 15, 2022
1 parent 805ef88 commit a4dd8e2
Showing 1 changed file with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package com.flowcrypt.email.extensions.android.webkit

import android.content.res.Configuration
import android.graphics.Color
import android.os.Build
import android.webkit.WebView
import androidx.webkit.WebSettingsCompat
import androidx.webkit.WebViewFeature
Expand All @@ -18,15 +19,31 @@ import androidx.webkit.WebViewFeature
* E-mail: [email protected]
*/
fun WebView.setupDayNight() {
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
setBackgroundColor(Color.TRANSPARENT)
when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES -> {
WebSettingsCompat.setForceDark(settings, WebSettingsCompat.FORCE_DARK_ON)
}
Configuration.UI_MODE_NIGHT_NO, Configuration.UI_MODE_NIGHT_UNDEFINED -> {
WebSettingsCompat.setForceDark(settings, WebSettingsCompat.FORCE_DARK_OFF)
setBackgroundColor(Color.TRANSPARENT)
if (WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, true)
}
} else {
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES -> {
@Suppress("DEPRECATION")
WebSettingsCompat.setForceDark(settings, WebSettingsCompat.FORCE_DARK_ON)
}
Configuration.UI_MODE_NIGHT_NO, Configuration.UI_MODE_NIGHT_UNDEFINED -> {
@Suppress("DEPRECATION")
WebSettingsCompat.setForceDark(settings, WebSettingsCompat.FORCE_DARK_OFF)
}
}
}

if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) {
@Suppress("DEPRECATION")
WebSettingsCompat.setForceDarkStrategy(
settings,
WebSettingsCompat.DARK_STRATEGY_PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING
)
}
}
}

0 comments on commit a4dd8e2

Please sign in to comment.