From bc56541ec104d8e284a5a45be53b1f430df9aa40 Mon Sep 17 00:00:00 2001 From: Dan Pasanen Date: Fri, 26 Sep 2014 22:29:05 -0500 Subject: [PATCH 1/2] core/lib: allow for sorting based on downloaded percent --- core/res/menu/activity_torrents.xml | 1 + core/res/values/strings.xml | 1 + core/src/org/transdroid/core/gui/TorrentsActivity.java | 5 +++++ lib/src/org/transdroid/daemon/TorrentsComparator.java | 4 ++++ lib/src/org/transdroid/daemon/TorrentsSortBy.java | 3 ++- 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/res/menu/activity_torrents.xml b/core/res/menu/activity_torrents.xml index a596e1ec..1b368620 100644 --- a/core/res/menu/activity_torrents.xml +++ b/core/res/menu/activity_torrents.xml @@ -69,6 +69,7 @@ + diff --git a/core/res/values/strings.xml b/core/res/values/strings.xml index eaa7d429..72c12dc4 100644 --- a/core/res/values/strings.xml +++ b/core/res/values/strings.xml @@ -32,6 +32,7 @@ Status Date done Date added + Percent downloaded Download speed Upload speed Ratio diff --git a/core/src/org/transdroid/core/gui/TorrentsActivity.java b/core/src/org/transdroid/core/gui/TorrentsActivity.java index 3d6bd178..611f5221 100644 --- a/core/src/org/transdroid/core/gui/TorrentsActivity.java +++ b/core/src/org/transdroid/core/gui/TorrentsActivity.java @@ -796,6 +796,11 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, fragmentTorrents.sortBy(TorrentsSortBy.DateAdded); } + @OptionsItem(resName = "action_sort_percent") + protected void sortByPercent() { + fragmentTorrents.sortBy(TorrentsSortBy.Percent); + } + @OptionsItem(resName = "action_sort_downspeed") protected void sortByDownspeed() { fragmentTorrents.sortBy(TorrentsSortBy.DownloadSpeed); diff --git a/lib/src/org/transdroid/daemon/TorrentsComparator.java b/lib/src/org/transdroid/daemon/TorrentsComparator.java index 64ea5bd6..57bfc15d 100644 --- a/lib/src/org/transdroid/daemon/TorrentsComparator.java +++ b/lib/src/org/transdroid/daemon/TorrentsComparator.java @@ -66,6 +66,8 @@ public class TorrentsComparator implements Comparator { return tor1.getDateAdded().compareTo(tor2.getDateAdded()); case DateDone: return tor1.getDateDone().compareTo(tor2.getDateDone()); + case Percent: + return new Float(tor1.getDownloadedPercentage()).compareTo(new Float(tor2.getDownloadedPercentage())); case DownloadSpeed: return new Integer(tor1.getRateDownload()).compareTo(new Integer(tor2.getRateDownload())); case UploadSpeed: @@ -87,6 +89,8 @@ public class TorrentsComparator implements Comparator { return 0 - tor1.getDateAdded().compareTo(tor2.getDateAdded()); case DateDone: return 0 - tor1.getDateDone().compareTo(tor2.getDateDone()); + case Percent: + return 0 - (new Float(tor1.getDownloadedPercentage()).compareTo(new Float(tor2.getDownloadedPercentage()))); case DownloadSpeed: return 0 - (new Integer(tor1.getRateDownload()).compareTo(new Integer(tor2.getRateDownload()))); case UploadSpeed: diff --git a/lib/src/org/transdroid/daemon/TorrentsSortBy.java b/lib/src/org/transdroid/daemon/TorrentsSortBy.java index c4d9a7a0..afc7a92b 100644 --- a/lib/src/org/transdroid/daemon/TorrentsSortBy.java +++ b/lib/src/org/transdroid/daemon/TorrentsSortBy.java @@ -28,7 +28,8 @@ public enum TorrentsSortBy { DateAdded (4), UploadSpeed (5), Ratio (6), - DownloadSpeed (7); + DownloadSpeed (7), + Percent (8); private int code; private static final Map lookup = new HashMap(); From 1473d8122498e9f6e9dd3c98cf7cac4c20174a69 Mon Sep 17 00:00:00 2001 From: Dan Pasanen Date: Tue, 7 Oct 2014 15:45:11 -0500 Subject: [PATCH 2/2] core/lib: allow for sorting based on torrent size --- core/res/menu/activity_torrents.xml | 1 + core/res/values/strings.xml | 1 + core/src/org/transdroid/core/gui/TorrentsActivity.java | 5 +++++ lib/src/org/transdroid/daemon/TorrentsComparator.java | 4 ++++ lib/src/org/transdroid/daemon/TorrentsSortBy.java | 3 ++- 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/res/menu/activity_torrents.xml b/core/res/menu/activity_torrents.xml index 1b368620..3e7d2c81 100644 --- a/core/res/menu/activity_torrents.xml +++ b/core/res/menu/activity_torrents.xml @@ -73,6 +73,7 @@ + Download speed Upload speed Ratio + Size Filter list Settings Help diff --git a/core/src/org/transdroid/core/gui/TorrentsActivity.java b/core/src/org/transdroid/core/gui/TorrentsActivity.java index 611f5221..ba2a3924 100644 --- a/core/src/org/transdroid/core/gui/TorrentsActivity.java +++ b/core/src/org/transdroid/core/gui/TorrentsActivity.java @@ -816,6 +816,11 @@ public class TorrentsActivity extends Activity implements OnNavigationListener, fragmentTorrents.sortBy(TorrentsSortBy.Ratio); } + @OptionsItem(resName = "action_sort_size") + protected void sortBySize() { + fragmentTorrents.sortBy(TorrentsSortBy.Size); + } + @OptionsItem(resName = "action_filter") protected void startFilterEntryDialog() { FilterEntryDialog.startFilterEntry(this); diff --git a/lib/src/org/transdroid/daemon/TorrentsComparator.java b/lib/src/org/transdroid/daemon/TorrentsComparator.java index 57bfc15d..c1682158 100644 --- a/lib/src/org/transdroid/daemon/TorrentsComparator.java +++ b/lib/src/org/transdroid/daemon/TorrentsComparator.java @@ -74,6 +74,8 @@ public class TorrentsComparator implements Comparator { return new Integer(tor1.getRateUpload()).compareTo(new Integer(tor2.getRateUpload())); case Ratio: return new Double(tor1.getRatio()).compareTo(new Double(tor2.getRatio())); + case Size: + return new Double(tor1.getTotalSize()).compareTo(new Double(tor2.getTotalSize())); default: return alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase()); } @@ -97,6 +99,8 @@ public class TorrentsComparator implements Comparator { return 0 - (new Integer(tor1.getRateUpload()).compareTo(new Integer(tor2.getRateUpload()))); case Ratio: return 0 - new Double(tor1.getRatio()).compareTo(new Double(tor2.getRatio())); + case Size: + return 0 - new Double(tor1.getTotalSize()).compareTo(new Double(tor2.getTotalSize())); default: return 0 - alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase()); } diff --git a/lib/src/org/transdroid/daemon/TorrentsSortBy.java b/lib/src/org/transdroid/daemon/TorrentsSortBy.java index afc7a92b..91e40d46 100644 --- a/lib/src/org/transdroid/daemon/TorrentsSortBy.java +++ b/lib/src/org/transdroid/daemon/TorrentsSortBy.java @@ -29,7 +29,8 @@ public enum TorrentsSortBy { UploadSpeed (5), Ratio (6), DownloadSpeed (7), - Percent (8); + Percent (8), + Size (9); private int code; private static final Map lookup = new HashMap();