Browse Source

rTorrent adapter should return the labels that it encountered during torrents retrieval.

pull/11/head
Eric Kok 12 years ago
parent
commit
fb9f19500f
  1. 4
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  2. 23
      core/src/org/transdroid/core/gui/navigation/FilterListAdapter.java
  3. 15
      core/src/org/transdroid/core/gui/navigation/Label.java
  4. 22
      lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java

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

@ -109,8 +109,10 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
navigationSpinnerAdapter = FilterListDropDownAdapter_.getInstance_(this).setNavigationFilterManager(this); navigationSpinnerAdapter = FilterListDropDownAdapter_.getInstance_(this).setNavigationFilterManager(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());
// Check if there was room for a dedicated filter list (i.e. on tablets)
if (filtersList != null) { if (filtersList != null) {
// There was room for a dedicated filter list; create adapter and add the status types // Create dedicated side list adapter and add the status types
navigationListAdapter = FilterListAdapter_.getInstance_(this); navigationListAdapter = FilterListAdapter_.getInstance_(this);
navigationListAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this)); navigationListAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this));
// 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)

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

@ -10,6 +10,7 @@ import org.transdroid.core.gui.lists.SimpleListItemAdapter;
import org.transdroid.core.gui.navigation.NavigationSelectionView.NavigationFilterManager; import org.transdroid.core.gui.navigation.NavigationSelectionView.NavigationFilterManager;
import android.content.Context; import android.content.Context;
import android.view.View;
import com.commonsware.cwac.merge.MergeAdapter; import com.commonsware.cwac.merge.MergeAdapter;
@ -27,6 +28,9 @@ public class FilterListAdapter extends MergeAdapter {
private SimpleListItemAdapter statusTypeItems = null; private SimpleListItemAdapter statusTypeItems = null;
private SimpleListItemAdapter labelItems = null; private SimpleListItemAdapter labelItems = null;
protected NavigationFilterManager navigationFilterManager; protected NavigationFilterManager navigationFilterManager;
private FilterSeparatorView statusTypeSeparator;
private FilterSeparatorView labelSeperator;
private FilterSeparatorView serverSeparator;
/** /**
* Stores which screen, or manager, handles navigation selection and display * Stores which screen, or manager, handles navigation selection and display
@ -44,12 +48,16 @@ public class FilterListAdapter extends MergeAdapter {
*/ */
public void updateServers(List<? extends SimpleListItem> servers) { public void updateServers(List<? extends SimpleListItem> servers) {
if (this.serverItems == null && servers != null) { if (this.serverItems == null && servers != null) {
addView(FilterSeparatorView_.build(context).setText(context.getString(R.string.navigation_servers)), false); serverSeparator = FilterSeparatorView_.build(context).setText(context.getString(R.string.navigation_servers));
serverSeparator.setVisibility(serverItems.isEmpty()? View.GONE: View.VISIBLE);
addView(serverSeparator, false);
this.serverItems = new SimpleListItemAdapter(context, servers); this.serverItems = new SimpleListItemAdapter(context, servers);
addAdapter(serverItems); addAdapter(serverItems);
} else if (this.serverItems != null && servers != null) { } else if (this.serverItems != null && servers != null) {
serverSeparator.setVisibility(serverItems.isEmpty()? View.GONE: View.VISIBLE);
this.serverItems.update(servers); this.serverItems.update(servers);
} else { } else {
serverSeparator.setVisibility(View.GONE);
this.serverItems = null; this.serverItems = null;
} }
} }
@ -60,12 +68,17 @@ public class FilterListAdapter extends MergeAdapter {
*/ */
public void updateStatusTypes(List<? extends SimpleListItem> statusTypes) { public void updateStatusTypes(List<? extends SimpleListItem> statusTypes) {
if (this.statusTypeItems == null && statusTypes != null) { if (this.statusTypeItems == null && statusTypes != null) {
addView(FilterSeparatorView_.build(context).setText(context.getString(R.string.navigation_status)), false); statusTypeSeparator = FilterSeparatorView_.build(context).setText(
context.getString(R.string.navigation_status));
statusTypeSeparator.setVisibility(statusTypeItems.isEmpty()? View.GONE: View.VISIBLE);
addView(statusTypeSeparator, false);
this.statusTypeItems = new SimpleListItemAdapter(context, statusTypes); this.statusTypeItems = new SimpleListItemAdapter(context, statusTypes);
addAdapter(statusTypeItems); addAdapter(statusTypeItems);
} else if (this.statusTypeItems != null && statusTypes != null) { } else if (this.statusTypeItems != null && statusTypes != null) {
statusTypeSeparator.setVisibility(statusTypeItems.isEmpty()? View.GONE: View.VISIBLE);
this.statusTypeItems.update(statusTypes); this.statusTypeItems.update(statusTypes);
} else { } else {
statusTypeSeparator.setVisibility(View.GONE);
this.statusTypeItems = null; this.statusTypeItems = null;
} }
} }
@ -76,12 +89,16 @@ public class FilterListAdapter extends MergeAdapter {
*/ */
public void updateLabels(List<? extends SimpleListItem> labels) { public void updateLabels(List<? extends SimpleListItem> labels) {
if (this.labelItems == null && labels != null) { if (this.labelItems == null && labels != null) {
addView(FilterSeparatorView_.build(context).setText(context.getString(R.string.navigation_labels)), false); labelSeperator = FilterSeparatorView_.build(context).setText(context.getString(R.string.navigation_labels));
labelSeperator.setVisibility(labelItems.isEmpty()? View.GONE: View.VISIBLE);
addView(labelSeperator, false);
this.labelItems = new SimpleListItemAdapter(context, labels); this.labelItems = new SimpleListItemAdapter(context, labels);
addAdapter(labelItems); addAdapter(labelItems);
} else if (this.serverItems != null && labels != null) { } else if (this.serverItems != null && labels != null) {
labelSeperator.setVisibility(labelItems.isEmpty()? View.GONE: View.VISIBLE);
this.labelItems.update(labels); this.labelItems.update(labels);
} else { } else {
labelSeperator.setVisibility(View.GONE);
this.labelItems = null; this.labelItems = null;
} }
} }

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

@ -1,5 +1,8 @@
package org.transdroid.core.gui.navigation; package org.transdroid.core.gui.navigation;
import java.util.ArrayList;
import java.util.List;
import org.transdroid.core.gui.lists.SimpleListItem; import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.daemon.Torrent; import org.transdroid.daemon.Torrent;
@ -10,7 +13,7 @@ import android.os.Parcelable;
* Represents some label that is active or available on the server. * Represents some label that is active or available on the server.
* @author Eric Kok * @author Eric Kok
*/ */
public class Label implements SimpleListItem, NavigationFilter { public class Label extends org.transdroid.daemon.Label implements SimpleListItem, NavigationFilter {
private final String name; private final String name;
@ -28,6 +31,16 @@ public class Label implements SimpleListItem, NavigationFilter {
return torrent.getLabelName() != null && torrent.getLabelName().equals(name); return torrent.getLabelName() != null && torrent.getLabelName().equals(name);
} }
public static List<Label> convertToNavigationLabels(List<org.transdroid.daemon.Label> daemonLabels) {
if (daemonLabels == null)
return null;
List<Label> localLabels = new ArrayList<Label>();
for (org.transdroid.daemon.Label label : daemonLabels) {
localLabels.add(new Label(label.getName()));
}
return localLabels;
}
private Label(Parcel in) { private Label(Parcel in) {
this.name = in.readString(); this.name = in.readString();
} }

22
lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java

@ -27,13 +27,17 @@ import java.net.URI;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.base64.android.Base64; import org.base64.android.Base64;
import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.DaemonException; import org.transdroid.daemon.DaemonException;
import org.transdroid.daemon.DaemonSettings; import org.transdroid.daemon.DaemonSettings;
import org.transdroid.daemon.IDaemonAdapter; import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Label;
import org.transdroid.daemon.Priority; import org.transdroid.daemon.Priority;
import org.transdroid.daemon.Torrent; import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentDetails; import org.transdroid.daemon.TorrentDetails;
@ -77,6 +81,7 @@ public class RtorrentAdapter implements IDaemonAdapter {
private DaemonSettings settings; private DaemonSettings settings;
private XMLRPCClient rpcclient; private XMLRPCClient rpcclient;
private List<Label> lastKnownLabels = null;
public RtorrentAdapter(DaemonSettings settings) { public RtorrentAdapter(DaemonSettings settings) {
this.settings = settings; this.settings = settings;
@ -90,7 +95,7 @@ public class RtorrentAdapter implements IDaemonAdapter {
case Retrieve: case Retrieve:
Object result = makeRtorrentCall("d.multicall", new String[] { "main", "d.get_hash=", "d.get_name=", "d.get_state=", "d.get_down_rate=", "d.get_up_rate=", "d.get_peers_connected=", "d.get_peers_not_connected=", "d.get_peers_accounted=", "d.get_bytes_done=", "d.get_up_total=", "d.get_size_bytes=", "d.get_creation_date=", "d.get_left_bytes=", "d.get_complete=", "d.is_active=", "d.is_hash_checking=", "d.get_base_path=", "d.get_base_filename=", "d.get_message=", "d.get_custom=addtime", "d.get_custom=seedingtime", "d.get_custom1=" }); Object result = makeRtorrentCall("d.multicall", new String[] { "main", "d.get_hash=", "d.get_name=", "d.get_state=", "d.get_down_rate=", "d.get_up_rate=", "d.get_peers_connected=", "d.get_peers_not_connected=", "d.get_peers_accounted=", "d.get_bytes_done=", "d.get_up_total=", "d.get_size_bytes=", "d.get_creation_date=", "d.get_left_bytes=", "d.get_complete=", "d.is_active=", "d.is_hash_checking=", "d.get_base_path=", "d.get_base_filename=", "d.get_message=", "d.get_custom=addtime", "d.get_custom=seedingtime", "d.get_custom1=" });
return new RetrieveTaskSuccessResult((RetrieveTask) task, onTorrentsRetrieved(result),null); return new RetrieveTaskSuccessResult((RetrieveTask) task, onTorrentsRetrieved(result), lastKnownLabels);
case GetTorrentDetails: case GetTorrentDetails:
@ -277,10 +282,8 @@ public class RtorrentAdapter implements IDaemonAdapter {
// Parse torrent list from response // Parse torrent list from response
// Formatted as Object[][], see http://libtorrent.rakshasa.no/wiki/RTorrentCommands#Download // Formatted as Object[][], see http://libtorrent.rakshasa.no/wiki/RTorrentCommands#Download
// 'Labels' are supported in rTorrent as 'groups' that can become the 'active view';
// support for this is not trivial since it requires multiple calls to get all the info at best
// (if it is even feasible with the current approach)
List<Torrent> torrents = new ArrayList<Torrent>(); List<Torrent> torrents = new ArrayList<Torrent>();
Map<String, Integer> labels = new HashMap<String, Integer>();
Object[] responseList = (Object[]) response; Object[] responseList = (Object[]) response;
for (int i = 0; i < responseList.length; i++) { for (int i = 0; i < responseList.length; i++) {
@ -323,7 +326,13 @@ public class RtorrentAdapter implements IDaemonAdapter {
String label = null; String label = null;
try { try {
label = URLDecoder.decode((String)info[21], "UTF-8"); label = URLDecoder.decode((String)info[21], "UTF-8");
if (labels.containsKey(label)) {
labels.put(label, labels.get(label) + 1);
} else {
labels.put(label, 0);
}
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
// Can't decode label name; ignore it
} }
if (info[3] instanceof Long) { if (info[3] instanceof Long) {
@ -388,6 +397,11 @@ public class RtorrentAdapter implements IDaemonAdapter {
} }
} }
lastKnownLabels = new ArrayList<Label>();
for (Entry<String, Integer> pair : labels.entrySet()) {
if (pair.getKey() != null)
lastKnownLabels.add(new Label(pair.getKey(), pair.getValue()));
}
return torrents; return torrents;
} }

Loading…
Cancel
Save