浏览代码

- Only three orders: A-Z, Big-Small, New-Old.
- Folder size is computed locally (therefore only downloaded files are
obeyed)

tobiasKaminsky 10 年之前
父节点
当前提交
a622b1dcfb

+ 3 - 6
res/values-de/strings.xml

@@ -14,12 +14,9 @@
   <string name="actionbar_sort">Sortieren</string>
   <string name="actionbar_sort">Sortieren</string>
   <string name="actionbar_sort_title">Sortieren nach</string>
   <string name="actionbar_sort_title">Sortieren nach</string>
   <string-array name="actionbar_sortby">
   <string-array name="actionbar_sortby">
-  	<item>Dateiname - aufsteigend</item>
-  	<item>Dateiname - absteigend</item>
-  	<item>Datum - aufsteigend</item>
-  	<item>Datum - absteigend</item>
-  	<item>Dateigröße - aufsteigend</item>
-  	<item>Dateigröße - absteigend</item>
+  	<item>A-Z</item>
+    	<item>Neu - Alt</item>
+    	<item>Groß - Klein</item>
   </string-array>
   </string-array>
   <string name="prefs_category_general">Allgemein</string>
   <string name="prefs_category_general">Allgemein</string>
   <string name="prefs_category_more">Mehr</string>
   <string name="prefs_category_more">Mehr</string>

+ 3 - 6
res/values/strings.xml

@@ -15,12 +15,9 @@
     <string name="actionbar_sort">Sort</string>
     <string name="actionbar_sort">Sort</string>
     <string name="actionbar_sort_title">Sort by</string>
     <string name="actionbar_sort_title">Sort by</string>
     <string-array name="actionbar_sortby">
     <string-array name="actionbar_sortby">
-    	<item>Filename - A-Z</item>
-    	<item>Filename - Z-A</item>
-    	<item>Date - oldest first</item>
-    	<item>Date - newest first</item>
-    	<item>Filesize - smallest first</item>
-    	<item>Filesize - biggest first</item>
+    	<item>A-Z</item>
+    	<item>Newest - Oldest</item>
+    	<item>Biggest - Smallest</item>
     </string-array>
     </string-array>
     <string name="prefs_category_general">General</string>
     <string name="prefs_category_general">General</string>
     <string name="prefs_category_more">More</string>
     <string name="prefs_category_more">More</string>

