From d390345073695da3aff48f861a1264c09fadba02 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 23 Mar 2019 07:27:03 +0100 Subject: [PATCH] show max file upload size in server info --- .../eu/siacs/conversations/ui/EditAccountActivity.java | 2 +- .../siacs/conversations/ui/adapter/MessageAdapter.java | 8 +------- .../java/eu/siacs/conversations/utils/UIHelper.java | 10 ++++++++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index d54299fa3..5be8525f6 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -1023,7 +1023,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.binding.serverInfoPep.setText(R.string.server_info_unavailable); } if (features.httpUpload(0)) { - this.binding.serverInfoHttpUpload.setText(R.string.server_info_available); + this.binding.serverInfoHttpUpload.setText(UIHelper.filesizeToString(features.getMaxHttpUploadSize())); } else if (features.p1S3FileTransfer()) { this.binding.serverInfoHttpUploadDescription.setText(R.string.p1_s3_filetransfer); this.binding.serverInfoHttpUpload.setText(R.string.server_info_available); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index b6324c510..54f376650 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -183,13 +183,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie && message.getMergedStatus() <= Message.STATUS_RECEIVED; if (message.isFileOrImage() || transferable != null) { FileParams params = message.getFileParams(); - if (params.size > (1.5 * 1024 * 1024)) { - filesize = Math.round(params.size * 1f / (1024 * 1024)) + " MiB"; - } else if (params.size >= 1024) { - filesize = Math.round(params.size * 1f / 1024) + " KiB"; - } else if (params.size > 0) { - filesize = params.size + " B"; - } + filesize = params.size > 0 ? UIHelper.filesizeToString(params.size) : null; if (transferable != null && transferable.getStatus() == Transferable.STATUS_FAILED) { error = true; } diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index 83cff19b4..e9360226f 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -572,4 +572,14 @@ public class UIHelper { return new ListItem.Tag(context.getString(R.string.presence_online), 0xff259b24); } } + + public static String filesizeToString(long size) { + if (size > (1.5 * 1024 * 1024)) { + return Math.round(size * 1f / (1024 * 1024)) + " MiB"; + } else if (size >= 1024) { + return Math.round(size * 1f / 1024) + " KiB"; + } else { + return size + " B"; + } + } }