Browse Source

code review plus fixed for the layouts and data to be displayed

now all file list view (uploader, upload external and standard file list have the same layout)
Andy Scherzinger 8 years ago
parent
commit
944af7e62b

+ 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"

+ 35 - 10
res/layout/uploader_list_item_layout.xml

@@ -19,7 +19,7 @@
  -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="56dp"
+    android:layout_height="@dimen/standard_list_item_size"
     android:background="@drawable/list_selector"
     android:orientation="horizontal">
 
@@ -33,7 +33,7 @@
 
     <LinearLayout
         android:layout_width="0dp"
-        android:layout_height="match_parent"
+        android:layout_height="@dimen/standard_list_item_size"
         android:layout_weight="1"
         android:gravity="center_vertical"
         android:orientation="vertical">
@@ -43,7 +43,7 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center_vertical"
-            android:layout_marginLeft="4dp"
+            android:layout_marginLeft="0dp"
             android:layout_marginRight="4dp"
             android:ellipsize="middle"
             android:singleLine="true"
@@ -51,15 +51,40 @@
             android:textColor="@color/textColor"
             android:textSize="16dip" />
 
-        <TextView
-            android:id="@+id/last_mod"
-            android:layout_width="wrap_content"
+        <LinearLayout
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginLeft="4dp"
+            android:layout_marginLeft="0dp"
             android:layout_marginRight="4dp"
-            android:text="TextView"
-            android:textColor="@color/list_item_lastmod_and_filesize_text"
-            android:textSize="12dip" />
+            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>
 

+ 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>

+ 15 - 15
src/com/owncloud/android/db/PreferenceManager.java

@@ -33,8 +33,8 @@ public abstract class PreferenceManager {
      * 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 = "sortOrder";
-    private static final String AUTO_PREF__SORT_ASCENDING = "sortAscending";
+    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";
@@ -60,7 +60,7 @@ public abstract class PreferenceManager {
      * 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)},
+     * @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) {
@@ -70,11 +70,11 @@ public abstract class PreferenceManager {
     /**
      * 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(String path, Context context) {
-        saveStringPreference(AUTO_PREF__LAST_UPLOAD_PATH, path, context);
+    public static void setLastUploadPath(Context context, String path) {
+        saveStringPreference(context, AUTO_PREF__LAST_UPLOAD_PATH, path);
     }
 
     /**
@@ -90,11 +90,11 @@ public abstract class PreferenceManager {
     /**
      * Save the sort order which the user has set last.
      *
-     * @param order   the sort order
      * @param context Caller {@link Context}, used to access to shared preferences manager.
+     * @param order   the sort order
      */
-    public static void setSortOrder(int order, Context context) {
-        saveIntPreference(AUTO_PREF__SORT_ORDER, order, context);
+    public static void setSortOrder(Context context, int order) {
+        saveIntPreference(context, AUTO_PREF__SORT_ORDER, order);
     }
 
     /**
@@ -110,26 +110,26 @@ public abstract class PreferenceManager {
     /**
      * Saves the ascending order flag which the user has set last.
      *
-     * @param ascending flag if sorting is ascending or descending
      * @param context   Caller {@link Context}, used to access to shared preferences manager.
+     * @param ascending flag if sorting is ascending or descending
      */
-    public static void setSortAscending(boolean ascending, Context context) {
-        saveBooleanPreference(AUTO_PREF__SORT_ASCENDING, ascending, context);
+    public static void setSortAscending(Context context, boolean ascending) {
+        saveBooleanPreference(context, AUTO_PREF__SORT_ASCENDING, ascending);
     }
 
-    private static void saveBooleanPreference(String key, boolean value, Context context) {
+    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(String key, String value, Context context) {
+    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(String key, int value, Context context) {
+    private static void saveIntPreference(Context context, String key, int value) {
         SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
         appPreferences.putInt(key, value);
         appPreferences.apply();

+ 1 - 3
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -94,8 +94,6 @@ import com.owncloud.android.utils.PermissionUtil;
 import java.io.File;
 import java.util.ArrayList;
 
-import static com.owncloud.android.db.PreferenceManager.*;
-
 /**
  * Displays, what files the user has available in his ownCloud. This is the main view.
  */
@@ -564,7 +562,7 @@ public class FileDisplayActivity extends HookActivity
                 break;
             }
             case R.id.action_sort: {
-                Integer sortOrder = getSortOrder(this);
+                Integer sortOrder = PreferenceManager.getSortOrder(this);
 
                 AlertDialog.Builder builder = new AlertDialog.Builder(this);
                 builder.setTitle(R.string.actionbar_sort_title)

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

@@ -500,7 +500,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();

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

@@ -191,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(DisplayUtils.getRelativeTimestamp(mContext, file));
+                    lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.getModificationTimestamp()));
 
                     checkBoxV.setVisibility(View.GONE);
 
@@ -422,8 +422,8 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
     
     
     public void setSortOrder(Integer order, boolean ascending) {
-        PreferenceManager.setSortOrder(order, mContext);
-        PreferenceManager.setSortAscending(ascending, mContext);
+        PreferenceManager.setSortOrder(mContext, order);
+        PreferenceManager.setSortAscending(mContext, ascending);
         
         FileStorageUtils.mSortOrder = order;
         FileStorageUtils.mSortAscending = ascending;

+ 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);
             }
 

+ 13 - 1
src/com/owncloud/android/ui/adapter/UploaderAdapter.java

@@ -76,7 +76,19 @@ public class UploaderAdapter extends SimpleAdapter {
         fileIcon.setTag(file.getFileId());
 
         TextView lastModV = (TextView) vi.findViewById(R.id.last_mod);
-        lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file));
+        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){

+ 10 - 3
src/com/owncloud/android/utils/DisplayUtils.java

@@ -163,9 +163,16 @@ public class DisplayUtils {
         }
     }
 
-    public static CharSequence getRelativeTimestamp(Context context, OCFile file) {
-        return getRelativeDateTimeString(context, file.getModificationTimestamp(),
-                DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0);
+    /**
+     * 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")