aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java90
1 files changed, 47 insertions, 43 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 7bd20f3e5..3e4962cdb 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -211,30 +211,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
@@ -635,6 +611,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;
@@ -1284,14 +1303,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));
}
@@ -2131,7 +2142,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
this.reInitRequiredOnStart = true;
pendingExtras.push(extras);
}
- updateUnreadMessagesCount();
+ resetUnreadMessagesCount();
}
private void reInit(Conversation conversation) {
@@ -2177,6 +2188,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();
@@ -2237,7 +2249,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return true;
}
- private void updateUnreadMessagesCount() {
+ private void resetUnreadMessagesCount() {
lastMessageUuid = null;
hideUnreadMessagesCount();
}
@@ -2254,6 +2266,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() {
@@ -2263,15 +2276,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);