mirror of https://github.com/readrops/Readrops.git
Removing div tag attributes to avoid images not fitting the screen width
This commit is contained in:
parent
64cc134d68
commit
d684ecaffd
|
@ -23,6 +23,9 @@ public class ItemWithFeed {
|
||||||
@ColumnInfo(name = "icon_url")
|
@ColumnInfo(name = "icon_url")
|
||||||
private String feedIconUrl;
|
private String feedIconUrl;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "siteUrl")
|
||||||
|
private String websiteUrl;
|
||||||
|
|
||||||
public Item getItem() {
|
public Item getItem() {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
@ -63,5 +66,11 @@ public class ItemWithFeed {
|
||||||
this.bgColor = bgColor;
|
this.bgColor = bgColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getWebsiteUrl() {
|
||||||
|
return websiteUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWebsiteUrl(String websiteUrl) {
|
||||||
|
this.websiteUrl = websiteUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,6 @@ public interface ItemDao {
|
||||||
@Insert
|
@Insert
|
||||||
void insertAll(List<Item> items);
|
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);
|
LiveData<ItemWithFeed> getItemById(int id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.readrops.app.utils;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
@ -12,7 +13,13 @@ import com.readrops.app.database.entities.Item;
|
||||||
import com.readrops.readropslibrary.Utils.LibUtils;
|
import com.readrops.readropslibrary.Utils.LibUtils;
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Attribute;
|
||||||
|
import org.jsoup.nodes.Attributes;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class ReadropsWebView extends WebView {
|
public class ReadropsWebView extends WebView {
|
||||||
|
|
||||||
|
@ -28,7 +35,7 @@ public class ReadropsWebView extends WebView {
|
||||||
public void setItem(ItemWithFeed itemWithFeed, int width) {
|
public void setItem(ItemWithFeed itemWithFeed, int width) {
|
||||||
this.itemWithFeed = itemWithFeed;
|
this.itemWithFeed = itemWithFeed;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
loadData(getText(), LibUtils.HTML_CONTENT_TYPE, "utf-8");
|
loadData(getText(), LibUtils.HTML_CONTENT_TYPE, "UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
|
@ -36,22 +43,39 @@ public class ReadropsWebView extends WebView {
|
||||||
WebSettings settings = getSettings();
|
WebSettings settings = getSettings();
|
||||||
|
|
||||||
settings.setJavaScriptEnabled(true);
|
settings.setJavaScriptEnabled(true);
|
||||||
|
settings.setBuiltInZoomControls(true);
|
||||||
|
settings.setDisplayZoomControls(false);
|
||||||
|
|
||||||
setBackgroundColor(getResources().getColor(R.color.colorBackground));
|
setBackgroundColor(getResources().getColor(R.color.colorBackground));
|
||||||
setPadding(0, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getText() {
|
private String getText() {
|
||||||
if (itemWithFeed.getItem().getText() != null) {
|
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() :
|
Utils.getCssColor(itemWithFeed.getBgColor() != 0 ? itemWithFeed.getBgColor() :
|
||||||
(itemWithFeed.getColor() != 0 ? itemWithFeed.getColor() : getResources().getColor(R.color.colorPrimary))),
|
(itemWithFeed.getColor() != 0 ? itemWithFeed.getColor() : getResources().getColor(R.color.colorPrimary))),
|
||||||
document.body().html());
|
document.body().html());
|
||||||
|
|
||||||
} else
|
} else
|
||||||
return null;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset=\"UTF-8\">
|
<meta charset=\"UTF-8\">
|
||||||
<meta name=\"viewport\" content=\"width=%1$s, initial-scale=1\">
|
|
||||||
<style type=\"text/css\">
|
<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 {
|
img, video {
|
||||||
display: inline;
|
display: inline;
|
||||||
|
@ -17,14 +18,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
margin-left: 0px;
|
margin: 0px;
|
||||||
margin-right: 0px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
%3$s
|
%2$s
|
||||||
</body>
|
</body>
|
||||||
</html>]]></string>
|
</html>]]></string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue