Browse Source

Allow quick multi-selection of torrents or files based on whether they are finished.

pull/82/head
Eric Kok 11 years ago
parent
commit
d55301f625
  1. 1
      core/res/values/strings.xml
  2. 13
      core/src/org/transdroid/core/app/settings/ServerSetting.java
  3. 17
      core/src/org/transdroid/core/gui/navigation/SelectionManagerMode.java
  4. 9
      core/src/org/transdroid/core/gui/navigation/SelectionModificationSpinner.java
  5. 23
      lib/src/org/transdroid/daemon/Finishable.java
  6. 18
      lib/src/org/transdroid/daemon/Torrent.java
  7. 18
      lib/src/org/transdroid/daemon/TorrentFile.java

1
core/res/values/strings.xml

@ -85,6 +85,7 @@
<item quantity="other">%1$d files selected</item> <item quantity="other">%1$d files selected</item>
</plurals> </plurals>
<string name="navigation_selectall">Select all</string> <string name="navigation_selectall">Select all</string>
<string name="navigation_selectfinished">Select finished</string>
<string name="navigation_invertselection">Invert selection</string> <string name="navigation_invertselection">Invert selection</string>
<string name="status_status">STATUS: %1$s</string> <string name="status_status">STATUS: %1$s</string>

13
core/src/org/transdroid/core/app/settings/ServerSetting.java

@ -279,14 +279,15 @@ public class ServerSetting implements SimpleListItem {
// The local integer key is converted to the idString string. // The local integer key is converted to the idString string.
// The host name address used is dependent on the network that we are currently connected to (to allow a // The host name address used is dependent on the network that we are currently connected to (to allow a
// distinct connection IP or host name when connected to a local network). // distinct connection IP or host name when connected to a local network).
if (localNetwork != null) if (!TextUtils.isEmpty(localNetwork))
Log.d(caller, "Creating adapter for " + name + " of type " + type.name() + ": connected to " Log.d(caller, "Creating adapter for " + name + " of type " + type.name() + ": connected to "
+ connectedToNetwork + " and configured local network is " + localNetwork); + connectedToNetwork + " and configured local network is " + localNetwork);
return new DaemonSettings(name, type, return new DaemonSettings(name, type,
connectedToNetwork != null && connectedToNetwork.equals(localNetwork) ? localAddress : address, !TextUtils.isEmpty(connectedToNetwork) && !TextUtils.isEmpty(localAddress)
connectedToNetwork != null && connectedToNetwork.equals(localNetwork) ? localPort : port, ssl, && connectedToNetwork.equals(localNetwork) ? localAddress : address,
sslTrustAll, sslTrustKey, folder, useAuthentication, username, password, extraPass, os, downloadDir, !TextUtils.isEmpty(connectedToNetwork) && connectedToNetwork.equals(localNetwork) ? localPort : port,
ftpUrl, ftpPassword, timeout, alarmOnFinishedDownload, alarmOnNewTorrent, Integer.toString(key), ssl, sslTrustAll, sslTrustKey, folder, useAuthentication, username, password, extraPass, os,
isAutoGenerated); downloadDir, ftpUrl, ftpPassword, timeout, alarmOnFinishedDownload, alarmOnNewTorrent,
Integer.toString(key), isAutoGenerated);
} }
} }

17
core/src/org/transdroid/core/gui/navigation/SelectionManagerMode.java

@ -17,6 +17,7 @@
package org.transdroid.core.gui.navigation; package org.transdroid.core.gui.navigation;
import org.transdroid.core.gui.navigation.SelectionModificationSpinner.OnModificationActionSelectedListener; import org.transdroid.core.gui.navigation.SelectionModificationSpinner.OnModificationActionSelectedListener;
import org.transdroid.daemon.Finishable;
import android.util.SparseBooleanArray; import android.util.SparseBooleanArray;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -117,7 +118,7 @@ public class SelectionManagerMode implements MultiChoiceModeListenerCompat, OnMo
* {@link ListView}. * {@link ListView}.
*/ */
@Override @Override
public void selectionAll() { public void selectAll() {
for (int i = 0; i < managedList.getAdapter().getCount(); i++) { for (int i = 0; i < managedList.getAdapter().getCount(); i++) {
if (managedList.getAdapter().isEnabled(i) if (managedList.getAdapter().isEnabled(i)
&& (onlyCheckClass == null || onlyCheckClass.isInstance(managedList.getItemAtPosition(i)))) && (onlyCheckClass == null || onlyCheckClass.isInstance(managedList.getItemAtPosition(i))))
@ -125,4 +126,18 @@ public class SelectionManagerMode implements MultiChoiceModeListenerCompat, OnMo
} }
} }
/**
* Implements the {@link SelectionModificationSpinner}'s select finished command by checking each (enabled) item
* that represents something that is {@link Finishable} and indeed is finished;
*/
@Override
public void selectFinished() {
for (int i = 0; i < managedList.getAdapter().getCount(); i++) {
if (managedList.getAdapter().isEnabled(i)
&& (onlyCheckClass == null || onlyCheckClass.isInstance(managedList.getItemAtPosition(i)))
&& managedList.getItemAtPosition(i) instanceof Finishable)
managedList.setItemChecked(i, ((Finishable) managedList.getItemAtPosition(i)).isFinished());
}
}
} }

