Browse Source

Merge pull request #5 from nextcloud/1193_uploader_layout

Optimizing the uploader layout & taking user configured sorting into account
Andy Scherzinger 8 years ago
parent
commit
0768bd9ff7

+ 2 - 1
AndroidManifest.xml

@@ -73,7 +73,8 @@
         <activity android:name=".ui.activity.UploadFilesActivity" />
         <activity android:name=".ui.activity.ReceiveExternalFilesActivity"
                   android:taskAffinity=""
-                  android:excludeFromRecents="true">
+                  android:excludeFromRecents="true"
+                  android:theme="@style/Theme.ownCloud">
             <intent-filter>
                 <action android:name="android.intent.action.SEND" />
 

+ 2 - 2
res/layout/grid_item.xml

@@ -32,8 +32,8 @@
 
         <ImageView
             android:id="@+id/thumbnail"
-            android:layout_width="72dp"
-            android:layout_height="72dp"
+            android:layout_width="@dimen/standard_list_item_size"
+            android:layout_height="@dimen/standard_list_item_size"
             android:layout_gravity="center_horizontal"
             android:layout_marginLeft="10dp"
             android:layout_marginRight="10dp"

+ 1 - 1
res/layout/list_footer.xml

@@ -15,7 +15,7 @@
         android:layout_gravity="center"
         android:gravity="center"
         android:textColor="@color/secondaryTextColor"
-        android:layout_marginBottom="56dp"
+        android:layout_marginBottom="@dimen/min_list_item_size"
         />
 
 </LinearLayout> 

+ 2 - 2
res/layout/list_item.xml

@@ -22,7 +22,7 @@
     android:layout_width="match_parent"
     android:background="@drawable/list_selector"
     android:orientation="vertical"
-    android:layout_height="72dp">
+    android:layout_height="@dimen/standard_list_item_size">
 
     <LinearLayout
         android:layout_width="match_parent"
@@ -31,7 +31,7 @@
 
         <FrameLayout
             android:layout_width="60dp"
-            android:layout_height="72dp"
+            android:layout_height="@dimen/standard_list_item_size"
             android:paddingLeft="12dp"
             android:paddingBottom="@dimen/standard_padding"
             android:paddingTop="@dimen/standard_padding"

+ 1 - 1
res/layout/listrow_details.xml

@@ -19,7 +19,7 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
-    android:layout_height="56dp"
+    android:layout_height="@dimen/min_list_item_size"
     android:clickable="true"
     android:orientation="vertical"
     android:background="#fff"

+ 3 - 3
res/layout/listrow_group.xml

@@ -21,11 +21,11 @@
     android:id="@+id/textView1"
     android:layout_width="wrap_content"
     android:background="#fff"
-    android:layout_height="56dp"
-    android:layout_marginLeft="8dp"
+    android:layout_height="@dimen/min_list_item_size"
+    android:layout_marginLeft="@dimen/standard_half_margin"
     android:gravity="left"
     android:paddingLeft="@dimen/standard_padding"
-    android:paddingTop="8dp"
+    android:paddingTop="@dimen/standard_half_padding"
     android:textSize="16dp"
     android:groupIndicator="@android:color/transparent"
 /> 

+ 3 - 3
res/layout/upload_list_item.xml

@@ -10,7 +10,7 @@
 
     <FrameLayout
         android:layout_width="60dp"
-        android:layout_height="72dp"
+        android:layout_height="@dimen/standard_list_item_size"
         android:focusable="false"
         android:focusableInTouchMode="false">
 
@@ -105,8 +105,8 @@
 
     
     <FrameLayout
-        android:layout_width="56dp"
-        android:layout_height="72dp"
+        android:layout_width="@dimen/min_list_item_size"
+        android:layout_height="@dimen/standard_list_item_size"
         android:focusable="false"
         android:focusableInTouchMode="false"
         android:layout_gravity="center_vertical"

+ 14 - 18
res/layout/uploader_layout.xml

@@ -18,25 +18,20 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-	android:layout_height="wrap_content" android:orientation="vertical"
-	android:layout_width="wrap_content" android:background="#fefefe"
+	android:layout_height="wrap_content"
+	android:orientation="vertical"
+	android:layout_width="wrap_content"
+	android:background="@color/white"
 	android:gravity="center">
 
