fixed read event when using fab scroll down

This commit is contained in:
Daniel Gultsch 2018-03-31 10:57:59 +02:00
parent aeaa58071c
commit 93ceb9db78
2 changed files with 58 additions and 54 deletions

View File

@ -607,7 +607,7 @@ public class XmppConnectionService extends Service {
} }
try { try {
restoredFromDatabaseLatch.await(); restoredFromDatabaseLatch.await();
sendReadMarker(c,null); sendReadMarker(c, null);
} catch (InterruptedException e) { } catch (InterruptedException e) {
Log.d(Config.LOGTAG, "unable to process notification read marker for conversation " + c.getName()); Log.d(Config.LOGTAG, "unable to process notification read marker for conversation " + c.getName());
} }
@ -1617,7 +1617,7 @@ public class XmppConnectionService extends Service {
public boolean isConversationStillOpen(final Conversation conversation) { public boolean isConversationStillOpen(final Conversation conversation) {
synchronized (this.conversations) { synchronized (this.conversations) {
for(Conversation current : this.conversations) { for (Conversation current : this.conversations) {
if (current == conversation) { if (current == conversation) {
return true; return true;
} }
@ -3265,7 +3265,7 @@ public class XmppConnectionService extends Service {
} }
public boolean markRead(final Conversation conversation, boolean dismiss) { public boolean markRead(final Conversation conversation, boolean dismiss) {
return markRead(conversation,null,dismiss).size() > 0; return markRead(conversation, null, dismiss).size() > 0;
} }
public boolean markRead(final Conversation conversation) { public boolean markRead(final Conversation conversation) {
@ -3306,7 +3306,7 @@ public class XmppConnectionService extends Service {
public void sendReadMarker(final Conversation conversation, String upToUuid) { public void sendReadMarker(final Conversation conversation, String upToUuid) {
final boolean isPrivateAndNonAnonymousMuc = conversation.getMode() == Conversation.MODE_MULTI && conversation.isPrivateAndNonAnonymous(); final boolean isPrivateAndNonAnonymousMuc = conversation.getMode() == Conversation.MODE_MULTI && conversation.isPrivateAndNonAnonymous();
final List<Message> readMessages = this.markRead(conversation,upToUuid,true); final List<Message> readMessages = this.markRead(conversation, upToUuid, true);
if (readMessages.size() > 0) { if (readMessages.size() > 0) {
updateConversationUi(); updateConversationUi();
} }

View File

@ -131,7 +131,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private static final String STATE_LAST_MESSAGE_UUID = "state_last_message_uuid"; private static final String STATE_LAST_MESSAGE_UUID = "state_last_message_uuid";
final protected List<Message> messageList = new ArrayList<>(); final protected List<Message> messageList = new ArrayList<>();
private String lastMessageUuid = null;
private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>(); private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
private final PendingItem<String> pendingConversationsUuid = new PendingItem<>(); private final PendingItem<String> pendingConversationsUuid = new PendingItem<>();
private final PendingItem<Bundle> pendingExtras = new PendingItem<>(); private final PendingItem<Bundle> pendingExtras = new PendingItem<>();
@ -141,6 +140,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private final PendingItem<Message> pendingMessage = new PendingItem<>(); private final PendingItem<Message> pendingMessage = new PendingItem<>();
public Uri mPendingEditorContent = null; public Uri mPendingEditorContent = null;
protected MessageAdapter messageListAdapter; protected MessageAdapter messageListAdapter;
private String lastMessageUuid = null;
private Conversation conversation; private Conversation conversation;
private FragmentConversationBinding binding; private FragmentConversationBinding binding;
private Toast messageLoaderToast; private Toast messageLoaderToast;
@ -185,30 +185,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}); });
} }
}; };
private void toggleScrollDownButton() {
toggleScrollDownButton(binding.messagesView);
}
private void toggleScrollDownButton(AbsListView listView) {
if (conversation == null) {
return;
}
if (scrolledToBottom(listView)) {
lastMessageUuid = null;
hideUnreadMessagesCount();
} else {
binding.scrollToBottomButton.setEnabled(true);
binding.scrollToBottomButton.setVisibility(View.VISIBLE);
if (lastMessageUuid == null) {
lastMessageUuid = conversation.getLatestMessage().getUuid();
}
if (conversation.getReceivedMessagesCountSinceUuid(lastMessageUuid) > 0) {
binding.unreadCountCustomView.setVisibility(View.VISIBLE);
}
}
}
private OnScrollListener mOnScrollListener = new OnScrollListener() { private OnScrollListener mOnScrollListener = new OnScrollListener() {
@Override @Override
@ -391,12 +367,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}; };
private OnClickListener mScrollButtonListener = new OnClickListener() { private OnClickListener mScrollButtonListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
stopScrolling(); stopScrolling();
setSelection(binding.messagesView.getCount() - 1); setSelection(binding.messagesView.getCount() - 1);
} }
}; };
private OnClickListener mSendButtonListener = new OnClickListener() { private OnClickListener mSendButtonListener = new OnClickListener() {
@Override @Override
@ -523,6 +499,49 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return null; return null;
} }
private static void hideSoftKeyboard(final Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
View view = activity.getCurrentFocus();
if (view != null && imm != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
private static boolean scrolledToBottom(AbsListView listView) {
final int count = listView.getCount();
if (count == 0) {
return true;
} else if (listView.getLastVisiblePosition() == count - 1) {
final View lastChild = listView.getChildAt(listView.getChildCount() - 1);
return lastChild != null && lastChild.getBottom() <= listView.getHeight();
} else {
return false;
}
}
private void toggleScrollDownButton() {
toggleScrollDownButton(binding.messagesView);
}
private void toggleScrollDownButton(AbsListView listView) {
if (conversation == null) {
return;
}
if (scrolledToBottom(listView)) {
lastMessageUuid = null;
hideUnreadMessagesCount();
} else {
binding.scrollToBottomButton.setEnabled(true);
binding.scrollToBottomButton.setVisibility(View.VISIBLE);
if (lastMessageUuid == null) {
lastMessageUuid = conversation.getLatestMessage().getUuid();
}
if (conversation.getReceivedMessagesCountSinceUuid(lastMessageUuid) > 0) {
binding.unreadCountCustomView.setVisibility(View.VISIBLE);
}
}
}
private int getIndexOf(String uuid, List<Message> messages) { private int getIndexOf(String uuid, List<Message> messages) {
if (uuid == null) { if (uuid == null) {
return messages.size() - 1; return messages.size() - 1;
@ -1011,14 +1030,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
} }
private static void hideSoftKeyboard(final Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
View view = activity.getCurrentFocus();
if (view != null && imm != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
private void quoteMessage(Message message) { private void quoteMessage(Message message) {
quoteText(MessageUtils.prepareQuote(message)); quoteText(MessageUtils.prepareQuote(message));
} }
@ -1569,7 +1580,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (pos >= 0) { if (pos >= 0) {
Message message = (Message) binding.messagesView.getItemAtPosition(pos); Message message = (Message) binding.messagesView.getItemAtPosition(pos);
if (message != null) { if (message != null) {
while(message.next() != null && message.next().wasMergedIntoPrevious()) { while (message.next() != null && message.next().wasMergedIntoPrevious()) {
message = message.next(); message = message.next();
} }
return message.getUuid(); return message.getUuid();
@ -1850,7 +1861,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
this.reInitRequiredOnStart = true; this.reInitRequiredOnStart = true;
pendingExtras.push(extras); pendingExtras.push(extras);
} }
updateUnreadMessagesCount(); resetUnreadMessagesCount();
} }
private void reInit(Conversation conversation) { private void reInit(Conversation conversation) {
@ -1895,6 +1906,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
Log.d(Config.LOGTAG, "scrolledToBottomAndNoPending=" + Boolean.toString(scrolledToBottomAndNoPending)); Log.d(Config.LOGTAG, "scrolledToBottomAndNoPending=" + Boolean.toString(scrolledToBottomAndNoPending));
if (hasExtras || scrolledToBottomAndNoPending) { if (hasExtras || scrolledToBottomAndNoPending) {
resetUnreadMessagesCount();
synchronized (this.messageList) { synchronized (this.messageList) {
Log.d(Config.LOGTAG, "jump to first unread message"); Log.d(Config.LOGTAG, "jump to first unread message");
final Message first = conversation.getFirstUnreadMessage(); final Message first = conversation.getFirstUnreadMessage();
@ -1917,7 +1929,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return true; return true;
} }
private void updateUnreadMessagesCount() { private void resetUnreadMessagesCount() {
lastMessageUuid = null; lastMessageUuid = null;
hideUnreadMessagesCount(); hideUnreadMessagesCount();
} }
@ -1934,6 +1946,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private void setSelection(int pos) { private void setSelection(int pos) {
this.binding.messagesView.setSelection(pos); this.binding.messagesView.setSelection(pos);
this.binding.messagesView.post(() -> this.binding.messagesView.setSelection(pos)); this.binding.messagesView.post(() -> this.binding.messagesView.setSelection(pos));
this.binding.messagesView.post(this::fireReadEvent);
} }
private boolean scrolledToBottom() { private boolean scrolledToBottom() {
@ -1943,15 +1956,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return scrolledToBottom(this.binding.messagesView); return scrolledToBottom(this.binding.messagesView);
} }
private static boolean scrolledToBottom(AbsListView listView) {
if (listView.getLastVisiblePosition() == listView.getCount() - 1) {
final View lastChild = listView.getChildAt(listView.getChildCount() - 1);
return lastChild != null && lastChild.getBottom() <= listView.getHeight();
} else {
return false;
}
}
private void processExtras(Bundle extras) { private void processExtras(Bundle extras) {
final String downloadUuid = extras.getString(ConversationsActivity.EXTRA_DOWNLOAD_UUID); final String downloadUuid = extras.getString(ConversationsActivity.EXTRA_DOWNLOAD_UUID);
final String text = extras.getString(ConversationsActivity.EXTRA_TEXT); final String text = extras.getString(ConversationsActivity.EXTRA_TEXT);