From cb203f5fd3813b920dc5912bcd4c6e8e595e2169 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 4 Mar 2017 08:04:31 +0100 Subject: [PATCH] Keep draft even when correcting previously sent msg fixes #1822. Thank you @singhalok641 --- .../conversations/entities/Conversation.java | 12 ++++++++++-- .../conversations/ui/ConversationFragment.java | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index eaf01dd0b..2f3989dd8 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -58,6 +58,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public static final String ATTRIBUTE_CRYPTO_TARGETS = "crypto_targets"; public static final String ATTRIBUTE_LAST_CLEAR_HISTORY = "last_clear_history"; + private String draftMessage; private String name; private String contactUuid; private String accountUuid; @@ -357,9 +358,8 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } public boolean setCorrectingMessage(Message correctingMessage) { - boolean corrected = this.correctingMessage != null && correctingMessage == null; this.correctingMessage = correctingMessage; - return corrected; + return correctingMessage == null && draftMessage != null; } public Message getCorrectingMessage() { @@ -383,6 +383,14 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } } + public void setDraftMessage(String draftMessage) { + this.draftMessage = draftMessage; + } + + public String getDraftMessage() { + return draftMessage; + } + public interface OnMessageFound { void onMessageFound(final Message message); } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index a8a1d0ba7..3ac2447ea 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -344,11 +344,11 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa break; case CANCEL: if (conversation != null) { - if (conversation.getCorrectingMessage() != null) { - conversation.setCorrectingMessage(null); + if(conversation.setCorrectingMessage(null)) { mEditMessage.getEditableText().clear(); - } - if (conversation.getMode() == Conversation.MODE_MULTI) { + mEditMessage.getEditableText().append(conversation.getDraftMessage()); + conversation.setDraftMessage(null); + } else if (conversation.getMode() == Conversation.MODE_MULTI) { conversation.setNextCounterpart(null); } updateChatMsgHint(); @@ -839,6 +839,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa message = message.next(); } this.conversation.setCorrectingMessage(message); + final Editable editable = mEditMessage.getText(); + this.conversation.setDraftMessage(editable.toString()); this.mEditMessage.getEditableText().clear(); this.mEditMessage.getEditableText().append(message.getBody()); @@ -1072,8 +1074,12 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa protected void messageSent() { mSendingPgpMessage.set(false); - mEditMessage.getEditableText().clear(); - conversation.setCorrectingMessage(null); + Editable editable = mEditMessage.getEditableText(); + editable.clear(); + if (conversation.setCorrectingMessage(null)) { + editable.append(conversation.getDraftMessage()); + conversation.setDraftMessage(null); + } updateChatMsgHint(); new Handler().post(new Runnable() { @Override