Browse Source

Sort files in details screen using natural order.

pull/11/head
Eric Kok 12 years ago
parent
commit
b81bf09e53
  1. 3
      core/res/values/strings.xml
  2. 2
      core/src/org/transdroid/core/gui/lists/TorrentDetailsView.java
  3. 9
      lib/src/org/transdroid/daemon/TorrentFilesComparator.java
  4. 4
      lib/src/org/transdroid/daemon/TorrentsComparator.java

3
core/res/values/strings.xml

@ -78,7 +78,8 @@
<string name="status_ratio">RATIO %1$s</string> <string name="status_ratio">RATIO %1$s</string>
<string name="status_peers">%1$s OF %2$s PEERS</string> <string name="status_peers">%1$s OF %2$s PEERS</string>
<string name="status_speed_up" translatable="false">↑ %1$s</string> <string name="status_speed_up" translatable="false">↑ %1$s</string>
<string name="status_speed_down" translatable="false">%1$s ↓</string> <string name="status_speed_down" translatable="false">↓ %1$s</string>
<string name="status_speed_down_details" translatable="false">%1$s ↓</string>
<string name="status_downloading">Downloading</string> <string name="status_downloading">Downloading</string>
<string name="status_seeding">Seeding</string> <string name="status_seeding">Seeding</string>
<string name="status_paused">Paused</string> <string name="status_paused">Paused</string>

2
core/src/org/transdroid/core/gui/lists/TorrentDetailsView.java

@ -84,7 +84,7 @@ public class TorrentDetailsView extends RelativeLayout {
downloadedunitText.setText(FileSizeConverter.getSizeUnit(torrent.getDownloadedEver()).toString()); downloadedunitText.setText(FileSizeConverter.getSizeUnit(torrent.getDownloadedEver()).toString());
uploadedText.setText(FileSizeConverter.getSize(torrent.getUploadedEver(), false)); uploadedText.setText(FileSizeConverter.getSize(torrent.getUploadedEver(), false));
uploadedunitText.setText(FileSizeConverter.getSizeUnit(torrent.getUploadedEver()).toString()); uploadedunitText.setText(FileSizeConverter.getSizeUnit(torrent.getUploadedEver()).toString());
downspeedText.setText(getResources().getString(R.string.status_speed_down, downspeedText.setText(getResources().getString(R.string.status_speed_down_details,
FileSizeConverter.getSize(torrent.getRateDownload()) + "/s")); FileSizeConverter.getSize(torrent.getRateDownload()) + "/s"));
upspeedText.setText(getResources().getString(R.string.status_speed_up, upspeedText.setText(getResources().getString(R.string.status_speed_up,
FileSizeConverter.getSize(torrent.getRateUpload()) + "/s")); FileSizeConverter.getSize(torrent.getRateUpload()) + "/s"));

9
lib/src/org/transdroid/daemon/TorrentFilesComparator.java

@ -28,8 +28,9 @@ import java.util.Comparator;
*/ */
public class TorrentFilesComparator implements Comparator<TorrentFile> { public class TorrentFilesComparator implements Comparator<TorrentFile> {
TorrentFilesSortBy sortBy; private TorrentFilesSortBy sortBy;
boolean reversed; private boolean reversed;
private Comparator<String> alphanumComparator = new AlphanumComparator();
/** /**
* Instantiate a torrent files comparator. * Instantiate a torrent files comparator.
@ -50,7 +51,7 @@ public class TorrentFilesComparator implements Comparator<TorrentFile> {
case TotalSize: case TotalSize:
return new Long(file1.getTotalSize()).compareTo(file2.getTotalSize()); return new Long(file1.getTotalSize()).compareTo(file2.getTotalSize());
default: default:
return file1.getName().toLowerCase().compareTo(file2.getName().toLowerCase()); return alphanumComparator.compare(file1.getName().toLowerCase(), file2.getName().toLowerCase());
} }
} else { } else {
switch (sortBy) { switch (sortBy) {
@ -59,7 +60,7 @@ public class TorrentFilesComparator implements Comparator<TorrentFile> {
case TotalSize: case TotalSize:
return 0 - new Long(file1.getTotalSize()).compareTo(file2.getTotalSize()); return 0 - new Long(file1.getTotalSize()).compareTo(file2.getTotalSize());
default: default:
return 0 - file1.getName().toLowerCase().compareTo(file2.getName().toLowerCase()); return 0 - alphanumComparator.compare(file1.getName().toLowerCase(), file2.getName().toLowerCase());
} }
} }
} }

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

@ -67,7 +67,7 @@ public class TorrentsComparator implements Comparator<Torrent> {
case Ratio: case Ratio:
return new Double(tor1.getRatio()).compareTo(new Double(tor2.getRatio())); return new Double(tor1.getRatio()).compareTo(new Double(tor2.getRatio()));
default: default:
return alphanumComparator.compare(tor1.getName(), tor2.getName()); return alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase());
} }
} else { } else {
switch (sortBy) { switch (sortBy) {
@ -82,7 +82,7 @@ public class TorrentsComparator implements Comparator<Torrent> {
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()));
default: default:
return 0 - alphanumComparator.compare(tor1.getName(), tor2.getName()); return 0 - alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase());
} }
} }
} }

Loading…
Cancel
Save