-	<TextView android:layout_width="fill_parent"
-		android:text="@string/uploader_top_message"
-		android:layout_height="wrap_content"
-		android:id="@+id/drawer_username"
-		android:textColor="@android:color/black"
-		android:gravity="center_horizontal">
-	</TextView>
+	<FrameLayout
+		android:layout_height="match_parent"
+		android:layout_width="match_parent"
+		android:id="@+id/upload_list"
+		android:layout_above="@+id/upload_actions">
 
-	<FrameLayout android:layout_height="fill_parent"
-		android:layout_width="fill_parent"
-		android:id="@+id/frameLayout1"
-		android:layout_below="@+id/drawer_username"
-		android:layout_above="@+id/linearLayout1">
-
-		<ListView android:id="@android:id/list"
+		<ListView
+			android:id="@android:id/list"
 			android:layout_width="fill_parent"
 			android:layout_height="fill_parent"
 			android:divider="@color/list_divider_background"
@@ -46,11 +41,12 @@
 	</FrameLayout>
 
 	<LinearLayout
-	    android:id="@+id/linearLayout1"
+	    android:id="@+id/upload_actions"
 	    android:layout_width="fill_parent"
 	    android:layout_height="wrap_content"
 	    android:layout_alignParentBottom="true"
-	    android:orientation="horizontal" >
+	    android:orientation="horizontal"
+	    android:padding="@dimen/standard_padding">
 
 		<android.support.v7.widget.AppCompatButton
 			android:theme="@style/Button"

+ 69 - 22
res/layout/uploader_list_item_layout.xml

@@ -17,28 +17,75 @@
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->
-<LinearLayout
-	xmlns:android="http://schemas.android.com/apk/res/android"
-	android:layout_width="fill_parent"
-	android:background="#fefefe"
-	android:orientation="horizontal"
-	android:layout_height="72dp"
-    android:padding="@dimen/standard_padding">
-  
-    <ImageView 
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="@dimen/standard_list_item_size"
+    android:background="@drawable/list_selector"
+    android:orientation="horizontal">
+
+    <ImageView
+        android:id="@+id/thumbnail"
         android:layout_width="@dimen/file_icon_size"
         android:layout_height="@dimen/file_icon_size"
-        android:layout_gravity="center_vertical|center"
-        android:src="@drawable/ic_menu_archive"
-        android:id="@+id/thumbnail"
-        android:layout_marginRight="@dimen/standard_padding"/>
-    
-    <TextView 
-        android:text="TextView" 
-        android:layout_width="fill_parent" 
-        android:id="@+id/filename"
-        android:layout_height="wrap_content"
-        android:textColor="@android:color/black"
-        android:textSize="16sp" />
-    
+        android:layout_gravity="center_vertical"
+        android:layout_margin="12dp"
+        android:src="@drawable/ic_menu_archive" />
+
+    <LinearLayout
+        android:layout_width="0dp"
+        android:layout_height="@dimen/standard_list_item_size"
+        android:layout_weight="1"
+        android:gravity="center_vertical"
+        android:orientation="vertical">
+
+        <TextView
+            android:id="@+id/filename"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical"
+            android:layout_marginLeft="0dp"
+            android:layout_marginRight="4dp"
+            android:ellipsize="middle"
+            android:singleLine="true"
+            android:text="TextView"
+            android:textColor="@color/textColor"
+            android:textSize="16dip" />
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="0dp"
+            android:layout_marginRight="4dp"
+            android:orientation="horizontal">
+
+            <TextView
+                android:id="@+id/file_size"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="Size MB"
+                android:textColor="@color/list_item_lastmod_and_filesize_text"
+                android:textSize="@dimen/two_line_secondary_text_size"/>
+
+            <TextView
+                android:id="@+id/file_separator"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:gravity="right"
+                android:text=", "
+                android:textColor="@color/list_item_lastmod_and_filesize_text"
+                android:textSize="@dimen/two_line_secondary_text_size"/>
+
+            <TextView
+                android:id="@+id/last_mod"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:gravity="right"
+                android:text="Mod Date"
+                android:textColor="@color/list_item_lastmod_and_filesize_text"
+                android:textSize="@dimen/two_line_secondary_text_size"/>
+
+        </LinearLayout>
+
+    </LinearLayout>
+
 </LinearLayout>

+ 2 - 0
res/values/dims.xml

@@ -28,6 +28,8 @@
     <dimen name="standard_half_padding">8dp</dimen>
     <dimen name="standard_margin">16dp</dimen>
     <dimen name="standard_half_margin">8dp</dimen>
