From 3ec502f4ed6db627302e5b8df34e49036a89b5c3 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Mon, 8 Jul 2013 15:55:22 +0200 Subject: [PATCH] Fix RSS feeds screen UI and hide/show setting button. --- .../core/gui/navigation/NavigationHelper.java | 2 ++ .../core/gui/rss/RssfeedsActivity.java | 36 ++++++++++++------- .../core/gui/rss/RssfeedsFragment.java | 3 +- .../core/gui/rss/RssitemsActivity.java | 4 ++- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java b/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java index 87f19769..2543ca11 100644 --- a/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java +++ b/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java @@ -124,6 +124,8 @@ public class NavigationHelper { * input string will be displayed using the Roboto Condensed font (if the OS has this) */ public static SpannableString buildCondensedFontString(String string) { + if (string == null) + return null; SpannableString s = new SpannableString(string); s.setSpan(new TypefaceSpan("sans-serif-condensed"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return s; diff --git a/core/src/org/transdroid/core/gui/rss/RssfeedsActivity.java b/core/src/org/transdroid/core/gui/rss/RssfeedsActivity.java index 7154beb6..d61f39e2 100644 --- a/core/src/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/core/src/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -21,8 +21,10 @@ import org.transdroid.core.rssparser.RssParser; import android.annotation.TargetApi; import android.content.Intent; +import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.text.TextUtils; import com.actionbarsherlock.app.SherlockFragmentActivity; @@ -119,24 +121,26 @@ public class RssfeedsActivity extends SherlockFragmentActivity { } /** - * Opens an RSS feed in the dedicated fragment (if there was space in the UI) or a new {@link RssitemsActivity}. - * Optionally this also registers in the user preferences that the feed was now viewed, so that in the future the + * Opens an RSS feed in the dedicated fragment (if there was space in the UI) or a new {@link RssitemsActivity}. + * Optionally this also registers in the user preferences that the feed was now viewed, so that in the future the * new items can be properly marked. * @param loader The RSS feed loader (with settings and the loaded content channel) to show - * @param markAsViewedNow True if the user settings should be updated to reflect this feed's last viewed date; false otherwise + * @param markAsViewedNow True if the user settings should be updated to reflect this feed's last viewed date; false + * otherwise */ public void openRssfeed(RssfeedLoader loader, boolean markAsViewedNow) { - + // The RSS feed content was loaded and can now be shown in the dedicated fragment or a new activity if (fragmentItems != null) { - // If desired, update the lastViewedDate of this feed in the user setting; this won't be loaded until the RSS + // If desired, update the lastViewedDate of this feed in the user setting; this won't be loaded until the + // RSS // feeds screen in opened again. if (!loader.hasError() && loader.getChannel() != null && markAsViewedNow) { applicationSettings.setRssfeedLastViewer(loader.getSetting().getOrder(), new Date()); } fragmentItems.update(loader.getChannel(), loader.hasError()); - + } else { // Error message or not yet loaded? Show a toast message instead of opening the items activity @@ -148,17 +152,25 @@ public class RssfeedsActivity extends SherlockFragmentActivity { Crouton.showText(this, R.string.rss_notloaded, NavigationHelper.CROUTON_INFO_STYLE); return; } - - // If desired, update the lastViewedDate of this feed in the user setting; this won't be loaded until the RSS + + // If desired, update the lastViewedDate of this feed in the user setting; this won't be loaded until the + // RSS // feeds screen in opened again if (markAsViewedNow) { applicationSettings.setRssfeedLastViewer(loader.getSetting().getOrder(), new Date()); } - - RssitemsActivity_.intent(this).rssfeed(loader.getChannel()).start(); - + + String name = loader.getChannel().getTitle(); + if (TextUtils.isEmpty(name)) + name = loader.getSetting().getName(); + if (TextUtils.isEmpty(name) && !TextUtils.isEmpty(loader.getSetting().getUrl())) { + String host = Uri.parse(loader.getSetting().getUrl()).getHost(); + name = host; + } + RssitemsActivity_.intent(this).rssfeed(loader.getChannel()).rssfeedName(name).start(); + } - + } } diff --git a/core/src/org/transdroid/core/gui/rss/RssfeedsFragment.java b/core/src/org/transdroid/core/gui/rss/RssfeedsFragment.java index 1fb3e8e5..e0bd46c4 100644 --- a/core/src/org/transdroid/core/gui/rss/RssfeedsFragment.java +++ b/core/src/org/transdroid/core/gui/rss/RssfeedsFragment.java @@ -53,7 +53,8 @@ public class RssfeedsFragment extends SherlockFragment { public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); menu.findItem(R.id.action_settings).setShowAsAction( - rssfeedsAdapter.getCount() == 0 ? MenuItem.SHOW_AS_ACTION_ALWAYS : MenuItem.SHOW_AS_ACTION_NEVER); + rssfeedsAdapter == null || rssfeedsAdapter.getCount() == 0 ? MenuItem.SHOW_AS_ACTION_ALWAYS + : MenuItem.SHOW_AS_ACTION_NEVER); } @OptionsItem(resName = "action_settings") diff --git a/core/src/org/transdroid/core/gui/rss/RssitemsActivity.java b/core/src/org/transdroid/core/gui/rss/RssitemsActivity.java index 2da24fde..9126af1d 100644 --- a/core/src/org/transdroid/core/gui/rss/RssitemsActivity.java +++ b/core/src/org/transdroid/core/gui/rss/RssitemsActivity.java @@ -23,6 +23,8 @@ public class RssitemsActivity extends SherlockFragmentActivity { @Extra protected Channel rssfeed = null; + @Extra + protected String rssfeedName; @FragmentById(resName = "rssitems_list") protected RssitemsFragment fragmentItems; @@ -48,7 +50,7 @@ public class RssitemsActivity extends SherlockFragmentActivity { // Simple action bar with up button and torrent name as title getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(rssfeed.getTitle())); + getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(rssfeedName)); // Get the intent extras and show them to the already loaded fragment fragmentItems.update(rssfeed, false);