Removing div tag attributes to avoid images not fitting the screen width

This commit is contained in:
Shinokuni 2019-02-10 17:15:37 +00:00
parent 64cc134d68
commit d684ecaffd
4 changed files with 45 additions and 10 deletions

View File

@ -23,6 +23,9 @@ public class ItemWithFeed {
@ColumnInfo(name = "icon_url")
private String feedIconUrl;
@ColumnInfo(name = "siteUrl")
private String websiteUrl;
public Item getItem() {
return item;
}
@ -63,5 +66,11 @@ public class ItemWithFeed {
this.bgColor = bgColor;
}
public String getWebsiteUrl() {
return websiteUrl;
}
public void setWebsiteUrl(String websiteUrl) {
this.websiteUrl = websiteUrl;
}
}

View File

@ -32,6 +32,6 @@ public interface ItemDao {
@Insert
void insertAll(List<Item> items);
@Query("Select title, Item.description, content, pub_date, image_link, author, text_color, background_color, read_time, name from Item Inner Join Feed on Item.feed_id = Feed.id And Item.id = :id")
@Query("Select title, Item.description, content, pub_date, image_link, author, text_color, background_color, read_time, name, siteUrl from Item Inner Join Feed on Item.feed_id = Feed.id And Item.id = :id")
LiveData<ItemWithFeed> getItemById(int id);
}

View File

@ -3,6 +3,7 @@ package com.readrops.app.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
@ -12,7 +13,13 @@ import com.readrops.app.database.entities.Item;
import com.readrops.readropslibrary.Utils.LibUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.util.Iterator;
public class ReadropsWebView extends WebView {
@ -28,7 +35,7 @@ public class ReadropsWebView extends WebView {
public void setItem(ItemWithFeed itemWithFeed, int width) {
this.itemWithFeed = itemWithFeed;
this.width = width;
loadData(getText(), LibUtils.HTML_CONTENT_TYPE, "utf-8");
loadData(getText(), LibUtils.HTML_CONTENT_TYPE, "UTF-8");
}
@SuppressLint("SetJavaScriptEnabled")
@ -36,22 +43,39 @@ public class ReadropsWebView extends WebView {
WebSettings settings = getSettings();
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
setBackgroundColor(getResources().getColor(R.color.colorBackground));
setPadding(0, 0, 0, 0);
}
private String getText() {
if (itemWithFeed.getItem().getText() != null) {
Document document = Jsoup.parse(itemWithFeed.getItem().getText());
Document document = Jsoup.parse(itemWithFeed.getItem().getText(), itemWithFeed.getWebsiteUrl());
return getContext().getString(R.string.webview_html_template, String.valueOf(width),
formatDocument(document);
return getContext().getString(R.string.webview_html_template,
Utils.getCssColor(itemWithFeed.getBgColor() != 0 ? itemWithFeed.getBgColor() :
(itemWithFeed.getColor() != 0 ? itemWithFeed.getColor() : getResources().getColor(R.color.colorPrimary))),
document.body().html());
} else
return null;
}
private void formatDocument(Document document) {
Elements elements = document.select("figure,figcaption");
for (Element element : elements) {
element.unwrap();
}
elements.clear();
elements = document.select("div");
for (Element element : elements) {
element.clearAttributes();
}
}

View File

@ -6,9 +6,10 @@
<html>
<head>
<meta charset=\"UTF-8\">
<meta name=\"viewport\" content=\"width=%1$s, initial-scale=1\">
<style type=\"text/css\">
a:link, a:active, a:hover { color: %2$s }
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
a:link, a:active, a:hover { color: %1$s }
img, video {
display: inline;
@ -17,14 +18,15 @@
}
body {
margin-left: 0px;
margin-right: 0px;
margin: 0px;
}
</style>
</head>
<body>
%3$s
%2$s
</body>
</html>]]></string>
</resources>