Add "go to last seen" (#1641)

This commit is contained in:
Hocuri
2020-10-07 13:16:23 +02:00
committed by GitHub
parent 33910e364d
commit a647911772
2 changed files with 26 additions and 9 deletions
@@ -126,7 +126,10 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
public void updateLastSeenPosition() {
this.lastSeenPosition = findLastSeenPosition(lastSeen);
}
void setLastSeenPosition(int pos) {
lastSeenPosition = pos;
}
public int getLastSeenPosition() {
@@ -172,6 +172,12 @@ public class ConversationFragment extends Fragment
super.onActivityCreated(bundle);
initializeResources();
initializeListAdapter();
int freshMsgs = dcContext.getFreshMsgCount((int) chatId);
if (freshMsgs > 0) {
setLastSeenPosition(freshMsgs - 1);
moveToLastSeen();
}
}
private void setNoMessageText() {
@@ -269,7 +275,7 @@ public class ConversationFragment extends Fragment
if (getListAdapter().getLastSeenPosition() < 0) {
return;
}
scrollToLastSeenPosition(getListAdapter().getLastSeenPosition());
scrollToLastSeenPosition(getListAdapter().getLastSeenPosition() + 1);
}
private void initializeResources() {
@@ -350,14 +356,24 @@ public class ConversationFragment extends Fragment
}
}
public void setLastSeen(long lastSeen) {
void setLastSeen(long lastSeen) {
getListAdapter().setLastSeen(lastSeen);
if (lastSeenDecoration != null) {
list.removeItemDecoration(lastSeenDecoration);
}
if (lastSeen > 0) {
lastSeenDecoration = new ConversationAdapter.LastSeenHeader(getListAdapter()/*, lastSeen*/);
lastSeenDecoration = new ConversationAdapter.LastSeenHeader(getListAdapter());
list.addItemDecoration(lastSeenDecoration);
}
}
private void setLastSeenPosition(int position) {
getListAdapter().setLastSeenPosition(position);
if (lastSeenDecoration != null) {
list.removeItemDecoration(lastSeenDecoration);
}
if (position >= 0) {
lastSeenDecoration = new ConversationAdapter.LastSeenHeader(getListAdapter());
list.addItemDecoration(lastSeenDecoration);
}
}
@@ -561,14 +577,12 @@ public class ConversationFragment extends Fragment
boolean currentlyAtZoomScrollHeight = isAtZoomScrollHeight();
// int positionId = getHeaderPositionId();
if (currentlyAtBottom && !wasAtBottom) {
ViewUtil.animateOut(scrollToBottomButton, scrollButtonOutAnimation, View.INVISIBLE);
}
if (currentlyAtZoomScrollHeight && !wasAtZoomScrollHeight) {
ViewUtil.animateIn(scrollToBottomButton, scrollButtonInAnimation);
} else if (currentlyAtBottom && !wasAtBottom) {
ViewUtil.animateOut(scrollToBottomButton, scrollButtonOutAnimation, View.INVISIBLE);
}
// if (positionId != lastPositionId) {
// bindScrollHeader(conversationDateHeader, positionId);
// }