diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-10-20 17:01:37 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-10-20 17:01:37 +0200 |
commit | 0bb2c3c4d5b2a4b676610276fafd50ea55f43706 (patch) | |
tree | 29b902a622b37260b263936db42cf1be5a4ba00b | |
parent | a8a37ec08df75fc2795d3b774d900b7f5af85aa3 (diff) |
keep reference to previous and next message in message
Diffstat (limited to '')
-rw-r--r-- | src/eu/siacs/conversations/entities/Conversation.java | 4 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/Message.java | 36 | ||||
-rw-r--r-- | src/eu/siacs/conversations/xmpp/XmppConnection.java | 1 |
3 files changed, 28 insertions, 13 deletions
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index 600b9d38..e9500a0c 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -57,8 +57,8 @@ public class Conversation extends AbstractEntity { private String nextPresence; - private transient ArrayList<Message> messages = new ArrayList<Message>(); - private transient Account account = null; + protected ArrayList<Message> messages = new ArrayList<Message>(); + protected Account account = null; private transient SessionImpl otrSession; diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java index a256d515..dab28539 100644 --- a/src/eu/siacs/conversations/entities/Message.java +++ b/src/eu/siacs/conversations/entities/Message.java @@ -62,6 +62,9 @@ public class Message extends AbstractEntity { protected Downloadable downloadable = null; public boolean markable = false; + private Message mNextMessage = null; + private Message mPreviousMessage = null; + private Message() { } @@ -293,21 +296,34 @@ public class Message extends AbstractEntity { } public Message next() { - int index = this.conversation.getMessages().indexOf(this); - if (index < 0 || index >= this.conversation.getMessages().size() - 1) { - return null; - } else { - return this.conversation.getMessages().get(index + 1); + if (this.mNextMessage == null) { + synchronized (this.conversation.messages) { + int index = this.conversation.messages.indexOf(this); + if (index < 0 + || index >= this.conversation.getMessages().size() - 1) { + this.mNextMessage = null; + } else { + this.mNextMessage = this.conversation.messages + .get(index + 1); + } + } } + return this.mNextMessage; } public Message prev() { - int index = this.conversation.getMessages().indexOf(this); - if (index <= 0 || index > this.conversation.getMessages().size()) { - return null; - } else { - return this.conversation.getMessages().get(index - 1); + if (this.mPreviousMessage == null) { + synchronized (this.conversation.messages) { + int index = this.conversation.messages.indexOf(this); + if (index <= 0 || index > this.conversation.messages.size()) { + this.mPreviousMessage = null; + } else { + this.mPreviousMessage = this.conversation.messages + .get(index - 1); + } + } } + return this.mPreviousMessage; } public boolean mergable(Message message) { diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 0252d80e..34ff70c9 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -40,7 +40,6 @@ import android.util.SparseArray; import eu.siacs.conversations.Config; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.services.XmppConnectionService; -import eu.siacs.conversations.ui.StartConversationActivity; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.DNSHelper; import eu.siacs.conversations.utils.zlib.ZLibOutputStream; |