diff --git a/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java b/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java
index f4c9619c..16f61d34 100644
--- a/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java
+++ b/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java
@@ -16,11 +16,11 @@
*/
package org.transdroid.core.app.settings;
-import java.security.InvalidParameterException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.preference.PreferenceManager;
+import android.text.TextUtils;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;
@@ -29,6 +29,7 @@ import org.androidannotations.annotations.RootContext;
import org.json.JSONArray;
import org.json.JSONException;
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.gui.navigation.NavigationFilter;
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.TorrentsSortBy;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
-import android.preference.PreferenceManager;
-import android.text.TextUtils;
+import java.security.InvalidParameterException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
/**
* 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()));
}
+ /**
+ * 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
* get the full last used sort settings.
diff --git a/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java b/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java
index ad10d9af..d65f66ca 100644
--- a/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java
+++ b/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.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
-import android.support.v7.view.ContextThemeWrapper;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
@@ -46,6 +45,7 @@ import org.androidannotations.annotations.SystemService;
import org.androidannotations.annotations.ViewById;
import org.transdroid.R;
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.settings.ApplicationSettings;
import org.transdroid.core.app.settings.SystemSettings_;
@@ -177,6 +177,14 @@ public class SearchActivity extends AppCompatActivity {
searchView.setIconifiedByDefault(false);
MenuItemCompat.setActionView(item, searchView);
searchMenu = item;
+ final MenuItem sortBySeeders = menu.findItem(R.id.action_sort_seeders);
+ final MenuItem 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;
}
@@ -304,7 +312,7 @@ public class SearchActivity extends AppCompatActivity {
getSupportActionBar()
.setTitle(NavigationHelper.buildCondensedFontString(getString(R.string.search_queryonsite, lastUsedQuery, lastUsedSite.getName())));
// 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 +322,23 @@ public class SearchActivity extends AppCompatActivity {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.transdroid.org/latest-search")));
}
+ @OptionsItem(R.id.action_sort_added)
+ protected void sortByDateAdded() {
+ if (applicationSettings.getLastUsedSearchSortOrder() == SearchSortOrder.Combined) {
+ return;
+ }
+ invalidateOptionsMenu();
+ applicationSettings.setLastUsedSearchSortOrder(SearchSortOrder.Combined);
+ refreshSearch();
+ }
+
+ @OptionsItem(R.id.action_sort_seeders)
+ protected void sortBySeeders() {
+ if (applicationSettings.getLastUsedSearchSortOrder() == SearchSortOrder.BySeeders) {
+ return;
+ }
+ invalidateOptionsMenu();
+ applicationSettings.setLastUsedSearchSortOrder(SearchSortOrder.BySeeders);
+ refreshSearch();
+ }
}
diff --git a/app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java b/app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java
index 6ecbbea9..2aa5c3bd 100644
--- a/app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java
+++ b/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);
resultsList.setVisibility(View.GONE);
emptyText.setVisibility(View.GONE);
- performSearch(query, site);
+ performSearch(query, site, sortBy);
}
@Background
- protected void performSearch(String query, SearchSite site) {
- results = searchHelper.search(query, site, SearchSortOrder.BySeeders);
+ protected void performSearch(String query, SearchSite site, SearchSortOrder sortBy) {
+ results = searchHelper.search(query, site, sortBy);
resultsSource = site.isPrivate() ? site.getKey() : null;
showResults();
}
diff --git a/app/src/main/res/menu/activity_search.xml b/app/src/main/res/menu/activity_search.xml
index 1d81b7fd..1af4a3f9 100644
--- a/app/src/main/res/menu/activity_search.xml
+++ b/app/src/main/res/menu/activity_search.xml
@@ -28,6 +28,24 @@
android:icon="@drawable/ic_action_refresh"
android:title="@string/action_refresh"
app:showAsAction="ifRoom" />
+ -
+
+
+
- Status
Date done
Date added
+ Seeders
Percent downloaded
Download speed
Upload speed