From bcd3be59ce78609e608f4a8f7a868be977fdb4bb Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 2 Jan 2015 12:04:33 +0100 Subject: put Conversations into background mode earlier --- .../siacs/conversations/parser/MessageParser.java | 8 +++--- .../services/NotificationService.java | 4 +++ .../services/XmppConnectionService.java | 18 ++++++++----- .../conversations/ui/ConversationActivity.java | 30 ++++++++++++++++++---- .../conversations/ui/ConversationFragment.java | 3 +-- 5 files changed, 44 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index a395be78..44cda261 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -226,7 +226,7 @@ public class MessageParser extends AbstractParser implements mXmppConnectionService.getConversations(), account, to.toBareJid()); if (conversation != null) { - mXmppConnectionService.markRead(conversation, false); + mXmppConnectionService.markRead(conversation); } } } @@ -503,8 +503,7 @@ public class MessageParser extends AbstractParser implements if (message != null) { if (message.getStatus() == Message.STATUS_SEND) { account.activateGracePeriod(); - mXmppConnectionService.markRead( - message.getConversation(), false); + mXmppConnectionService.markRead(message.getConversation()); } else { message.markUnread(); } @@ -529,8 +528,7 @@ public class MessageParser extends AbstractParser implements if (message.getStatus() == Message.STATUS_RECEIVED) { message.markUnread(); } else { - mXmppConnectionService.markRead(message.getConversation(), - false); + mXmppConnectionService.markRead(message.getConversation()); account.activateGracePeriod(); } } diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index c27ab72a..a30cf2f1 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -16,6 +16,7 @@ import android.support.v4.app.NotificationCompat.Builder; import android.support.v4.app.TaskStackBuilder; import android.text.Html; import android.util.DisplayMetrics; +import android.util.Log; import java.io.FileNotFoundException; import java.util.ArrayList; @@ -368,6 +369,9 @@ public class NotificationService { } public void setIsInForeground(final boolean foreground) { + if (foreground != this.mIsInForeground) { + Log.d(Config.LOGTAG,"setIsInForeground("+Boolean.toString(foreground)+")"); + } this.mIsInForeground = foreground; } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index dc895e5b..bdc51783 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1272,7 +1272,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa private boolean checkListeners() { return (this.mOnAccountUpdate == null - && this.mOnConversationUpdate == null && this.mOnRosterUpdate == null); + && this.mOnConversationUpdate == null + && this.mOnRosterUpdate == null + && this.mOnUpdateBlocklist == null); } private void switchToForeground() { @@ -1996,20 +1998,22 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa return null; } - public void markRead(Conversation conversation, boolean calledByUi) { + public void markRead(final Conversation conversation) { mNotificationService.clear(conversation); - final Message markable = conversation.getLatestMarkableMessage(); conversation.markRead(); - if (confirmMessages() && markable != null && markable.getRemoteMsgId() != null && calledByUi) { + } + + public void sendReadMarker(final Conversation conversation) { + final Message markable = conversation.getLatestMarkableMessage(); + this.markRead(conversation); + if (confirmMessages() && markable != null && markable.getRemoteMsgId() != null) { Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid()+ ": sending read marker to " + markable.getCounterpart().toString()); Account account = conversation.getAccount(); final Jid to = markable.getCounterpart(); MessagePacket packet = mMessageGenerator.confirm(account, to, markable.getRemoteMsgId()); this.sendMessagePacket(conversation.getAccount(),packet); } - if (!calledByUi) { - updateConversationUi(); - } + updateConversationUi(); } public SecureRandom getRNG() { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 71074d3d..306f61eb 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -85,6 +85,8 @@ public class ConversationActivity extends XmppActivity private Toast prepareFileToast; + private boolean mActivityPaused = false; + public List getConversationList() { return this.conversationList; @@ -262,11 +264,15 @@ public class ConversationActivity extends XmppActivity this.updateActionBarTitle(); this.invalidateOptionsMenu(); if (xmppConnectionServiceBound) { - xmppConnectionService.getNotificationService().setOpenConversation(getSelectedConversation()); - if (!getSelectedConversation().isRead()) { - xmppConnectionService.markRead(getSelectedConversation(), true); - listView.invalidateViews(); - } + final Conversation conversation = getSelectedConversation(); + xmppConnectionService.getNotificationService().setOpenConversation(conversation); + sendReadMarkerIfNecessary(conversation); + } + } + + public void sendReadMarkerIfNecessary(final Conversation conversation) { + if (!mActivityPaused && !conversation.isRead()) { + xmppConnectionService.sendReadMarker(conversation); } } @@ -737,6 +743,15 @@ public class ConversationActivity extends XmppActivity } } + @Override + public void onPause() { + super.onPause(); + this.mActivityPaused = true; + if (this.xmppConnectionServiceBound) { + this.xmppConnectionService.getNotificationService().setIsInForeground(false); + } + } + @Override public void onResume() { super.onResume(); @@ -744,6 +759,10 @@ public class ConversationActivity extends XmppActivity if (this.mTheme != theme) { recreate(); } + this.mActivityPaused = false; + if (this.xmppConnectionServiceBound) { + this.xmppConnectionService.getNotificationService().setIsInForeground(true); + } } @Override @@ -763,6 +782,7 @@ public class ConversationActivity extends XmppActivity @Override void onBackendConnected() { + this.xmppConnectionService.getNotificationService().setIsInForeground(true); updateConversationList(); if (xmppConnectionService.getAccounts().size() == 0) { startActivity(new Intent(this, EditAccountActivity.class)); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index c3b47d76..98f70728 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -665,8 +665,7 @@ public class ConversationFragment extends Fragment { this.messageListAdapter.notifyDataSetChanged(); updateChatMsgHint(); if (!activity.isConversationsOverviewVisable() || !activity.isConversationsOverviewHideable()) { - activity.xmppConnectionService.markRead(conversation, true); - activity.updateConversationList(); + activity.sendReadMarkerIfNecessary(conversation); } this.updateSendButton(); } -- cgit v1.2.3