Prevent flickering

This commit is contained in:
M66B 2022-07-04 08:49:20 +02:00
parent 512c5d390a
commit a2e2f7f93f
1 changed files with 18 additions and 0 deletions

View File

@ -43,12 +43,15 @@ import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewCompat; import androidx.webkit.WebViewCompat;
import androidx.webkit.WebViewFeature; import androidx.webkit.WebViewFeature;
import java.util.Objects;
public class WebViewEx extends WebView implements DownloadListener, View.OnLongClickListener { public class WebViewEx extends WebView implements DownloadListener, View.OnLongClickListener {
private int height; private int height;
private int maxHeight; private int maxHeight;
private boolean legacy; private boolean legacy;
private IWebView intf; private IWebView intf;
private Runnable onPageLoaded; private Runnable onPageLoaded;
private String hash;
private static String userAgent = null; private static String userAgent = null;
@ -219,6 +222,21 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
settings.setBlockNetworkImage(!show_images); settings.setBlockNetworkImage(!show_images);
} }
@Override
public void loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl) {
try {
// Prevent flickering
String h = (data == null ? null : Helper.md5(data.getBytes()));
if (Objects.equals(hash, h))
return;
this.hash = h;
} catch (Throwable ex) {
Log.w(ex);
}
super.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
}
@Override @Override
public void setMinimumHeight(int minHeight) { public void setMinimumHeight(int minHeight) {
super.setMinimumHeight(minHeight); super.setMinimumHeight(minHeight);