Fit html message to width

pull/162/head
M66B 5 years ago
parent d0b02d85ed
commit 0881c3f9d1

@ -1377,7 +1377,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
WebSettings settings = webView.getSettings(); WebSettings settings = webView.getSettings();
settings.setUseWideViewPort(false); settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true); settings.setLoadWithOverviewMode(true);
settings.setBuiltInZoomControls(true); settings.setBuiltInZoomControls(true);
@ -1399,8 +1399,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
settings.setBlockNetworkImage(!show_images); settings.setBlockNetworkImage(!show_images);
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
if (size != 0) webView.setInitialScale(size == 0 ? 1 : Math.round(size * 100));
webView.setInitialScale(Math.round(size * 100));
wvBody.setMinimumHeight(height); wvBody.setMinimumHeight(height);
if (position != null) { if (position != null) {
wvBody.setScrollX(position.first); wvBody.setScrollX(position.first);
@ -1469,7 +1468,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
args.putBoolean("has_images", has_images); args.putBoolean("has_images", has_images);
if (show_full) { if (show_full) {
HtmlHelper.removeViewportLimitations(document); HtmlHelper.setViewport(document);
if (inline || show_images) if (inline || show_images)
HtmlHelper.embedInlineImages(context, message.id, document); HtmlHelper.embedInlineImages(context, message.id, document);

@ -565,23 +565,15 @@ public class HtmlHelper {
} }
} }
static void removeViewportLimitations(Document document) { static void setViewport(Document document) {
for (Element meta : document.select("meta").select("[name=viewport]")) { // https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag
String content = meta.attr("content"); document.head().select("meta").select("[name=viewport]").remove();
String[] params = content.split(";");
if (params.length > 0) { document.head().prependChild(document.createElement("meta")
List<String> viewport = new ArrayList<>(); .attr("name", "viewport")
for (String param : params) .attr("content", "width=device-width, initial-scale=1.0"));
if (!param.toLowerCase(Locale.ROOT).contains("maximum-scale") &&
!param.toLowerCase(Locale.ROOT).contains("user-scalable")) Log.i(document.head().html());
viewport.add(param.trim());
if (viewport.size() == 0)
meta.attr("content", "");
else
meta.attr("content", TextUtils.join(" ;", viewport) + ";");
}
}
} }
static String getPreview(String body) { static String getPreview(String body) {

Loading…
Cancel
Save