Browse Source

Finilized and fixed the dummy adapter.

pull/11/head
Eric Kok 12 years ago
parent
commit
dcf90270e4
  1. BIN
      core/libs/transdroid-connect.jar
  2. 41
      lib/src/org/transdroid/daemon/DummyAdapter.java
  3. 6
      lib/src/org/transdroid/daemon/Torrent.java

BIN
core/libs/transdroid-connect.jar

Binary file not shown.

41
lib/src/org/transdroid/daemon/DummyAdapter.java

@ -35,12 +35,17 @@ import org.transdroid.daemon.task.DaemonTaskResult;
import org.transdroid.daemon.task.DaemonTaskSuccessResult; import org.transdroid.daemon.task.DaemonTaskSuccessResult;
import org.transdroid.daemon.task.GetFileListTask; import org.transdroid.daemon.task.GetFileListTask;
import org.transdroid.daemon.task.GetFileListTaskSuccessResult; import org.transdroid.daemon.task.GetFileListTaskSuccessResult;
import org.transdroid.daemon.task.GetStatsTask;
import org.transdroid.daemon.task.GetStatsTaskSuccessResult;
import org.transdroid.daemon.task.GetTorrentDetailsTask; import org.transdroid.daemon.task.GetTorrentDetailsTask;
import org.transdroid.daemon.task.GetTorrentDetailsTaskSuccessResult; import org.transdroid.daemon.task.GetTorrentDetailsTaskSuccessResult;
import org.transdroid.daemon.task.RetrieveTask; import org.transdroid.daemon.task.RetrieveTask;
import org.transdroid.daemon.task.RetrieveTaskSuccessResult; import org.transdroid.daemon.task.RetrieveTaskSuccessResult;
import org.transdroid.daemon.task.SetAlternativeModeTask;
import org.transdroid.daemon.task.SetDownloadLocationTask;
import org.transdroid.daemon.task.SetFilePriorityTask; import org.transdroid.daemon.task.SetFilePriorityTask;
import org.transdroid.daemon.task.SetLabelTask; import org.transdroid.daemon.task.SetLabelTask;
import org.transdroid.daemon.task.SetTrackersTask;
import org.transdroid.daemon.util.DLog; import org.transdroid.daemon.util.DLog;
import android.net.Uri; import android.net.Uri;
@ -57,6 +62,9 @@ public class DummyAdapter implements IDaemonAdapter {
private DaemonSettings settings; private DaemonSettings settings;
private List<Torrent> dummyTorrents; private List<Torrent> dummyTorrents;
private List<Label> dummyLabels; private List<Label> dummyLabels;
private boolean alternativeModeEnabled = false;
private List<String> trackersList = new ArrayList<String>(Arrays.asList("udp://tracker.com/announce:80",
"https://torrents.org/announce:443"));
/** /**
* Initialises a dummy adapter with some dummy data that may be manipulated. * Initialises a dummy adapter with some dummy data that may be manipulated.
@ -69,14 +77,14 @@ public class DummyAdapter implements IDaemonAdapter {
String[] labels = new String[] { "docs", "books", "isos", "music", "software" }; String[] labels = new String[] { "docs", "books", "isos", "music", "software" };
TorrentStatus[] statuses = new TorrentStatus[] { TorrentStatus.Seeding, TorrentStatus.Downloading, TorrentStatus.Paused, TorrentStatus.Queued, TorrentStatus.Downloading, TorrentStatus.Seeding, TorrentStatus.Error }; TorrentStatus[] statuses = new TorrentStatus[] { TorrentStatus.Seeding, TorrentStatus.Downloading, TorrentStatus.Paused, TorrentStatus.Queued, TorrentStatus.Downloading, TorrentStatus.Seeding, TorrentStatus.Error };
Random random = new Random(); Random random = new Random();
for (int i = 0; i < 25; i++) { for (int i = 1; i < 26; i++) {
String name = names[i % names.length] + Integer.toString(i); String name = names[i % names.length] + Integer.toString(i);
TorrentStatus status = statuses[i % statuses.length]; TorrentStatus status = statuses[i % statuses.length];
int peersGetting = status == TorrentStatus.Downloading ? i * random.nextInt(16) : 0; int peersGetting = status == TorrentStatus.Downloading ? i * random.nextInt(16) : 0;
int peersSending = status == TorrentStatus.Downloading ? i * random.nextInt(16) : 0; int peersSending = status == TorrentStatus.Downloading ? i * random.nextInt(16) : 0;
long size = (long) (1024D * 1024D * 1024D * i * random.nextDouble()); long size = (long) (1024D * 1024D * 1024D * i * random.nextDouble());
long left = status == TorrentStatus.Downloading ? (long) ((double)(size) / random.nextDouble()) : 0; long left = status == TorrentStatus.Downloading ? (long) (size * random.nextDouble()) : 0;
int rateDownload = status == TorrentStatus.Downloading ? (int) (1024D * 1024D * i * random.nextDouble()) int rateDownload = status == TorrentStatus.Downloading ? (int) (1024D * 100D * i * random.nextDouble())
: 0; : 0;
int rateUpload = status == TorrentStatus.Downloading || status == TorrentStatus.Seeding ? (int) (1024D * 1024D * i * random int rateUpload = status == TorrentStatus.Downloading || status == TorrentStatus.Seeding ? (int) (1024D * 1024D * i * random
.nextDouble()) : 0; .nextDouble()) : 0;
@ -96,7 +104,7 @@ public class DummyAdapter implements IDaemonAdapter {
(int) (status == TorrentStatus.Downloading? (int) (status == TorrentStatus.Downloading?
left / rateDownload: 0), // Eta left / rateDownload: 0), // Eta
size - left, size - left,
(long)((double)(size - left * 2) * random.nextDouble()), // Up to twice the amount downloaded (long)((double)(size - left) * 3D * random.nextDouble()), // Up to 3 times the amount downloaded
size, size,
(float)(size - left) / size, // Part done (float)(size - left) / size, // Part done
1F, // Always 100% available 1F, // Always 100% available
@ -108,8 +116,7 @@ public class DummyAdapter implements IDaemonAdapter {
settings.getType())); settings.getType()));
} }
for (String label : labels) { for (String label : labels) {
// TODO: // Add count? dummyLabels.add(new Label(label, 5));
dummyLabels.add(new Label(label, 0));
} }
} }
@ -125,7 +132,7 @@ public class DummyAdapter implements IDaemonAdapter {
case GetTorrentDetails: case GetTorrentDetails:
return new GetTorrentDetailsTaskSuccessResult((GetTorrentDetailsTask) task, new TorrentDetails( return new GetTorrentDetailsTaskSuccessResult((GetTorrentDetailsTask) task, new TorrentDetails(
Arrays.asList("udp://tracker.com/announce:80", "https://torrents.org/announce:443"), trackersList,
task.getTargetTorrent().getStatusCode() == TorrentStatus.Error ? task.getTargetTorrent().getStatusCode() == TorrentStatus.Error ?
Arrays.asList("Trackers not working.", "Files not available.") : null)); Arrays.asList("Trackers not working.", "Files not available.") : null));
@ -133,8 +140,8 @@ public class DummyAdapter implements IDaemonAdapter {
Torrent t = task.getTargetTorrent(); Torrent t = task.getTargetTorrent();
List<TorrentFile> dummyFiles = new ArrayList<TorrentFile>(); List<TorrentFile> dummyFiles = new ArrayList<TorrentFile>();
Priority priorities[] = new Priority[] { Priority.Normal, Priority.High, Priority.High, Priority.Low, Priority.Normal }; Priority priorities[] = new Priority[] { Priority.Normal, Priority.Normal, Priority.High, Priority.Low, Priority.Normal };
for (int i = 0; i < 25; i++) { for (int i = 1; i < 16; i++) {
String fileName = "file_" + i + ".ext"; String fileName = "file_" + i + ".ext";
// Every file has equal part in the total size // Every file has equal part in the total size
long size = t.getTotalSize() / 25; long size = t.getTotalSize() / 25;
@ -145,6 +152,10 @@ public class DummyAdapter implements IDaemonAdapter {
} }
return new GetFileListTaskSuccessResult((GetFileListTask) task, dummyFiles); return new GetFileListTaskSuccessResult((GetFileListTask) task, dummyFiles);
case GetStats:
return new GetStatsTaskSuccessResult((GetStatsTask) task, alternativeModeEnabled, 1024L * 1024L * 1024L * 100);
case AddByFile: case AddByFile:
String file = ((AddByFileTask) task).getFile(); String file = ((AddByFileTask) task).getFile();
@ -251,7 +262,17 @@ public class DummyAdapter implements IDaemonAdapter {
case SetTrackers: case SetTrackers:
// TODO: Override the trackers? trackersList = new ArrayList<String>(((SetTrackersTask)task).getNewTrackers());
return new DaemonTaskSuccessResult(task);
case SetDownloadLocation:
task.getTargetTorrent().mimicNewLocation(((SetDownloadLocationTask) task).getNewLocation());
return new DaemonTaskSuccessResult(task);
case SetAlternativeMode:
alternativeModeEnabled = ((SetAlternativeModeTask) task).isAlternativeModeEnabled();
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
default: default:

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

@ -35,7 +35,7 @@ public final class Torrent implements Parcelable, Comparable<Torrent> {
final private String hash; final private String hash;
final private String name; final private String name;
private TorrentStatus statusCode; private TorrentStatus statusCode;
final private String locationDir; private String locationDir;
final private int rateDownload; final private int rateDownload;
final private int rateUpload; final private int rateUpload;
@ -246,6 +246,10 @@ public final class Torrent implements Parcelable, Comparable<Torrent> {
label = newLabel; label = newLabel;
} }
public void mimicNewLocation(String newLocation) {
locationDir = newLocation;
}
@Override @Override
public String toString() { public String toString() {
// (HASH_OR_ID) NAME // (HASH_OR_ID) NAME

Loading…
Cancel
Save