parent
0271e4c918
commit
5943b9d7d6
3 changed files with 22 additions and 4 deletions
|
@ -1424,7 +1424,10 @@ public class ConversationFragment extends LoggingFragment {
|
|||
public ConversationSnapToTopDataObserver(@NonNull RecyclerView recyclerView,
|
||||
@Nullable ScrollRequestValidator scrollRequestValidator)
|
||||
{
|
||||
super(recyclerView, scrollRequestValidator);
|
||||
super(recyclerView, scrollRequestValidator, () -> {
|
||||
list.scrollToPosition(0);
|
||||
list.post(ConversationFragment.this::postMarkAsReadRequest);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -223,7 +223,7 @@ public class ConversationListFragment extends MainFragment implements ActionMode
|
|||
list.setItemAnimator(new DeleteItemAnimator());
|
||||
list.addOnScrollListener(new ScrollListener());
|
||||
|
||||
snapToTopDataObserver = new SnapToTopDataObserver(list, null);
|
||||
snapToTopDataObserver = new SnapToTopDataObserver(list);
|
||||
|
||||
new ItemTouchHelper(new ArchiveListenerCallback()).attachToRecyclerView(list);
|
||||
|
||||
|
|
|
@ -24,14 +24,22 @@ public class SnapToTopDataObserver extends RecyclerView.AdapterDataObserver {
|
|||
private final LinearLayoutManager layoutManager;
|
||||
private final Deferred deferred;
|
||||
private final ScrollRequestValidator scrollRequestValidator;
|
||||
private final ScrollToTop scrollToTop;
|
||||
|
||||
public SnapToTopDataObserver(@NonNull RecyclerView recyclerView) {
|
||||
this(recyclerView, null, null);
|
||||
}
|
||||
|
||||
public SnapToTopDataObserver(@NonNull RecyclerView recyclerView,
|
||||
@Nullable ScrollRequestValidator scrollRequestValidator)
|
||||
@Nullable ScrollRequestValidator scrollRequestValidator,
|
||||
@Nullable ScrollToTop scrollToTop)
|
||||
{
|
||||
this.recyclerView = recyclerView;
|
||||
this.layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
|
||||
this.deferred = new Deferred();
|
||||
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) {
|
||||
layoutManager.scrollToPosition(0);
|
||||
scrollToTop.scrollToTop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,6 +152,13 @@ public class SnapToTopDataObserver extends RecyclerView.AdapterDataObserver {
|
|||
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 {
|
||||
private final int position;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue