fixed read event when using fab scroll down
This commit is contained in:
parent
aeaa58071c
commit
93ceb9db78
|
@ -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
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue