Browse Source

core/lib: allow for sorting based on downloaded percent

pull/165/head
Dan Pasanen 10 years ago
parent
commit
bc56541ec1
  1. 1
      core/res/menu/activity_torrents.xml
  2. 1
      core/res/values/strings.xml
  3. 5
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  4. 4
      lib/src/org/transdroid/daemon/TorrentsComparator.java
  5. 3
      lib/src/org/transdroid/daemon/TorrentsSortBy.java

1
core/res/menu/activity_torrents.xml

@ -69,6 +69,7 @@
<item android:id="@+id/action_sort_status" android:title="@string/action_sort_status" /> <item android:id="@+id/action_sort_status" android:title="@string/action_sort_status" />
<item android:id="@+id/action_sort_done" android:title="@string/action_sort_done" /> <item android:id="@+id/action_sort_done" android:title="@string/action_sort_done" />
<item android:id="@+id/action_sort_added" android:title="@string/action_sort_added" /> <item android:id="@+id/action_sort_added" android:title="@string/action_sort_added" />
<item android:id="@+id/action_sort_percent" android:title="@string/action_sort_percent" />
<item android:id="@+id/action_sort_downspeed" android:title="@string/action_sort_downspeed" /> <item android:id="@+id/action_sort_downspeed" android:title="@string/action_sort_downspeed" />
<item android:id="@+id/action_sort_upspeed" android:title="@string/action_sort_upspeed" /> <item android:id="@+id/action_sort_upspeed" android:title="@string/action_sort_upspeed" />
<item android:id="@+id/action_sort_ratio" android:title="@string/action_sort_ratio" /> <item android:id="@+id/action_sort_ratio" android:title="@string/action_sort_ratio" />

1
core/res/values/strings.xml

@ -32,6 +32,7 @@
<string name="action_sort_status">Status</string> <string name="action_sort_status">Status</string>
<string name="action_sort_done">Date done</string> <string name="action_sort_done">Date done</string>
<string name="action_sort_added">Date added</string> <string name="action_sort_added">Date added</string>
<string name="action_sort_percent">Percent downloaded</string>
<string name="action_sort_downspeed">Download speed</string> <string name="action_sort_downspeed">Download speed</string>
<string name="action_sort_upspeed">Upload speed</string> <string name="action_sort_upspeed">Upload speed</string>
<string name="action_sort_ratio">Ratio</string> <string name="action_sort_ratio">Ratio</string>

5
core/src/org/transdroid/core/gui/TorrentsActivity.java

@ -796,6 +796,11 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
fragmentTorrents.sortBy(TorrentsSortBy.DateAdded); fragmentTorrents.sortBy(TorrentsSortBy.DateAdded);
} }
@OptionsItem(resName = "action_sort_percent")
protected void sortByPercent() {
fragmentTorrents.sortBy(TorrentsSortBy.Percent);
}
@OptionsItem(resName = "action_sort_downspeed") @OptionsItem(resName = "action_sort_downspeed")
protected void sortByDownspeed() { protected void sortByDownspeed() {
fragmentTorrents.sortBy(TorrentsSortBy.DownloadSpeed); fragmentTorrents.sortBy(TorrentsSortBy.DownloadSpeed);

4
lib/src/org/transdroid/daemon/TorrentsComparator.java

@ -66,6 +66,8 @@ public class TorrentsComparator implements Comparator<Torrent> {
return tor1.getDateAdded().compareTo(tor2.getDateAdded()); return tor1.getDateAdded().compareTo(tor2.getDateAdded());
case DateDone: case DateDone:
return tor1.getDateDone().compareTo(tor2.getDateDone()); return tor1.getDateDone().compareTo(tor2.getDateDone());
case Percent:
return new Float(tor1.getDownloadedPercentage()).compareTo(new Float(tor2.getDownloadedPercentage()));
case DownloadSpeed: case DownloadSpeed:
return new Integer(tor1.getRateDownload()).compareTo(new Integer(tor2.getRateDownload())); return new Integer(tor1.getRateDownload()).compareTo(new Integer(tor2.getRateDownload()));
case UploadSpeed: case UploadSpeed:
@ -87,6 +89,8 @@ public class TorrentsComparator implements Comparator<Torrent> {
return 0 - tor1.getDateAdded().compareTo(tor2.getDateAdded()); return 0 - tor1.getDateAdded().compareTo(tor2.getDateAdded());
case DateDone: case DateDone:
return 0 - tor1.getDateDone().compareTo(tor2.getDateDone()); return 0 - tor1.getDateDone().compareTo(tor2.getDateDone());
case Percent:
return 0 - (new Float(tor1.getDownloadedPercentage()).compareTo(new Float(tor2.getDownloadedPercentage())));
case DownloadSpeed: case DownloadSpeed:
return 0 - (new Integer(tor1.getRateDownload()).compareTo(new Integer(tor2.getRateDownload()))); return 0 - (new Integer(tor1.getRateDownload()).compareTo(new Integer(tor2.getRateDownload())));
case UploadSpeed: case UploadSpeed:

3
lib/src/org/transdroid/daemon/TorrentsSortBy.java

@ -28,7 +28,8 @@ public enum TorrentsSortBy {
DateAdded (4), DateAdded (4),
UploadSpeed (5), UploadSpeed (5),
Ratio (6), Ratio (6),
DownloadSpeed (7); DownloadSpeed (7),
Percent (8);
private int code; private int code;
private static final Map<Integer,TorrentsSortBy> lookup = new HashMap<Integer,TorrentsSortBy>(); private static final Map<Integer,TorrentsSortBy> lookup = new HashMap<Integer,TorrentsSortBy>();

Loading…
Cancel
Save