+ 10 - 14
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -153,6 +153,8 @@ OnSslUntrustedCertListener, SwipeRefreshLayout.OnRefreshListener {
     private String DIALOG_UNTRUSTED_CERT;
     private String DIALOG_UNTRUSTED_CERT;
     
     
     private OCFile mWaitingToSend;
     private OCFile mWaitingToSend;
+    
+    private Integer sortItemChecked = 0;
 
 
     @Override
     @Override
     protected void onCreate(Bundle savedInstanceState) {
     protected void onCreate(Bundle savedInstanceState) {
@@ -494,33 +496,27 @@ OnSslUntrustedCertListener, SwipeRefreshLayout.OnRefreshListener {
         case R.id.action_sort: {
         case R.id.action_sort: {
             AlertDialog.Builder builder = new AlertDialog.Builder(this);
             AlertDialog.Builder builder = new AlertDialog.Builder(this);
             builder.setTitle(R.string.actionbar_sort_title)
             builder.setTitle(R.string.actionbar_sort_title)
-            .setItems(R.array.actionbar_sortby, new DialogInterface.OnClickListener() {
+            .setSingleChoiceItems(R.array.actionbar_sortby, sortItemChecked , new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int which) {
                 public void onClick(DialogInterface dialog, int which) {
-                    Log_OC.d("default view", " number " + which + "clicked");
+                    sortItemChecked = which;
+
                     switch (which){
                     switch (which){
                     case 0:
                     case 0:
                         sortByName(true);
                         sortByName(true);
                         break;
                         break;
                     case 1:
                     case 1:
-                        sortByName(false);
-                        break;
-                    case 2:
-                        sortByDate(true);
-                        break;
-                    case 3:
                         sortByDate(false);
                         sortByDate(false);
                         break;
                         break;
-                    case 4:
-                        sortBySize(true);
-                        break;
-                    case 5:
+                    case 2:
                         sortBySize(false);
                         sortBySize(false);
                         break;
                         break;
                     }
                     }
+                    
+                    dialog.dismiss();
+                    
                 }
                 }
             });
             });
-            builder.create();
-            builder.show();
+            builder.create().show();
             break;
             break;
         }
         }
         default:
         default:

+ 65 - 3
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -17,6 +17,7 @@
  */
  */
 package com.owncloud.android.ui.adapter;
 package com.owncloud.android.ui.adapter;
 
 
+import java.io.File;
 import java.util.Collections;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Comparator;
 import java.util.Vector;
 import java.util.Vector;
@@ -41,6 +42,8 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.ui.activity.ComponentsGetter;
 import com.owncloud.android.ui.activity.ComponentsGetter;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.DisplayUtils;
+import com.owncloud.android.utils.FileStorageUtils;
+import com.owncloud.android.utils.Log_OC;
 
 
 
 
 /**
 /**
@@ -183,9 +186,13 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
                 }
                 }
             } 
             } 
             else {
             else {
+                if (FileStorageUtils.getDefaultSavePathFor(mAccount.name, file) != null){
+                    fileSizeV.setVisibility(View.VISIBLE);
+                    fileSizeV.setText(getFolderSizeHuman(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file)));
+                } else {
+                    fileSizeV.setVisibility(View.INVISIBLE);
+                }
                 
                 
-                fileSizeV.setVisibility(View.INVISIBLE);
-                //fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
                 lastModV.setVisibility(View.VISIBLE);
                 lastModV.setVisibility(View.VISIBLE);
                 lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
                 lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
                 checkBoxV.setVisibility(View.GONE);
                 checkBoxV.setVisibility(View.GONE);
@@ -214,6 +221,48 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
 
 
         return view;
         return view;
     }
     }
+    
+    /**
+     * Local Folder size in human readable format
+     * @param path String
+     * @return Size in human readable format
+     */
+    private String getFolderSizeHuman(String path) {
+
+        File dir = new File(path);
+
+        if(dir.exists()) {
+            long bytes = getFolderSize(dir);
+            if (bytes < 1024) return bytes + " B";
+            int exp = (int) (Math.log(bytes) / Math.log(1024));
+            String pre = ("KMGTPE").charAt(exp-1) + "";
+
+            return String.format("%.1f %sB", bytes / Math.pow(1024, exp), pre);
+        }
+
+        return "0 B";
+    }
+
+    /**
+     * Local Folder size
+     * @param dir File
+     * @return Size in bytes
+     */
+    private long getFolderSize(File dir) {
+        if (dir.exists()) {
+            long result = 0;
+            File[] fileList = dir.listFiles();
+            for(int i = 0; i < fileList.length; i++) {
+                if(fileList[i].isDirectory()) {
+                    result += getFolderSize(fileList[i]);
+                } else {
+                    result += fileList[i].length();
+                }
+            }
+            return result;
+        }
+        return 0;
+    } 
 
 
     @Override
     @Override
     public int getViewTypeCount() {
     public int getViewTypeCount() {
@@ -305,6 +354,10 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
                 && file.getPermissions() != null && file.getPermissions().contains(PERMISSION_SHARED_WITH_ME));
                 && file.getPermissions() != null && file.getPermissions().contains(PERMISSION_SHARED_WITH_ME));
     }
     }
 
 
+    /**
+     * Sorts list by Date
+     * @param sortAscending true: ascending, false: descending
+     */
     private void sortByDate(boolean sortAscending){
     private void sortByDate(boolean sortAscending){
         final Integer val;
         final Integer val;
         if (sortAscending){
         if (sortAscending){
@@ -331,6 +384,10 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
         });
         });
     }
     }
 
 
+    /**
+     * Sorts list by Size
+     * @param sortAscending true: ascending, false: descending
+     */
     private void sortBySize(boolean sortAscending){
     private void sortBySize(boolean sortAscending){
         final Integer val;
         final Integer val;
         if (sortAscending){
         if (sortAscending){
@@ -342,7 +399,8 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
         Collections.sort(mFiles, new Comparator<OCFile>() {
         Collections.sort(mFiles, new Comparator<OCFile>() {
             public int compare(OCFile o1, OCFile o2) {
             public int compare(OCFile o1, OCFile o2) {
                 if (o1.isFolder() && o2.isFolder()) {
                 if (o1.isFolder() && o2.isFolder()) {
-                    return o1.getRemotePath().toLowerCase().compareTo(o2.getRemotePath().toLowerCase());
+                    return val * Long.compare(getFolderSize(new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, o1))), 
+                                              getFolderSize(new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, o2))));
                 }
                 }
                 else if (o1.isFolder()) {
                 else if (o1.isFolder()) {
                     return -1;
                     return -1;
@@ -357,6 +415,10 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
         });
         });
     }
     }
 
 
+    /**
+     * Sorts list by Name
+     * @param sortAscending true: ascending, false: descending
+     */
     private void sortByName(boolean sortAscending){
     private void sortByName(boolean sortAscending){
         final Integer val;
         final Integer val;
         if (sortAscending){
         if (sortAscending){