Merge branch '1193_uploader_layout' of https://github.com/owncloud/android into beta
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / Uploader.java
index 0194092..daa136d 100644 (file)
@@ -84,6 +84,7 @@ import com.owncloud.android.ui.dialog.LoadingDialog;
 import com.owncloud.android.utils.CopyTmpFileAsyncTask;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.ErrorMessageAdapter;
+import com.owncloud.android.utils.FileStorageUtils;
 
 
 /**
@@ -333,7 +334,10 @@ public class Uploader extends FileActivity
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
         // click on folder in the list
         Log_OC.d(TAG, "on item click");
-        Vector<OCFile> tmpfiles = getStorageManager().getFolderContent(mFile, false);
+        // TODO Enable when "On Device" is recovered ?
+        Vector<OCFile> tmpfiles = getStorageManager().getFolderContent(mFile , false);
+        tmpfiles = sortFileList(tmpfiles);
+
         if (tmpfiles.size() <= 0) return;
         // filter on dirtype
         Vector<OCFile> files = new Vector<OCFile>();
@@ -398,16 +402,17 @@ public class Uploader extends FileActivity
         setContentView(R.layout.uploader_layout);
         
         ListView mListView = (ListView) findViewById(android.R.id.list);
+        ActionBar actionBar = getSupportActionBar();
 
         String current_dir = mParents.peek();
         if(current_dir.equals("")){
-            getSupportActionBar().setTitle(getString(R.string.default_display_name_for_root_folder));
+            actionBar.setTitle(getString(R.string.uploader_top_message));
         }
         else{
-            getSupportActionBar().setTitle(current_dir);
+            actionBar.setTitle(current_dir);
         }
         boolean notRoot = (mParents.size() > 1);
-        ActionBar actionBar = getSupportActionBar();
+
         actionBar.setDisplayHomeAsUpEnabled(notRoot);
         actionBar.setHomeButtonEnabled(notRoot);
 
@@ -417,20 +422,24 @@ public class Uploader extends FileActivity
 
         mFile = getStorageManager().getFileByPath(full_path);
         if (mFile != null) {
+            // TODO Enable when "On Device" is recovered ?
             Vector<OCFile> files = getStorageManager().getFolderContent(mFile, false);
+            files = sortFileList(files);
+
             List<HashMap<String, Object>> data = new LinkedList<HashMap<String,Object>>();
             for (OCFile f : files) {
-                HashMap<String, Object> h = new HashMap<String, Object>();
                 if (f.isFolder()) {
+                    HashMap<String, Object> h = new HashMap<String, Object>();
                     h.put("dirname", f.getFileName());
+                    h.put("last_mod", DisplayUtils.getRelativeTimestamp(this, f));
                     data.add(h);
                 }
             }
             SimpleAdapter sa = new SimpleAdapter(this,
                                                 data,
                                                 R.layout.uploader_list_item_layout,
-                                                new String[] {"dirname"},
-                                                new int[] {R.id.filename});
+                                                new String[] {"dirname", "last_mod"},
+                                                new int[] {R.id.filename, R.id.last_mod});
             
             mListView.setAdapter(sa);
             Button btnChooseFolder = (Button) findViewById(R.id.uploader_choose_folder);
@@ -443,6 +452,18 @@ public class Uploader extends FileActivity
         }
     }
 
+    private Vector<OCFile> sortFileList(Vector<OCFile> files) {
+        SharedPreferences sharedPreferences = PreferenceManager
+                .getDefaultSharedPreferences(this);
+
+        // Read sorting order, default to sort by name ascending
+        FileStorageUtils.mSortOrder = sharedPreferences.getInt("sortOrder", 0);
+        FileStorageUtils.mSortAscending = sharedPreferences.getBoolean("sortAscending", true);
+
+        files = FileStorageUtils.sortOcFolder(files);
+        return files;
+    }
+
     private String generatePath(Stack<String> dirs) {
         String full_path = "";