Remove viewport limitations

This commit is contained in:
M66B 2019-05-21 18:06:06 +02:00
parent 986dbfcac9
commit 2a11d95440
1 changed files with 67 additions and 21 deletions

View File

@ -1839,10 +1839,50 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
private void onShowFull(TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
new SimpleTask<String>() {
@Override
protected String onExecute(Context context, Bundle args) {
long id = args.getLong("id");
String html = properties.getHtml(id);
// Remove viewport limitations
Document doc = Jsoup.parse(html);
for (Element meta : doc.select("meta").select("[name=viewport]")) {
String content = meta.attr("content");
String[] params = content.split(";");
if (params.length > 0) {
List<String> viewport = new ArrayList<>();
for (String param : params)
if (!param.toLowerCase().contains("maximum-scale") &&
!param.toLowerCase().contains("user-scalable"))
viewport.add(param.trim());
if (viewport.size() == 0)
meta.attr("content", "");
else
meta.attr("content", TextUtils.join(" ;", viewport) + ";");
}
}
return doc.html();
}
@Override
protected void onExecuted(Bundle args, String html) {
long id = args.getLong("id");
TupleMessageEx amessage = getMessage();
if (amessage == null || !amessage.id.equals(id))
return;
WebView webView = new WebView(context);
setupWebView(webView);
boolean show_images = properties.getValue("images", message.id);
boolean show_images = properties.getValue("images", id);
WebSettings settings = webView.getSettings();
settings.setDefaultFontSize(Math.round(textSize));
@ -1851,7 +1891,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
String html = properties.getHtml(message.id);
webView.loadDataWithBaseURL("", html, "text/html", "UTF-8", null);
final Dialog dialog = new Dialog(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
@ -1870,6 +1909,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
});
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, owner, ex);
}
}.execute(context, owner, args, "message:full");
}
private void setupWebView(WebView webView) {
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {