OSDN Git Service

CMFileManager: Include sort by type
authorRaj Yengisetty <raj@cyngn.com>
Tue, 13 Jan 2015 03:21:26 +0000 (11:21 +0800)
committerRaj Yengisetty <raj@cyngn.com>
Tue, 13 Jan 2015 03:23:22 +0000 (11:23 +0800)
Change-Id: I44730f6493ee79bbcff49045568d14192544839b

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

index 0a0f259..997eb5c 100644 (file)
@@ -23,6 +23,8 @@
         <item>@string/sort_by_date_desc</item>
         <item>@string/sort_by_size_asc</item>
         <item>@string/sort_by_size_desc</item>
+        <item>@string/sort_by_type_asc</item>
+        <item>@string/sort_by_type_desc</item>
     </string-array>
 
     <!-- The strings of the menu for navigation layout mode enumeration -->
index c1f79f9..2684aae 100644 (file)
     <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 - Sort - Sort by type (ascending) -->
+    <string name="sort_by_type_asc">By type \u25B2</string>
+    <!-- Navigation View - Sort - Sort by type (descending) -->
+    <string name="sort_by_type_desc">By type \u25BC</string>
 
     <!-- Navigation View - Layout - Icons -->
     <string name="layout_icons">Icons</string>
index 317ae59..c577137 100644 (file)
@@ -44,7 +44,15 @@ public enum NavigationSortMode implements ObjectIdentifier {
     /**
      * That mode sorts objects by size (descending).
      */
-    SIZE_DESC(5);
+    SIZE_DESC(5),
+    /**
+     * That mode sorts objects by type (ascending).
+     */
+    TYPE_ASC(6),
+    /**
+     * That mode sorts objects by type (descending).
+     */
+    TYPE_DESC(7);
 
     private int mId;
 
index 339fa8e..3efa9ee 100644 (file)
@@ -785,6 +785,17 @@ public final class FileHelper {
             return Long.compare(fso1.getSize(), fso2.getSize()) * -1;
         }
 
+        //Type (ascending)
+        if (mode.getId() == NavigationSortMode.TYPE_ASC.getId()) {
+            // Shouldn't need context here, mimetypes should be loaded
+            return MimeTypeHelper.compareFSO(null, fso1, fso2);
+        }
+        //Type (descending)
+        if (mode.getId() == NavigationSortMode.TYPE_DESC.getId()) {
+            // Shouldn't need context here, mimetypes should be loaded
+            return MimeTypeHelper.compareFSO(null, fso1, fso2) * -1;
+        }
+
         //Comparison between files directly
         return fso1.compareTo(fso2);
     }
index ebcdcad..34563db 100644 (file)
@@ -337,6 +337,22 @@ public final class MimeTypeHelper {
     }
 
     /**
+     * Method that compares {@link FileSystemObject} by MimeTypeCategory
+     *
+     * @param context The current context
+     * @param fso1 File system object 1
+     * @param fso2 File system object 2
+     * @return int Either -1, 0, 1 based on if fso1 appears before or after fso2
+     */
+    public static final int compareFSO(Context context, FileSystemObject fso1,
+            FileSystemObject fso2) {
+        MimeTypeCategory mtc1 = getCategory(context, fso1);
+        MimeTypeCategory mtc2 = getCategory(context, fso2);
+
+        return mtc1.compareTo(mtc2);
+    }
+
+    /**
      * Method that returns the mime/type description of the {@link FileSystemObject}.
      *
      * @param context The current context