+    <dimen name="min_list_item_size">56dp</dimen>
+    <dimen name="standard_list_item_size">72dp</dimen>
 
     <dimen name="two_line_primary_text_size">16sp</dimen>
     <dimen name="two_line_secondary_text_size">14sp</dimen>

+ 1 - 1
res/values/strings.xml

@@ -61,7 +61,7 @@
     <string name="sync_string_files">Files</string>
     <string name="setup_btn_connect">Connect</string>
     <string name="uploader_btn_upload_text">Upload</string>
-    <string name="uploader_top_message">Choose upload folder:</string>
+    <string name="uploader_top_message">Choose upload folder</string>
     <string name="uploader_wrn_no_account_title">No account found</string>
     <string name="uploader_wrn_no_account_text">There are no %1$s accounts on your device. Please set up an account first.</string>
     <string name="uploader_wrn_no_account_setup_btn_text">Setup</string>

+ 81 - 31
src/com/owncloud/android/db/PreferenceManager.java

@@ -22,70 +22,120 @@ package com.owncloud.android.db;
 import android.content.Context;
 import android.content.SharedPreferences;
 
+import com.owncloud.android.utils.FileStorageUtils;
+
 /**
  * Helper to simplify reading of Preferences all around the app
  */
-
-public class PreferenceManager {
-
+public abstract class PreferenceManager {
     /**
      * Constant to access value of last path selected by the user to upload a file shared from other app.
      * Value handled by the app without direct access in the UI.
      */
     private static final String AUTO_PREF__LAST_UPLOAD_PATH = "last_upload_path";
+    private static final String AUTO_PREF__SORT_ORDER = "sort_order";
+    private static final String AUTO_PREF__SORT_ASCENDING = "sort_ascending";
+    private static final String PREF__INSTANT_UPLOADING = "instant_uploading";
+    private static final String PREF__INSTANT_VIDEO_UPLOADING = "instant_video_uploading";
+    private static final String PREF__INSTANT_UPLOAD_ON_WIFI = "instant_upload_on_wifi";
+    private static final String PREF__INSTANT_VIDEO_UPLOAD_ON_WIFI = "instant_video_upload_on_wifi";
 
     public static boolean instantPictureUploadEnabled(Context context) {
-        return android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
-                "instant_uploading",
-                false
-        );
+        return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_UPLOADING, false);
     }
 
     public static boolean instantVideoUploadEnabled(Context context) {
-        return android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
-                "instant_video_uploading",
-                false
-        );
+        return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_VIDEO_UPLOADING, false);
     }
 
     public static boolean instantPictureUploadViaWiFiOnly(Context context) {
-        return android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
-                "instant_upload_on_wifi",
-                false
-        );
+        return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_UPLOAD_ON_WIFI, false);
     }
 
     public static boolean instantVideoUploadViaWiFiOnly(Context context) {
-        return android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
-                "instant_video_upload_on_wifi",
-                false
-        );
+        return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_VIDEO_UPLOAD_ON_WIFI, false);
     }
 
     /**
      * Gets the path where the user selected to do the last upload of a file shared from other app.
      *
-     * @param context   Caller {@link Context}, used to access to shared preferences manager.
-     * @return path     Absolute path to a folder, as previously stored by {@link #setLastUploadPath(String, Context)},
-     *                  or empty String if never saved before.
+     * @param context Caller {@link Context}, used to access to shared preferences manager.
+     * @return path     Absolute path to a folder, as previously stored by {@link #setLastUploadPath(Context, String)},
+     * or empty String if never saved before.
      */
     public static String getLastUploadPath(Context context) {
-        SharedPreferences appPreferences = android.preference.PreferenceManager
-            .getDefaultSharedPreferences(context.getApplicationContext());
-        return appPreferences.getString(AUTO_PREF__LAST_UPLOAD_PATH, "");
+        return getDefaultSharedPreferences(context).getString(AUTO_PREF__LAST_UPLOAD_PATH, "");
     }
 
     /**
      * Saves the path where the user selected to do the last upload of a file shared from other app.
      *
-     * @param path      Absolute path to a folder.
+     * @param context Caller {@link Context}, used to access to shared preferences manager.
+     * @param path    Absolute path to a folder.
+     */
+    public static void setLastUploadPath(Context context, String path) {
+        saveStringPreference(context, AUTO_PREF__LAST_UPLOAD_PATH, path);
+    }
+
+    /**
+     * Gets the sort order which the user has set last.
+     *
+     * @param context Caller {@link Context}, used to access to shared preferences manager.
+     * @return sort order     the sort order, default is {@link FileStorageUtils#SORT_NAME} (sort by name)
+     */
+    public static int getSortOrder(Context context) {
+        return getDefaultSharedPreferences(context).getInt(AUTO_PREF__SORT_ORDER, FileStorageUtils.SORT_NAME);
+    }
+
+    /**
+     * Save the sort order which the user has set last.
+     *
+     * @param context Caller {@link Context}, used to access to shared preferences manager.
+     * @param order   the sort order
+     */
+    public static void setSortOrder(Context context, int order) {
+        saveIntPreference(context, AUTO_PREF__SORT_ORDER, order);
+    }
+
+    /**
+     * Gets the ascending order flag which the user has set last.
+     *
+     * @param context Caller {@link Context}, used to access to shared preferences manager.
+     * @return ascending order     the ascending order, default is true
+     */
+    public static boolean getSortAscending(Context context) {
+        return getDefaultSharedPreferences(context).getBoolean(AUTO_PREF__SORT_ASCENDING, true);
+    }
+
+    /**
+     * Saves the ascending order flag which the user has set last.
+     *
      * @param context   Caller {@link Context}, used to access to shared preferences manager.
+     * @param ascending flag if sorting is ascending or descending
      */
