Browse Source

Show/hide menu options depending on the connected server type.

pull/11/head
Eric Kok 11 years ago
parent
commit
940ce5fad8
  1. 2
      core/res/menu/fragment_details.xml
  2. 10
      core/res/menu/fragment_torrents_cab.xml
  3. 5
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  4. 26
      core/src/org/transdroid/core/gui/TorrentsFragment.java

2
core/res/menu/fragment_details.xml

@ -32,7 +32,7 @@
android:id="@+id/action_start" android:id="@+id/action_start"
android:icon="?attr/ic_action_start" android:icon="?attr/ic_action_start"
android:showAsAction="ifRoom" android:showAsAction="ifRoom"
android:title="@string/action_start" android:title="@string/action_start_default"
android:orderInCategory="202"> android:orderInCategory="202">
<menu> <menu>
<item android:id="@+id/action_start_default" android:title="@string/action_start_default" /> <item android:id="@+id/action_start_default" android:title="@string/action_start_default" />

10
core/res/menu/fragment_torrents_cab.xml

@ -26,6 +26,16 @@
android:icon="?attr/ic_action_pause" android:icon="?attr/ic_action_pause"
android:showAsAction="always" android:showAsAction="always"
android:title="@string/action_pause" /> android:title="@string/action_pause" />
<item
android:id="@+id/action_start"
android:icon="?attr/ic_action_start"
android:showAsAction="always"
android:title="@string/action_start" />
<item
android:id="@+id/action_stop"
android:icon="?attr/ic_action_stop"
android:showAsAction="always"
android:title="@string/action_stop" />
<item <item
android:id="@+id/action_remove" android:id="@+id/action_remove"
android:icon="?attr/ic_action_remove" android:icon="?attr/ic_action_remove"

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

@ -288,7 +288,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
menu.findItem(R.id.action_settings).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); menu.findItem(R.id.action_settings).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.findItem(R.id.action_help).setVisible(true); menu.findItem(R.id.action_help).setVisible(true);
if (fragmentTorrents != null) if (fragmentTorrents != null)
fragmentTorrents.updateConnectionStatus(false); fragmentTorrents.updateConnectionStatus(false, null);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
return true; return true;
} }
@ -302,11 +302,12 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
menu.findItem(R.id.action_disableturtle).setVisible(hasAltMode && turleModeEnabled); menu.findItem(R.id.action_disableturtle).setVisible(hasAltMode && turleModeEnabled);
menu.findItem(R.id.action_refresh).setVisible(true); menu.findItem(R.id.action_refresh).setVisible(true);
menu.findItem(R.id.action_sort).setVisible(true); menu.findItem(R.id.action_sort).setVisible(true);
menu.findItem(R.id.action_sort_added).setVisible(Daemon.supportsDateAdded(currentConnection.getType()));
menu.findItem(R.id.action_filter).setVisible(true); menu.findItem(R.id.action_filter).setVisible(true);
menu.findItem(R.id.action_settings).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); menu.findItem(R.id.action_settings).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.findItem(R.id.action_help).setVisible(false); menu.findItem(R.id.action_help).setVisible(false);
if (fragmentTorrents != null) if (fragmentTorrents != null)
fragmentTorrents.updateConnectionStatus(true); fragmentTorrents.updateConnectionStatus(true, currentConnection.getType());
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
return true; return true;

26
core/src/org/transdroid/core/gui/TorrentsFragment.java

@ -84,6 +84,8 @@ public class TorrentsFragment extends SherlockFragment implements OnLabelPickedL
protected boolean isLoading = true; protected boolean isLoading = true;
@InstanceState @InstanceState
protected String connectionErrorMessage = null; protected String connectionErrorMessage = null;
@InstanceState
protected Daemon daemonType;
// Views // Views
@ViewById(resName = "torrent_list") @ViewById(resName = "torrent_list")
@ -222,7 +224,14 @@ public class TorrentsFragment extends SherlockFragment implements OnLabelPickedL
@Override @Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return selectionManagerMode.onPrepareActionMode(mode, menu); selectionManagerMode.onPrepareActionMode(mode, menu);
// Hide/show options depending on the type of server we are connected to
if (daemonType != null) {
menu.findItem(R.id.action_start).setVisible(Daemon.supportsStoppingStarting(daemonType));
menu.findItem(R.id.action_stop).setVisible(Daemon.supportsStoppingStarting(daemonType));
menu.findItem(R.id.action_setlabel).setVisible(Daemon.supportsSetLabel(daemonType));
}
return true;
} }
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
@ -248,6 +257,18 @@ public class TorrentsFragment extends SherlockFragment implements OnLabelPickedL
} }
mode.finish(); mode.finish();
return true; return true;
} else if (itemId == R.id.action_start) {
for (Torrent torrent : checked) {
getTasksExecutor().startTorrent(torrent, false);
}
mode.finish();
return true;
} else if (itemId == R.id.action_stop) {
for (Torrent torrent : checked) {
getTasksExecutor().stopTorrent(torrent);
}
mode.finish();
return true;
} else if (itemId == R.id.action_remove_default) { } else if (itemId == R.id.action_remove_default) {
for (Torrent torrent : checked) { for (Torrent torrent : checked) {
getTasksExecutor().removeTorrent(torrent, false); getTasksExecutor().removeTorrent(torrent, false);
@ -300,8 +321,9 @@ public class TorrentsFragment extends SherlockFragment implements OnLabelPickedL
* need to show a message suggesting help). This should only ever be called on the UI thread. * need to show a message suggesting help). This should only ever be called on the UI thread.
* @param hasAConnection True if the user has servers configured and therefore has a connection that can be used * @param hasAConnection True if the user has servers configured and therefore has a connection that can be used
*/ */
public void updateConnectionStatus(boolean hasAConnection) { public void updateConnectionStatus(boolean hasAConnection, Daemon daemonType) {
this.hasAConnection = hasAConnection; this.hasAConnection = hasAConnection;
this.daemonType = daemonType;
if (!hasAConnection) { if (!hasAConnection) {
clear(true, true); // Indirectly also calls updateViewVisibility() clear(true, true); // Indirectly also calls updateViewVisibility()
} else { } else {

Loading…
Cancel
Save