make sure account is connected before attempting to download p1s3

This commit is contained in:
Daniel Gultsch 2018-05-27 20:39:12 +02:00
parent be3955ba8f
commit 4557a3fc4f
2 changed files with 20 additions and 2 deletions

View file

@ -8,6 +8,7 @@ import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Proxy; import java.net.Proxy;
import java.net.URL;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.List; import java.util.List;
@ -52,6 +53,15 @@ public class HttpConnectionManager extends AbstractConnectionManager {
this.uploadConnections.add(connection); 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) { public void finishConnection(HttpDownloadConnection connection) {
this.downloadConnections.remove(connection); this.downloadConnections.remove(connection);
} }

View file

@ -1387,7 +1387,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
Transferable transferable = message.getTransferable(); Transferable transferable = message.getTransferable();
if (transferable != null) { if (transferable != null) {
if (transferable instanceof TransferablePlaceholder && message.hasFileOnRemoteHost()) { if (transferable instanceof TransferablePlaceholder && message.hasFileOnRemoteHost()) {
activity.xmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message, true); createNewConnection(message);
return; return;
} }
if (!transferable.start()) { 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(); Toast.makeText(getActivity(), R.string.not_connected_try_again, Toast.LENGTH_SHORT).show();
} }
} else if (message.treatAsDownloadable()) { } 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") @SuppressLint("InflateParams")
protected void clearHistoryDialog(final Conversation conversation) { protected void clearHistoryDialog(final Conversation conversation) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());