parent
9de3da33aa
commit
e73eed4a9b
@ -1,49 +0,0 @@
|
||||
package eu.kanade.tachiyomi.widget;
|
||||
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import rx.functions.Action0;
|
||||
|
||||
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.
|
||||
private static final int VISIBLE_THRESHOLD = 5; // The minimum amount of items to have below your current scroll position before loading more.
|
||||
private int firstVisibleItem, visibleItemCount, totalItemCount;
|
||||
|
||||
private final GridLayoutManager layoutManager;
|
||||
|
||||
private final Action0 requestNext;
|
||||
|
||||
public EndlessGridScrollListener(GridLayoutManager 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 + VISIBLE_THRESHOLD)) {
|
||||
// End has been reached
|
||||
requestNext.call();
|
||||
loading = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
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 static final int VISIBLE_THRESHOLD = 5; // The minimum amount of items to have below your current scroll position before loading more.
|
||||
private int firstVisibleItem, visibleItemCount, totalItemCount;
|
||||
|
||||
private LinearLayoutManager layoutManager;
|
||||
|
||||
private final 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 + VISIBLE_THRESHOLD)) {
|
||||
// End has been reached
|
||||
requestNext.call();
|
||||
loading = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
|
||||
class EndlessScrollListener(
|
||||
private val layoutManager: LinearLayoutManager,
|
||||
private val requestNext: () -> Unit)
|
||||
: RecyclerView.OnScrollListener() {
|
||||
|
||||
companion object {
|
||||
// The minimum amount of items to have below your current scroll position before loading
|
||||
// more.
|
||||
private val VISIBLE_THRESHOLD = 5
|
||||
}
|
||||
|
||||
private var previousTotal = 0 // The total number of items in the dataset after the last load
|
||||
private var loading = true // True if we are still waiting for the last set of data to load.
|
||||
private var firstVisibleItem = 0
|
||||
private var visibleItemCount = 0
|
||||
private var totalItemCount = 0
|
||||
|
||||
fun resetScroll() {
|
||||
previousTotal = 0
|
||||
loading = true
|
||||
}
|
||||
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
|
||||
visibleItemCount = recyclerView.childCount
|
||||
totalItemCount = layoutManager.itemCount
|
||||
firstVisibleItem = layoutManager.findFirstVisibleItemPosition()
|
||||
|
||||
if (loading && totalItemCount > previousTotal) {
|
||||
loading = false
|
||||
previousTotal = totalItemCount
|
||||
}
|
||||
if (!loading && totalItemCount - visibleItemCount <= firstVisibleItem + VISIBLE_THRESHOLD) {
|
||||
// End has been reached
|
||||
requestNext()
|
||||
loading = true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue