diff --git a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java
index 255002dd24..2fb0299384 100644
--- a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java
+++ b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java
@@ -464,14 +464,26 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("
\n");
}
out.write("\n
");
+ // cycle through sort by name or type
+ boolean isTypeSort = false;
if (showSort) {
- sort = (currentSort == null || "0".equals(currentSort) || "1".equals(currentSort)) ? "-1" : "";
+ if (currentSort == null || "0".equals(currentSort) || "1".equals(currentSort)) {
+ sort = "-1";
+ } else if ("-1".equals(currentSort)) {
+ sort = "12";
+ isTypeSort = true;
+ } else if ("12".equals(currentSort)) {
+ sort = "-12";
+ isTypeSort = true;
+ } else {
+ sort = "";
+ }
out.write("");
}
out.write(" 9: Up rate
*10: Remaining (needed)
*11: Upload ratio
+ *11: File type
*
+ *
+ * @param servlet for file type callback only
*/
- public static Comparator getComparator(int type) {
+ public static Comparator getComparator(int type, I2PSnarkServlet servlet) {
boolean rev = type < 0;
Comparator rv;
switch (type) {
@@ -96,6 +100,11 @@ class Sorters {
rv = new RatioComparator(rev);
break;
+ case -12:
+ case 12:
+ rv = new FileTypeComparator(rev, servlet);
+ break;
+
}
return rv;
}
@@ -303,4 +312,30 @@ class Sorters {
return compLong(ld, rd);
}
}
+
+ private static class FileTypeComparator extends Sort {
+
+ private final I2PSnarkServlet servlet;
+
+ public FileTypeComparator(boolean rev, I2PSnarkServlet servlet) {
+ super(rev);
+ this.servlet = servlet;
+ }
+
+ public int compareIt(Snark l, Snark r) {
+ String ls = toName(l);
+ String rs = toName(r);
+ return ls.compareTo(rs);
+ }
+
+ private String toName(Snark snark) {
+ MetaInfo meta = snark.getMetaInfo();
+ if (meta == null)
+ return "0";
+ if (meta.getFiles() != null)
+ return "1";
+ // arbitrary sort based on icon name
+ return servlet.toIcon(meta.getName());
+ }
+ }
}
|