From: Andy Scherzinger Date: Fri, 16 Oct 2015 12:47:12 +0000 (+0200) Subject: Merge branch 'fix_1192_date_time' of https://github.com/owncloud/android into materia... X-Git-Tag: beta-20151202~3^2~27 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/0e6920c8787c16791f737f28bad678f806c7e5c7?ds=inline;hp=-c Merge branch 'fix_1192_date_time' of https://github.com/owncloud/android into material_fab --- 0e6920c8787c16791f737f28bad678f806c7e5c7 diff --combined src/com/owncloud/android/utils/DisplayUtils.java index 46c66737,ff6cd8b0..99c465ec --- a/src/com/owncloud/android/utils/DisplayUtils.java +++ b/src/com/owncloud/android/utils/DisplayUtils.java @@@ -37,7 -37,6 +37,7 @@@ import com.owncloud.android.MainApp import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; +import java.math.BigDecimal; import java.net.IDN; import java.text.DateFormat; import java.util.Calendar; @@@ -53,7 -52,6 +53,7 @@@ public class DisplayUtils private static final String OWNCLOUD_APP_NAME = "ownCloud"; 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 Map mimeType2HumanReadable; @@@ -74,24 -72,19 +74,24 @@@ /** * Converts the file size in bytes to human readable output. - * + * + * * @param bytes Input file size * @return Like something readable like "12 MB" */ public static String bytesToHumanReadable(long bytes) { double result = bytes; - int attachedsuff = 0; - while (result > 1024 && attachedsuff < sizeSuffixes.length) { + int attachedSuff = 0; + while (result > 1024 && attachedSuff < sizeSuffixes.length) { result /= 1024.; - attachedsuff++; + attachedSuff++; } - result = ((int) (result * 100)) / 100.; - return result + " " + sizeSuffixes[attachedsuff]; + + return new BigDecimal(result).setScale( + sizeScales[attachedSuff], BigDecimal.ROUND_HALF_UP) + " " + sizeSuffixes[attachedSuff]; } /** @@@ -214,8 -207,17 +214,17 @@@ dateString = DateUtils.getRelativeDateTimeString(c, time, minResolution, transitionResolution, flags); } } - - return dateString.toString().split(",")[0]; + + String[] parts = dateString.toString().split(","); + if (parts.length == 2) { + if (parts[1].contains(":") && !parts[0].contains(":")) { + return parts[0]; + } else if (parts[0].contains(":") && !parts[1].contains(":")) { + return parts[1]; + } + } + //dateString contains unexpected format. use localized, absolute date. + return DisplayUtils.unixTimeToHumanReadable(time); } /**