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 { @@ -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();
}
}

21
core/src/org/transdroid/core/gui/search/SearchActivity.java

@ -13,10 +13,8 @@ import org.androidannotations.annotations.ViewById; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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);
}
}

1
core/src/org/transdroid/core/gui/search/SearchHistoryProvider.java

@ -14,7 +14,6 @@ public class SearchHistoryProvider extends SearchRecentSuggestionsProvider { @@ -14,7 +14,6 @@ public class SearchHistoryProvider extends SearchRecentSuggestionsProvider {
public final static int MODE = DATABASE_MODE_QUERIES;
public SearchHistoryProvider() {
super();
setupSuggestions(AUTHORITY, MODE);
}

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

@ -17,7 +17,6 @@ import android.view.ViewGroup; @@ -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<? extends SimpleListItem> items) {
super(context, items);
@ -27,11 +26,14 @@ public class SearchSettingsDropDownAdapter extends FilterListItemAdapter { @@ -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

Loading…
Cancel
Save