diff options
author | steckbrief <steckbrief@chefmail.de> | 2018-05-05 20:28:04 +0200 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2018-05-06 13:46:22 +0200 |
commit | 132b27adeef3ab4d305facda7dd035015b00766f (patch) | |
tree | ce90c05d96d747ea1f6cf80129462119a1291dc1 /src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java | |
parent | 853f50e43f68599774469dd12240f35800144991 (diff) |
introduces new message state model
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java index cd2ee4f8..4cecd7f8 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java @@ -43,6 +43,8 @@ import java.util.Collections; import java.util.List; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; +import de.thedevstack.conversationsplus.enums.MessageDirection; +import de.thedevstack.conversationsplus.enums.MessageStatus; import de.thedevstack.conversationsplus.services.filetransfer.FileTransferManager; import de.thedevstack.conversationsplus.services.filetransfer.http.delete.DeleteRemoteFileService; import de.thedevstack.conversationsplus.ui.dialogs.SimpleConfirmDialog; @@ -124,8 +126,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa private RelativeLayout snackbar; private TextView snackbarMessage; private TextView snackbarAction; - private boolean messagesLoaded = true; - private Toast messageLoaderToast; private final int KEYCHAIN_UNLOCK_NOT_REQUIRED = 0; private final int KEYCHAIN_UNLOCK_REQUIRED = 1; private final int KEYCHAIN_UNLOCK_PENDING = 2; @@ -242,16 +242,13 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa private ConversationActivity activity; private Message selectedMessage; - public void setMessagesLoaded() { - this.messagesLoaded = true; - } - private void sendMessage() { final String body = mEditMessage.getText().toString(); if (body.length() == 0 || this.conversation == null) { return; } - Message message = new Message(conversation, body, conversation.getNextEncryption()); + Message message = MessageUtil.createOutgoingMessage(conversation, body); + if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getNextCounterpart() != null) { message.setCounterpart(conversation.getNextCounterpart()); @@ -503,8 +500,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa if (treatAsFile || (GeoHelper.isGeoUri(m.getBody()))) { shareWith.setVisible(true); } - if (m.getStatus() == Message.STATUS_SEND_FAILED - || Message.STATUS_SEND_CANCELED == m.getStatus()) { + if (MessageUtil.isOutgoingMessage(m) + && (MessageStatus.FAILED == m.getMessageStatus() + || MessageStatus.CANCELED == m.getMessageStatus())) { sendAgain.setVisible(true); } if (m.hasFileOnRemoteHost() @@ -518,15 +516,17 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m))); } if ((t != null && !(t instanceof TransferablePlaceholder)) - || (m.isFileOrImage() && (m.getStatus() == Message.STATUS_WAITING - || m.getStatus() == Message.STATUS_OFFERED))) { + || (m.isFileOrImage() && (MessageStatus.WAITING == m.getMessageStatus() || MessageStatus.TRANSMITTING == m.getMessageStatus()))) { // TODO Welche Einschraenkung noch um uebertragung abzubrechen? cancelTransmission.setVisible(true); } if (treatAsFile) { deleteFile.setVisible(true); deleteFile.setTitle(activity.getString(R.string.delete_x_file,UIHelper.getFileDescriptionString(activity, m))); } - if (m.isHttpUploaded() && MessageUtil.isMessageSent(m) && AccountUtil.isFileTransferHttpAvailable(m.getConversation().getAccount())) { + if (m.isHttpUploaded() + && AccountUtil.isFileTransferHttpAvailable(m.getConversation().getAccount()) + && MessageUtil.isOutgoingMessage(m) + && (MessageUtil.isMessageTransmittedOrDisplayedOrReceived(m) || MessageStatus.FAILED == m.getMessageStatus())) { MenuItem deleteRemoteFile = menu.findItem(R.id.msg_ctx_menu_delete_remote_file); deleteRemoteFile.setVisible(true); } @@ -613,7 +613,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa return; } } - activity.xmppConnectionService.resendFailedMessages(message); + activity.xmppConnectionService.resendFailedOrCanceledMessages(message); } private void copyUrl(Message message) { @@ -651,7 +651,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa if (transferable != null) { transferable.cancel(); } else { - MessageUtil.markMessage(message, Message.STATUS_SEND_CANCELED); + MessageUtil.setAndSaveMessageStatus(message, MessageStatus.CANCELED); } } @@ -726,7 +726,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa this.mEditMessage.setKeyboardListener(this); this.messagesView.setAdapter(messageListAdapter); updateMessages(); - this.messagesLoaded = true; int size = this.messageList.size(); if (size > 0) { messagesView.setSelection(size - 1); @@ -878,7 +877,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa private Message getLastPgpDecryptableMessage() { for (final Message message : this.messageList) { if (message.getEncryption() == Message.ENCRYPTION_PGP - && (message.getStatus() == Message.STATUS_RECEIVED || message.getStatus() >= Message.STATUS_SEND) + && MessageUtil.isMessageTransmittedOrDisplayedOrReceived(message) && message.getTransferable() == null) { return message; } @@ -1047,18 +1046,15 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa synchronized (this.messageList) { if (conversation.getMode() == Conversation.MODE_SINGLE) { ChatState state = conversation.getIncomingChatState(); - if (state == ChatState.COMPOSING) { - //this.messageList.add(Message.createStatusMessage(conversation, getString(R.string.contact_is_typing, conversation.getName()))); - } else if (state == ChatState.PAUSED) { - //this.messageList.add(Message.createStatusMessage(conversation, getString(R.string.contact_has_stopped_typing, conversation.getName()))); - } else { + if (state != ChatState.COMPOSING && state != ChatState.PAUSED) { // Do not show status message for (int i = this.messageList.size() - 1; i >= 0; --i) { - if (this.messageList.get(i).getStatus() == Message.STATUS_RECEIVED) { + Message message = this.messageList.get(i); + if (MessageUtil.isIncomingMessage(message)) { return; } else { - if (this.messageList.get(i).getStatus() == Message.STATUS_SEND_DISPLAYED) { + if (MessageStatus.DISPLAYED == message.getMessageStatus()) { this.messageList.add(i + 1, - Message.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, conversation.getName()))); + MessageUtil.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, conversation.getName()))); return; } } @@ -1315,7 +1311,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa updatePgpMessages(); } else if (requestCode == ConversationActivity.REQUEST_TRUST_KEYS_TEXT) { final String body = mEditMessage.getText().toString(); - Message message = new Message(conversation, body, conversation.getNextEncryption()); + Message message = MessageUtil.createOutgoingMessage(conversation, body); sendAxolotlMessage(message); } else if (requestCode == ConversationActivity.REQUEST_TRUST_KEYS_MENU) { int choice = data.getIntExtra("choice", ConversationActivity.ATTACHMENT_CHOICE_INVALID); |