aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-23 21:48:57 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-23 21:48:57 +0200
commit5f5bd7413c22505b08638c6b29b582fe03b6c636 (patch)
tree82dbbdeba726f63d45f0adc8528224e1b241f3f8 /src/main/java/de/pixart
parent3e487b928d7969dbb1adac68771d8e8959dfad45 (diff)
provide fallback in case synchronizing around message list fails for some reason
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java59
1 files changed, 32 insertions, 27 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 0b399393d..debc7bdd2 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -143,7 +143,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private static final String STATE_LAST_MESSAGE_UUID = "state_last_message_uuid";
- final protected List<Message> messageList = new ArrayList<>();
+ private final List<Message> messageList = new ArrayList<>();
final private List<Uri> mPendingImageUris = new ArrayList<>();
private String lastMessageUuid = null;
public Uri mPendingEditorContent = null;
@@ -239,33 +239,33 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return;
}
runOnUiThread(() -> {
- final int oldPosition = binding.messagesView.getFirstVisiblePosition();
- Message message = null;
- int childPos;
- for (childPos = 0; childPos + oldPosition < messageList.size(); ++childPos) {
- message = messageList.get(oldPosition + childPos);
- if (message.getType() != Message.TYPE_STATUS) {
- break;
+ synchronized (messageList) {
+ final int oldPosition = binding.messagesView.getFirstVisiblePosition();
+ Message message = null;
+ int childPos;
+ for (childPos = 0; childPos + oldPosition < messageList.size(); ++childPos) {
+ message = messageList.get(oldPosition + childPos);
+ if (message.getType() != Message.TYPE_STATUS) {
+ break;
+ }
}
+ final String uuid = message != null ? message.getUuid() : null;
+ View v = binding.messagesView.getChildAt(childPos);
+ final int pxOffset = (v == null) ? 0 : v.getTop();
+ ConversationFragment.this.conversation.populateWithMessages(ConversationFragment.this.messageList);
+ try {
+ updateStatusMessages();
+ } catch (IllegalStateException e) {
+ Log.d(Config.LOGTAG, "caught illegal state exception while updating status messages");
+ }
+ messageListAdapter.notifyDataSetChanged();
+ int pos = Math.max(getIndexOf(uuid, messageList), 0);
+ binding.messagesView.setSelectionFromTop(pos, pxOffset);
+ if (messageLoaderToast != null) {
+ messageLoaderToast.cancel();
+ }
+ conversation.messagesLoaded.set(true);
}
- final String uuid = message != null ? message.getUuid() : null;
- View v = binding.messagesView.getChildAt(childPos);
- final int pxOffset = (v == null) ? 0 : v.getTop();
- ConversationFragment.this.conversation.populateWithMessages(ConversationFragment.this.messageList);
- try {
- updateStatusMessages();
- } catch (IllegalStateException e) {
- Log.d(Config.LOGTAG, "caught illegal state exception while updating status messages");
- }
- messageListAdapter.notifyDataSetChanged();
- int pos = Math.max(getIndexOf(uuid, messageList), 0);
- binding.messagesView.setSmoothScrollbarEnabled(true);
- binding.messagesView.setFastScrollEnabled(false);
- binding.messagesView.setSelectionFromTop(pos, pxOffset);
- if (messageLoaderToast != null) {
- messageLoaderToast.cancel();
- }
- conversation.messagesLoaded.set(true);
});
}
@@ -1863,7 +1863,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (pos >= 0) {
Message message = null;
for (int i = pos; i >= 0; --i) {
- message = (Message) binding.messagesView.getItemAtPosition(i);
+ try {
+ message = (Message) binding.messagesView.getItemAtPosition(i);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ //should not happen if we synchronize properly. however if that fails we just gonna try item -1
+ continue;
+ }
if (message.getType() != Message.TYPE_STATUS) {
break;
}