From 7226fc0010b4b35591930793c2e56174d5d4c193 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 18 Oct 2016 13:06:24 +0200 Subject: update conversation in database background thread --- .../siacs/conversations/services/XmppConnectionService.java | 13 +++++++++---- .../eu/siacs/conversations/ui/ConversationActivity.java | 13 +++++-------- .../eu/siacs/conversations/ui/ConversationFragment.java | 6 ++---- src/main/java/eu/siacs/conversations/ui/XmppActivity.java | 2 +- .../eu/siacs/conversations/ui/adapter/MessageAdapter.java | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 774842a7..e96704f3 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1610,7 +1610,7 @@ public class XmppConnectionService extends Service { ); } } - this.databaseBackend.updateConversation(conversation); + updateConversation(conversation); this.conversations.remove(conversation); updateConversationUi(); } @@ -2140,7 +2140,7 @@ public class XmppConnectionService extends Service { } pushBookmarks(conversation.getAccount()); } - databaseBackend.updateConversation(conversation); + updateConversation(conversation); joinMuc(conversation); } } @@ -2860,8 +2860,13 @@ public class XmppConnectionService extends Service { } } - public void updateConversation(Conversation conversation) { - this.databaseBackend.updateConversation(conversation); + public void updateConversation(final Conversation conversation) { + mDatabaseExecutor.execute(new Runnable() { + @Override + public void run() { + databaseBackend.updateConversation(conversation); + } + }); } private void reconnectAccount(final Account account, final boolean force, final boolean interactive) { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 82b59dfc..85be017a 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -611,10 +611,8 @@ public class ConversationActivity extends XmppActivity @Override public void onClick(DialogInterface dialog, int which) { - conversation - .setNextEncryption(Message.ENCRYPTION_NONE); - xmppConnectionService.databaseBackend - .updateConversation(conversation); + conversation.setNextEncryption(Message.ENCRYPTION_NONE); + xmppConnectionService.updateConversation(conversation); selectPresenceToAttachFile(attachmentChoice, Message.ENCRYPTION_NONE); } }); @@ -888,7 +886,7 @@ public class ConversationActivity extends XmppActivity conversation.setNextEncryption(Message.ENCRYPTION_NONE); break; } - xmppConnectionService.databaseBackend.updateConversation(conversation); + xmppConnectionService.updateConversation(conversation); fragment.updateChatMsgHint(); invalidateOptionsMenu(); refreshUi(); @@ -947,8 +945,7 @@ public class ConversationActivity extends XmppActivity till = System.currentTimeMillis() + (durations[which] * 1000); } conversation.setMutedTill(till); - ConversationActivity.this.xmppConnectionService.databaseBackend - .updateConversation(conversation); + ConversationActivity.this.xmppConnectionService.updateConversation(conversation); updateConversationList(); ConversationActivity.this.mConversationFragment.updateMessages(); invalidateOptionsMenu(); @@ -959,7 +956,7 @@ public class ConversationActivity extends XmppActivity public void unmuteConversation(final Conversation conversation) { conversation.setMutedTill(0); - this.xmppConnectionService.databaseBackend.updateConversation(conversation); + this.xmppConnectionService.updateConversation(conversation); updateConversationList(); ConversationActivity.this.mConversationFragment.updateMessages(); invalidateOptionsMenu(); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index df01e87c..9c23052a 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1262,8 +1262,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa int which) { conversation .setNextEncryption(Message.ENCRYPTION_NONE); - xmppService.databaseBackend - .updateConversation(conversation); + xmppService.updateConversation(conversation); message.setEncryption(Message.ENCRYPTION_NONE); xmppService.sendMessage(message); messageSent(); @@ -1291,8 +1290,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa conversation .setNextEncryption(Message.ENCRYPTION_NONE); message.setEncryption(Message.ENCRYPTION_NONE); - xmppService.databaseBackend - .updateConversation(conversation); + xmppService.updateConversation(conversation); xmppService.sendMessage(message); messageSent(); } diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index e8047ce2..5172e18d 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -574,7 +574,7 @@ public abstract class XmppActivity extends Activity { xmppConnectionService.sendPresence(account); if (conversation != null) { conversation.setNextEncryption(Message.ENCRYPTION_PGP); - xmppConnectionService.databaseBackend.updateConversation(conversation); + xmppConnectionService.updateConversation(conversation); refreshUi(); } if (onSuccess != null) { diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index e9f4bf13..fbd40745 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -450,7 +450,7 @@ public class MessageAdapter extends ArrayAdapter { private void loadMoreMessages(Conversation conversation) { conversation.setLastClearHistory(0); - activity.xmppConnectionService.databaseBackend.updateConversation(conversation); + activity.xmppConnectionService.updateConversation(conversation); conversation.setHasMessagesLeftOnServer(true); conversation.setFirstMamReference(null); long timestamp = conversation.getLastMessageTransmitted(); -- cgit v1.2.3