9
core/src/org/transdroid/core/gui/navigation/SelectionModificationSpinner.java

@ -66,8 +66,10 @@ public class SelectionModificationSpinner extends Spinner {
@Override @Override
public void setSelection(int position) { public void setSelection(int position) {
if (position == 0) { if (position == 0) {
onModificationActionSelected.selectionAll(); onModificationActionSelected.selectAll();
} else if (position == 1) { } else if (position == 1) {
onModificationActionSelected.selectFinished();
} else if (position == 2) {
onModificationActionSelected.invertSelection(); onModificationActionSelected.invertSelection();
} }
super.setSelection(position); super.setSelection(position);
@ -84,6 +86,7 @@ public class SelectionModificationSpinner extends Spinner {
public SelectionDropDownAdapter(Context context) { public SelectionDropDownAdapter(Context context) {
super(context, android.R.layout.simple_list_item_1, new String[] { super(context, android.R.layout.simple_list_item_1, new String[] {
context.getString(R.string.navigation_selectall), context.getString(R.string.navigation_selectall),
context.getString(R.string.navigation_selectfinished),
context.getString(R.string.navigation_invertselection) }); context.getString(R.string.navigation_invertselection) });
titleView = new TextView(getContext()); titleView = new TextView(getContext());
} }
@ -106,9 +109,9 @@ public class SelectionModificationSpinner extends Spinner {
* Interface to implement if an interface want to respond to selection modification actions. * Interface to implement if an interface want to respond to selection modification actions.
*/ */
public interface OnModificationActionSelectedListener { public interface OnModificationActionSelectedListener {
public void selectAll();
public void selectFinished();
public void invertSelection(); public void invertSelection();
public void selectionAll();
} }
} }

23
lib/src/org/transdroid/daemon/Finishable.java

@ -0,0 +1,23 @@
package org.transdroid.daemon;
/**
* Represents an object that has a notion of being able to start, being in progress and being able to finish, such as
* something that can be downloaded (like a torrent or a torrent file).
* @author erickok
*/
public interface Finishable {
/**
* Whether the represented object has been started, but is not yet finished.
* @return True iif the object (like the data transfer) was started and is in progress, but was not finished yet.
*/
public boolean isStarted();
/**
* Whether the represented object has been finished.
* @return True iif the object (like the data transfer) was finished, which means it is no longer started or in
* progress.
*/
public boolean isFinished();
}

18
lib/src/org/transdroid/daemon/Torrent.java

@ -29,7 +29,7 @@ import android.os.Parcelable;
* @author erickok * @author erickok
* *
*/ */
public final class Torrent implements Parcelable, Comparable<Torrent> { public final class Torrent implements Parcelable, Comparable<Torrent>, Finishable {
final private long id; final private long id;
final private String hash; final private String hash;
@ -207,6 +207,22 @@ public final class Torrent implements Parcelable, Comparable<Torrent> {
return statusCode == TorrentStatus.Seeding && (!dormantAsInactive || rateUpload > 0); return statusCode == TorrentStatus.Seeding && (!dormantAsInactive || rateUpload > 0);
} }
/**
* {@inheritDoc}
*/
@Override
public boolean isStarted() {
return partDone > 0;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isFinished() {
return partDone >= 1;
}
/** /**
* Indicates if the torrent can be paused at this moment * Indicates if the torrent can be paused at this moment
* @return If it can be paused * @return If it can be paused

18
lib/src/org/transdroid/daemon/TorrentFile.java

@ -31,7 +31,7 @@ import android.os.Parcelable;
* @author erickok * @author erickok
* *
*/ */
public final class TorrentFile implements Parcelable, Comparable<TorrentFile> { public final class TorrentFile implements Parcelable, Comparable<TorrentFile>, Finishable {
private final String key; private final String key;
private final String name; private final String name;
@ -142,6 +142,22 @@ public final class TorrentFile implements Parcelable, Comparable<TorrentFile> {
return null; return null;
} }
/**
* {@inheritDoc}
*/
@Override
public boolean isStarted() {
return getPartDone() > 0;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isFinished() {
return getPartDone() >= 1;
}
@Override @Override
public String toString() { public String toString() {
return name; return name;

Loading…
Cancel
Save