Browse Source

Update action bar spinner view on new filter selection.

pull/11/head
Eric Kok 12 years ago
parent
commit
b13d8d7491
  1. 2
      core/res/layout/list_item_navigation.xml
  2. 42
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  3. 12
      core/src/org/transdroid/core/gui/navigation/FilterListAdapter.java
  4. 30
      core/src/org/transdroid/core/gui/navigation/FilterListDropDownAdapter.java
  5. 27
      core/src/org/transdroid/core/gui/navigation/NavigationSelectionView.java

2
core/res/layout/list_item_navigation.xml

@ -20,6 +20,6 @@
android:layout_marginTop="-4dip" android:layout_marginTop="-4dip"
android:textColor="@android:color/primary_text_dark" android:textColor="@android:color/primary_text_dark"
android:textIsSelectable="false" android:textIsSelectable="false"
android:textSize="13sp" /> android:textSize="14sp" />
</LinearLayout> </LinearLayout>

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

@ -21,9 +21,15 @@ import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.lists.SimpleListItem; import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.log.Log_; import org.transdroid.core.gui.log.Log_;
import org.transdroid.core.gui.navigation.*; import org.transdroid.core.gui.navigation.FilterListAdapter;
import org.transdroid.core.gui.navigation.NavigationSelectionView.NavigationFilterManager; import org.transdroid.core.gui.navigation.FilterListAdapter_;
import org.transdroid.core.gui.settings.*; 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.StatusType;
import org.transdroid.core.gui.settings.MainSettingsActivity_;
import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.IDaemonAdapter; import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Torrent; import org.transdroid.daemon.Torrent;
@ -66,8 +72,7 @@ import de.keyboardsurfer.android.widget.crouton.Crouton;
@EActivity(resName = "activity_torrents") @EActivity(resName = "activity_torrents")
@OptionsMenu(resName = "activity_torrents") @OptionsMenu(resName = "activity_torrents")
public class TorrentsActivity extends SherlockFragmentActivity implements OnNavigationListener, TorrentTasksExecutor, public class TorrentsActivity extends SherlockFragmentActivity implements OnNavigationListener, TorrentTasksExecutor {
NavigationFilterManager {
// Navigation components // Navigation components
@Bean @Bean
@ -75,7 +80,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
@ViewById @ViewById
protected SherlockListView filtersList; protected SherlockListView filtersList;
protected FilterListAdapter navigationListAdapter = null; protected FilterListAdapter navigationListAdapter = null;
protected FilterListAdapter navigationSpinnerAdapter = null; protected FilterListDropDownAdapter navigationSpinnerAdapter = null;
@SystemService @SystemService
protected SearchManager searchManager; protected SearchManager searchManager;
@ -105,7 +110,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setHomeButtonEnabled(false); getSupportActionBar().setHomeButtonEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false);
navigationSpinnerAdapter = FilterListDropDownAdapter_.getInstance_(this).setNavigationFilterManager(this); navigationSpinnerAdapter = FilterListDropDownAdapter_.getInstance_(this);
// Servers are always added to the action bar spinner // Servers are always added to the action bar spinner
navigationSpinnerAdapter.updateServers(applicationSettings.getServerSettings()); navigationSpinnerAdapter.updateServers(applicationSettings.getServerSettings());
@ -125,8 +130,8 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
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
getSupportActionBar().setListNavigationCallbacks(navigationSpinnerAdapter, this);
currentFilter = StatusType.getShowAllType(this); currentFilter = StatusType.getShowAllType(this);
getSupportActionBar().setListNavigationCallbacks(navigationSpinnerAdapter, this);
// Log messages from the server daemons using our singleton logger // Log messages from the server daemons using our singleton logger
DLog.setLogger(Log_.getInstance_(this)); DLog.setLogger(Log_.getInstance_(this));
@ -138,7 +143,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
return; return;
} }
// Set this as selection in the action bar spinner; we can use the server setting key since we have stable ids // Set this as selection in the action bar spinner; we can use the server setting key since we have stable ids
// TODO: Does this call the action bar item selection callback? And refreshes?
getSupportActionBar().setSelectedNavigationItem(lastUsed.getOrder()); getSupportActionBar().setSelectedNavigationItem(lastUsed.getOrder());
// Handle any start up intents // Handle any start up intents
@ -160,7 +164,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
updateFragmentVisibility(false); updateFragmentVisibility(false);
return; return;
} }
// TODO: See if this does not mean the refresh is called twice (first in onCreate)
// There is a server know (now): forcefully select it to establish a connection // There is a server know (now): forcefully select it to establish a connection
filterSelected(lastUsed, true); filterSelected(lastUsed, true);
} }
@ -262,7 +265,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (item instanceof ServerSetting) { if (item instanceof ServerSetting) {
ServerSetting server = (ServerSetting) item; ServerSetting server = (ServerSetting) item;
if (currentConnection != null && server.equals(currentConnection.getSettings())) { if (!forceNewConnection && currentConnection != null && server.equals(currentConnection.getSettings())) {
// Already connected to this server; just ask for a refresh instead // Already connected to this server; just ask for a refresh instead
fragmentTorrents.updateIsLoading(true); fragmentTorrents.updateIsLoading(true);
refreshTorrents(); refreshTorrents();
@ -272,7 +275,11 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Update connection to the newly selected server and refresh // Update connection to the newly selected server and refresh
currentConnection = server.createServerAdapter(); currentConnection = server.createServerAdapter();
applicationSettings.setLastUsedServer(server); applicationSettings.setLastUsedServer(server);
// Clear the currently shown list of torrent and perhaps the details navigationSpinnerAdapter.updateCurrentServer(currentConnection);
if (forceNewConnection)
navigationSpinnerAdapter.updateCurrentFilter(currentFilter);
// Clear the currently shown list of torrents and perhaps the details
fragmentTorrents.clear(); fragmentTorrents.clear();
if (fragmentDetails != null) { if (fragmentDetails != null) {
fragmentDetails.clear(); fragmentDetails.clear();
@ -288,6 +295,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (item instanceof NavigationFilter) { if (item instanceof NavigationFilter) {
currentFilter = (NavigationFilter) item; currentFilter = (NavigationFilter) item;
fragmentTorrents.applyFilter(currentFilter); fragmentTorrents.applyFilter(currentFilter);
navigationSpinnerAdapter.updateCurrentFilter(currentFilter);
// Clear the details view // Clear the details view
if (fragmentDetails != null) { if (fragmentDetails != null) {
fragmentDetails.clear(); fragmentDetails.clear();
@ -296,16 +304,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
} }
@Override
public String getActiveFilterText() {
return currentFilter.getName();
}
@Override
public String getActiveServerText() {
return currentConnection.getSettings().getName();
}
/** /**
* Hides the filter list and details fragment's full view if there is no configured connection * Hides the filter list and details fragment's full view if there is no configured connection
* @param hasServerSettings Whether there are server settings available, so we can continue to connect * @param hasServerSettings Whether there are server settings available, so we can continue to connect

12
core/src/org/transdroid/core/gui/navigation/FilterListAdapter.java

@ -7,7 +7,6 @@ import org.androidannotations.annotations.RootContext;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.app.settings.ServerSetting; import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.lists.SimpleListItemAdapter; import org.transdroid.core.gui.lists.SimpleListItemAdapter;
import org.transdroid.core.gui.navigation.NavigationSelectionView.NavigationFilterManager;
import org.transdroid.core.gui.navigation.StatusType.StatusTypeFilter; import org.transdroid.core.gui.navigation.StatusType.StatusTypeFilter;
import android.content.Context; import android.content.Context;
@ -28,21 +27,10 @@ public class FilterListAdapter extends MergeAdapter {
private SimpleListItemAdapter serverItems = null; private SimpleListItemAdapter serverItems = null;
private SimpleListItemAdapter statusTypeItems = null; private SimpleListItemAdapter statusTypeItems = null;
private SimpleListItemAdapter labelItems = null; private SimpleListItemAdapter labelItems = null;
protected NavigationFilterManager navigationFilterManager;
private FilterSeparatorView statusTypeSeparator; private FilterSeparatorView statusTypeSeparator;
private FilterSeparatorView labelSeperator; private FilterSeparatorView labelSeperator;
private FilterSeparatorView serverSeparator; private FilterSeparatorView serverSeparator;
/**
* Stores which screen, or manager, handles navigation selection and display
* @param manager The navigation manager, which knows about the currently selected filter and server
* @return Itself, for method chaining
*/
public FilterListAdapter setNavigationFilterManager(NavigationFilterManager manager) {
this.navigationFilterManager = manager;
return this;
}
/** /**
* Update the list of available servers * Update the list of available servers
* @param servers The new list of available servers * @param servers The new list of available servers

30
core/src/org/transdroid/core/gui/navigation/FilterListDropDownAdapter.java

@ -1,6 +1,7 @@
package org.transdroid.core.gui.navigation; package org.transdroid.core.gui.navigation;
import org.androidannotations.annotations.EBean; import org.androidannotations.annotations.EBean;
import org.transdroid.daemon.IDaemonAdapter;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -13,17 +14,18 @@ import android.view.ViewGroup;
@EBean @EBean
public class FilterListDropDownAdapter extends FilterListAdapter { public class FilterListDropDownAdapter extends FilterListAdapter {
protected NavigationSelectionView navigationSelectionView = null;
private String currentServer = null;
private String currentFilter = null;
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
// This returns the item shown in the spinner // This returns the singleton navigation spinner view
NavigationSelectionView filterItemView; if (navigationSelectionView == null) {
if (convertView == null || !(convertView instanceof NavigationSelectionView)) { navigationSelectionView = NavigationSelectionView_.build(context);
filterItemView = NavigationSelectionView_.build(context).setNavigationFilterManager(navigationFilterManager);
} else {
filterItemView = (NavigationSelectionView) convertView;
} }
filterItemView.bind(); navigationSelectionView.bind(currentServer, currentFilter);
return filterItemView; return navigationSelectionView;
} }
@Override @Override
@ -31,5 +33,17 @@ public class FilterListDropDownAdapter extends FilterListAdapter {
// This returns the item to show in the drop down list // This returns the item to show in the drop down list
return super.getView(position, convertView, parent); return super.getView(position, convertView, parent);
} }
public void updateCurrentFilter(NavigationFilter currentFilter) {
this.currentFilter = currentFilter.getName();
if (navigationSelectionView != null)
navigationSelectionView.bind(this.currentServer, this.currentFilter);
}
public void updateCurrentServer(IDaemonAdapter currentConnection) {
this.currentServer = currentConnection.getSettings().getName();
if (navigationSelectionView != null)
navigationSelectionView.bind(this.currentServer, this.currentFilter);
}
} }

27
core/src/org/transdroid/core/gui/navigation/NavigationSelectionView.java

@ -19,33 +19,18 @@ public class NavigationSelectionView extends LinearLayout {
@ViewById @ViewById
protected TextView serverText; protected TextView serverText;
private NavigationFilterManager navigationFilterManager;
public NavigationSelectionView(Context context) { public NavigationSelectionView(Context context) {
super(context); super(context);
} }
/** /**
* Stores which screen, or manager, handles navigation selection and display * Binds the names of the current connected server and selected filter to this navigation view.
* @param manager The navigation manager, which knows about the currently selected filter and server * @param currentServer The name of the server currently connected to
* @return Itself, for method chaining * @param currentFilter The name of the filter that is currently selected
*/
public NavigationSelectionView setNavigationFilterManager(NavigationFilterManager manager) {
this.navigationFilterManager = manager;
return this;
}
public void bind() {
filterText.setText(navigationFilterManager.getActiveFilterText());
serverText.setText(navigationFilterManager.getActiveServerText());
}
/**
* Interface that the manager of navigation (selecting servers and filters) should implement
*/ */
public interface NavigationFilterManager { public void bind(String currentServer, String currentFilter) {
String getActiveFilterText(); serverText.setText(currentServer);
String getActiveServerText(); filterText.setText(currentFilter);
} }
} }

Loading…
Cancel
Save