Force dark for WebView if possible

pull/192/head
M66B 4 years ago
parent 068bf2f646
commit 3d23ff094d

@ -239,6 +239,7 @@ dependencies {
def appcompat_version = "1.3.0-beta01" def appcompat_version = "1.3.0-beta01"
def activity_version = "1.2.0-rc01" def activity_version = "1.2.0-rc01"
def fragment_version = "1.3.0-rc01" def fragment_version = "1.3.0-rc01"
def webkit_version = "1.4.0"
def recyclerview_version = "1.2.0-beta01" def recyclerview_version = "1.2.0-beta01"
def coordinatorlayout_version = "1.1.0" def coordinatorlayout_version = "1.1.0"
def constraintlayout_version = "2.0.2" def constraintlayout_version = "2.0.2"
@ -288,6 +289,10 @@ dependencies {
implementation "androidx.activity:activity:$activity_version" implementation "androidx.activity:activity:$activity_version"
implementation "androidx.fragment:fragment:$fragment_version" implementation "androidx.fragment:fragment:$fragment_version"
// https://developer.android.com/jetpack/androidx/releases/webkit
// https://mvnrepository.com/artifact/androidx.webkit/webkit
implementation "androidx.webkit:webkit:$webkit_version"
// https://mvnrepository.com/artifact/androidx.viewpager2/viewpager2 // https://mvnrepository.com/artifact/androidx.viewpager2/viewpager2
//implementation "androidx.viewpager2:viewpager2:1.1.0-alpha01" //implementation "androidx.viewpager2:viewpager2:1.1.0-alpha01"

@ -140,6 +140,7 @@ import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager; import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import androidx.webkit.WebViewFeature;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
@ -3740,7 +3741,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (full) { if (full) {
TextView tvDark = dview.findViewById(R.id.tvDark); TextView tvDark = dview.findViewById(R.id.tvDark);
tvDark.setVisibility(Helper.isDarkTheme(context) ? View.VISIBLE : View.GONE); tvDark.setVisibility(Helper.isDarkTheme(context)
&& !WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)
? View.VISIBLE : View.GONE);
} else { } else {
boolean disable_tracking = prefs.getBoolean("disable_tracking", true); boolean disable_tracking = prefs.getBoolean("disable_tracking", true);

@ -33,6 +33,11 @@ import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewFeature;
import static androidx.webkit.WebSettingsCompat.FORCE_DARK_OFF;
import static androidx.webkit.WebSettingsCompat.FORCE_DARK_ON;
public class WebViewEx extends WebView implements DownloadListener, View.OnLongClickListener { public class WebViewEx extends WebView implements DownloadListener, View.OnLongClickListener {
private int height; private int height;
@ -67,6 +72,10 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
settings.setSafeBrowsingEnabled(safe_browsing); settings.setSafeBrowsingEnabled(safe_browsing);
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK))
WebSettingsCompat.setForceDark(settings,
Helper.isDarkTheme(context) ? FORCE_DARK_ON : FORCE_DARK_OFF);
} }
void init(int height, float size, Pair<Integer, Integer> position, IWebView intf) { void init(int height, float size, Pair<Integer, Integer> position, IWebView intf) {

Loading…
Cancel
Save