From 3e6989fa493a5c52793e8dc3bea6fb91a5ecf0aa Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Fri, 4 Oct 2013 09:41:55 +0200 Subject: [PATCH] Hide search and RSS settings if not supported (i.e. in Lite version). --- .../gui/settings/MainSettingsActivity.java | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/core/src/org/transdroid/core/gui/settings/MainSettingsActivity.java b/core/src/org/transdroid/core/gui/settings/MainSettingsActivity.java index cd0d0c37..66a1da02 100644 --- a/core/src/org/transdroid/core/gui/settings/MainSettingsActivity.java +++ b/core/src/org/transdroid/core/gui/settings/MainSettingsActivity.java @@ -29,7 +29,8 @@ import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.RssfeedSetting; import org.transdroid.core.app.settings.ServerSetting; import org.transdroid.core.app.settings.WebsearchSetting; -import org.transdroid.core.gui.*; +import org.transdroid.core.gui.TorrentsActivity_; +import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.core.gui.settings.RssfeedPreference.OnRssfeedClickedListener; import org.transdroid.core.gui.settings.ServerPreference.OnServerClickedListener; import org.transdroid.core.gui.settings.WebsearchPreference.OnWebsearchClickedListener; @@ -52,6 +53,8 @@ import com.actionbarsherlock.app.SherlockPreferenceActivity; @EActivity public class MainSettingsActivity extends SherlockPreferenceActivity { + @Bean + protected NavigationHelper navigationHelper; @Bean protected ApplicationSettings applicationSettings; @Bean @@ -69,15 +72,20 @@ public class MainSettingsActivity extends SherlockPreferenceActivity { super.onResume(); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - + if (getPreferenceScreen() != null) getPreferenceScreen().removeAll(); - + + boolean enableSearchUi = navigationHelper.enableSearchUi(); + boolean enableRssUi = navigationHelper.enableRssUi(); + // Load the preference menu and attach actions addPreferencesFromResource(R.xml.pref_main); findPreference("header_addserver").setOnPreferenceClickListener(onAddServer); - findPreference("header_addwebsearch").setOnPreferenceClickListener(onAddWebsearch); - findPreference("header_addrssfeed").setOnPreferenceClickListener(onAddRssfeed); + if (enableSearchUi) + findPreference("header_addwebsearch").setOnPreferenceClickListener(onAddWebsearch); + if (enableRssUi) + findPreference("header_addrssfeed").setOnPreferenceClickListener(onAddRssfeed); findPreference("header_background").setOnPreferenceClickListener(onBackgroundSettings); findPreference("header_system").setOnPreferenceClickListener(onSystemSettings); @@ -89,6 +97,25 @@ public class MainSettingsActivity extends SherlockPreferenceActivity { onServerClicked)); } + // Add existing RSS feeds + if (!enableRssUi) { + // RSS should be disabled + getPreferenceScreen().removePreference(findPreference("header_rssfeeds")); + } else { + List rssfeeds = applicationSettings.getRssfeedSettings(); + for (RssfeedSetting rssfeedSetting : rssfeeds) { + getPreferenceScreen().addPreference( + new RssfeedPreference(this).setRssfeedSetting(rssfeedSetting).setOnRssfeedClickedListener( + onRssfeedClicked)); + } + } + + if (!enableSearchUi) { + // Search should be disabled + getPreferenceScreen().removePreference(findPreference("header_searchsites")); + return; + } + // Add existing websearch sites List websearches = applicationSettings.getWebsearchSettings(); for (WebsearchSetting websearchSetting : websearches) { @@ -97,14 +124,6 @@ public class MainSettingsActivity extends SherlockPreferenceActivity { onWebsearchClicked)); } - // Add existing RSS feeds - List rssfeeds = applicationSettings.getRssfeedSettings(); - for (RssfeedSetting rssfeedSetting : rssfeeds) { - getPreferenceScreen().addPreference( - new RssfeedPreference(this).setRssfeedSetting(rssfeedSetting).setOnRssfeedClickedListener( - onRssfeedClicked)); - } - // Construct list of all available search sites, in-app and web ListPreference setSite = (ListPreference) findPreference("header_setsearchsite"); // Retrieve the available in-app search sites (using the Torrent Search package) @@ -124,7 +143,7 @@ public class MainSettingsActivity extends SherlockPreferenceActivity { // Supply the Preference list names and values setSite.setEntries(siteNames.toArray(new String[siteNames.size()])); setSite.setEntryValues(siteValues.toArray(new String[siteValues.size()])); - + } @TargetApi(Build.VERSION_CODES.HONEYCOMB)