Cleaner CSS, item templates
Moved favorite item CSS to main template file. Added template files for feed information and favorite episode information, reducing in-line HTML usage in Java code.
This commit is contained in:
parent
4d74233151
commit
35dde1fadb
|
@ -0,0 +1,4 @@
|
||||||
|
<li><span>
|
||||||
|
{FAV_TITLE}<br>
|
||||||
|
<a href="{FAV_WEBSITE}">Website</a> • <a href="{FAV_MEDIA}">Media</a>
|
||||||
|
</span></li>
|
|
@ -0,0 +1,7 @@
|
||||||
|
<img src="{FEED_IMG}" />
|
||||||
|
<p>
|
||||||
|
{FEED_TITLE}
|
||||||
|
<span>
|
||||||
|
<a href="{FEED_LINK}">Website</a> • <a href="{FEED_WEBSITE}">Feed</a>
|
||||||
|
</span>
|
||||||
|
</p>
|
|
@ -72,6 +72,13 @@
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
clear:left;
|
clear:left;
|
||||||
}
|
}
|
||||||
|
ul > li > span {
|
||||||
|
width: 100%;
|
||||||
|
border-top: 1px solid #eee8e8;
|
||||||
|
padding: 5px;
|
||||||
|
box-shadow: none;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -25,28 +25,38 @@ public class FavoritesWriter implements ExportWriter {
|
||||||
|
|
||||||
private static final int PAGE_LIMIT = 100;
|
private static final int PAGE_LIMIT = 100;
|
||||||
|
|
||||||
|
private static final String FAVORITE_TEMPLATE = "html-export-fatorites-item-template.html";
|
||||||
|
private static final String FEED_TEMPLATE = "html-export-feed-template.html";
|
||||||
|
private static final String UTF_8 = "UTF-8";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeDocument(List<Feed> feeds, Writer writer, Context context)
|
public void writeDocument(List<Feed> feeds, Writer writer, Context context)
|
||||||
throws IllegalArgumentException, IllegalStateException, IOException {
|
throws IllegalArgumentException, IllegalStateException, IOException {
|
||||||
Log.d(TAG, "Starting to write document");
|
Log.d(TAG, "Starting to write document");
|
||||||
|
|
||||||
InputStream templateStream = context.getAssets().open("html-export-template.html");
|
InputStream templateStream = context.getAssets().open("html-export-template.html");
|
||||||
String template = IOUtils.toString(templateStream, "UTF-8");
|
String template = IOUtils.toString(templateStream, UTF_8);
|
||||||
template = template.replaceAll("\\{TITLE\\}", "Favorites");
|
template = template.replaceAll("\\{TITLE\\}", "Favorites");
|
||||||
String[] templateParts = template.split("\\{FEEDS\\}");
|
String[] templateParts = template.split("\\{FEEDS\\}");
|
||||||
|
|
||||||
|
InputStream favTemplateStream = context.getAssets().open(FAVORITE_TEMPLATE);
|
||||||
|
String favTemplate = IOUtils.toString(favTemplateStream, UTF_8);
|
||||||
|
|
||||||
|
InputStream feedTemplateStream = context.getAssets().open(FEED_TEMPLATE);
|
||||||
|
String feedTemplate = IOUtils.toString(feedTemplateStream, UTF_8);
|
||||||
|
|
||||||
Map<Long, List<FeedItem>> favoriteByFeed = getFeedMap(getFavorites());
|
Map<Long, List<FeedItem>> favoriteByFeed = getFeedMap(getFavorites());
|
||||||
|
|
||||||
writer.append(templateParts[0]);
|
writer.append(templateParts[0]);
|
||||||
|
|
||||||
for (Long feedId : favoriteByFeed.keySet()) {
|
for (Long feedId : favoriteByFeed.keySet()) {
|
||||||
List<FeedItem> favorites = favoriteByFeed.get(feedId);
|
List<FeedItem> favorites = favoriteByFeed.get(feedId);
|
||||||
writer.append("<li><div>");
|
writer.append("<li><div>\n");
|
||||||
writeFeed(writer, favorites.get(0).getFeed());
|
writeFeed(writer, favorites.get(0).getFeed(), feedTemplate);
|
||||||
|
|
||||||
writer.append("<ul>");
|
writer.append("<ul>\n");
|
||||||
for (FeedItem item : favorites) {
|
for (FeedItem item : favorites) {
|
||||||
writeFavoriteItem(writer, item);
|
writeFavoriteItem(writer, item, favTemplate);
|
||||||
}
|
}
|
||||||
writer.append("</ul></div></li>\n");
|
writer.append("</ul></div></li>\n");
|
||||||
}
|
}
|
||||||
|
@ -96,26 +106,23 @@ public class FavoritesWriter implements ExportWriter {
|
||||||
return feedMap;
|
return feedMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeFeed(Writer writer, Feed feed) throws IOException {
|
private void writeFeed(Writer writer, Feed feed, String feedTemplate) throws IOException {
|
||||||
writer.append("<img src=\"");
|
String feedInfo = feedTemplate
|
||||||
writer.append(feed.getImageUrl());
|
.replaceAll("\\{FEED_IMG\\}", feed.getImageUrl())
|
||||||
writer.append("\" /><p>");
|
.replaceAll("\\{FEED_TITLE\\}", feed.getTitle())
|
||||||
writer.append(feed.getTitle());
|
.replaceAll("\\{FEED_LINK\\}", feed.getLink())
|
||||||
writer.append(" <span><a href=\"");
|
.replaceAll("\\{FEED_WEBSITE\\}", feed.getDownload_url());
|
||||||
writer.append(feed.getLink());
|
|
||||||
writer.append("\">Website</a> • <a href=\"");
|
writer.append(feedInfo);
|
||||||
writer.append(feed.getDownload_url());
|
|
||||||
writer.append("\">Feed</a></span></p>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeFavoriteItem(Writer writer, FeedItem item) throws IOException {
|
private void writeFavoriteItem(Writer writer, FeedItem item, String favoriteTemplate) throws IOException {
|
||||||
writer.append("<li><div style=\"border-top: 1px solid #eee8e8; padding: 0px; box-shadow: none\"><span>");
|
String favItem = favoriteTemplate
|
||||||
writer.append(item.getTitle().trim());
|
.replaceAll("\\{FAV_TITLE\\}", item.getTitle().trim())
|
||||||
writer.append("<br>\n<a href=\"");
|
.replaceAll("\\{FAV_WEBSITE\\}", item.getLink())
|
||||||
writer.append(item.getLink());
|
.replaceAll("\\{FAV_MEDIA\\}", item.getMedia().getDownload_url());
|
||||||
writer.append("\">Website</a> • <a href=\"");
|
|
||||||
writer.append(item.getMedia().getDownload_url());
|
writer.append(favItem);
|
||||||
writer.append("\">Media</a></span><div></li>\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue