Browse Source

Add Sort-By Action to Search Activity

pull/409/head
Alon Albert 7 years ago
parent
commit
43ed12b083
  1. 39
      app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java
  2. 33
      app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java
  3. 8
      app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java
  4. 18
      app/src/main/res/menu/activity_search.xml
  5. 1
      app/src/main/res/values/strings.xml

39
app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java

@ -16,11 +16,11 @@
*/ */
package org.transdroid.core.app.settings; package org.transdroid.core.app.settings;
import java.security.InvalidParameterException; import android.content.Context;
import java.util.ArrayList; import android.content.SharedPreferences;
import java.util.Collections; import android.content.SharedPreferences.Editor;
import java.util.Date; import android.preference.PreferenceManager;
import java.util.List; import android.text.TextUtils;
import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean; import org.androidannotations.annotations.EBean;
@ -29,6 +29,7 @@ import org.androidannotations.annotations.RootContext;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.transdroid.core.app.search.SearchHelper; import org.transdroid.core.app.search.SearchHelper;
import org.transdroid.core.app.search.SearchHelper.SearchSortOrder;
import org.transdroid.core.app.search.SearchSite; import org.transdroid.core.app.search.SearchSite;
import org.transdroid.core.gui.navigation.NavigationFilter; import org.transdroid.core.gui.navigation.NavigationFilter;
import org.transdroid.core.gui.navigation.StatusType; import org.transdroid.core.gui.navigation.StatusType;
@ -39,11 +40,11 @@ import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.OS; import org.transdroid.daemon.OS;
import org.transdroid.daemon.TorrentsSortBy; import org.transdroid.daemon.TorrentsSortBy;
import android.content.Context; import java.security.InvalidParameterException;
import android.content.SharedPreferences; import java.util.ArrayList;
import android.content.SharedPreferences.Editor; import java.util.Collections;
import android.preference.PreferenceManager; import java.util.Date;
import android.text.TextUtils; import java.util.List;
/** /**
* Singleton object to access all application settings, including stored servers, web search sites and RSS feeds. * Singleton object to access all application settings, including stored servers, web search sites and RSS feeds.
@ -558,6 +559,24 @@ public class ApplicationSettings {
.getStatus(prefs.getInt("system_lastusedsortorder", TorrentsSortBy.Alphanumeric.getCode())); .getStatus(prefs.getInt("system_lastusedsortorder", TorrentsSortBy.Alphanumeric.getCode()));
} }
/**
* Registers the search list sort order as being last used by the user
* @param currentSortOrder The sort order property the user selected last
*/
public void setLastUsedSearchSortOrder(SearchSortOrder currentSortOrder) {
Editor edit = prefs.edit();
edit.putInt("system_lastusedsearchsortorder", currentSortOrder.ordinal());
edit.apply();
}
/**
* Returns the search sort order property that the user last used.
* @return The last used sort order enumeration value
*/
public SearchSortOrder getLastUsedSearchSortOrder() {
return SearchSortOrder.values()[(prefs.getInt("system_lastusedsearchsortorder", SearchSortOrder.BySeeders.ordinal()))];
}
/** /**
* Returns the sort order direction that the user last used. Use together with {@link #getLastUsedSortOrder()} to * Returns the sort order direction that the user last used. Use together with {@link #getLastUsedSortOrder()} to
* get the full last used sort settings. * get the full last used sort settings.

33
app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java

@ -25,7 +25,6 @@ import android.os.Bundle;
import android.provider.SearchRecentSuggestions; import android.provider.SearchRecentSuggestions;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ContextThemeWrapper;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -46,6 +45,7 @@ import org.androidannotations.annotations.SystemService;
import org.androidannotations.annotations.ViewById; import org.androidannotations.annotations.ViewById;
import org.transdroid.R; import org.transdroid.R;
import org.transdroid.core.app.search.SearchHelper; import org.transdroid.core.app.search.SearchHelper;
import org.transdroid.core.app.search.SearchHelper.SearchSortOrder;
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.ApplicationSettings;
import org.transdroid.core.app.settings.SystemSettings_; import org.transdroid.core.app.settings.SystemSettings_;
@ -85,6 +85,8 @@ public class SearchActivity extends AppCompatActivity {
private List<SearchSetting> searchSites; private List<SearchSetting> searchSites;
private SearchSetting lastUsedSite; private SearchSetting lastUsedSite;
private String lastUsedQuery; private String lastUsedQuery;
private MenuItem sortByAdded;
private MenuItem sortBySeeders;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -177,6 +179,14 @@ public class SearchActivity extends AppCompatActivity {
searchView.setIconifiedByDefault(false); searchView.setIconifiedByDefault(false);
MenuItemCompat.setActionView(item, searchView); MenuItemCompat.setActionView(item, searchView);
searchMenu = item; searchMenu = item;
sortBySeeders = menu.findItem(R.id.action_sort_seeders);
sortByAdded = menu.findItem(R.id.action_sort_added);
final SearchSortOrder sortOrder = applicationSettings.getLastUsedSearchSortOrder();
if (sortOrder == SearchSortOrder.BySeeders) {
sortBySeeders.setChecked(true);
} else {
sortByAdded.setChecked(true);
}
return true; return true;
} }
@ -304,7 +314,7 @@ public class SearchActivity extends AppCompatActivity {
getSupportActionBar() getSupportActionBar()
.setTitle(NavigationHelper.buildCondensedFontString(getString(R.string.search_queryonsite, lastUsedQuery, lastUsedSite.getName()))); .setTitle(NavigationHelper.buildCondensedFontString(getString(R.string.search_queryonsite, lastUsedQuery, lastUsedSite.getName())));
// Ask the results fragment to start a search for the specified query // Ask the results fragment to start a search for the specified query
fragmentResults.startSearch(lastUsedQuery, (SearchSite) lastUsedSite); fragmentResults.startSearch(lastUsedQuery, (SearchSite) lastUsedSite, applicationSettings.getLastUsedSearchSortOrder());
} }
} }
@ -314,4 +324,23 @@ public class SearchActivity extends AppCompatActivity {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.transdroid.org/latest-search"))); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.transdroid.org/latest-search")));
} }
@OptionsItem(R.id.action_sort_added)
protected void sortByDateAdded() {
if (sortByAdded.isChecked()) {
return;
}
sortByAdded.setChecked(true);
applicationSettings.setLastUsedSearchSortOrder(SearchSortOrder.Combined);
refreshSearch();
}
@OptionsItem(R.id.action_sort_seeders)
protected void sortBySeeders() {
if (sortBySeeders.isChecked()) {
return;
}
sortBySeeders.setChecked(true);
applicationSettings.setLastUsedSearchSortOrder(SearchSortOrder.BySeeders);
refreshSearch();
}
} }

8
app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java

@ -102,16 +102,16 @@ public class SearchResultsFragment extends Fragment {
} }
public void startSearch(String query, SearchSite site) { public void startSearch(String query, SearchSite site, SearchSortOrder sortBy) {
loadingProgress.setVisibility(View.VISIBLE); loadingProgress.setVisibility(View.VISIBLE);
resultsList.setVisibility(View.GONE); resultsList.setVisibility(View.GONE);
emptyText.setVisibility(View.GONE); emptyText.setVisibility(View.GONE);
performSearch(query, site); performSearch(query, site, sortBy);
} }
@Background @Background
protected void performSearch(String query, SearchSite site) { protected void performSearch(String query, SearchSite site, SearchSortOrder sortBy) {
results = searchHelper.search(query, site, SearchSortOrder.BySeeders); results = searchHelper.search(query, site, sortBy);
resultsSource = site.isPrivate() ? site.getKey() : null; resultsSource = site.isPrivate() ? site.getKey() : null;
showResults(); showResults();
} }

18
app/src/main/res/menu/activity_search.xml

@ -28,6 +28,24 @@
android:icon="@drawable/ic_action_refresh" android:icon="@drawable/ic_action_refresh"
android:title="@string/action_refresh" android:title="@string/action_refresh"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
<item
android:id="@+id/action_sort"
android:icon="@drawable/ic_action_sort"
android:title="@string/action_sort"
app:showAsAction="ifRoom">
<menu>
<group
android:checkableBehavior="single">
<item
android:id="@+id/action_sort_seeders"
android:title="@string/action_sort_seeders" />
<item
android:id="@+id/action_sort_added"
android:title="@string/action_sort_added" />
</group>
</menu>
</item>
<item <item
android:id="@+id/action_downloadsearch" android:id="@+id/action_downloadsearch"
android:title="@string/search_download" android:title="@string/search_download"

1
app/src/main/res/values/strings.xml

@ -33,6 +33,7 @@
<string name="action_sort_status">Status</string> <string name="action_sort_status">Status</string>
<string name="action_sort_done">Date done</string> <string name="action_sort_done">Date done</string>
<string name="action_sort_added">Date added</string> <string name="action_sort_added">Date added</string>
<string name="action_sort_seeders">Seeders</string>
<string name="action_sort_percent">Percent downloaded</string> <string name="action_sort_percent">Percent downloaded</string>
<string name="action_sort_downspeed">Download speed</string> <string name="action_sort_downspeed">Download speed</string>
<string name="action_sort_upspeed">Upload speed</string> <string name="action_sort_upspeed">Upload speed</string>

Loading…
Cancel
Save