Browse Source

Add the empty ('Unlabeled') label in the filter list. Fixes #39.

pull/82/head
Eric Kok 11 years ago
parent
commit
51daf887ae
  1. 21
      core/src/org/transdroid/core/gui/navigation/Label.java
  2. 8
      core/src/org/transdroid/core/gui/navigation/SetLabelDialog.java

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

@ -35,12 +35,18 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label
private static String unnamedLabelText = null; private static String unnamedLabelText = null;
private final boolean isEmptyLabel;
private final String name; private final String name;
private final int count; private final int count;
private Label(String name, int count, boolean isEmptyLabel) {
this.name = name;
this.count = count;
this.isEmptyLabel = isEmptyLabel;
}
public Label(org.transdroid.daemon.Label daemonLabel) { public Label(org.transdroid.daemon.Label daemonLabel) {
this.name = daemonLabel.getName(); this(daemonLabel.getName(), daemonLabel.getCount(), false);
this.count = daemonLabel.getCount();
} }
@Override @Override
@ -54,11 +60,17 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label
return count; return count;
} }
public boolean isEmptyLabel() {
return isEmptyLabel;
}
/** /**
* Returns true if the torrent label's name matches this (selected) label's name, false otherwise * Returns true if the torrent label's name matches this (selected) label's name, false otherwise
*/ */
@Override @Override
public boolean matches(Torrent torrent) { public boolean matches(Torrent torrent) {
if (isEmptyLabel)
return TextUtils.isEmpty(torrent.getLabelName());
return torrent.getLabelName() != null && torrent.getLabelName().equals(name); return torrent.getLabelName() != null && torrent.getLabelName().equals(name);
} }
@ -78,8 +90,9 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label
String unnamedLabel) { String unnamedLabel) {
if (daemonLabels == null) if (daemonLabels == null)
return null; return null;
unnamedLabelText = unnamedLabel;
ArrayList<Label> localLabels = new ArrayList<Label>(); ArrayList<Label> localLabels = new ArrayList<Label>();
unnamedLabelText = unnamedLabel;
localLabels.add(new Label(unnamedLabel, -1, true));
for (org.transdroid.daemon.Label label : daemonLabels) { for (org.transdroid.daemon.Label label : daemonLabels) {
localLabels.add(new Label(label)); localLabels.add(new Label(label));
} }
@ -90,6 +103,7 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label
private Label(Parcel in) { private Label(Parcel in) {
this.name = in.readString(); this.name = in.readString();
this.count = in.readInt(); this.count = in.readInt();
this.isEmptyLabel = in.readInt() == 1;
} }
public static final Parcelable.Creator<Label> CREATOR = new Parcelable.Creator<Label>() { public static final Parcelable.Creator<Label> CREATOR = new Parcelable.Creator<Label>() {
@ -111,6 +125,7 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name); dest.writeString(name);
dest.writeInt(count); dest.writeInt(count);
dest.writeInt(isEmptyLabel? 1: 0);
} }
} }

8
core/src/org/transdroid/core/gui/navigation/SetLabelDialog.java

@ -17,6 +17,7 @@
package org.transdroid.core.gui.navigation; package org.transdroid.core.gui.navigation;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.transdroid.core.R; import org.transdroid.core.R;
@ -64,7 +65,12 @@ public class SetLabelDialog extends DialogFragment {
* @param currentLabels The list of torrent labels * @param currentLabels The list of torrent labels
* @return This dialog, for method chaining * @return This dialog, for method chaining
*/ */
public SetLabelDialog setCurrentLabels(List<? extends SimpleListItem> currentLabels) { public SetLabelDialog setCurrentLabels(List<Label> currentLabels) {
// Discard the empty label in this list before storing it locally
for (Iterator<Label> iter = currentLabels.iterator(); iter.hasNext();) {
if (iter.next().isEmptyLabel())
iter.remove();
}
this.currentLabels = currentLabels; this.currentLabels = currentLabels;
return this; return this;
} }

Loading…
Cancel
Save