synchronized message list in conversation fragment

This commit is contained in:
iNPUTmice 2014-11-18 14:43:15 +01:00
parent dcebc120ac
commit 10bf2b77a8
1 changed files with 118 additions and 113 deletions

View File

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