From 35dde1fadbd2bfa70ab96c09e8bd332aa9768cd9 Mon Sep 17 00:00:00 2001 From: malockin Date: Sat, 23 May 2020 22:16:19 +0300 Subject: [PATCH] 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. --- .../html-export-fatorites-item-template.html | 4 ++ .../assets/html-export-feed-template.html | 7 +++ .../src/main/assets/html-export-template.html | 7 +++ .../export/favorites/FavoritesWriter.java | 53 +++++++++++-------- 4 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 core/src/main/assets/html-export-fatorites-item-template.html create mode 100644 core/src/main/assets/html-export-feed-template.html diff --git a/core/src/main/assets/html-export-fatorites-item-template.html b/core/src/main/assets/html-export-fatorites-item-template.html new file mode 100644 index 000000000..83f06a458 --- /dev/null +++ b/core/src/main/assets/html-export-fatorites-item-template.html @@ -0,0 +1,4 @@ +
  • + {FAV_TITLE}
    + WebsiteMedia +
  • diff --git a/core/src/main/assets/html-export-feed-template.html b/core/src/main/assets/html-export-feed-template.html new file mode 100644 index 000000000..0646d5953 --- /dev/null +++ b/core/src/main/assets/html-export-feed-template.html @@ -0,0 +1,7 @@ + +

    + {FEED_TITLE} + + WebsiteFeed + +

    \ No newline at end of file diff --git a/core/src/main/assets/html-export-template.html b/core/src/main/assets/html-export-template.html index fd54a8dc6..19d63f6ca 100644 --- a/core/src/main/assets/html-export-template.html +++ b/core/src/main/assets/html-export-template.html @@ -72,6 +72,13 @@ margin-top: 10px; clear:left; } + ul > li > span { + width: 100%; + border-top: 1px solid #eee8e8; + padding: 5px; + box-shadow: none; + text-align: left; + } diff --git a/core/src/main/java/de/danoeh/antennapod/core/export/favorites/FavoritesWriter.java b/core/src/main/java/de/danoeh/antennapod/core/export/favorites/FavoritesWriter.java index cc66eebd0..914faca05 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/export/favorites/FavoritesWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/export/favorites/FavoritesWriter.java @@ -25,28 +25,38 @@ public class FavoritesWriter implements ExportWriter { 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 public void writeDocument(List feeds, Writer writer, Context context) throws IllegalArgumentException, IllegalStateException, IOException { Log.d(TAG, "Starting to write document"); 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"); 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> favoriteByFeed = getFeedMap(getFavorites()); writer.append(templateParts[0]); for (Long feedId : favoriteByFeed.keySet()) { List favorites = favoriteByFeed.get(feedId); - writer.append("
  • "); - writeFeed(writer, favorites.get(0).getFeed()); + writer.append("
  • \n"); + writeFeed(writer, favorites.get(0).getFeed(), feedTemplate); - writer.append("
      "); + writer.append("
        \n"); for (FeedItem item : favorites) { - writeFavoriteItem(writer, item); + writeFavoriteItem(writer, item, favTemplate); } writer.append("
  • \n"); } @@ -96,26 +106,23 @@ public class FavoritesWriter implements ExportWriter { return feedMap; } - private void writeFeed(Writer writer, Feed feed) throws IOException { - writer.append("

    "); - writer.append(feed.getTitle()); - writer.append(" WebsiteFeed

    "); + private void writeFeed(Writer writer, Feed feed, String feedTemplate) throws IOException { + String feedInfo = feedTemplate + .replaceAll("\\{FEED_IMG\\}", feed.getImageUrl()) + .replaceAll("\\{FEED_TITLE\\}", feed.getTitle()) + .replaceAll("\\{FEED_LINK\\}", feed.getLink()) + .replaceAll("\\{FEED_WEBSITE\\}", feed.getDownload_url()); + + writer.append(feedInfo); } - private void writeFavoriteItem(Writer writer, FeedItem item) throws IOException { - writer.append("
  • "); - writer.append(item.getTitle().trim()); - writer.append("
    \nWebsiteMedia
  • \n"); + private void writeFavoriteItem(Writer writer, FeedItem item, String favoriteTemplate) throws IOException { + String favItem = favoriteTemplate + .replaceAll("\\{FAV_TITLE\\}", item.getTitle().trim()) + .replaceAll("\\{FAV_WEBSITE\\}", item.getLink()) + .replaceAll("\\{FAV_MEDIA\\}", item.getMedia().getDownload_url()); + + writer.append(favItem); } @Override