diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-06-01 21:23:34 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-06-01 21:23:34 +0200 |
commit | c689078d018fe2d2da4153cab1d5e05a450b7fde (patch) | |
tree | 3567db2f60451de2a3c26b2b2ccdce07eb030294 /src | |
parent | aa85b4a17cb0e04cbb845ee5f0ded3064ca147b9 (diff) |
make sure account is connected before attempting to download p1s3
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/de/pixart/messenger/http/HttpConnectionManager.java | 11 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ConversationFragment.java | 12 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/http/HttpConnectionManager.java b/src/main/java/de/pixart/messenger/http/HttpConnectionManager.java index a16a369d4..fbb93d916 100644 --- a/src/main/java/de/pixart/messenger/http/HttpConnectionManager.java +++ b/src/main/java/de/pixart/messenger/http/HttpConnectionManager.java @@ -6,6 +6,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; @@ -16,6 +17,7 @@ import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.X509TrustManager; +import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Message; import de.pixart.messenger.services.AbstractConnectionManager; import de.pixart.messenger.services.XmppConnectionService; @@ -47,6 +49,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/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index dfc150e5a..40cd257fb 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -1635,7 +1635,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()) { @@ -1643,10 +1643,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()); |