-    public static void setLastUploadPath(String path, Context context) {
-        SharedPreferences.Editor appPrefs = android.preference.PreferenceManager
-            .getDefaultSharedPreferences(context.getApplicationContext()).edit();
-        appPrefs.putString(AUTO_PREF__LAST_UPLOAD_PATH, path);
-        appPrefs.apply();
+    public static void setSortAscending(Context context, boolean ascending) {
+        saveBooleanPreference(context, AUTO_PREF__SORT_ASCENDING, ascending);
     }
 
+    private static void saveBooleanPreference(Context context, String key, boolean value) {
+        SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
+        appPreferences.putBoolean(key, value);
+        appPreferences.apply();
+    }
+
+    private static void saveStringPreference(Context context, String key, String value) {
+        SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
+        appPreferences.putString(key, value);
+        appPreferences.apply();
+    }
+
+    private static void saveIntPreference(Context context, String key, int value) {
+        SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
+        appPreferences.putInt(key, value);
+        appPreferences.apply();
+    }
+
+    private static SharedPreferences getDefaultSharedPreferences(Context context) {
+        return android.preference.PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
+    }
 }

+ 2 - 9
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -33,7 +33,6 @@ import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.ServiceConnection;
-import android.content.SharedPreferences;
 import android.content.SyncRequest;
 import android.content.pm.PackageManager;
 import android.content.res.Resources.NotFoundException;
@@ -41,7 +40,6 @@ import android.os.Build;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.Parcelable;
-import android.preference.PreferenceManager;
 import android.support.design.widget.Snackbar;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
@@ -60,6 +58,7 @@ import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.db.PreferenceManager;
 import com.owncloud.android.files.services.FileDownloader;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader;
@@ -90,7 +89,6 @@ import com.owncloud.android.ui.preview.PreviewTextFragment;
 import com.owncloud.android.ui.preview.PreviewVideoActivity;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.ErrorMessageAdapter;
-import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.PermissionUtil;
 
 import java.io.File;
@@ -564,12 +562,7 @@ public class FileDisplayActivity extends HookActivity
                 break;
             }
             case R.id.action_sort: {
-                SharedPreferences appPreferences = PreferenceManager
-                        .getDefaultSharedPreferences(this);
-
-                // Read sorting order, default to sort by name ascending
-                Integer sortOrder = appPreferences
-                        .getInt("sortOrder", FileStorageUtils.SORT_NAME);
+                Integer sortOrder = PreferenceManager.getSortOrder(this);
 
                 AlertDialog.Builder builder = new AlertDialog.Builder(this);
                 builder.setTitle(R.string.actionbar_sort_title)

+ 23 - 8
src/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java

@@ -35,6 +35,7 @@ import android.content.IntentFilter;
 import android.content.DialogInterface.OnCancelListener;
 import android.content.DialogInterface.OnClickListener;
 import android.content.Intent;
+import android.content.SharedPreferences;
 import android.content.res.Resources.NotFoundException;
 import android.os.Bundle;
 import android.os.Parcelable;
@@ -73,6 +74,7 @@ import com.owncloud.android.ui.fragment.TaskRetainerFragment;
 import com.owncloud.android.ui.helpers.UriUploader;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.ErrorMessageAdapter;
+import com.owncloud.android.utils.FileStorageUtils;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -313,6 +315,8 @@ public class ReceiveExternalFilesActivity extends FileActivity
         Log_OC.d(TAG, "on item click");
         // TODO Enable when "On Device" is recovered ?
         Vector<OCFile> tmpfiles = getStorageManager().getFolderContent(mFile /*, false*/);
+        sortFileList(tmpfiles);
+
         if (tmpfiles.size() <= 0) return;
         // filter on dirtype
         Vector<OCFile> files = new Vector<>();
@@ -378,15 +382,17 @@ public class ReceiveExternalFilesActivity 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);
 
