show cancelled instead of delivery failed if user requested to abort transfer

This commit is contained in:
Daniel Gultsch 2018-10-07 14:59:08 +02:00
parent 284861de65
commit de0741bdf7
4 changed files with 13 additions and 9 deletions

View File

@ -73,6 +73,8 @@ public class Message extends AbstractEntity {
public static final String MARKABLE = "markable"; public static final String MARKABLE = "markable";
public static final String ME_COMMAND = "/me "; public static final String ME_COMMAND = "/me ";
public static final String ERROR_MESSAGE_CANCELLED = "eu.siacs.conversations.cancelled";
public boolean markable = false; public boolean markable = false;
protected String conversationUuid; protected String conversationUuid;

View File

@ -2,11 +2,8 @@ package eu.siacs.conversations.http;
import android.os.PowerManager; import android.os.PowerManager;
import android.util.Log; import android.util.Log;
import android.util.Pair;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
@ -43,7 +40,7 @@ public class HttpUploadConnection implements Transferable {
private final SlotRequester mSlotRequester; private final SlotRequester mSlotRequester;
private final Method method; private final Method method;
private final boolean mUseTor; private final boolean mUseTor;
private boolean canceled = false; private boolean cancelled = false;
private boolean delayed = false; private boolean delayed = false;
private DownloadableFile file; private DownloadableFile file;
private Message message; private Message message;
@ -86,13 +83,13 @@ public class HttpUploadConnection implements Transferable {
@Override @Override
public void cancel() { public void cancel() {
this.canceled = true; this.cancelled = true;
} }
private void fail(String errorMessage) { private void fail(String errorMessage) {
mHttpConnectionManager.finishUploadConnection(this); mHttpConnectionManager.finishUploadConnection(this);
message.setTransferable(null); message.setTransferable(null);
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED, errorMessage); mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED, cancelled ? Message.ERROR_MESSAGE_CANCELLED : errorMessage);
} }
public void init(Message message, boolean delay) { public void init(Message message, boolean delay) {
@ -132,7 +129,7 @@ public class HttpUploadConnection implements Transferable {
this.mSlotRequester.request(method, account, file, mime, md5, new SlotRequester.OnSlotRequested() { this.mSlotRequester.request(method, account, file, mime, md5, new SlotRequester.OnSlotRequested() {
@Override @Override
public void success(SlotRequester.Slot slot) { public void success(SlotRequester.Slot slot) {
if (!canceled) { if (!cancelled) {
HttpUploadConnection.this.slot = slot; HttpUploadConnection.this.slot = slot;
new Thread(HttpUploadConnection.this::upload).start(); new Thread(HttpUploadConnection.this::upload).start();
} }
@ -185,7 +182,7 @@ public class HttpUploadConnection implements Transferable {
transmitted = 0; transmitted = 0;
int count; int count;
byte[] buffer = new byte[4096]; byte[] buffer = new byte[4096];
while (((count = innerInputStream.read(buffer)) != -1) && !canceled) { while (((count = innerInputStream.read(buffer)) != -1) && !cancelled) {
transmitted += count; transmitted += count;
os.write(buffer, 0, count); os.write(buffer, 0, count);
mHttpConnectionManager.updateConversationUi(false); mHttpConnectionManager.updateConversationUi(false);

View File

@ -255,7 +255,11 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
} }
break; break;
case Message.STATUS_SEND_FAILED: case Message.STATUS_SEND_FAILED:
if (Message.ERROR_MESSAGE_CANCELLED.equals(message.getErrorMessage())) {
info = getContext().getString(R.string.cancelled);
} else {
info = getContext().getString(R.string.send_failed); info = getContext().getString(R.string.send_failed);
}
error = true; error = true;
break; break;
default: default:

View File

@ -744,4 +744,5 @@
<string name="pref_video_compression_summary">Lower quality means smaller files</string> <string name="pref_video_compression_summary">Lower quality means smaller files</string>
<string name="video_360p">Medium (360p)</string> <string name="video_360p">Medium (360p)</string>
<string name="video_720p">High (720p)</string> <string name="video_720p">High (720p)</string>
<string name="cancelled">cancelled</string>
</resources> </resources>