aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-03-31 11:15:31 +0200
committerChristian Schneppe <christian@pix-art.de>2019-03-31 11:15:31 +0200
commit0aadf62cd597662493a26a1d0d522670a805578a (patch)
tree4d32386ef503db98410b96fe264547dbdce7ec31 /src/main/java/de/pixart/messenger
parent061771300e0b85463e149366293a0e59d01e6bdf (diff)
rework max file upload size in server info
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/ui/EditAccountActivity.java28
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java8
-rw-r--r--src/main/java/de/pixart/messenger/utils/UIHelper.java10
3 files changed, 12 insertions, 34 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
index 9f06bcf2a..f1f2912ae 100644
--- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
@@ -1166,11 +1166,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.binding.serverInfoPep.setText(R.string.server_info_unavailable);
}
if (features.httpUpload(0)) {
- if (getHttpUploadMaxFileSize().equals("0")) {
- this.binding.serverInfoHttpUpload.setText(R.string.server_info_available);
- } else {
- this.binding.serverInfoHttpUpload.setText(getHttpUploadMaxFileSize());
- }
+ 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);
@@ -1280,28 +1276,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
}
- private String getHttpUploadMaxFileSize() {
- XmppConnection connection = mAccount.getXmppConnection();
- for (String namespace : new String[]{Namespace.HTTP_UPLOAD, Namespace.HTTP_UPLOAD_LEGACY}) {
- List<Map.Entry<Jid, ServiceDiscoveryResult>> items = connection.findDiscoItemsByFeature(namespace);
- if (items.size() > 0) {
- try {
- long maxsize = Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(namespace, "max-file-size"));
- if (maxsize > (1 * 1024 * 1024)) {
- return Math.round(maxsize * 1f / (1024 * 1024)) + " MiB";
- } else if (maxsize >= (1 * 1024)) {
- return Math.round(maxsize * 1f / 1024) + " KiB";
- } else if (maxsize > 0) {
- return maxsize + " B";
- }
- } catch (Exception e) {
- return "0";
- }
- }
- }
- return "0";
- }
-
private void updateDisplayName(String displayName) {
if (TextUtils.isEmpty(displayName)) {
this.binding.yourName.setText(R.string.no_name_set_instructions);
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
index be483a5f6..203b3a343 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -221,13 +221,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
&& message.getMergedStatus() <= Message.STATUS_RECEIVED;
if (message.isFileOrImage() || transferable != null) {
FileParams params = message.getFileParams();
- if (params.size > (1 * 1024 * 1024)) {
- filesize = Math.round(params.size * 1f / (1024 * 1024)) + " MiB";
- } else if (params.size >= (1 * 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/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java
index ea1878557..a2a536cea 100644
--- a/src/main/java/de/pixart/messenger/utils/UIHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java
@@ -569,4 +569,14 @@ public class UIHelper {
return new ListItem.Tag(context.getString(R.string.presence_online), 0xff259b24, 0);
}
}
+
+ public static String filesizeToString(long size) {
+ if (size > (1 * 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";
+ }
+ }
}