@@ -398,11 +404,13 @@ public class ReceiveExternalFilesActivity extends FileActivity
         if (mFile != null) {
             // TODO Enable when "On Device" is recovered ?
             Vector<OCFile> files = getStorageManager().getFolderContent(mFile/*, false*/);
-            List<HashMap<String, OCFile>> data = new LinkedList<>();
+            sortFileList(files);
+
+            List<HashMap<String, Object>> data = new LinkedList<>();
             for (OCFile f : files) {
-                HashMap<String, OCFile> h = new HashMap<>();
-                    h.put("dirname", f);
-                    data.add(h);
+                HashMap<String, Object> h = new HashMap<>();
+                h.put("dirname", f);
+                data.add(h);
             }
 
             UploaderAdapter sa = new UploaderAdapter(this,
@@ -446,6 +454,12 @@ public class ReceiveExternalFilesActivity extends FileActivity
         synchFolderOp.execute(getAccount(), this, null, null);
     }
 
+    private void sortFileList(Vector<OCFile> files) {
+        // Read sorting order, default to sort by name ascending
+        FileStorageUtils.mSortOrder = PreferenceManager.getSortOrder(this);
+        FileStorageUtils.mSortAscending = PreferenceManager.getSortAscending(this);
+        FileStorageUtils.sortFolder(files);
+    }
 
     private String generatePath(Stack<String> dirs) {
         String full_path = "";
@@ -484,7 +498,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
         UriUploader.UriUploaderResultCode resultCode = uploader.uploadUris();
 
         // Save the path to shared preferences; even if upload is not possible, user chose the folder
-        PreferenceManager.setLastUploadPath(mUploadPath, this);
+        PreferenceManager.setLastUploadPath(this, mUploadPath);
 
         if (resultCode == UriUploader.UriUploaderResultCode.OK) {
             finish();
@@ -577,6 +591,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
         MenuInflater inflater = getMenuInflater();
         inflater.inflate(R.menu.main_menu, menu);
         menu.findItem(R.id.action_sort).setVisible(false);
+        menu.findItem(R.id.action_switch_view).setVisible(false);
         menu.findItem(R.id.action_sync_account).setVisible(false);
         return true;
     }

+ 6 - 23
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -26,11 +26,8 @@ package com.owncloud.android.ui.adapter;
 
 import android.accounts.Account;
 import android.content.Context;
-import android.content.SharedPreferences;
 import android.graphics.Bitmap;
 import android.os.Build;
-import android.preference.PreferenceManager;
-import android.text.format.DateUtils;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -46,6 +43,7 @@ import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
+import com.owncloud.android.db.PreferenceManager;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
@@ -75,8 +73,6 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
     private boolean mGridMode;
 
     private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM };
-
-    private SharedPreferences mAppPreferences;
     
     public FileListListAdapter(
             boolean justFolders, 
@@ -89,14 +85,10 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
         mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
 
         mTransferServiceGetter = transferServiceGetter;
-
-        mAppPreferences = PreferenceManager
-                .getDefaultSharedPreferences(mContext);
         
         // Read sorting order, default to sort by name ascending
-
-        FileStorageUtils.mSortOrder = mAppPreferences.getInt("sortOrder", 0);
-        FileStorageUtils.mSortAscending = mAppPreferences.getBoolean("sortAscending", true);
+        FileStorageUtils.mSortOrder = PreferenceManager.getSortOrder(mContext);
+        FileStorageUtils.mSortAscending = PreferenceManager.getSortAscending(mContext);
         
         // initialise thumbnails cache on background thread
         new ThumbnailsCacheManager.InitDiskCacheTask().execute();
@@ -199,7 +191,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
                     ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
 
                     lastModV.setVisibility(View.VISIBLE);
-                    lastModV.setText(showRelativeTimestamp(file));
+                    lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.getModificationTimestamp()));
 
                     checkBoxV.setVisibility(View.GONE);
 
