From bcabc271eb120f59489025e61d6281f0541bf1fc Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Wed, 24 Jul 2013 14:26:58 +0200 Subject: [PATCH] Fixed search site selection and selection persistence. --- .../app/settings/ApplicationSettings.java | 4 ++-- .../core/gui/search/SearchActivity.java | 21 +++++++++++-------- .../gui/search/SearchHistoryProvider.java | 1 - .../search/SearchSettingsDropDownAdapter.java | 12 ++++++----- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/core/src/org/transdroid/core/app/settings/ApplicationSettings.java b/core/src/org/transdroid/core/app/settings/ApplicationSettings.java index 02104dc4..7f2c524e 100644 --- a/core/src/org/transdroid/core/app/settings/ApplicationSettings.java +++ b/core/src/org/transdroid/core/app/settings/ApplicationSettings.java @@ -456,8 +456,8 @@ public class ApplicationSettings { * Registers the unique key of some web search or in-app search site as being last used by the user * @param order The key identifying the specific server */ - public void setLastUsedSearchSite(String siteKey) { - prefs.edit().putString("header_setsearchsite", siteKey).commit(); + public void setLastUsedSearchSite(SearchSite site) { + prefs.edit().putString("header_setsearchsite", site.getKey()).commit(); } } diff --git a/core/src/org/transdroid/core/gui/search/SearchActivity.java b/core/src/org/transdroid/core/gui/search/SearchActivity.java index e09d0f4d..da834b76 100644 --- a/core/src/org/transdroid/core/gui/search/SearchActivity.java +++ b/core/src/org/transdroid/core/gui/search/SearchActivity.java @@ -13,10 +13,8 @@ import org.androidannotations.annotations.ViewById; import org.transdroid.core.R; import org.transdroid.core.app.search.SearchHelper; import org.transdroid.core.app.search.SearchSite; -import org.transdroid.core.app.settings.ApplicationSettings; -import org.transdroid.core.app.settings.SystemSettings_; -import org.transdroid.core.app.settings.WebsearchSetting; -import org.transdroid.core.gui.TorrentsActivity_; +import org.transdroid.core.app.settings.*; +import org.transdroid.core.gui.*; import org.transdroid.core.gui.navigation.NavigationHelper; import android.annotation.TargetApi; @@ -97,8 +95,10 @@ public class SearchActivity extends SherlockFragmentActivity implements OnNaviga int lastUsedPosition = -1; if (lastUsedSite != null) { for (int i = 0; i < searchSites.size(); i++) { - if (searchSites.get(i).getKey().equals(lastUsedSite.getKey())) + if (searchSites.get(i).getKey().equals(lastUsedSite.getKey())) { lastUsedPosition = i; + break; + } } } @@ -117,7 +117,8 @@ public class SearchActivity extends SherlockFragmentActivity implements OnNaviga // Use the action bar spinner to select sites getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setDisplayShowTitleEnabled(false); - getSupportActionBar().setListNavigationCallbacks(new SearchSettingsDropDownAdapter(this, searchSites), this); + getSupportActionBar() + .setListNavigationCallbacks(new SearchSettingsDropDownAdapter(this, searchSites), this); // Select the last used site; this also starts the search! if (lastUsedPosition >= 0) getSupportActionBar().setSelectedNavigationItem(lastUsedPosition); @@ -168,7 +169,7 @@ public class SearchActivity extends SherlockFragmentActivity implements OnNaviga } private void handleIntent(Intent intent) { - lastUsedQuery = getQuery(intent); + lastUsedQuery = parseQuery(intent); getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(lastUsedQuery)); // Is this actually a full HTTP URL? Then redirect this request to add the URL directly @@ -208,7 +209,7 @@ public class SearchActivity extends SherlockFragmentActivity implements OnNaviga * Extracts the query string from the search {@link Intent} * @return The query string that was entered by the user */ - private String getQuery(Intent intent) { + private String parseQuery(Intent intent) { String query = null; if (intent.getAction().equals(Intent.ACTION_SEARCH)) { @@ -235,7 +236,9 @@ public class SearchActivity extends SherlockFragmentActivity implements OnNaviga startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(websearch.getBaseUrl(), lastUsedQuery)))); } else if (lastUsedSite instanceof SearchSite) { - // Ask the resutls fragment to start a search for the specified query + // Save the search site currently used to search for future usage + applicationSettings.setLastUsedSearchSite((SearchSite) lastUsedSite); + // Ask the results fragment to start a search for the specified query fragmentResults.startSearch(lastUsedQuery, (SearchSite) lastUsedSite); } } diff --git a/core/src/org/transdroid/core/gui/search/SearchHistoryProvider.java b/core/src/org/transdroid/core/gui/search/SearchHistoryProvider.java index fc270f22..1419d177 100644 --- a/core/src/org/transdroid/core/gui/search/SearchHistoryProvider.java +++ b/core/src/org/transdroid/core/gui/search/SearchHistoryProvider.java @@ -14,7 +14,6 @@ public class SearchHistoryProvider extends SearchRecentSuggestionsProvider { public final static int MODE = DATABASE_MODE_QUERIES; public SearchHistoryProvider() { - super(); setupSuggestions(AUTHORITY, MODE); } diff --git a/core/src/org/transdroid/core/gui/search/SearchSettingsDropDownAdapter.java b/core/src/org/transdroid/core/gui/search/SearchSettingsDropDownAdapter.java index 525d6b25..a82c3029 100644 --- a/core/src/org/transdroid/core/gui/search/SearchSettingsDropDownAdapter.java +++ b/core/src/org/transdroid/core/gui/search/SearchSettingsDropDownAdapter.java @@ -17,7 +17,6 @@ import android.view.ViewGroup; public class SearchSettingsDropDownAdapter extends FilterListItemAdapter { private final Context context; - protected SearchSettingSelectionView searchSettingView = null; public SearchSettingsDropDownAdapter(Context context, List items) { super(context, items); @@ -27,11 +26,14 @@ public class SearchSettingsDropDownAdapter extends FilterListItemAdapter { @Override public View getView(int position, View convertView, ViewGroup parent) { // This returns the item to show in the action bar spinner - if (searchSettingView == null) { - searchSettingView = SearchSettingSelectionView_.build(context); + SearchSettingSelectionView filterItemView; + if (convertView == null || !(convertView instanceof SearchSettingSelectionView)) { + filterItemView = SearchSettingSelectionView_.build(context); + } else { + filterItemView = (SearchSettingSelectionView) convertView; } - searchSettingView.bind((SearchSetting) getItem(position)); - return searchSettingView; + filterItemView.bind((SearchSetting) getItem(position)); + return filterItemView; } @Override