From 4557a3fc4fe5b93807961eae7b0527b7d8cf13e7 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 27 May 2018 20:39:12 +0200 Subject: [PATCH] make sure account is connected before attempting to download p1s3 --- .../conversations/http/HttpConnectionManager.java | 10 ++++++++++ .../siacs/conversations/ui/ConversationFragment.java | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/http/HttpConnectionManager.java b/src/main/java/eu/siacs/conversations/http/HttpConnectionManager.java index f91a02042..1a7df8ee5 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/http/HttpConnectionManager.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Proxy; +import java.net.URL; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.util.List; @@ -52,6 +53,15 @@ public class HttpConnectionManager extends AbstractConnectionManager { this.uploadConnections.add(connection); } + public boolean checkConnection(Message message) { + final Account account = message.getConversation().getAccount(); + final URL url = message.getFileParams().url; + if (url.getProtocol().equalsIgnoreCase(P1S3UrlStreamHandler.PROTOCOL_NAME) && account.getStatus() != Account.State.ONLINE) { + return false; + } + return mXmppConnectionService.hasInternetConnection(); + } + public void finishConnection(HttpDownloadConnection connection) { this.downloadConnections.remove(connection); } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 9b1d7bfbd..9b32a535f 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1387,7 +1387,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke Transferable transferable = message.getTransferable(); if (transferable != null) { if (transferable instanceof TransferablePlaceholder && message.hasFileOnRemoteHost()) { - activity.xmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message, true); + createNewConnection(message); return; } if (!transferable.start()) { @@ -1395,10 +1395,18 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke Toast.makeText(getActivity(), R.string.not_connected_try_again, Toast.LENGTH_SHORT).show(); } } else if (message.treatAsDownloadable()) { - activity.xmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message, true); + createNewConnection(message); } } + private void createNewConnection(final Message message) { + if (!activity.xmppConnectionService.getHttpConnectionManager().checkConnection(message)) { + Toast.makeText(getActivity(), R.string.not_connected_try_again, Toast.LENGTH_SHORT).show(); + return; + } + activity.xmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message, true); + } + @SuppressLint("InflateParams") protected void clearHistoryDialog(final Conversation conversation) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());