OSDN Git Service

CMFileManager: Add sort by size
authorRaj Yengisetty <raj@cyngn.com>
Mon, 12 Jan 2015 08:12:21 +0000 (16:12 +0800)
committerRaj Yengisetty <raj@cyngn.com>
Mon, 12 Jan 2015 08:17:30 +0000 (16:17 +0800)
Change-Id: Iae8c47beb8f229bb5e1936c0dbd153f356b099d7

res/values/arrays.xml
res/values/strings.xml
src/com/cyanogenmod/filemanager/preferences/NavigationSortMode.java
src/com/cyanogenmod/filemanager/util/FileHelper.java

index 5efc570..0a0f259 100644 (file)
@@ -21,6 +21,8 @@
         <item>@string/sort_by_name_desc</item>
         <item>@string/sort_by_date_asc</item>
         <item>@string/sort_by_date_desc</item>
+        <item>@string/sort_by_size_asc</item>
+        <item>@string/sort_by_size_desc</item>
     </string-array>
 
     <!-- The strings of the menu for navigation layout mode enumeration -->
index aef1e5b..c1f79f9 100644 (file)
     <string name="sort_by_date_asc">By date \u25B2</string>
     <!-- Navigation View - Sort - Sort by date (descending) -->
     <string name="sort_by_date_desc">By date \u25BC</string>
+    <!-- Navigation View - Sort - Sort by size (ascending) -->
+    <string name="sort_by_size_asc">By size \u25B2</string>
+    <!-- Navigation View - Sort - Sort by size (descending) -->
+    <string name="sort_by_size_desc">By size \u25BC</string>
 
     <!-- Navigation View - Layout - Icons -->
     <string name="layout_icons">Icons</string>
index 41e9779..317ae59 100644 (file)
@@ -36,7 +36,15 @@ public enum NavigationSortMode implements ObjectIdentifier {
     /**
      * That mode sorts objects by date (descending).
      */
-    DATE_DESC(3);
+    DATE_DESC(3),
+    /**
+     * That mode sorts objects by size (ascending).
+     */
+    SIZE_ASC(4),
+    /**
+     * That mode sorts objects by size (descending).
+     */
+    SIZE_DESC(5);
 
     private int mId;
 
index d49d31f..339fa8e 100644 (file)
@@ -776,6 +776,15 @@ public final class FileHelper {
             return fso1.getLastModifiedTime().compareTo(fso2.getLastModifiedTime()) * -1;
         }
 
+        //Size (ascending)
+        if (mode.getId() == NavigationSortMode.SIZE_ASC.getId()) {
+            return Long.compare(fso1.getSize(), fso2.getSize());
+        }
+        //Size (descending)
+        if (mode.getId() == NavigationSortMode.SIZE_DESC.getId()) {
+            return Long.compare(fso1.getSize(), fso2.getSize()) * -1;
+        }
+
         //Comparison between files directly
         return fso1.compareTo(fso2);
     }