put Conversations into background mode earlier
This commit is contained in:
parent
8d2f454479
commit
bcd3be59ce
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,21 +1998,23 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
public SecureRandom getRNG() {
|
||||
return this.mRandom;
|
||||
|
|
|
@ -85,6 +85,8 @@ public class ConversationActivity extends XmppActivity
|
|||
|
||||
private Toast prepareFileToast;
|
||||
|
||||
private boolean mActivityPaused = false;
|
||||
|
||||
|
||||
public List<Conversation> getConversationList() {
|
||||
return this.conversationList;
|
||||
|
@ -262,12 +264,16 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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));
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue