From 5e28a8f8d5eeed87418ca5769c65074c5e9f13c4 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 23 Feb 2018 19:22:38 +0100 Subject: [PATCH] make read markers work --- .../ui/ConversationActivity.java | 21 ++++++++++++++++++- .../ui/ConversationFragment.java | 21 +++++++++++++------ .../ui/ConversationLegacyActivity.java | 4 ++-- .../ui/ConversationsOverviewFragment.java | 1 - 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index d4f0ffa20..d5ebbca9d 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -72,6 +72,7 @@ public class ConversationActivity extends XmppActivity implements OnConversation int[] FRAGMENT_ID_NOTIFICATION_ORDER = {R.id.secondary_fragment, R.id.main_fragment}; private final PendingItem pendingViewIntent = new PendingItem<>(); private ActivityConversationsBinding binding; + private boolean mActivityPaused = true; private static boolean isViewIntent(Intent i) { return i != null && ACTION_VIEW_CONVERSATION.equals(i.getAction()) && i.hasExtra(EXTRA_CONVERSATION); @@ -214,6 +215,22 @@ public class ConversationActivity extends XmppActivity implements OnConversation } } + @Override + public void onPause() { + this.mActivityPaused = true; + super.onPause(); + } + + @Override + public void onResume() { + super.onResume(); + final int theme = findTheme(); + if (this.mTheme != theme) { + recreate(); + } + this.mActivityPaused = false; + } + private void initializeFragments() { FragmentTransaction transaction = getFragmentManager().beginTransaction(); Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment); @@ -287,7 +304,9 @@ public class ConversationActivity extends XmppActivity implements OnConversation @Override public void onConversationRead(Conversation conversation) { - Log.d(Config.LOGTAG, "read event for " + conversation.getName() + " received"); + if (!mActivityPaused && pendingViewIntent.peek() == null) { + xmppConnectionService.sendReadMarker(conversation); + } } @Override diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index c6fb891c7..0334dbfae 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1579,17 +1579,17 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } - public boolean reInit(Conversation conversation) { + public void reInit(Conversation conversation) { Log.d(Config.LOGTAG, "reInit()"); if (conversation == null) { Log.d(Config.LOGTAG, "conversation was null :("); - return false; + return; } if (this.activity == null) { Log.d(Config.LOGTAG, "activity was null"); this.conversation = conversation; - return false; + return; } setupIme(); @@ -1617,8 +1617,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke this.binding.textinput.setKeyboardListener(this); messageListAdapter.updatePreferences(); this.binding.messagesView.setAdapter(messageListAdapter); - refresh(); + refresh(false); this.conversation.messagesLoaded.set(true); + final boolean isAtBottom; synchronized (this.messageList) { final Message first = conversation.getFirstUnreadMessage(); final int bottom = Math.max(0, this.messageList.size() - 1); @@ -1630,7 +1631,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke pos = i < 0 ? bottom : i; } this.binding.messagesView.setSelection(pos); - return pos == bottom; + isAtBottom = pos == bottom; + } + if (activity != null) { + activity.onConversationRead(this.conversation); } } @@ -1727,6 +1731,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke @Override public void refresh() { + this.refresh(true); + } + + + private void refresh(boolean notifyConversationRead) { synchronized (this.messageList) { if (this.conversation != null) { conversation.populateWithMessages(this.messageList); @@ -1734,7 +1743,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke updateStatusMessages(); this.messageListAdapter.notifyDataSetChanged(); updateChatMsgHint(); - if (activity != null) { + if (notifyConversationRead && activity != null) { activity.onConversationRead(this.conversation); } updateSendButton(); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationLegacyActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationLegacyActivity.java index ad7484b68..b1d6a8e36 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationLegacyActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationLegacyActivity.java @@ -645,10 +645,10 @@ public class ConversationLegacyActivity extends XmppActivity updateActionBarTitle(true); } } - if (this.mConversationFragment.reInit(getSelectedConversation())) { + /*if (this.mConversationFragment.reInit(getSelectedConversation())) { Log.d(Config.LOGTAG, "setting scroll position on fragment"); this.mConversationFragment.setScrollPosition(mScrollPosition); - } + }*/ mOpenConversation = null; } else if (intent != null && ACTION_VIEW_CONVERSATION.equals(intent.getAction())) { clearPending(); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java index 91bf9f64a..d3aa69b8d 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java @@ -31,7 +31,6 @@ package eu.siacs.conversations.ui; import android.app.Activity; import android.app.Fragment; -import android.content.Context; import android.databinding.DataBindingUtil; import android.os.Bundle; import android.util.Log;