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

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

@ -21,9 +21,15 @@ import org.transdroid.core.gui.lists.LocalTorrent; @@ -21,9 +21,15 @@ import org.transdroid.core.gui.lists.LocalTorrent;
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.navigation.*;
import org.transdroid.core.gui.navigation.NavigationSelectionView.NavigationFilterManager;
import org.transdroid.core.gui.settings.*;
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.StatusType;
import org.transdroid.core.gui.settings.MainSettingsActivity_;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Torrent;
@ -66,8 +72,7 @@ import de.keyboardsurfer.android.widget.crouton.Crouton; @@ -66,8 +72,7 @@ import de.keyboardsurfer.android.widget.crouton.Crouton;
@EActivity(resName = "activity_torrents")
@OptionsMenu(resName = "activity_torrents")
public class TorrentsActivity extends SherlockFragmentActivity implements OnNavigationListener, TorrentTasksExecutor,
NavigationFilterManager {
public class TorrentsActivity extends SherlockFragmentActivity implements OnNavigationListener, TorrentTasksExecutor {
// Navigation components
@Bean
@ -75,7 +80,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -75,7 +80,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
@ViewById
protected SherlockListView filtersList;
protected FilterListAdapter navigationListAdapter = null;
protected FilterListAdapter navigationSpinnerAdapter = null;
protected FilterListDropDownAdapter navigationSpinnerAdapter = null;
@SystemService
protected SearchManager searchManager;
@ -105,7 +110,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -105,7 +110,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setHomeButtonEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);
navigationSpinnerAdapter = FilterListDropDownAdapter_.getInstance_(this).setNavigationFilterManager(this);
navigationSpinnerAdapter = FilterListDropDownAdapter_.getInstance_(this);
// Servers are always added to the action bar spinner
navigationSpinnerAdapter.updateServers(applicationSettings.getServerSettings());
@ -125,8 +130,8 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -125,8 +130,8 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
navigationSpinnerAdapter.updateLabels(new ArrayList<Label>());
}
// Now that all items (or at least their adapters) have been added
getSupportActionBar().setListNavigationCallbacks(navigationSpinnerAdapter, this);
currentFilter = StatusType.getShowAllType(this);
getSupportActionBar().setListNavigationCallbacks(navigationSpinnerAdapter, this);
// Log messages from the server daemons using our singleton logger
DLog.setLogger(Log_.getInstance_(this));
@ -138,7 +143,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -138,7 +143,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
return;
}
// 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());
// Handle any start up intents
@ -160,7 +164,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -160,7 +164,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
updateFragmentVisibility(false);
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
filterSelected(lastUsed, true);
}
@ -262,7 +265,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -262,7 +265,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (item instanceof ServerSetting) {
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
fragmentTorrents.updateIsLoading(true);
refreshTorrents();
@ -272,7 +275,11 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -272,7 +275,11 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Update connection to the newly selected server and refresh
currentConnection = server.createServerAdapter();
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();
if (fragmentDetails != null) {
fragmentDetails.clear();
@ -288,6 +295,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -288,6 +295,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (item instanceof NavigationFilter) {
currentFilter = (NavigationFilter) item;
fragmentTorrents.applyFilter(currentFilter);
navigationSpinnerAdapter.updateCurrentFilter(currentFilter);
// Clear the details view
if (fragmentDetails != null) {
fragmentDetails.clear();
@ -296,16 +304,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -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
* @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; @@ -7,7 +7,6 @@ import org.androidannotations.annotations.RootContext;
import org.transdroid.core.R;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.lists.SimpleListItemAdapter;
import org.transdroid.core.gui.navigation.NavigationSelectionView.NavigationFilterManager;
import org.transdroid.core.gui.navigation.StatusType.StatusTypeFilter;
import android.content.Context;
@ -28,21 +27,10 @@ public class FilterListAdapter extends MergeAdapter { @@ -28,21 +27,10 @@ public class FilterListAdapter extends MergeAdapter {
private SimpleListItemAdapter serverItems = null;
private SimpleListItemAdapter statusTypeItems = null;
private SimpleListItemAdapter labelItems = null;
protected NavigationFilterManager navigationFilterManager;
private FilterSeparatorView statusTypeSeparator;
private FilterSeparatorView labelSeperator;
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
* @param servers The new list of available servers

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

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
package org.transdroid.core.gui.navigation;
import org.androidannotations.annotations.EBean;
import org.transdroid.daemon.IDaemonAdapter;
import android.view.View;
import android.view.ViewGroup;
@ -13,17 +14,18 @@ import android.view.ViewGroup; @@ -13,17 +14,18 @@ import android.view.ViewGroup;
@EBean
public class FilterListDropDownAdapter extends FilterListAdapter {
protected NavigationSelectionView navigationSelectionView = null;
private String currentServer = null;
private String currentFilter = null;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// This returns the item shown in the spinner
NavigationSelectionView filterItemView;
if (convertView == null || !(convertView instanceof NavigationSelectionView)) {
filterItemView = NavigationSelectionView_.build(context).setNavigationFilterManager(navigationFilterManager);
} else {
filterItemView = (NavigationSelectionView) convertView;
// This returns the singleton navigation spinner view
if (navigationSelectionView == null) {
navigationSelectionView = NavigationSelectionView_.build(context);
}
filterItemView.bind();
return filterItemView;
navigationSelectionView.bind(currentServer, currentFilter);
return navigationSelectionView;
}
@Override
@ -32,4 +34,16 @@ public class FilterListDropDownAdapter extends FilterListAdapter { @@ -32,4 +34,16 @@ public class FilterListDropDownAdapter extends FilterListAdapter {
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 { @@ -19,33 +19,18 @@ public class NavigationSelectionView extends LinearLayout {
@ViewById
protected TextView serverText;
private NavigationFilterManager navigationFilterManager;
public NavigationSelectionView(Context context) {
super(context);
}
/**
* 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 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
* Binds the names of the current connected server and selected filter to this navigation view.
* @param currentServer The name of the server currently connected to
* @param currentFilter The name of the filter that is currently selected
*/
public interface NavigationFilterManager {
String getActiveFilterText();
String getActiveServerText();
public void bind(String currentServer, String currentFilter) {
serverText.setText(currentServer);
filterText.setText(currentFilter);
}
}

Loading…
Cancel
Save