aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Gultsch <inputmice@siacs.eu>2015-01-02 12:04:33 +0100
committerDaniel Gultsch <inputmice@siacs.eu>2015-01-02 12:04:33 +0100
commitbcd3be59ce78609e608f4a8f7a868be977fdb4bb (patch)
tree4437c8567a7c18786f8f35b76f3aff444dfe3511
parent8d2f454479632465387d8d824a56bd46aa9397e5 (diff)
put Conversations into background mode earlier
-rw-r--r--src/main/java/eu/siacs/conversations/parser/MessageParser.java8
-rw-r--r--src/main/java/eu/siacs/conversations/services/NotificationService.java4
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java18
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationActivity.java30
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java3
5 files changed, 44 insertions, 19 deletions
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<Conversation> 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);
}
}
@@ -738,12 +744,25 @@ 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();
int theme = findTheme();
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();
}