reduce complexity of method "getHtmlPage"
This commit is contained in:
parent
d93c5cf66d
commit
cb67e17b53
1 changed files with 84 additions and 72 deletions
|
@ -88,105 +88,39 @@ public class RssItemToHtmlTask extends AsyncTask<Void, Void, String> {
|
||||||
String favIconUrl = null;
|
String favIconUrl = null;
|
||||||
|
|
||||||
Feed feed = rssItem.getFeed();
|
Feed feed = rssItem.getFeed();
|
||||||
//int[] colors = ColorHelper.getColorsFromAttributes(context,
|
|
||||||
// R.attr.dividerLineColor,
|
|
||||||
// R.attr.rssItemListBackground);
|
|
||||||
|
|
||||||
//int feedColor = colors[0];
|
//int feedColor = colors[0];
|
||||||
if (feed != null) {
|
if (feed != null) {
|
||||||
feedTitle = Html.escapeHtml(feed.getFeedTitle());
|
feedTitle = Html.escapeHtml(feed.getFeedTitle());
|
||||||
favIconUrl = feed.getFaviconUrl();
|
favIconUrl = feed.getFaviconUrl();
|
||||||
//if(feed.getAvgColour() != null) {
|
|
||||||
// feedColor = Integer.parseInt(feed.getAvgColour());
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (favIconUrl != null) {
|
if (favIconUrl != null) {
|
||||||
DiskCache diskCache = ImageLoader.getInstance().getDiskCache();
|
favIconUrl = getCachedFavIcon(favIconUrl);
|
||||||
File file = diskCache.get(favIconUrl);
|
|
||||||
if(file != null) {
|
|
||||||
favIconUrl = "file://" + file.getAbsolutePath();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
favIconUrl = "file:///android_res/drawable/default_feed_icon_light.png";
|
favIconUrl = "file:///android_res/drawable/default_feed_icon_light.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
String body_id = null;
|
String body_id = getSelectedTheme();
|
||||||
THEME selectedTheme = ThemeChooser.getSelectedTheme();
|
|
||||||
switch (selectedTheme) {
|
|
||||||
case LIGHT:
|
|
||||||
body_id = "lightTheme";
|
|
||||||
break;
|
|
||||||
case DARK:
|
|
||||||
body_id = "darkTheme";
|
|
||||||
break;
|
|
||||||
case OLED:
|
|
||||||
body_id = "darkThemeOLED";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.v(TAG, "Selected Theme: " + body_id);
|
Log.v(TAG, "Selected Theme: " + body_id);
|
||||||
|
|
||||||
String rtlClass = isRightToLeft ? "rtl" : "";
|
String rtlClass = isRightToLeft ? "rtl" : "";
|
||||||
//String borderSide = isRightToLeft ? "right" : "left";
|
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
builder.append("<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=0\" />");
|
builder.append("<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=0\" />");
|
||||||
builder.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"web.css\" />");
|
builder.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"web.css\" />");
|
||||||
|
|
||||||
|
|
||||||
// font size scaling
|
// font size scaling
|
||||||
double scalingFactor = Float.parseFloat(mPrefs.getString(SettingsActivity.SP_FONT_SIZE, "1.0"));
|
|
||||||
DecimalFormat fontFormat = new DecimalFormat("#.#");
|
|
||||||
|
|
||||||
builder.append("<style type=\"text/css\">");
|
builder.append("<style type=\"text/css\">");
|
||||||
builder.append(String.format(
|
builder.append(getFontSizeScalingCss(mPrefs));
|
||||||
":root { \n" +
|
|
||||||
"--fontsize-body: %sem; \n" +
|
|
||||||
"--fontsize-header: %sem; \n" +
|
|
||||||
"--fontsize-subscript: %sem; \n" +
|
|
||||||
"}",
|
|
||||||
fontFormat.format(scalingFactor*BODY_FONT_SIZE),
|
|
||||||
fontFormat.format(scalingFactor*HEADING_FONT_SIZE),
|
|
||||||
fontFormat.format(scalingFactor*SUBSCRIPT_FONT_SIZE)
|
|
||||||
));
|
|
||||||
builder.append("</style>");
|
builder.append("</style>");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
builder.append(String.format("</head><body class=\"%s\" class=\"%s\">", body_id, rtlClass));
|
builder.append(String.format("</head><body class=\"%s\" class=\"%s\">", body_id, rtlClass));
|
||||||
|
|
||||||
if (showHeader) {
|
if (showHeader) {
|
||||||
builder.append("<div id=\"top_section\">");
|
builder.append(
|
||||||
builder.append(String.format("<div id=\"header\" class=\"%s\">", body_id));
|
buildHeader(rssItem, body_id, feedTitle, favIconUrl)
|
||||||
String title = Html.escapeHtml(rssItem.getTitle());
|
);
|
||||||
String linkToFeed = Html.escapeHtml(rssItem.getLink());
|
|
||||||
builder.append(String.format("<a href=\"%s\">%s</a>", linkToFeed, title));
|
|
||||||
builder.append("</div>");
|
|
||||||
|
|
||||||
String authorOfArticle = Html.escapeHtml(rssItem.getAuthor());
|
|
||||||
if (authorOfArticle != null)
|
|
||||||
if (!authorOfArticle.trim().equals(""))
|
|
||||||
feedTitle += " - " + authorOfArticle.trim();
|
|
||||||
|
|
||||||
builder.append("<div id=\"header_small_text\">");
|
|
||||||
|
|
||||||
builder.append("<div id=\"subscription\">");
|
|
||||||
builder.append(String.format("<img id=\"imgFavicon\" src=\"%s\" />", favIconUrl));
|
|
||||||
builder.append(feedTitle.trim());
|
|
||||||
builder.append("</div>");
|
|
||||||
|
|
||||||
Date date = rssItem.getPubDate();
|
|
||||||
if (date != null) {
|
|
||||||
String dateString = (String) DateUtils.getRelativeTimeSpanString(date.getTime());
|
|
||||||
builder.append("<div id=\"datetime\">");
|
|
||||||
builder.append(dateString);
|
|
||||||
builder.append("</div>");
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.append("</div>");
|
|
||||||
builder.append("</div>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String description = rssItem.getBody();
|
String description = rssItem.getBody();
|
||||||
|
@ -207,6 +141,84 @@ public class RssItemToHtmlTask extends AsyncTask<Void, Void, String> {
|
||||||
return builder.toString().replaceAll("\"//", "\"https://");
|
return builder.toString().replaceAll("\"//", "\"https://");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getSelectedTheme() {
|
||||||
|
THEME selectedTheme = ThemeChooser.getSelectedTheme();
|
||||||
|
switch (selectedTheme) {
|
||||||
|
case LIGHT:
|
||||||
|
return "lightTheme";
|
||||||
|
case DARK:
|
||||||
|
return "darkTheme";
|
||||||
|
case OLED:
|
||||||
|
return "darkThemeOLED";
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildHeader(RssItem rssItem, String body_id, String feedTitle, String favIconUrl) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
builder.append("<div id=\"top_section\">");
|
||||||
|
builder.append(String.format("<div id=\"header\" class=\"%s\">", body_id));
|
||||||
|
String title = Html.escapeHtml(rssItem.getTitle());
|
||||||
|
String linkToFeed = Html.escapeHtml(rssItem.getLink());
|
||||||
|
builder.append(String.format("<a href=\"%s\">%s</a>", linkToFeed, title));
|
||||||
|
builder.append("</div>");
|
||||||
|
|
||||||
|
String authorOfArticle = Html.escapeHtml(rssItem.getAuthor());
|
||||||
|
if (authorOfArticle != null) {
|
||||||
|
if (!authorOfArticle.trim().equals("")) {
|
||||||
|
feedTitle += " - " + authorOfArticle.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.append("<div id=\"header_small_text\">");
|
||||||
|
|
||||||
|
builder.append("<div id=\"subscription\">");
|
||||||
|
builder.append(String.format("<img id=\"imgFavicon\" src=\"%s\" />", favIconUrl));
|
||||||
|
builder.append(feedTitle.trim());
|
||||||
|
builder.append("</div>");
|
||||||
|
|
||||||
|
Date date = rssItem.getPubDate();
|
||||||
|
if (date != null) {
|
||||||
|
String dateString = (String) DateUtils.getRelativeTimeSpanString(date.getTime());
|
||||||
|
builder.append("<div id=\"datetime\">");
|
||||||
|
builder.append(dateString);
|
||||||
|
builder.append("</div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.append("</div>");
|
||||||
|
builder.append("</div>");
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getCachedFavIcon(String favIconUrl) {
|
||||||
|
DiskCache diskCache = ImageLoader.getInstance().getDiskCache();
|
||||||
|
File file = diskCache.get(favIconUrl);
|
||||||
|
if(file != null) {
|
||||||
|
return "file://" + file.getAbsolutePath();
|
||||||
|
} else {
|
||||||
|
return favIconUrl; // Return favicon url if not cached
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getFontSizeScalingCss(SharedPreferences mPrefs) {
|
||||||
|
// font size scaling
|
||||||
|
double scalingFactor = Float.parseFloat(mPrefs.getString(SettingsActivity.SP_FONT_SIZE, "1.0"));
|
||||||
|
DecimalFormat fontFormat = new DecimalFormat("#.#");
|
||||||
|
return String.format(
|
||||||
|
":root { \n" +
|
||||||
|
"--fontsize-body: %sem; \n" +
|
||||||
|
"--fontsize-header: %sem; \n" +
|
||||||
|
"--fontsize-subscript: %sem; \n" +
|
||||||
|
"}",
|
||||||
|
fontFormat.format(scalingFactor*BODY_FONT_SIZE),
|
||||||
|
fontFormat.format(scalingFactor*HEADING_FONT_SIZE),
|
||||||
|
fontFormat.format(scalingFactor*SUBSCRIPT_FONT_SIZE)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private static String getDescriptionWithCachedImages(String text) {
|
private static String getDescriptionWithCachedImages(String text) {
|
||||||
List<String> links = ImageHandler.getImageLinksFromText(text);
|
List<String> links = ImageHandler.getImageLinksFromText(text);
|
||||||
DiskCache diskCache = ImageLoader.getInstance().getDiskCache();
|
DiskCache diskCache = ImageLoader.getInstance().getDiskCache();
|
||||||
|
|
Loading…
Reference in a new issue