mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-02 10:23:33 +00:00
First experiment with on-scrolling pagination on track list by genre
This commit is contained in:
parent
b345695fa2
commit
35bc02e6d9
4 changed files with 83 additions and 16 deletions
|
|
@ -0,0 +1,36 @@
|
|||
package com.cappielloantonio.play.helper.recyclerview;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
||||
public abstract class PaginationScrollListener extends RecyclerView.OnScrollListener {
|
||||
private static final String TAG = "PaginationScrollListener";
|
||||
|
||||
private LinearLayoutManager layoutManager;
|
||||
|
||||
protected PaginationScrollListener(LinearLayoutManager layoutManager) {
|
||||
this.layoutManager = layoutManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
|
||||
int visibleItemCount = layoutManager.getChildCount();
|
||||
int totalItemCount = layoutManager.getItemCount();
|
||||
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
|
||||
|
||||
if (!isLoading()) {
|
||||
if (firstVisibleItemPosition >= 0 && (visibleItemCount + firstVisibleItemPosition) >= totalItemCount) {
|
||||
loadMoreItems();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void loadMoreItems();
|
||||
|
||||
public abstract boolean isLoading();
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue