From de0741bdf767a2ba74e5a983776f53bd6a10ddb4 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 7 Oct 2018 14:59:08 +0200 Subject: [PATCH] show cancelled instead of delivery failed if user requested to abort transfer --- .../eu/siacs/conversations/entities/Message.java | 2 ++ .../conversations/http/HttpUploadConnection.java | 13 +++++-------- .../conversations/ui/adapter/MessageAdapter.java | 6 +++++- src/main/res/values/strings.xml | 1 + 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index 0957b5fb7..6cbcad7d6 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -73,6 +73,8 @@ public class Message extends AbstractEntity { public static final String MARKABLE = "markable"; public static final String ME_COMMAND = "/me "; + public static final String ERROR_MESSAGE_CANCELLED = "eu.siacs.conversations.cancelled"; + public boolean markable = false; protected String conversationUuid; diff --git a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java index 2a6bdec3a..0dfd2fc0b 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java @@ -2,11 +2,8 @@ package eu.siacs.conversations.http; import android.os.PowerManager; import android.util.Log; -import android.util.Pair; import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; @@ -43,7 +40,7 @@ public class HttpUploadConnection implements Transferable { private final SlotRequester mSlotRequester; private final Method method; private final boolean mUseTor; - private boolean canceled = false; + private boolean cancelled = false; private boolean delayed = false; private DownloadableFile file; private Message message; @@ -86,13 +83,13 @@ public class HttpUploadConnection implements Transferable { @Override public void cancel() { - this.canceled = true; + this.cancelled = true; } private void fail(String errorMessage) { mHttpConnectionManager.finishUploadConnection(this); 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) { @@ -132,7 +129,7 @@ public class HttpUploadConnection implements Transferable { this.mSlotRequester.request(method, account, file, mime, md5, new SlotRequester.OnSlotRequested() { @Override public void success(SlotRequester.Slot slot) { - if (!canceled) { + if (!cancelled) { HttpUploadConnection.this.slot = slot; new Thread(HttpUploadConnection.this::upload).start(); } @@ -185,7 +182,7 @@ public class HttpUploadConnection implements Transferable { transmitted = 0; int count; byte[] buffer = new byte[4096]; - while (((count = innerInputStream.read(buffer)) != -1) && !canceled) { + while (((count = innerInputStream.read(buffer)) != -1) && !cancelled) { transmitted += count; os.write(buffer, 0, count); mHttpConnectionManager.updateConversationUi(false); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index ff580a005..08fe56483 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -255,7 +255,11 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie } break; case Message.STATUS_SEND_FAILED: - info = getContext().getString(R.string.send_failed); + if (Message.ERROR_MESSAGE_CANCELLED.equals(message.getErrorMessage())) { + info = getContext().getString(R.string.cancelled); + } else { + info = getContext().getString(R.string.send_failed); + } error = true; break; default: diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 2193328c1..a729a134d 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -744,4 +744,5 @@ Lower quality means smaller files Medium (360p) High (720p) + cancelled