blob: 29ce3c35a2d7d7bbe933f75964619f2d0eadb424 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package it.niedermann.android.crosstabdnd;
import android.os.Handler;
import androidx.recyclerview.widget.RecyclerView;
@SuppressWarnings("WeakerAccess")
public class ScrollHelper implements Runnable {
private static final int SCROLL_SPEED = 200;
public enum ScrollDirection {
UP,
DOWN
}
private boolean shouldScroll = false;
private ScrollDirection scrollDirection;
private RecyclerView currentRecyclerView;
private final Handler handler = new Handler();
public void startScroll(RecyclerView recyclerView, ScrollDirection scrollDirection) {
this.scrollDirection = scrollDirection;
this.currentRecyclerView = recyclerView;
if (!shouldScroll) {
this.shouldScroll = true;
handler.post(this);
}
}
public void stopScroll() {
this.shouldScroll = false;
}
@Override
public void run() {
if (scrollDirection == ScrollDirection.UP) {
currentRecyclerView.smoothScrollBy(0, SCROLL_SPEED * -1);
} else {
currentRecyclerView.smoothScrollBy(0, SCROLL_SPEED);
}
if (shouldScroll) {
handler.postDelayed(this, 100);
}
}
}
|