Browse Source

Remember the last selected navigation filter (status type, label) and preselect it on the next startup. Fixes #113.

pull/148/merge
Eric Kok 11 years ago
parent
commit
6b62ce09c0
  1. 19
      core/src/org/transdroid/core/app/settings/ApplicationSettings.java
  2. 58
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  3. 6
      core/src/org/transdroid/core/gui/navigation/Label.java
  4. 7
      core/src/org/transdroid/core/gui/navigation/NavigationFilter.java
  5. 6
      core/src/org/transdroid/core/gui/navigation/StatusType.java

19
core/src/org/transdroid/core/app/settings/ApplicationSettings.java

@ -30,6 +30,7 @@ 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.SearchSite; import org.transdroid.core.app.search.SearchSite;
import org.transdroid.core.gui.navigation.NavigationFilter;
import org.transdroid.core.gui.navigation.StatusType; import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.search.SearchSetting; import org.transdroid.core.gui.search.SearchSetting;
import org.transdroid.core.seedbox.SeedboxProvider; import org.transdroid.core.seedbox.SeedboxProvider;
@ -284,6 +285,24 @@ public class ApplicationSettings {
prefs.edit().putInt("system_lastusedserver", order).commit(); prefs.edit().putInt("system_lastusedserver", order).commit();
} }
/**
* Returns the unique code that (should) uniquely identify a navigation filter, such as a label, in the list of all
* available filters
* @return A code that the last used navigation filter reported as uniquely identifying itself, or null if no last
* used filter is known
*/
public String getLastUsedNavigationFilter() {
return prefs.getString("system_lastusedfilter", null);
}
/**
* Registers some navigation filter as being the last used by the user
* @param server The navigation filter that the user last used in the interface
*/
public void setLastUsedNavigationFilter(NavigationFilter filter) {
prefs.edit().putString("system_lastusedfilter", filter.getCode()).commit();
}
/** /**
* Returns all available user-configured web-based (as opped to in-app) search sites * Returns all available user-configured web-based (as opped to in-app) search sites
* @return A list of all stored web search site settings objects * @return A list of all stored web search site settings objects

58
core/src/org/transdroid/core/gui/TorrentsActivity.java

@ -44,18 +44,31 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.cookie.BasicClientCookie; import org.apache.http.impl.cookie.BasicClientCookie;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.app.search.*; import org.transdroid.core.app.search.SearchHelper_;
import org.transdroid.core.app.settings.*; import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.app.settings.SystemSettings;
import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.app.settings.WebsearchSetting;
import org.transdroid.core.gui.lists.LocalTorrent; import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.lists.NoProgressHeaderTransformer; import org.transdroid.core.gui.lists.NoProgressHeaderTransformer;
import org.transdroid.core.gui.lists.SimpleListItem; import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.log.*; import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.navigation.*; import org.transdroid.core.gui.log.Log_;
import org.transdroid.core.gui.rss.*; import org.transdroid.core.gui.navigation.FilterListAdapter;
import org.transdroid.core.gui.navigation.FilterListAdapter_;
import org.transdroid.core.gui.navigation.FilterListDropDownAdapter;
import org.transdroid.core.gui.navigation.FilterListDropDownAdapter_;
import org.transdroid.core.gui.navigation.Label;
import org.transdroid.core.gui.navigation.NavigationFilter;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.gui.navigation.RefreshableActivity;
import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.rss.RssfeedsActivity_;
import org.transdroid.core.gui.search.BarcodeHelper; import org.transdroid.core.gui.search.BarcodeHelper;
import org.transdroid.core.gui.search.FilePickerHelper; import org.transdroid.core.gui.search.FilePickerHelper;
import org.transdroid.core.gui.search.UrlEntryDialog; import org.transdroid.core.gui.search.UrlEntryDialog;
import org.transdroid.core.gui.settings.*; import org.transdroid.core.gui.settings.MainSettingsActivity_;
import org.transdroid.core.service.BootReceiver; import org.transdroid.core.service.BootReceiver;
import org.transdroid.core.service.ConnectivityHelper; import org.transdroid.core.service.ConnectivityHelper;
import org.transdroid.core.widget.ListWidgetProvider; import org.transdroid.core.widget.ListWidgetProvider;
@ -163,6 +176,8 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
@InstanceState @InstanceState
protected NavigationFilter currentFilter = null; protected NavigationFilter currentFilter = null;
@InstanceState @InstanceState
protected String preselectNavigationFilter = null;
@InstanceState
protected boolean turleModeEnabled = false; protected boolean turleModeEnabled = false;
@InstanceState @InstanceState
protected ArrayList<Label> lastNavigationLabels; protected ArrayList<Label> lastNavigationLabels;
@ -220,7 +235,8 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Add an empty labels list (which will be updated later, but the adapter needs to be created now) // Add an empty labels list (which will be updated later, but the adapter needs to be created now)
navigationSpinnerAdapter.updateLabels(new ArrayList<Label>()); navigationSpinnerAdapter.updateLabels(new ArrayList<Label>());
} }
// Now that all items (or at least their adapters) have been added // Now that all items (or at least their adapters) have been added, ensure a filter is selected
// NOTE When this is a fresh start, it might override the filter later (based on the last user selection)
if (currentFilter == null) { if (currentFilter == null) {
currentFilter = StatusType.getShowAllType(this); currentFilter = StatusType.getShowAllType(this);
} }
@ -258,6 +274,8 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (firstStart) { if (firstStart) {
// Force first torrents refresh // Force first torrents refresh
filterSelected(lastUsed, true); filterSelected(lastUsed, true);
// Perhaps we can select the last used navigation filter, but only after a first refresh was completed
preselectNavigationFilter = applicationSettings.getLastUsedNavigationFilter();
// Handle any start up intents // Handle any start up intents
if (openTorrent != null) { if (openTorrent != null) {
openDetails(openTorrent); openDetails(openTorrent);
@ -313,7 +331,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
} }
} }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void startAutoRefresh() { public void startAutoRefresh() {
// Check if already running // Check if already running
@ -479,6 +496,9 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
*/ */
protected void filterSelected(SimpleListItem item, boolean forceNewConnection) { protected void filterSelected(SimpleListItem item, boolean forceNewConnection) {
// No longer apply the last used filter (on a fresh application start), if we still needed to
preselectNavigationFilter = null;
// Server selection // Server selection
if (item instanceof ServerSetting) { if (item instanceof ServerSetting) {
ServerSetting server = (ServerSetting) item; ServerSetting server = (ServerSetting) item;
@ -512,9 +532,12 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Status type or label selection - both of which are navigation filters // Status type or label selection - both of which are navigation filters
if (item instanceof NavigationFilter) { if (item instanceof NavigationFilter) {
// Set new filter
currentFilter = (NavigationFilter) item; currentFilter = (NavigationFilter) item;
fragmentTorrents.applyNavigationFilter(currentFilter); fragmentTorrents.applyNavigationFilter(currentFilter);
navigationSpinnerAdapter.updateCurrentFilter(currentFilter); navigationSpinnerAdapter.updateCurrentFilter(currentFilter);
// Remember that the user last selected this
applicationSettings.setLastUsedNavigationFilter(currentFilter);
// Clear the details view // Clear the details view
if (fragmentDetails != null) { if (fragmentDetails != null) {
fragmentDetails.updateIsLoading(false, null); fragmentDetails.updateIsLoading(false, null);
@ -1203,6 +1226,25 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (fragmentDetails != null) if (fragmentDetails != null)
fragmentDetails.updateLabels(lastNavigationLabels); fragmentDetails.updateLabels(lastNavigationLabels);
// Perhaps we were still waiting to preselect the last used filter (on a fresh application start)
if (preselectNavigationFilter != null) {
FilterListAdapter adapter = navigationListAdapter != null ? navigationListAdapter
: navigationSpinnerAdapter;
for (int i = 0; i < adapter.getCount(); i++) {
// Regardless of the navigation style (side list or action bar spinner), we can look up the navigation
// filter item, which is represented as simple list item (and might not exist any more, such as with a
// label that is deleted on the server)
Object item = adapter.getItem(i);
if (item instanceof SimpleListItem && item instanceof NavigationFilter
&& ((NavigationFilter) item).getCode().equals(preselectNavigationFilter)) {
filterSelected((SimpleListItem) item, false);
break;
}
}
// Only preselect after the first update we receive (even if the filter wasn't found any more)
preselectNavigationFilter = null;
}
// Update the server status (counts and speeds) in the action bar // Update the server status (counts and speeds) in the action bar
serverStatusView.update(torrents, systemSettings.treatDormantAsInactive()); serverStatusView.update(torrents, systemSettings.treatDormantAsInactive());

6
core/src/org/transdroid/core/gui/navigation/Label.java

@ -56,6 +56,12 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label
return this.name; return this.name;
} }
@Override
public String getCode() {
// Use the class name and label name to provide a unique navigation filter code
return Label.class.getSimpleName() + "_" + name;
}
public int getCount() { public int getCount() {
return count; return count;
} }

7
core/src/org/transdroid/core/gui/navigation/NavigationFilter.java

@ -42,4 +42,11 @@ public interface NavigationFilter extends Parcelable {
*/ */
String getName(); String getName();
/**
* Implementations should return a code that (within reasonable expectations) uniquely identifies it in the list of
* navigation filters
* @return The code to uniquely identify this specific navigation filter, such as the name with a class name prefix
*/
String getCode();
} }

6
core/src/org/transdroid/core/gui/navigation/StatusType.java

@ -105,6 +105,12 @@ public enum StatusType {
return name; return name;
} }
@Override
public String getCode() {
// Uses the class name and status type enum to provide a unique navigation filter code
return StatusTypeFilter.class.getSimpleName() + "_" + statusType.name();
}
/** /**
* Returns true if the torrent status matches this (selected) status type, false otherwise * Returns true if the torrent status matches this (selected) status type, false otherwise
* @param torrent The torrent to match against this status type * @param torrent The torrent to match against this status type

Loading…
Cancel
Save