Browse Source

Merge pull request #165 from invisiblek/merge

Sort by Size and Download Percentage
pull/177/head
Eric Kok 10 years ago
parent
commit
e7c5374a68
  1. 2
      core/res/menu/activity_torrents.xml
  2. 2
      core/res/values/strings.xml
  3. 10
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  4. 8
      lib/src/org/transdroid/daemon/TorrentsComparator.java
  5. 4
      lib/src/org/transdroid/daemon/TorrentsSortBy.java

2
core/res/menu/activity_torrents.xml

@ -69,9 +69,11 @@
<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" />
<item android:id="@+id/action_sort_size" android:title="@string/action_sort_size" />
</menu> </menu>
</item> </item>
<item <item

2
core/res/values/strings.xml

@ -32,9 +32,11 @@
<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>
<string name="action_sort_size">Size</string>
<string name="action_filter">Filter list</string> <string name="action_filter">Filter list</string>
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
<string name="action_help">Help</string> <string name="action_help">Help</string>

10
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);
@ -811,6 +816,11 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
fragmentTorrents.sortBy(TorrentsSortBy.Ratio); fragmentTorrents.sortBy(TorrentsSortBy.Ratio);
} }
@OptionsItem(resName = "action_sort_size")
protected void sortBySize() {
fragmentTorrents.sortBy(TorrentsSortBy.Size);
}
@OptionsItem(resName = "action_filter") @OptionsItem(resName = "action_filter")
protected void startFilterEntryDialog() { protected void startFilterEntryDialog() {
FilterEntryDialog.startFilterEntry(this); FilterEntryDialog.startFilterEntry(this);

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

@ -66,12 +66,16 @@ 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:
return new Integer(tor1.getRateUpload()).compareTo(new Integer(tor2.getRateUpload())); return new Integer(tor1.getRateUpload()).compareTo(new Integer(tor2.getRateUpload()));
case Ratio: case Ratio:
return new Double(tor1.getRatio()).compareTo(new Double(tor2.getRatio())); return new Double(tor1.getRatio()).compareTo(new Double(tor2.getRatio()));
case Size:
return new Double(tor1.getTotalSize()).compareTo(new Double(tor2.getTotalSize()));
default: default:
return alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase()); return alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase());
} }
@ -87,12 +91,16 @@ 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:
return 0 - (new Integer(tor1.getRateUpload()).compareTo(new Integer(tor2.getRateUpload()))); return 0 - (new Integer(tor1.getRateUpload()).compareTo(new Integer(tor2.getRateUpload())));
case Ratio: case Ratio:
return 0 - new Double(tor1.getRatio()).compareTo(new Double(tor2.getRatio())); 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: default:
return 0 - alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase()); return 0 - alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase());
} }

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

@ -28,7 +28,9 @@ public enum TorrentsSortBy {
DateAdded (4), DateAdded (4),
UploadSpeed (5), UploadSpeed (5),
Ratio (6), Ratio (6),
DownloadSpeed (7); DownloadSpeed (7),
Percent (8),
Size (9);
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