@@ -430,23 +422,14 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
     
     
     public void setSortOrder(Integer order, boolean ascending) {
-        SharedPreferences.Editor editor = mAppPreferences.edit();
-        editor.putInt("sortOrder", order);
-        editor.putBoolean("sortAscending", ascending);
-        editor.commit();
+        PreferenceManager.setSortOrder(mContext, order);
+        PreferenceManager.setSortAscending(mContext, ascending);
         
         FileStorageUtils.mSortOrder = order;
         FileStorageUtils.mSortAscending = ascending;
-        
 
         mFiles = FileStorageUtils.sortFolder(mFiles);
         notifyDataSetChanged();
-
-    }
-    
-    private CharSequence showRelativeTimestamp(OCFile file){
-        return DisplayUtils.getRelativeDateTimeString(mContext, file.getModificationTimestamp(),
-                DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0);
     }
 
     public void setGridMode(boolean gridMode) {

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

@@ -124,13 +124,14 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
             TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator);
             TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
             ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
+            lastModV.setVisibility(View.VISIBLE);
+            lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.lastModified()));
+
             if (!file.isDirectory()) {
                 fileSizeSeparatorV.setVisibility(View.VISIBLE);
                 fileSizeV.setVisibility(View.VISIBLE);
                 fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.length()));
 
-                lastModV.setVisibility(View.VISIBLE);
-                lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.lastModified()));
                 ListView parentList = (ListView) parent;
                 if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) { 
                     checkBoxV.setVisibility(View.GONE);
@@ -179,7 +180,6 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter {
             } else {
                 fileSizeSeparatorV.setVisibility(View.GONE);
                 fileSizeV.setVisibility(View.GONE);
-                lastModV.setVisibility(View.GONE);
                 checkBoxV.setVisibility(View.GONE);
             }
 

+ 15 - 3
src/com/owncloud/android/ui/adapter/UploaderAdapter.java

@@ -35,6 +35,7 @@ import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncDrawable;
+import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.MimetypeIconUtil;
 
 import java.util.HashMap;
@@ -74,9 +75,20 @@ public class UploaderAdapter extends SimpleAdapter {
         ImageView fileIcon = (ImageView) vi.findViewById(R.id.thumbnail);
         fileIcon.setTag(file.getFileId());
 
-        // TODO enable after #1277 is merged
-//        TextView lastModV = (TextView) vi.findViewById(R.id.last_mod);
-//        lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file));
+        TextView lastModV = (TextView) vi.findViewById(R.id.last_mod);
+        lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.getModificationTimestamp()));
+
+        TextView fileSizeV = (TextView) vi.findViewById(R.id.file_size);
+        TextView fileSizeSeparatorV = (TextView) vi.findViewById(R.id.file_separator);
+
+        if(!file.isFolder()) {
+            fileSizeV.setVisibility(View.VISIBLE);
+            fileSizeSeparatorV.setVisibility(View.VISIBLE);
+            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
+        } else {
+            fileSizeV.setVisibility(View.GONE);
+            fileSizeSeparatorV.setVisibility(View.GONE);
+        }
         
         // get Thumbnail if file is image
         if (file.isImage() && file.getRemoteId() != null){

+ 12 - 0
src/com/owncloud/android/utils/DisplayUtils.java

@@ -163,6 +163,18 @@ public class DisplayUtils {
         }
     }
 
+    /**
+     * calculates the relative time string based on the given modificaion timestamp.
+     *
+     * @param context the app's context
+     * @param modificationTimestamp the UNIX timestamp of the file modification time.
+     * @return a relative time string
+     */
+    public static CharSequence getRelativeTimestamp(Context context, long modificationTimestamp) {
+        return getRelativeDateTimeString(context, modificationTimestamp, DateUtils.SECOND_IN_MILLIS,
+                DateUtils.WEEK_IN_MILLIS, 0);
+    }
+
     @SuppressWarnings("deprecation")
     public static CharSequence getRelativeDateTimeString (
             Context c, long time, long minResolution, long transitionResolution, int flags