Browse Source

Fixed search site selection and selection persistence.

pull/11/head
Eric Kok 11 years ago
parent
commit
bcabc271eb
  1. 4
      core/src/org/transdroid/core/app/settings/ApplicationSettings.java
  2. 21
      core/src/org/transdroid/core/gui/search/SearchActivity.java
  3. 1
      core/src/org/transdroid/core/gui/search/SearchHistoryProvider.java
  4. 12
      core/src/org/transdroid/core/gui/search/SearchSettingsDropDownAdapter.java

4
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 * 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 * @param order The key identifying the specific server
*/ */
public void setLastUsedSearchSite(String siteKey) { public void setLastUsedSearchSite(SearchSite site) {
prefs.edit().putString("header_setsearchsite", siteKey).commit(); prefs.edit().putString("header_setsearchsite", site.getKey()).commit();
} }
} }

21
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.R;
import org.transdroid.core.app.search.SearchHelper; import org.transdroid.core.app.search.SearchHelper;
import org.transdroid.core.app.search.SearchSite; import org.transdroid.core.app.search.SearchSite;
import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.*;
import org.transdroid.core.app.settings.SystemSettings_; import org.transdroid.core.gui.*;
import org.transdroid.core.app.settings.WebsearchSetting;
import org.transdroid.core.gui.TorrentsActivity_;
import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.core.gui.navigation.NavigationHelper;
import android.annotation.TargetApi; import android.annotation.TargetApi;
@ -97,8 +95,10 @@ public class SearchActivity extends SherlockFragmentActivity implements OnNaviga
int lastUsedPosition = -1; int lastUsedPosition = -1;
if (lastUsedSite != null) { if (lastUsedSite != null) {
for (int i = 0; i < searchSites.size(); i++) { 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; lastUsedPosition = i;
break;
}
} }
} }
@ -117,7 +117,8 @@ public class SearchActivity extends SherlockFragmentActivity implements OnNaviga
// Use the action bar spinner to select sites // Use the action bar spinner to select sites
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setDisplayShowTitleEnabled(false); 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! // Select the last used site; this also starts the search!
if (lastUsedPosition >= 0) if (lastUsedPosition >= 0)
getSupportActionBar().setSelectedNavigationItem(lastUsedPosition); getSupportActionBar().setSelectedNavigationItem(lastUsedPosition);
@ -168,7 +169,7 @@ public class SearchActivity extends SherlockFragmentActivity implements OnNaviga
} }
private void handleIntent(Intent intent) { private void handleIntent(Intent intent) {
lastUsedQuery = getQuery(intent); lastUsedQuery = parseQuery(intent);
getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(lastUsedQuery)); getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(lastUsedQuery));
// Is this actually a full HTTP URL? Then redirect this request to add the URL directly // 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} * Extracts the query string from the search {@link Intent}
* @return The query string that was entered by the user * @return The query string that was entered by the user
*/ */
private String getQuery(Intent intent) { private String parseQuery(Intent intent) {
String query = null; String query = null;
if (intent.getAction().equals(Intent.ACTION_SEARCH)) { if (intent.getAction().equals(Intent.ACTION_SEARCH)) {
@ -235,7 +236,9 @@ public class SearchActivity extends SherlockFragmentActivity implements OnNaviga
startActivity(new Intent(Intent.ACTION_VIEW, startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format(websearch.getBaseUrl(), lastUsedQuery)))); Uri.parse(String.format(websearch.getBaseUrl(), lastUsedQuery))));
} else if (lastUsedSite instanceof SearchSite) { } 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); fragmentResults.startSearch(lastUsedQuery, (SearchSite) lastUsedSite);
} }
} }

1
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 final static int MODE = DATABASE_MODE_QUERIES;
public SearchHistoryProvider() { public SearchHistoryProvider() {
super();
setupSuggestions(AUTHORITY, MODE); setupSuggestions(AUTHORITY, MODE);
} }

12
core/src/org/transdroid/core/gui/search/SearchSettingsDropDownAdapter.java

@ -17,7 +17,6 @@ import android.view.ViewGroup;
public class SearchSettingsDropDownAdapter extends FilterListItemAdapter { public class SearchSettingsDropDownAdapter extends FilterListItemAdapter {
private final Context context; private final Context context;
protected SearchSettingSelectionView searchSettingView = null;
public SearchSettingsDropDownAdapter(Context context, List<? extends SimpleListItem> items) { public SearchSettingsDropDownAdapter(Context context, List<? extends SimpleListItem> items) {
super(context, items); super(context, items);
@ -27,11 +26,14 @@ public class SearchSettingsDropDownAdapter extends FilterListItemAdapter {
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
// This returns the item to show in the action bar spinner // This returns the item to show in the action bar spinner
if (searchSettingView == null) { SearchSettingSelectionView filterItemView;
searchSettingView = SearchSettingSelectionView_.build(context); if (convertView == null || !(convertView instanceof SearchSettingSelectionView)) {
filterItemView = SearchSettingSelectionView_.build(context);
} else {
filterItemView = (SearchSettingSelectionView) convertView;
} }
searchSettingView.bind((SearchSetting) getItem(position)); filterItemView.bind((SearchSetting) getItem(position));
return searchSettingView; return filterItemView;
} }
@Override @Override

Loading…
Cancel
Save