From 2311c756aea378a778e475250e2fb4bcbbb756ee Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Mon, 27 Jan 2020 17:59:39 +0100 Subject: Updated html export design --- core/src/main/assets/html-export-template.html | 85 +++++++++++++++++ .../antennapod/core/backup/OpmlBackupAgent.java | 2 +- .../antennapod/core/export/ExportWriter.java | 8 +- .../antennapod/core/export/html/HtmlSymbols.java | 30 ------ .../antennapod/core/export/html/HtmlWriter.java | 72 ++++----------- .../antennapod/core/export/opml/OpmlWriter.java | 101 ++++++++++----------- 6 files changed, 160 insertions(+), 138 deletions(-) create mode 100644 core/src/main/assets/html-export-template.html delete mode 100644 core/src/main/java/de/danoeh/antennapod/core/export/html/HtmlSymbols.java (limited to 'core') diff --git a/core/src/main/assets/html-export-template.html b/core/src/main/assets/html-export-template.html new file mode 100644 index 000000000..ddab27a43 --- /dev/null +++ b/core/src/main/assets/html-export-template.html @@ -0,0 +1,85 @@ + + + + AntennaPod Subscriptions + + + + + +

AntennaPod Subscriptions

+ + Get AntennaPod + + diff --git a/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java b/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java index 80ce6cf56..61e4e599b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java +++ b/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java @@ -93,7 +93,7 @@ public class OpmlBackupAgent extends BackupAgentHelper { try { // Write OPML - new OpmlWriter().writeDocument(DBReader.getFeedList(), writer); + new OpmlWriter().writeDocument(DBReader.getFeedList(), writer, mContext); // Compare checksum of new and old file to see if we need to perform a backup at all if (digester != null) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/export/ExportWriter.java b/core/src/main/java/de/danoeh/antennapod/core/export/ExportWriter.java index d6a187b21..e0f0d4626 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/export/ExportWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/export/ExportWriter.java @@ -11,8 +11,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package de.danoeh.antennapod.core.export; +import android.content.Context; import java.io.IOException; import java.io.Writer; import java.util.List; @@ -21,9 +23,9 @@ import de.danoeh.antennapod.core.feed.Feed; public interface ExportWriter { - void writeDocument(List feeds, Writer writer) - throws IllegalArgumentException, IllegalStateException, IOException; + void writeDocument(List feeds, Writer writer, Context context) + throws IllegalArgumentException, IllegalStateException, IOException; - String fileExtension(); + String fileExtension(); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/export/html/HtmlSymbols.java b/core/src/main/java/de/danoeh/antennapod/core/export/html/HtmlSymbols.java deleted file mode 100644 index 1ca126469..000000000 --- a/core/src/main/java/de/danoeh/antennapod/core/export/html/HtmlSymbols.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package de.danoeh.antennapod.core.export.html; - -import de.danoeh.antennapod.core.export.CommonSymbols; - -class HtmlSymbols extends CommonSymbols { - - static final String HTML = "html"; - - static final String ORDERED_LIST = "ol"; - static final String LIST_ITEM = "li"; - - static final String HEADING = "h1"; - - static final String LINK = "a"; - static final String LINK_DESTINATION = "href"; - -} diff --git a/core/src/main/java/de/danoeh/antennapod/core/export/html/HtmlWriter.java b/core/src/main/java/de/danoeh/antennapod/core/export/html/HtmlWriter.java index c24b39812..93b66daed 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/export/html/HtmlWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/export/html/HtmlWriter.java @@ -1,77 +1,45 @@ package de.danoeh.antennapod.core.export.html; -import android.text.TextUtils; +import android.content.Context; import android.util.Log; -import android.util.Xml; - -import org.xmlpull.v1.XmlSerializer; - +import de.danoeh.antennapod.core.export.ExportWriter; +import de.danoeh.antennapod.core.feed.Feed; import java.io.IOException; +import java.io.InputStream; import java.io.Writer; import java.util.List; - -import de.danoeh.antennapod.core.export.ExportWriter; -import de.danoeh.antennapod.core.feed.Feed; +import org.apache.commons.io.IOUtils; /** Writes HTML documents. */ public class HtmlWriter implements ExportWriter { - private static final String TAG = "HtmlWriter"; - private static final String ENCODING = "UTF-8"; - private static final String HTML_TITLE = "AntennaPod Subscriptions"; /** * Takes a list of feeds and a writer and writes those into an HTML * document. - * - * @throws IOException - * @throws IllegalStateException - * @throws IllegalArgumentException */ @Override - public void writeDocument(List feeds, Writer writer) + public void writeDocument(List feeds, Writer writer, Context context) throws IllegalArgumentException, IllegalStateException, IOException { Log.d(TAG, "Starting to write document"); - XmlSerializer xs = Xml.newSerializer(); - xs.setFeature(HtmlSymbols.XML_FEATURE_INDENT_OUTPUT, true); - xs.setOutput(writer); - xs.startDocument(ENCODING, false); - xs.startTag(null, HtmlSymbols.HTML); - xs.startTag(null, HtmlSymbols.HEAD); - xs.startTag(null, HtmlSymbols.TITLE); - xs.text(HTML_TITLE); - xs.endTag(null, HtmlSymbols.TITLE); - xs.endTag(null, HtmlSymbols.HEAD); + InputStream templateStream = context.getAssets().open("html-export-template.html"); + String template = IOUtils.toString(templateStream, "UTF-8"); + String[] templateParts = template.split("\\{FEEDS\\}"); - xs.startTag(null, HtmlSymbols.BODY); - xs.startTag(null, HtmlSymbols.HEADING); - xs.text(HTML_TITLE); - xs.endTag(null, HtmlSymbols.HEADING); - xs.startTag(null, HtmlSymbols.ORDERED_LIST); + writer.append(templateParts[0]); for (Feed feed : feeds) { - xs.startTag(null, HtmlSymbols.LIST_ITEM); - xs.text(feed.getTitle()); - if (!TextUtils.isEmpty(feed.getLink())) { - xs.text(" ["); - xs.startTag(null, HtmlSymbols.LINK); - xs.attribute(null, HtmlSymbols.LINK_DESTINATION, feed.getLink()); - xs.text("Website"); - xs.endTag(null, HtmlSymbols.LINK); - xs.text("]"); - } - xs.text(" ["); - xs.startTag(null, HtmlSymbols.LINK); - xs.attribute(null, HtmlSymbols.LINK_DESTINATION, feed.getDownload_url()); - xs.text("Feed"); - xs.endTag(null, HtmlSymbols.LINK); - xs.text("]"); - xs.endTag(null, HtmlSymbols.LIST_ITEM); + writer.append("
  • "); + writer.append(feed.getTitle()); + writer.append(" WebsiteFeed

  • \n"); } - xs.endTag(null, HtmlSymbols.ORDERED_LIST); - xs.endTag(null, HtmlSymbols.BODY); - xs.endTag(null, HtmlSymbols.HTML); - xs.endDocument(); + writer.append(templateParts[1]); Log.d(TAG, "Finished writing document"); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/export/opml/OpmlWriter.java b/core/src/main/java/de/danoeh/antennapod/core/export/opml/OpmlWriter.java index fd0922f72..c93d4e8e0 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/export/opml/OpmlWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/export/opml/OpmlWriter.java @@ -1,5 +1,6 @@ package de.danoeh.antennapod.core.export.opml; +import android.content.Context; import android.util.Log; import android.util.Xml; @@ -17,62 +18,58 @@ import de.danoeh.antennapod.core.util.DateUtils; /** Writes OPML documents. */ public class OpmlWriter implements ExportWriter { - private static final String TAG = "OpmlWriter"; - private static final String ENCODING = "UTF-8"; - private static final String OPML_VERSION = "2.0"; - private static final String OPML_TITLE = "AntennaPod Subscriptions"; + private static final String TAG = "OpmlWriter"; + private static final String ENCODING = "UTF-8"; + private static final String OPML_VERSION = "2.0"; + private static final String OPML_TITLE = "AntennaPod Subscriptions"; - /** - * Takes a list of feeds and a writer and writes those into an OPML - * document. - * - * @throws IOException - * @throws IllegalStateException - * @throws IllegalArgumentException - */ - @Override - public void writeDocument(List feeds, Writer writer) - throws IllegalArgumentException, IllegalStateException, IOException { - Log.d(TAG, "Starting to write document"); - XmlSerializer xs = Xml.newSerializer(); - xs.setFeature(OpmlSymbols.XML_FEATURE_INDENT_OUTPUT, true); - xs.setOutput(writer); + /** + * Takes a list of feeds and a writer and writes those into an OPML + * document. + */ + @Override + public void writeDocument(List feeds, Writer writer, Context context) + throws IllegalArgumentException, IllegalStateException, IOException { + Log.d(TAG, "Starting to write document"); + XmlSerializer xs = Xml.newSerializer(); + xs.setFeature(OpmlSymbols.XML_FEATURE_INDENT_OUTPUT, true); + xs.setOutput(writer); - xs.startDocument(ENCODING, false); - xs.startTag(null, OpmlSymbols.OPML); - xs.attribute(null, OpmlSymbols.VERSION, OPML_VERSION); + xs.startDocument(ENCODING, false); + xs.startTag(null, OpmlSymbols.OPML); + xs.attribute(null, OpmlSymbols.VERSION, OPML_VERSION); - xs.startTag(null, OpmlSymbols.HEAD); - xs.startTag(null, OpmlSymbols.TITLE); - xs.text(OPML_TITLE); - xs.endTag(null, OpmlSymbols.TITLE); - xs.startTag(null, OpmlSymbols.DATE_CREATED); - xs.text(DateUtils.formatRFC822Date(new Date())); - xs.endTag(null, OpmlSymbols.DATE_CREATED); - xs.endTag(null, OpmlSymbols.HEAD); + xs.startTag(null, OpmlSymbols.HEAD); + xs.startTag(null, OpmlSymbols.TITLE); + xs.text(OPML_TITLE); + xs.endTag(null, OpmlSymbols.TITLE); + xs.startTag(null, OpmlSymbols.DATE_CREATED); + xs.text(DateUtils.formatRFC822Date(new Date())); + xs.endTag(null, OpmlSymbols.DATE_CREATED); + xs.endTag(null, OpmlSymbols.HEAD); - xs.startTag(null, OpmlSymbols.BODY); - for (Feed feed : feeds) { - xs.startTag(null, OpmlSymbols.OUTLINE); - xs.attribute(null, OpmlSymbols.TEXT, feed.getTitle()); - xs.attribute(null, OpmlSymbols.TITLE, feed.getTitle()); - if (feed.getType() != null) { - xs.attribute(null, OpmlSymbols.TYPE, feed.getType()); - } - xs.attribute(null, OpmlSymbols.XMLURL, feed.getDownload_url()); - if (feed.getLink() != null) { - xs.attribute(null, OpmlSymbols.HTMLURL, feed.getLink()); - } - xs.endTag(null, OpmlSymbols.OUTLINE); - } - xs.endTag(null, OpmlSymbols.BODY); - xs.endTag(null, OpmlSymbols.OPML); - xs.endDocument(); - Log.d(TAG, "Finished writing document"); - } + xs.startTag(null, OpmlSymbols.BODY); + for (Feed feed : feeds) { + xs.startTag(null, OpmlSymbols.OUTLINE); + xs.attribute(null, OpmlSymbols.TEXT, feed.getTitle()); + xs.attribute(null, OpmlSymbols.TITLE, feed.getTitle()); + if (feed.getType() != null) { + xs.attribute(null, OpmlSymbols.TYPE, feed.getType()); + } + xs.attribute(null, OpmlSymbols.XMLURL, feed.getDownload_url()); + if (feed.getLink() != null) { + xs.attribute(null, OpmlSymbols.HTMLURL, feed.getLink()); + } + xs.endTag(null, OpmlSymbols.OUTLINE); + } + xs.endTag(null, OpmlSymbols.BODY); + xs.endTag(null, OpmlSymbols.OPML); + xs.endDocument(); + Log.d(TAG, "Finished writing document"); + } - public String fileExtension() { - return "opml"; - } + public String fileExtension() { + return "opml"; + } } -- cgit v1.2.3