diff options
6 files changed, 32 insertions, 25 deletions
diff --git a/app/src/main/java/org/rssin/android/FeedItemAdapter.java b/app/src/main/java/org/rssin/android/FeedItemAdapter.java index 8124861..a927317 100755 --- a/app/src/main/java/org/rssin/android/FeedItemAdapter.java +++ b/app/src/main/java/org/rssin/android/FeedItemAdapter.java @@ -27,6 +27,7 @@ import android.view.ViewGroup; import android.widget.TextView;
import org.rssin.neurons.Feedback;
+import org.rssin.rss.FeedItem;
import org.rssin.rssin.R;
import org.rssin.summaries.BablukiAPI;
import org.rssin.summaries.LengthMode;
@@ -70,17 +71,19 @@ class FeedItemAdapter extends RecyclerView.Adapter<FeedItemAdapter.FeedItemHolde @Override
public void onBindViewHolder(FeedItemHolder holder, int position) {
SortedFeedItemContainer item = feedItems.get(position);
- holder.title.setText(item.getFeeditem().getTitle());
+ FeedItem feedItem = item.getFeeditem();
- String summaryText = sapInterface.getSummary(item.getFeeditem()).getText();
- // Remove img and media tags
- summaryText = summaryText.replaceAll("(<img.*\\/>|<img.*><\\/img>|<img.*>)", "");
- summaryText = summaryText.replaceAll("(<media.*\\/>|<media.*><\\/media>)", "");
- summaryText = summaryText.replace((char) 160, (char) 32).replace((char) 65532, (char) 32).trim();
+ if (feedItem != null) {
+ String summaryText = sapInterface.getSummary(item.getFeeditem()).getText();
+ // Remove img and media tags
+ summaryText = summaryText.replaceAll("(<img.*\\/>|<img.*><\\/img>|<img.*>)", "");
+ summaryText = summaryText.replaceAll("(<media.*\\/>|<media.*><\\/media>)", "");
+ summaryText = summaryText.replace((char) 160, (char) 32).replace((char) 65532, (char) 32).trim();
- holder.summary.setText(Html.fromHtml(summaryText));
- holder.date.setText(item.getFeeditem().getPubDate().toString());
- holder.item = item;
+ holder.summary.setText(Html.fromHtml(summaryText));
+ holder.date.setText(item.getFeeditem().getPubDate().toString());
+ holder.item = item;
+ }
}
@Override
diff --git a/app/src/main/java/org/rssin/android/FeedItemsListFragment.java b/app/src/main/java/org/rssin/android/FeedItemsListFragment.java index f229098..27c4eb5 100644 --- a/app/src/main/java/org/rssin/android/FeedItemsListFragment.java +++ b/app/src/main/java/org/rssin/android/FeedItemsListFragment.java @@ -23,6 +23,7 @@ import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -114,6 +115,7 @@ public class FeedItemsListFragment extends Fragment { @Override public void onError(Object error) { Frontend.error(context, R.string.error_net_load); + Log.w("FILF", error.toString()); } } ); diff --git a/app/src/main/java/org/rssin/android/SharedPreferencesStorageProvider.java b/app/src/main/java/org/rssin/android/SharedPreferencesStorageProvider.java index 40863fd..bd43305 100644 --- a/app/src/main/java/org/rssin/android/SharedPreferencesStorageProvider.java +++ b/app/src/main/java/org/rssin/android/SharedPreferencesStorageProvider.java @@ -108,6 +108,7 @@ class SharedPreferencesStorageProvider implements StorageProvider, FilterStorage ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(decoded)); Object obj = ois.readObject(); + ois.close(); return (Storable) className.cast(obj); } diff --git a/app/src/main/java/org/rssin/rss/FeedLoader.java b/app/src/main/java/org/rssin/rss/FeedLoader.java index bb4485b..f83138a 100644 --- a/app/src/main/java/org/rssin/rss/FeedLoader.java +++ b/app/src/main/java/org/rssin/rss/FeedLoader.java @@ -18,6 +18,8 @@ */ package org.rssin.rss; +import android.util.Log; + import org.rssin.http.Fetcher; import org.rssin.http.Request; import org.rssin.listener.FallibleListener; diff --git a/app/src/main/java/org/rssin/rssin/Feed.java b/app/src/main/java/org/rssin/rssin/Feed.java index 75b5616..bf9aa5d 100755 --- a/app/src/main/java/org/rssin/rssin/Feed.java +++ b/app/src/main/java/org/rssin/rssin/Feed.java @@ -66,7 +66,7 @@ public class Feed implements Storable, Comparable<Feed>, Jsonable { */ public Feed(URL url, Context context, FeedStorageProvider storage, Fetcher fetcher, FallibleListener<String, Object> titleHasChanged) { this.url = url; - setTitleFromURL(context, storage, fetcher, titleHasChanged); + setTitleFromURL(storage, fetcher, titleHasChanged); } /** @@ -124,10 +124,9 @@ public class Feed implements Storable, Comparable<Feed>, Jsonable { } /** - * Cleverly make up a title based on the URL - * @todo make it really really clever + * Get the title from the feed, or, if that fails, cleverly make up a title based on the URL */ - public void setTitleFromURL(Context context, final FeedStorageProvider storageProvider, Fetcher fetcher, final FallibleListener<String, Object> titlehasChanged) { + public void setTitleFromURL(final FeedStorageProvider storageProvider, Fetcher fetcher, final FallibleListener<String, Object> titlehasChanged) { String newTitle = url.getHost(); String strUrl = url.toString(); if (strUrl.lastIndexOf('/') < strUrl.lastIndexOf('.') && strUrl.lastIndexOf('/') != -1) { @@ -150,16 +149,19 @@ public class Feed implements Storable, Comparable<Feed>, Jsonable { @Override public void onReceive(Object data) { - title = loader.getFeed().getTitle(); - if(titlehasChanged != null) - { - titlehasChanged.onReceive(title); - } try { - store(storageProvider); - } catch (Exception e) { - e.printStackTrace(); - } + if (loader.getFeed().getTitle() != null) { + title = loader.getFeed().getTitle(); + try { + store(storageProvider); + } catch (Exception e) { + e.printStackTrace(); + } + if (titlehasChanged != null) { + titlehasChanged.onReceive(title); + } + } + } catch (Exception e) {} } }); } diff --git a/app/src/main/res/values/feeds.xml b/app/src/main/res/values/feeds.xml index efd3f58..720e029 100755 --- a/app/src/main/res/values/feeds.xml +++ b/app/src/main/res/values/feeds.xml @@ -28,8 +28,5 @@ <item>http://feeds.reuters.com/reuters/environment</item> <item>http://feeds.reuters.com/reuters/financialsNews</item> <item>http://feeds.reuters.com/reuters/worldNews</item> - <item>http://rss.nytimes.com/services/xml/rss/nyt/Environment.xml</item> - <item>http://rss.nytimes.com/services/xml/rss/nyt/Music.xml</item> - <item>http://rss.nytimes.com/services/xml/rss/nyt/Travel.xml</item> </string-array> </resources>
\ No newline at end of file |