From d5b28dc206440cd234fb8afc59b0ae121c2dd904 Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Tue, 28 Jun 2022 14:44:09 +0300 Subject: [PATCH] Switched to use Theme.Material3.DayNight. Fixed use the dark theme in WebView.| #1870 --- FlowCrypt/build.gradle | 2 +- .../fragment/HtmlViewFromAssetsRawFragment.kt | 9 +++++++++ .../ui/activity/fragment/LegalSettingsFragment.kt | 12 +++++++++++- .../activity/fragment/dialog/InfoDialogFragment.kt | 7 +++++++ .../com/flowcrypt/email/ui/widget/EmailWebView.kt | 6 ++++++ FlowCrypt/src/main/res/values/themes.xml | 6 ++---- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/FlowCrypt/build.gradle b/FlowCrypt/build.gradle index c45414edd1..3cf0fee49a 100644 --- a/FlowCrypt/build.gradle +++ b/FlowCrypt/build.gradle @@ -391,7 +391,7 @@ dependencies { implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2' implementation 'androidx.navigation:navigation-ui-ktx:2.4.2' implementation 'androidx.navigation:navigation-runtime-ktx:2.4.2' - + implementation 'androidx.webkit:webkit:1.4.0' //https://developers.google.com/android/guides/setup implementation 'com.google.android.gms:play-services-base:18.0.1' diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/HtmlViewFromAssetsRawFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/HtmlViewFromAssetsRawFragment.kt index 42eb0d3f37..13cc091caf 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/HtmlViewFromAssetsRawFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/HtmlViewFromAssetsRawFragment.kt @@ -10,6 +10,8 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.navigation.fragment.navArgs +import androidx.webkit.WebSettingsCompat +import androidx.webkit.WebViewFeature import com.flowcrypt.email.databinding.FragmentHtmlViewFromAssetsRawBinding import com.flowcrypt.email.extensions.supportActionBar import com.flowcrypt.email.ui.activity.fragment.base.BaseFragment @@ -29,6 +31,13 @@ class HtmlViewFromAssetsRawFragment : BaseFragment() { binding?.swipeRefreshLayout?.isRefreshing = false } } - assetsPath?.let { binding?.webView?.loadUrl(it) } + assetsPath?.let { + if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) { + binding?.webView?.settings?.let { settings -> + WebSettingsCompat.setForceDark(settings, WebSettingsCompat.FORCE_DARK_ON) + } + } + + binding?.webView?.loadUrl(it) + } } companion object { diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/InfoDialogFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/InfoDialogFragment.kt index 5216fd7309..1687a9d642 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/InfoDialogFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/dialog/InfoDialogFragment.kt @@ -12,6 +12,8 @@ import androidx.appcompat.app.AlertDialog import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import androidx.navigation.fragment.navArgs +import androidx.webkit.WebSettingsCompat +import androidx.webkit.WebViewFeature import com.flowcrypt.email.R import com.flowcrypt.email.extensions.navController import com.flowcrypt.email.util.GeneralUtil @@ -58,6 +60,11 @@ class InfoDialogFragment : BaseDialogFragment() { if (args.useWebViewToRender) { val webView = WebView(requireContext()) webView.id = R.id.webView + + if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) { + WebSettingsCompat.setForceDark(webView.settings, WebSettingsCompat.FORCE_DARK_ON) + } + args.dialogMsg?.let { webView.loadDataWithBaseURL( null, diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/widget/EmailWebView.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/widget/EmailWebView.kt index 86dab50175..1f8c99b9db 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/widget/EmailWebView.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/widget/EmailWebView.kt @@ -17,6 +17,8 @@ import android.webkit.WebViewClient import androidx.browser.customtabs.CustomTabColorSchemeParams import androidx.browser.customtabs.CustomTabsIntent import androidx.core.content.ContextCompat +import androidx.webkit.WebSettingsCompat +import androidx.webkit.WebViewFeature import com.flowcrypt.email.R import com.flowcrypt.email.model.MessageType import com.flowcrypt.email.ui.activity.CreateMessageActivity @@ -67,6 +69,10 @@ class EmailWebView : WebView { webSettings.loadsImagesAutomatically = true webSettings.blockNetworkLoads = true webSettings.javaScriptEnabled = false + + if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) { + WebSettingsCompat.setForceDark(webSettings, WebSettingsCompat.FORCE_DARK_ON) + } } fun setOnPageLoadingListener(onPageLoadingListener: OnPageLoadingListener) { diff --git a/FlowCrypt/src/main/res/values/themes.xml b/FlowCrypt/src/main/res/values/themes.xml index 1041cc1b9a..1157b6856f 100644 --- a/FlowCrypt/src/main/res/values/themes.xml +++ b/FlowCrypt/src/main/res/values/themes.xml @@ -5,14 +5,14 @@ -