fix #1110: accents not sorted
authortobiasKaminsky <tobias@kaminsky.me>
Tue, 25 Aug 2015 13:55:45 +0000 (15:55 +0200)
committertobiasKaminsky <tobias@kaminsky.me>
Tue, 25 Aug 2015 13:55:45 +0000 (15:55 +0200)
src/com/owncloud/android/utils/FileStorageUtils.java
src/third_parties/daveKoeller/AlphanumComparator.java

index e70302f..2b6d68b 100644 (file)
@@ -254,7 +254,7 @@ public class FileStorageUtils {
         Collections.sort(files, new Comparator<OCFile>() {
             public int compare(OCFile o1, OCFile o2) {
                 if (o1.isFolder() && o2.isFolder()) {
-                    return val * o1.getRemotePath().toLowerCase().compareTo(o2.getRemotePath().toLowerCase());
+                    return val * new AlphanumComparator().compare(o1, o2);
                 } else if (o1.isFolder()) {
                     return -1;
                 } else if (o2.isFolder()) {
index e6bd6f3..e86c3c4 100644 (file)
@@ -23,6 +23,7 @@
  */\r
 \r
 package third_parties.daveKoeller;\r
+import java.text.Collator;\r
 import java.util.Comparator;\r
 \r
 import com.owncloud.android.datamodel.OCFile;\r
@@ -48,14 +49,12 @@ public class AlphanumComparator implements Comparator<OCFile>
     }\r
 \r
     /** Length of string is passed in for improved efficiency (only need to calculate it once) **/\r
-    private final String getChunk(String s, int slength, int marker)\r
-    {\r
+    private final String getChunk(String s, int slength, int marker){\r
         StringBuilder chunk = new StringBuilder();\r
         char c = s.charAt(marker);\r
         chunk.append(c);\r
         marker++;\r
-        if (isDigit(c))\r
-        {\r
+        if (isDigit(c)){\r
             while (marker < slength)\r
             {\r
                 c = s.charAt(marker);\r
@@ -64,8 +63,7 @@ public class AlphanumComparator implements Comparator<OCFile>
                 chunk.append(c);\r
                 marker++;\r
             }\r
-        } else\r
-        {\r
+        } else {\r
             while (marker < slength)\r
             {\r
                 c = s.charAt(marker);\r
@@ -78,8 +76,7 @@ public class AlphanumComparator implements Comparator<OCFile>
         return chunk.toString();\r
     }\r
 \r
-    public int compare(OCFile o1, OCFile o2)\r
-    {\r
+    public int compare(OCFile o1, OCFile o2){\r
         String s1 = (String)o1.getRemotePath().toLowerCase();\r
         String s2 = (String)o2.getRemotePath().toLowerCase();\r
 \r
@@ -88,8 +85,7 @@ public class AlphanumComparator implements Comparator<OCFile>
         int s1Length = s1.length();\r
         int s2Length = s2.length();\r
 \r
-        while (thisMarker < s1Length && thatMarker < s2Length)\r
-        {\r
+        while (thisMarker < s1Length && thatMarker < s2Length) {\r
             String thisChunk = getChunk(s1, s1Length, thisMarker);\r
             thisMarker += thisChunk.length();\r
 \r
@@ -98,26 +94,24 @@ public class AlphanumComparator implements Comparator<OCFile>
 \r
             // If both chunks contain numeric characters, sort them numerically\r
             int result = 0;\r
-            if (isDigit(thisChunk.charAt(0)) && isDigit(thatChunk.charAt(0)))\r
-            {\r
+            if (isDigit(thisChunk.charAt(0)) && isDigit(thatChunk.charAt(0))) {\r
                 // Simple chunk comparison by length.\r
                 int thisChunkLength = thisChunk.length();\r
                 result = thisChunkLength - thatChunk.length();\r
                 // If equal, the first different number counts\r
-                if (result == 0)\r
-                {\r
-                    for (int i = 0; i < thisChunkLength; i++)\r
-                    {\r
+                if (result == 0) {\r
+                    for (int i = 0; i < thisChunkLength; i++) {\r
                         result = thisChunk.charAt(i) - thatChunk.charAt(i);\r
-                        if (result != 0)\r
-                        {\r
+                        if (result != 0) {\r
                             return result;\r
                         }\r
                     }\r
                 }\r
-            } else\r
-            {\r
-                result = thisChunk.compareTo(thatChunk);\r
+            } else {\r
+                Collator collator = Collator.getInstance();\r
+                collator.setStrength(Collator.PRIMARY);\r
+                result = collator.compare(thisChunk, thatChunk);\r
+//                result = thisChunk.compareTo(thatChunk);\r
             }\r
 \r
             if (result != 0)\r