From ed18a08cdb38adeda7f73456d197849fad5d1bc5 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Tue, 17 Apr 2018 12:39:04 +0300 Subject: [PATCH] Extract method for formatting size to AndroidUtils --- OsmAnd/src/net/osmand/AndroidUtils.java | 15 +++++++++++++++ .../plus/audionotes/AudioVideoNotesPlugin.java | 18 +++--------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 1d72eba831..41d101444d 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -29,6 +29,7 @@ import android.view.inputmethod.InputMethodManager; import android.widget.TextView; import net.osmand.plus.R; +import net.osmand.plus.download.DownloadActivity; import java.io.BufferedReader; import java.io.File; @@ -128,6 +129,20 @@ public class AndroidUtils { return DateFormat.getTimeFormat(ctx).format(new Date(time)); } + public static String formatSize(long sizeBytes) { + int sizeKb = (int) ((sizeBytes + 512) >> 10); + if (sizeKb > 0) { + if (sizeKb > 1 << 20) { + return DownloadActivity.formatGb.format(new Object[]{(float) sizeKb / (1 << 20)}); + } else if (sizeBytes > (100 * (1 << 10))) { + return DownloadActivity.formatMb.format(new Object[]{(float) sizeBytes / (1 << 20)}); + } else { + return DownloadActivity.formatKb.format(new Object[]{(float) sizeBytes / (1 << 10)}); + } + } + return ""; + } + public static View findParentViewById(View view, int id) { ViewParent viewParent = view.getParent(); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index b5e47ac15f..709b971d61 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -467,24 +467,12 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { public String getExtendedDescription(Context ctx) { DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(ctx); String date = dateFormat.format(file.lastModified()); - int size = (int) ((file.length() + 512) >> 10); - String sz = ""; - if (size > 0) { - if (size > 1 << 20) { - sz = DownloadActivity.formatGb.format(new Object[]{(float) size / (1 << 20)}); - } else { - if (file.length() > (100 * (1 << 10))) { - sz = DownloadActivity.formatMb.format(new Object[]{(float) file.length() / (1 << 20)}); - } else { - sz = DownloadActivity.formatKb.format(new Object[]{(float) file.length() / (1 << 10)}); - } - } - } + String size = AndroidUtils.formatSize(file.length()); if (isPhoto()) { - return date + " • " + sz; + return date + " • " + size; } updateInternalDescription(); - return date + " • " + sz + " • " + getDuration(ctx, false); + return date + " • " + size + " • " + getDuration(ctx, false); } public String getTypeWithDuration(Context ctx) {