diff options
Diffstat (limited to 'app/src')
-rwxr-xr-x | app/src/main/java/org/rssin/android/SharedPreferencesStorageProvider.java | 22 | ||||
-rw-r--r-- | app/src/main/res/values/feeds.xml | 86 |
2 files changed, 102 insertions, 6 deletions
diff --git a/app/src/main/java/org/rssin/android/SharedPreferencesStorageProvider.java b/app/src/main/java/org/rssin/android/SharedPreferencesStorageProvider.java index 4c23fa9..2818a08 100755 --- a/app/src/main/java/org/rssin/android/SharedPreferencesStorageProvider.java +++ b/app/src/main/java/org/rssin/android/SharedPreferencesStorageProvider.java @@ -7,6 +7,7 @@ import android.util.Log; import org.rssin.rssin.Feed; import org.rssin.rssin.Filter; +import org.rssin.rssin.R; import org.rssin.storage.FeedStorageProvider; import org.rssin.storage.FilterStorageProvider; import org.rssin.storage.Storable; @@ -17,6 +18,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.net.MalformedURLException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -76,8 +78,6 @@ class SharedPreferencesStorageProvider implements StorageProvider, FilterStorage .edit() .putString(element.getClass().getName(), base64) .apply(); - - Log.v("SPSP", "Store to " + key.toString() + ":\n" + base64); } @Override @@ -88,7 +88,6 @@ class SharedPreferencesStorageProvider implements StorageProvider, FilterStorage } ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(Base64.decode(serialized.getBytes(), Base64.DEFAULT))); Object obj = ois.readObject(); - Log.v("SPSP", "Fetch " + className.toString() + " from " + key.toString() + ": " + obj.toString()); return (Storable) className.cast(obj); } @@ -116,10 +115,8 @@ class SharedPreferencesStorageProvider implements StorageProvider, FilterStorage .getStringSet("filters", new HashSet<String>()); List<Filter> filters = new ArrayList<>(); for (String name : names) { - Log.v("SPSP", "allFilters: " + name); Filter filter = getFilter(name); if (filter != null) { - Log.v("SPSP", "allFilters: not null, returning"); filters.add(filter); } } @@ -137,7 +134,7 @@ class SharedPreferencesStorageProvider implements StorageProvider, FilterStorage try { return (Filter) fetch(key.toString(), Filter.class); } catch (Exception e) { - Log.w("SPSP", "Fetch filter " + key.toString(), e); + Log.w("SPSP", "Fetch filter failed: " + key.toString(), e); return null; } } @@ -171,6 +168,19 @@ class SharedPreferencesStorageProvider implements StorageProvider, FilterStorage @Override public List<Feed> allFeeds() { Set<String> names = context.getSharedPreferences(ADMIN_PREF_KEY, Context.MODE_PRIVATE).getStringSet("feeds", new HashSet<String>()); + if (names.isEmpty() && !context.getSharedPreferences(ADMIN_PREF_KEY, Context.MODE_PRIVATE).getBoolean("firstload", false)) { + String[] feedsList = context.getResources().getStringArray(R.array.default_feeds); + for (String url : feedsList) { + try { + Feed f = new Feed(url); + f.store(this); + } catch (Exception e) { + Log.w("SPSP", "Couldn't add " + url, e); + } + } + context.getSharedPreferences(ADMIN_PREF_KEY, Context.MODE_PRIVATE).edit().putBoolean("firstload", true).apply(); + names = context.getSharedPreferences(ADMIN_PREF_KEY, Context.MODE_PRIVATE).getStringSet("feeds", new HashSet<String>()); + } List<Feed> feeds = new ArrayList<>(); for (String name : names) { Feed feed = getFeed(name); diff --git a/app/src/main/res/values/feeds.xml b/app/src/main/res/values/feeds.xml new file mode 100644 index 0000000..e4ae386 --- /dev/null +++ b/app/src/main/res/values/feeds.xml @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string-array name="default_feeds"> + <item>http://feeds.bbci.co.uk/news/business/rss.xml</item> + <item>http://feeds.bbci.co.uk/news/entertainment_and_arts/rss.xml</item> + <item>http://feeds.bbci.co.uk/news/health/rss.xml</item> + <item>http://feeds.bbci.co.uk/news/politics/rss.xml</item> + <item>http://feeds.bbci.co.uk/news/science_and_environment/rss.xml</item> + <item>http://feeds.bbci.co.uk/news/technology/rss.xml</item> + <item>http://feeds.bbci.co.uk/news/uk/rss.xml</item> + <item>http://feeds.bbci.co.uk/news/world/rss.xml</item> + <item>http://feeds.bbci.co.uk/sport/0/rss.xml</item> + <item>http://feeds.foxnews.com/foxnews/internal/travel/mixed</item> + <item>http://feeds.foxnews.com/foxnews/opinion</item> + <item>http://feeds.foxnews.com/foxnews/politics</item> + <item>http://feeds.foxnews.com/foxnews/science</item> + <item>http://feeds.foxnews.com/foxnews/section/lifestyle</item> + <item>http://feeds.foxnews.com/foxnews/sports</item> + <item>http://feeds.foxnews.com/foxnews/tech</item> + <item>http://feeds.mashable.com/mashable/business</item> + <item>http://feeds.mashable.com/mashable/entertainment</item> + <item>http://feeds.mashable.com/mashable/socialmedia</item> + <item>http://feeds.mashable.com/mashable/tech</item> + <item>http://feeds.reuters.com/news/artsculture</item> + <item>http://feeds.reuters.com/news/economy</item> + <item>http://feeds.reuters.com/news/reutersmedia</item> + <item>http://feeds.reuters.com/news/wealth</item> + <item>http://feeds.reuters.com/reuters/businessNews</item> + <item>http://feeds.reuters.com/reuters/entertainment</item> + <item>http://feeds.reuters.com/reuters/environment</item> + <item>http://feeds.reuters.com/reuters/financialsNews</item> + <item>http://feeds.reuters.com/reuters/healthNews</item> + <item>http://feeds.reuters.com/reuters/hotStocksNews</item> + <item>http://feeds.reuters.com/reuters/lifestyle</item> + <item>http://feeds.reuters.com/reuters/oddlyEnoughNews</item> + <item>http://feeds.reuters.com/Reuters/PoliticsNews</item> + <item>http://feeds.reuters.com/reuters/scienceNews</item> + <item>http://feeds.reuters.com/reuters/sportsNews</item> + <item>http://feeds.reuters.com/reuters/technologyNews</item> + <item>http://feeds.reuters.com/reuters/technologysectorNews</item> + <item>http://feeds.reuters.com/reuters/UShealthcareNews</item> + <item>http://feeds.reuters.com/reuters/worldNews</item> + <item>http://rss.cnn.com/rss/edition_entertainment.rss</item> + <item>http://rss.cnn.com/rss/edition_space.rss</item> + <item>http://rss.cnn.com/rss/edition_sport.rss</item> + <item>http://rss.cnn.com/rss/edition_technology.rss</item> + <item>http://rss.cnn.com/rss/money_news_international.rss</item> + <item>http://rss.cnn.com/rss/si_topstories.rss</item> + <item>http://rss.nytimes.com/services/xml/rss/nyt/Books.xml</item> + <item>http://rss.nytimes.com/services/xml/rss/nyt/Business.xml</item> + <item>http://rss.nytimes.com/services/xml/rss/nyt/Dance.xml</item> + <item>http://rss.nytimes.com/services/xml/rss/nyt/Economy.xml</item> + <item>http://rss.nytimes.com/services/xml/rss/nyt/Environment.xml</item> + <item>http://rss.nytimes.com/services/xml/rss/nyt/FashionandStyle.xml</item> + <item>http://rss.nytimes.com/services/xml/rss/nyt/MediaandAdvertising.xml</item> + <item>http://rss.nytimes.com/services/xml/rss/nyt/Movies.xml</item> + <item>http://rss.nytimes.com/services/xml/rss/nyt/Music.xml</item> + <item>http://rss.nytimes.com/services/xml/rss/nyt/Science.xml</item> + <item>http://rss.nytimes.com/services/xml/rss/nyt/Sports.xml</item> + <item>http://rss.nytimes.com/services/xml/rss/nyt/Technology.xml</item> + <item>http://rss.nytimes.com/services/xml/rss/nyt/Travel.xml</item> + <item>http://www.cnet.com/rss/news/</item> + <item>http://www.dailymail.co.uk/health/index.rss</item> + <item>http://www.dailymail.co.uk/money/index.rss</item> + <item>http://www.dailymail.co.uk/sciencetech/index.rss</item> + <item>http://www.dailymail.co.uk/sport/index.rss</item> + <item>http://www.dailymail.co.uk/tvshowbiz/index.rss</item> + <item>http://www.thesundaily.my/rss/business</item> + <item>http://www.thesundaily.my/rss/lifestyle/food</item> + <item>http://www.thesundaily.my/rss/lifestyle/health</item> + <item>http://www.thesundaily.my/rss/lifestyle/tech</item> + <item>http://www.thesundaily.my/rss/lifestyle/travel</item> + <item>http://www.thesundaily.my/rss/media-marketing</item> + <item>http://www.thesundaily.my/rss/opinion</item> + <item>http://www.thesundaily.my/rss/showbiz</item> + <item>http://www.thesundaily.my/rss/sports</item> + <item>http://www.thesundaily.my/rss/style</item> + <item>http://www.washingtontimes.com/rss/headlines/culture/autos/</item> + <item>http://www.washingtontimes.com/rss/headlines/culture/entertainment/</item> + <item>http://www.washingtontimes.com/rss/headlines/culture/health/</item> + <item>http://www.washingtontimes.com/rss/headlines/culture/travel/</item> + <item>http://www.washingtontimes.com/rss/headlines/news/politics/</item> + <item>http://www.washingtontimes.com/rss/headlines/opinion/</item> + <item>http://www.washingtontimes.com/rss/headlines/sports/</item> + </string-array> +</resources>
\ No newline at end of file |