synchronized message list in conversation fragment

This commit is contained in:
iNPUTmice 2014-11-18 14:43:15 +01:00
parent dcebc120ac
commit 10bf2b77a8

View file

@ -114,13 +114,13 @@ public class ConversationFragment extends Fragment {
@Override @Override
public void onScroll(AbsListView view, int firstVisibleItem, public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) { int visibleItemCount, int totalItemCount) {
synchronized (ConversationFragment.this.messageList) {
if (firstVisibleItem == 0 && messagesLoaded) { if (firstVisibleItem == 0 && messagesLoaded) {
long timestamp = messageList.get(0).getTimeSent(); long timestamp = ConversationFragment.this.messageList.get(0).getTimeSent();
messagesLoaded = false; messagesLoaded = false;
int size = activity.xmppConnectionService.loadMoreMessages( int size = activity.xmppConnectionService.loadMoreMessages(conversation, timestamp);
conversation, timestamp); ConversationFragment.this.messageList.clear();
messageList.clear(); ConversationFragment.this.messageList.addAll(conversation.getMessages());
messageList.addAll(conversation.getMessages());
updateStatusMessages(); updateStatusMessages();
messageListAdapter.notifyDataSetChanged(); messageListAdapter.notifyDataSetChanged();
if (size != 0) { if (size != 0) {
@ -129,6 +129,7 @@ public class ConversationFragment extends Fragment {
messagesView.setSelectionFromTop(size + 1, 0); messagesView.setSelectionFromTop(size + 1, 0);
} }
} }
}
}; };
private IntentSender askForPassphraseIntent = null; private IntentSender askForPassphraseIntent = null;
protected OnClickListener clickToDecryptListener = new OnClickListener() { protected OnClickListener clickToDecryptListener = new OnClickListener() {
@ -284,10 +285,8 @@ public class ConversationFragment extends Fragment {
messagesView = (ListView) view.findViewById(R.id.messages_view); messagesView = (ListView) view.findViewById(R.id.messages_view);
messagesView.setOnScrollListener(mOnScrollListener); messagesView.setOnScrollListener(mOnScrollListener);
messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL); messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
messageListAdapter = new MessageAdapter( messageListAdapter = new MessageAdapter((ConversationActivity) getActivity(), this.messageList);
(ConversationActivity) getActivity(), this.messageList); messageListAdapter.setOnContactPictureClicked(new OnContactPictureClicked() {
messageListAdapter
.setOnContactPictureClicked(new OnContactPictureClicked() {
@Override @Override
public void onContactPictureClicked(Message message) { public void onContactPictureClicked(Message message) {
@ -342,11 +341,13 @@ public class ConversationFragment extends Fragment {
@Override @Override
public void onCreateContextMenu(ContextMenu menu, View v, public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) { ContextMenuInfo menuInfo) {
synchronized (this.messageList) {
super.onCreateContextMenu(menu, v, menuInfo); super.onCreateContextMenu(menu, v, menuInfo);
AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo; AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
this.selectedMessage = this.messageList.get(acmi.position); this.selectedMessage = this.messageList.get(acmi.position);
populateContextMenu(menu); populateContextMenu(menu);
} }
}
private void populateContextMenu(ContextMenu menu) { private void populateContextMenu(ContextMenu menu) {
if (this.selectedMessage.getType() != Message.TYPE_STATUS) { if (this.selectedMessage.getType() != Message.TYPE_STATUS) {
@ -512,6 +513,7 @@ public class ConversationFragment extends Fragment {
} }
public void updateMessages() { public void updateMessages() {
synchronized (this.messageList) {
if (getView() == null) { if (getView() == null) {
return; return;
} }
@ -603,6 +605,7 @@ public class ConversationFragment extends Fragment {
this.updateSendButton(); this.updateSendButton();
} }
} }
}
private void decryptNext() { private void decryptNext() {
Message next = this.mEncryptedMessages.peek(); Message next = this.mEncryptedMessages.peek();
@ -695,6 +698,7 @@ public class ConversationFragment extends Fragment {
} }
protected void updateStatusMessages() { protected void updateStatusMessages() {
synchronized (this.messageList) {
if (conversation.getMode() == Conversation.MODE_SINGLE) { if (conversation.getMode() == Conversation.MODE_SINGLE) {
for (int i = this.messageList.size() - 1; i >= 0; --i) { for (int i = this.messageList.size() - 1; i >= 0; --i) {
if (this.messageList.get(i).getStatus() == Message.STATUS_RECEIVED) { if (this.messageList.get(i).getStatus() == Message.STATUS_RECEIVED) {
@ -709,6 +713,7 @@ public class ConversationFragment extends Fragment {
} }
} }
} }
}
protected void makeFingerprintWarning() { protected void makeFingerprintWarning() {
if (conversation.smpRequested()) { if (conversation.smpRequested()) {