mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-08 22:38:37 +00:00
parent
0271e4c918
commit
5943b9d7d6
@ -1424,7 +1424,10 @@ public class ConversationFragment extends LoggingFragment {
|
|||||||
public ConversationSnapToTopDataObserver(@NonNull RecyclerView recyclerView,
|
public ConversationSnapToTopDataObserver(@NonNull RecyclerView recyclerView,
|
||||||
@Nullable ScrollRequestValidator scrollRequestValidator)
|
@Nullable ScrollRequestValidator scrollRequestValidator)
|
||||||
{
|
{
|
||||||
super(recyclerView, scrollRequestValidator);
|
super(recyclerView, scrollRequestValidator, () -> {
|
||||||
|
list.scrollToPosition(0);
|
||||||
|
list.post(ConversationFragment.this::postMarkAsReadRequest);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -223,7 +223,7 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
|||||||
list.setItemAnimator(new DeleteItemAnimator());
|
list.setItemAnimator(new DeleteItemAnimator());
|
||||||
list.addOnScrollListener(new ScrollListener());
|
list.addOnScrollListener(new ScrollListener());
|
||||||
|
|
||||||
snapToTopDataObserver = new SnapToTopDataObserver(list, null);
|
snapToTopDataObserver = new SnapToTopDataObserver(list);
|
||||||
|
|
||||||
new ItemTouchHelper(new ArchiveListenerCallback()).attachToRecyclerView(list);
|
new ItemTouchHelper(new ArchiveListenerCallback()).attachToRecyclerView(list);
|
||||||
|
|
||||||
|
@ -24,14 +24,22 @@ public class SnapToTopDataObserver extends RecyclerView.AdapterDataObserver {
|
|||||||
private final LinearLayoutManager layoutManager;
|
private final LinearLayoutManager layoutManager;
|
||||||
private final Deferred deferred;
|
private final Deferred deferred;
|
||||||
private final ScrollRequestValidator scrollRequestValidator;
|
private final ScrollRequestValidator scrollRequestValidator;
|
||||||
|
private final ScrollToTop scrollToTop;
|
||||||
|
|
||||||
|
public SnapToTopDataObserver(@NonNull RecyclerView recyclerView) {
|
||||||
|
this(recyclerView, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
public SnapToTopDataObserver(@NonNull RecyclerView recyclerView,
|
public SnapToTopDataObserver(@NonNull RecyclerView recyclerView,
|
||||||
@Nullable ScrollRequestValidator scrollRequestValidator)
|
@Nullable ScrollRequestValidator scrollRequestValidator,
|
||||||
|
@Nullable ScrollToTop scrollToTop)
|
||||||
{
|
{
|
||||||
this.recyclerView = recyclerView;
|
this.recyclerView = recyclerView;
|
||||||
this.layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
|
this.layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
|
||||||
this.deferred = new Deferred();
|
this.deferred = new Deferred();
|
||||||
this.scrollRequestValidator = scrollRequestValidator;
|
this.scrollRequestValidator = scrollRequestValidator;
|
||||||
|
this.scrollToTop = scrollToTop == null ? () -> layoutManager.scrollToPosition(0)
|
||||||
|
: scrollToTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,7 +116,7 @@ public class SnapToTopDataObserver extends RecyclerView.AdapterDataObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (layoutManager.findFirstVisibleItemPosition() == 0) {
|
if (layoutManager.findFirstVisibleItemPosition() == 0) {
|
||||||
layoutManager.scrollToPosition(0);
|
scrollToTop.scrollToTop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,6 +152,13 @@ public class SnapToTopDataObserver extends RecyclerView.AdapterDataObserver {
|
|||||||
void onPerformScroll(@NonNull LinearLayoutManager layoutManager, int position);
|
void onPerformScroll(@NonNull LinearLayoutManager layoutManager, int position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method Object for scrolling to the top of a view, in case special handling is desired.
|
||||||
|
*/
|
||||||
|
public interface ScrollToTop {
|
||||||
|
void scrollToTop();
|
||||||
|
}
|
||||||
|
|
||||||
public final class ScrollRequestBuilder {
|
public final class ScrollRequestBuilder {
|
||||||
private final int position;
|
private final int position;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user