mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-28 12:57:57 +01:00
Allow to display manga from catalogue as a simple list (#35)
This commit is contained in:
@@ -5,7 +5,7 @@ import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import rx.functions.Action0;
|
||||
|
||||
public class EndlessRecyclerScrollListener extends RecyclerView.OnScrollListener {
|
||||
public class EndlessGridScrollListener extends RecyclerView.OnScrollListener {
|
||||
|
||||
private int previousTotal = 0; // The total number of items in the dataset after the last load
|
||||
private boolean loading = true; // True if we are still waiting for the last set of data to load.
|
||||
@@ -16,7 +16,7 @@ public class EndlessRecyclerScrollListener extends RecyclerView.OnScrollListener
|
||||
|
||||
private Action0 requestNext;
|
||||
|
||||
public EndlessRecyclerScrollListener(GridLayoutManager layoutManager, Action0 requestNext) {
|
||||
public EndlessGridScrollListener(GridLayoutManager layoutManager, Action0 requestNext) {
|
||||
this.layoutManager = layoutManager;
|
||||
this.requestNext = requestNext;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package eu.kanade.tachiyomi.widget;
|
||||
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import rx.functions.Action0;
|
||||
|
||||
public class EndlessListScrollListener extends RecyclerView.OnScrollListener {
|
||||
|
||||
private int previousTotal = 0; // The total number of items in the dataset after the last load
|
||||
private boolean loading = true; // True if we are still waiting for the last set of data to load.
|
||||
private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more.
|
||||
int firstVisibleItem, visibleItemCount, totalItemCount;
|
||||
|
||||
private LinearLayoutManager layoutManager;
|
||||
|
||||
private Action0 requestNext;
|
||||
|
||||
public EndlessListScrollListener(LinearLayoutManager layoutManager, Action0 requestNext) {
|
||||
this.layoutManager = layoutManager;
|
||||
this.requestNext = requestNext;
|
||||
}
|
||||
|
||||
public void resetScroll() {
|
||||
previousTotal = 0;
|
||||
loading = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
|
||||
visibleItemCount = recyclerView.getChildCount();
|
||||
totalItemCount = layoutManager.getItemCount();
|
||||
firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
|
||||
|
||||
if (loading && (totalItemCount > previousTotal)) {
|
||||
loading = false;
|
||||
previousTotal = totalItemCount;
|
||||
}
|
||||
if (!loading && (totalItemCount - visibleItemCount)
|
||||
<= (firstVisibleItem + visibleThreshold)) {
|
||||
// End has been reached
|
||||
requestNext.call();
|
||||
loading = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user