diff --git a/res/layout/list_item.xml b/res/layout/list_item.xml index 24bbec75c1..a3918c7299 100644 --- a/res/layout/list_item.xml +++ b/res/layout/list_item.xml @@ -30,12 +30,12 @@ android:orientation="horizontal"> @@ -89,14 +89,22 @@ android:layout_height="wrap_content" android:layout_marginLeft="0dp" android:layout_marginRight="4dp" - android:weightSum="1"> + android:orientation="horizontal"> + + @@ -107,7 +115,6 @@ android:gravity="right" android:text="TextView" android:textColor="@color/list_item_lastmod_and_filesize_text" - android:layout_weight=".5" android:textSize="@dimen/two_line_secondary_text_size"/> diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index baa293281d..f839c23b40 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -192,6 +192,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { switch (viewType){ case LIST_ITEM: TextView fileSizeV = (TextView) view.findViewById(R.id.file_size); + 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); @@ -200,6 +201,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { checkBoxV.setVisibility(View.GONE); + fileSizeSeparatorV.setVisibility(View.VISIBLE); fileSizeV.setVisibility(View.VISIBLE); fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength())); @@ -221,6 +223,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { } } else { //Folder + fileSizeSeparatorV.setVisibility(View.INVISIBLE); fileSizeV.setVisibility(View.INVISIBLE); } diff --git a/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java b/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java index 06745f8de3..d8abc664db 100644 --- a/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java @@ -111,9 +111,11 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter { fileIcon.setTag(file.hashCode()); TextView fileSizeV = (TextView) view.findViewById(R.id.file_size); + 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); if (!file.isDirectory()) { + fileSizeSeparatorV.setVisibility(View.VISIBLE); fileSizeV.setVisibility(View.VISIBLE); fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.length())); @@ -163,6 +165,7 @@ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter { } } else { + fileSizeSeparatorV.setVisibility(View.GONE); fileSizeV.setVisibility(View.GONE); lastModV.setVisibility(View.GONE); checkBoxV.setVisibility(View.GONE); diff --git a/src/com/owncloud/android/utils/DisplayUtils.java b/src/com/owncloud/android/utils/DisplayUtils.java index 7030c87f09..d81fe78630 100644 --- a/src/com/owncloud/android/utils/DisplayUtils.java +++ b/src/com/owncloud/android/utils/DisplayUtils.java @@ -22,6 +22,7 @@ package com.owncloud.android.utils; +import java.math.BigDecimal; import java.net.IDN; import java.text.DateFormat; import java.util.Arrays; @@ -55,6 +56,7 @@ public class DisplayUtils { //private static String TAG = DisplayUtils.class.getSimpleName(); private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; + private static final int[] sizeScales = { 0, 0, 0, 1, 1, 2, 2, 2, 2 }; private static HashMap mimeType2HUmanReadable; static { @@ -114,7 +116,11 @@ public class DisplayUtils { /** * Converts the file size in bytes to human readable output. - * + *
    + *
  • appends a size suffix, e.g. B, KB, MB etc.
  • + *
  • rounds the size based on the suffix to 0,1 or 2 decimals
  • + *
+ * * @param bytes Input file size * @return Like something readable like "12 MB" */ @@ -125,8 +131,9 @@ public class DisplayUtils { result /= 1024.; attachedsuff++; } - result = ((int) (result * 100)) / 100.; - return result + " " + sizeSuffixes[attachedsuff]; + + return new BigDecimal(result).setScale( + sizeScales[attachedsuff], BigDecimal.ROUND_HALF_UP) + " " + sizeSuffixes[attachedsuff]; } /**