diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-11-08 19:01:13 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-11-08 19:01:13 +0100 |
commit | a23f0b4d6726fb606a8d5a7bd6f84c3c7f35c88b (patch) | |
tree | a737806c35f21720b70ce430e62c6e3f29d54dd8 | |
parent | afa869ddd22ba9913a87da13d2194e069379f910 (diff) |
show max file size for httpupload in profile --> server info
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/EditAccountActivity.java | 31 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/xmpp/XmppConnection.java | 2 | ||||
-rw-r--r-- | src/main/res/values/strings.xml | 5 |
3 files changed, 34 insertions, 4 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 9d5bd279b..775e8f6dc 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -41,6 +41,7 @@ import org.openintents.openpgp.util.OpenPgpUtils; import java.net.URL; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; @@ -53,6 +54,7 @@ import de.pixart.messenger.databinding.DialogPresenceBinding; import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Presence; import de.pixart.messenger.entities.PresenceTemplate; +import de.pixart.messenger.entities.ServiceDiscoveryResult; import de.pixart.messenger.services.BarcodeProvider; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.services.XmppConnectionService.OnAccountUpdate; @@ -63,6 +65,7 @@ import de.pixart.messenger.ui.util.PendingItem; import de.pixart.messenger.ui.util.SoftKeyboardUtils; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.MenuDoubleTabUtil; +import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xml.Element; @@ -1053,7 +1056,11 @@ 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); + if (getHttpUploadMaxFileSize().equals("0")) { + this.binding.serverInfoHttpUpload.setText(R.string.server_info_available); + } else { + this.binding.serverInfoHttpUpload.setText(getString(R.string.server_info_available_with, getHttpUploadMaxFileSize())); + } } else if (features.p1S3FileTransfer()) { this.binding.serverInfoHttpUploadDescription.setText(R.string.p1_s3_filetransfer); this.binding.serverInfoHttpUpload.setText(R.string.server_info_available); @@ -1163,6 +1170,28 @@ 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 removeErrorsOnAllBut(TextInputLayout exception) { if (this.binding.accountJidLayout != exception) { this.binding.accountJidLayout.setErrorEnabled(false); diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index eed687222..a40670c55 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -1516,7 +1516,7 @@ public class XmppConnection implements Runnable { this.streamId = null; } - private List<Entry<Jid, ServiceDiscoveryResult>> findDiscoItemsByFeature(final String feature) { + public List<Entry<Jid, ServiceDiscoveryResult>> findDiscoItemsByFeature(final String feature) { synchronized (this.disco) { final List<Entry<Jid, ServiceDiscoveryResult>> items = new ArrayList<>(); for (final Entry<Jid, ServiceDiscoveryResult> cursor : this.disco.entrySet()) { diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index ef6cddbfb..81be5072d 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -182,8 +182,8 @@ <string name="server_info_pep">XEP-0163: PEP (Avatars / OMEMO)</string> <string name="server_info_http_upload">XEP-0363: HTTP File Upload</string> <string name="server_info_push">XEP-0357: Push</string> - <string name="server_info_available">available</string> - <string name="server_info_unavailable">unavailable</string> + <string name="server_info_available">yes</string> + <string name="server_info_unavailable">no</string> <string name="missing_public_keys">Missing public key announcements</string> <string name="last_seen_now">online</string> <string name="last_seen_min">1 minute ago</string> @@ -836,5 +836,6 @@ <string name="remote_server_timeout">Remote server timeout</string> <string name="already_drafting_message">You are already drafting a message.</string> <string name="bad_key_for_encryption">Bad key for encryption.</string> + <string name="server_info_available_with">yes, %s</string> </resources> |