packages/apps/FileManager
Révision | 5fb77b20764f6b01bceebbd79b18f1296335d6bd (tree) |
---|---|
l'heure | 2011-06-20 09:30:42 |
Auteur | Joe Berria <nexesdevelopment@gmai...> |
Commiter | Joe Berria |
improved sorting by type and size
@@ -474,9 +474,10 @@ public class FileManager { | ||
474 | 474 | public int compare(String arg0, String arg1) { |
475 | 475 | String dir = mPathStack.peek(); |
476 | 476 | Long first = new File(dir + "/" + arg0).length(); |
477 | - Long second = new File(dir + "/" + arg0).length(); | |
477 | + Long second = new File(dir + "/" + arg1).length(); | |
478 | 478 | |
479 | - return (int) (first - second); | |
479 | + Log.e("FILE MANAGER", "first: " + first + "\nsecond: " + second); | |
480 | + return first.compareTo(second);//(int) (first - second); | |
480 | 481 | } |
481 | 482 | }; |
482 | 483 |
@@ -485,16 +486,21 @@ public class FileManager { | ||
485 | 486 | public int compare(String arg0, String arg1) { |
486 | 487 | String ext = null; |
487 | 488 | String ext2 = null; |
489 | + int ret; | |
488 | 490 | |
489 | 491 | try { |
490 | - ext = arg0.substring(arg0.lastIndexOf(".") + 1, arg0.length()); | |
491 | - ext2 = arg1.substring(arg1.lastIndexOf(".") + 1, arg1.length()); | |
492 | + ext = arg0.substring(arg0.lastIndexOf(".") + 1, arg0.length()).toLowerCase(); | |
493 | + ext2 = arg1.substring(arg1.lastIndexOf(".") + 1, arg1.length()).toLowerCase(); | |
492 | 494 | |
493 | 495 | } catch (IndexOutOfBoundsException e) { |
494 | 496 | return 0; |
495 | 497 | } |
498 | + ret = ext.compareTo(ext2); | |
496 | 499 | |
497 | - return ext.compareTo(ext2); | |
500 | + if (ret == 0) | |
501 | + return arg0.toLowerCase().compareTo(arg1.toLowerCase()); | |
502 | + | |
503 | + return ret; | |
498 | 504 | } |
499 | 505 | }; |
500 | 506 |
@@ -548,14 +554,16 @@ public class FileManager { | ||
548 | 554 | break; |
549 | 555 | |
550 | 556 | case SORT_SIZE: |
557 | + int index = 0; | |
551 | 558 | Object[] size_ar = mDirContent.toArray(); |
552 | 559 | String dir = mPathStack.peek(); |
553 | 560 | |
554 | 561 | Arrays.sort(size_ar, size); |
562 | + | |
555 | 563 | mDirContent.clear(); |
556 | - for (Object a : size_ar){ | |
564 | + for (Object a : size_ar) { | |
557 | 565 | if(new File(dir + "/" + (String)a).isDirectory()) |
558 | - mDirContent.add(0, (String)a); | |
566 | + mDirContent.add(index++, (String)a); | |
559 | 567 | else |
560 | 568 | mDirContent.add((String)a); |
561 | 569 | } |
@@ -563,20 +571,17 @@ public class FileManager { | ||
563 | 571 | |
564 | 572 | case SORT_TYPE: |
565 | 573 | int dirindex = 0; |
566 | - int fileindex = dirindex; | |
567 | 574 | Object[] type_ar = mDirContent.toArray(); |
568 | 575 | String current = mPathStack.peek(); |
569 | 576 | |
570 | 577 | Arrays.sort(type_ar, type); |
571 | 578 | mDirContent.clear(); |
572 | 579 | |
573 | - for (Object a : type_ar){ | |
580 | + for (Object a : type_ar) { | |
574 | 581 | if(new File(current + "/" + (String)a).isDirectory()) |
575 | 582 | mDirContent.add(dirindex++, (String)a); |
576 | 583 | else |
577 | - mDirContent.add(fileindex, (String)a); | |
578 | - | |
579 | - fileindex = dirindex; | |
584 | + mDirContent.add((String)a); | |
580 | 585 | } |
581 | 586 | break; |
582 | 587 | } |