From a2757866402f01c6683d0ba17cf19e3e7d158fbe Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Sun, 15 Jun 2014 21:02:35 +0200 Subject: [PATCH] Remove HTML markup in OnlineFeedView. closes #401 --- assets/LICENSE_JSOUP.txt | 21 ++++++++++++++ assets/about.html | 2 ++ build.gradle | 1 + .../DefaultOnlineFeedViewActivity.java | 29 +++++++++++++++++-- .../activity/OnlineFeedViewActivity.java | 12 +++++++- 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 assets/LICENSE_JSOUP.txt diff --git a/assets/LICENSE_JSOUP.txt b/assets/LICENSE_JSOUP.txt new file mode 100644 index 000000000..f3ef71dbf --- /dev/null +++ b/assets/LICENSE_JSOUP.txt @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2009, 2010, 2011, 2012, 2013 Jonathan Hedley + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/assets/about.html b/assets/about.html index 1d509459c..de5e9836e 100644 --- a/assets/about.html +++ b/assets/about.html @@ -62,5 +62,7 @@ licensed under the Apache 2.0 license (View) licensed under the Apache 2.0 license (View)

Better Pickers (Link)

licensed under the Apache 2.0 license (View) +

jsoup (Link)

+licensed under the MIT license (View) diff --git a/build.gradle b/build.gradle index f1a8a5534..d367f5687 100644 --- a/build.gradle +++ b/build.gradle @@ -33,6 +33,7 @@ dependencies { compile ("com.doomonafireball.betterpickers:library:1.5.2") { exclude group: 'com.android.support', module: 'support-v4' } + compile 'org.jsoup:jsoup:1.7.3' } android { diff --git a/src/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java b/src/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java index 597189885..9c4634d93 100644 --- a/src/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java +++ b/src/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java @@ -5,19 +5,26 @@ import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.NavUtils; +import android.util.Log; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.widget.*; +import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.FeedItemlistDescriptionAdapter; import de.danoeh.antennapod.asynctask.ImageDiskCache; import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.Feed; +import de.danoeh.antennapod.feed.FeedItem; import de.danoeh.antennapod.storage.DBReader; import de.danoeh.antennapod.storage.DownloadRequestException; import de.danoeh.antennapod.storage.DownloadRequester; +import org.apache.commons.lang3.StringUtils; +import org.jsoup.Jsoup; +import org.jsoup.examples.HtmlToPlainText; +import org.jsoup.nodes.Document; import java.util.ArrayList; import java.util.Date; @@ -25,9 +32,11 @@ import java.util.List; import java.util.Map; /** - * Created by daniel on 24.08.13. + * Default implementation of OnlineFeedViewActivity. Shows the downloaded feed's items with their descriptions, + * a subscribe button and a spinner for choosing alternate feed URLs. */ public class DefaultOnlineFeedViewActivity extends OnlineFeedViewActivity { + private static final String TAG = "DefaultOnlineFeedViewActivity"; private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED | EventDistributor.DOWNLOAD_QUEUED | EventDistributor.FEED_LIST_UPDATE; private volatile List feeds; @@ -63,6 +72,22 @@ public class DefaultOnlineFeedViewActivity extends OnlineFeedViewActivity { feeds = DBReader.getFeedList(this); } + @Override + protected void beforeShowFeedInformation(Feed feed, Map alternateFeedUrls) { + super.beforeShowFeedInformation(feed, alternateFeedUrls); + + // remove HTML tags from descriptions + + if (BuildConfig.DEBUG) Log.d(TAG, "Removing HTML from shownotes"); + if (feed.getItems() != null) { + HtmlToPlainText formatter = new HtmlToPlainText(); + for (FeedItem item : feed.getItems()) { + Document description = Jsoup.parse(item.getDescription()); + item.setDescription(StringUtils.trim(formatter.getPlainText(description))); + } + } + } + @Override protected void showFeedInformation(final Feed feed, final Map alternateFeedUrls) { super.showFeedInformation(feed, alternateFeedUrls); @@ -131,7 +156,7 @@ public class DefaultOnlineFeedViewActivity extends OnlineFeedViewActivity { for (String url : alternateFeedUrls.keySet()) { alternateUrlsTitleList.add(alternateFeedUrls.get(url)); } - ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, alternateUrlsTitleList); + ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, alternateUrlsTitleList); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spAlternateUrls.setAdapter(adapter); spAlternateUrls.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { diff --git a/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java index e397ff2ca..322c32741 100644 --- a/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -253,6 +253,7 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity { } if (successful) { + beforeShowFeedInformation(feed, alternateFeedUrls); runOnUiThread(new Runnable() { @Override public void run() { @@ -285,7 +286,16 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity { } /** - * Called when feed parsed successfully + * Called after the feed has been downloaded and parsed and before showFeedInformation is called. + * This method is executed on a background thread + */ + protected void beforeShowFeedInformation(Feed feed, Map alternateFeedUrls) { + + } + + /** + * Called when feed parsed successfully. + * This method is executed on the GUI thread. */ protected void showFeedInformation(Feed feed, Map alternateFeedUrls) {