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

@ -131,7 +131,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private static final String STATE_LAST_MESSAGE_UUID = "state_last_message_uuid";
final protected List<Message> messageList = new ArrayList<>();
private String lastMessageUuid = null;
private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
private final PendingItem<String> pendingConversationsUuid = 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<>();
public Uri mPendingEditorContent = null;
protected MessageAdapter messageListAdapter;
private String lastMessageUuid = null;
private Conversation conversation;
private FragmentConversationBinding binding;
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() {
@Override
@ -523,6 +499,49 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
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) {
if (uuid == null) {
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) {
quoteText(MessageUtils.prepareQuote(message));
}
@ -1850,7 +1861,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
this.reInitRequiredOnStart = true;
pendingExtras.push(extras);
}
updateUnreadMessagesCount();
resetUnreadMessagesCount();
}
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));
if (hasExtras || scrolledToBottomAndNoPending) {
resetUnreadMessagesCount();
synchronized (this.messageList) {
Log.d(Config.LOGTAG, "jump to first unread message");
final Message first = conversation.getFirstUnreadMessage();
@ -1917,7 +1929,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return true;
}
private void updateUnreadMessagesCount() {
private void resetUnreadMessagesCount() {
lastMessageUuid = null;
hideUnreadMessagesCount();
}
@ -1934,6 +1946,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private void setSelection(int pos) {
this.binding.messagesView.setSelection(pos);
this.binding.messagesView.post(() -> this.binding.messagesView.setSelection(pos));
this.binding.messagesView.post(this::fireReadEvent);
}
private boolean scrolledToBottom() {
@ -1943,15 +1956,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
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) {
final String downloadUuid = extras.getString(ConversationsActivity.EXTRA_DOWNLOAD_UUID);
final String text = extras.getString(ConversationsActivity.EXTRA_TEXT);