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

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

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.transdroid.core.gui.navigation;
import java.security.InvalidParameterException;
import java.util.Iterator;
import java.util.List;
import org.transdroid.core.R;
@ -64,7 +65,12 @@ public class SetLabelDialog extends DialogFragment { @@ -64,7 +65,12 @@ public class SetLabelDialog extends DialogFragment {
* @param currentLabels The list of torrent labels
* @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;
return this;
}

Loading…
Cancel
Save