Always show downloaded data in megabytes

We omit the unit for the downloaded data and assume it's MB, so
we must always show megabytes.
This commit is contained in:
Gabriele M
2017-07-18 13:18:41 +02:00
parent 8ce10da9ce
commit 6abafa60a8
2 changed files with 8 additions and 5 deletions

View File

@@ -123,8 +123,8 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
final String downloadId = update.getDownloadId();
if (mUpdaterController.isDownloading(downloadId)) {
String downloaded = Formatter.formatBytes(mContext.getResources(),
update.getFile().length(), Formatter.FLAG_SHORTER).value;
String downloaded = StringGenerator.bytesToMegabytes(mContext,
update.getFile().length());
String total = Formatter.formatShortFileSize(mContext, update.getFileSize());
long eta = update.getEta();
if (eta > 0) {
@@ -153,8 +153,8 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
} else {
canDelete = true;
setButtonAction(viewHolder.mAction, Action.RESUME, downloadId, !busy);
String downloaded = Formatter.formatBytes(mContext.getResources(),
update.getFile().length(), Formatter.FLAG_SHORTER).value;
String downloaded = StringGenerator.bytesToMegabytes(mContext,
update.getFile().length());
String total = Formatter.formatShortFileSize(mContext, update.getFileSize());
viewHolder.mProgressText.setText(mContext.getString(R.string.list_download_progress,
downloaded, total));

View File

@@ -60,9 +60,12 @@ public final class StringGenerator {
return f.format(date);
}
public static String bytesToMegabytes(Context context, long bytes) {
return String.format(getCurrentLocale(context), "%.0f", bytes / 1024.f / 1024.f);
}
public static Locale getCurrentLocale(Context context) {
return context.getResources().getConfiguration().getLocales()
.getFirstMatch(context.getResources().getAssets().getLocales());
}
}