2017-09-28 13:06:48 +00:00
|
|
|
package org.schabi.newpipe.util;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.PointF;
|
2020-03-31 17:20:15 +00:00
|
|
|
|
2019-10-04 12:59:08 +00:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.LinearSmoothScroller;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2017-09-28 13:06:48 +00:00
|
|
|
|
|
|
|
public class LayoutManagerSmoothScroller extends LinearLayoutManager {
|
2020-03-31 17:20:15 +00:00
|
|
|
public LayoutManagerSmoothScroller(final Context context) {
|
2017-09-28 13:06:48 +00:00
|
|
|
super(context, VERTICAL, false);
|
|
|
|
}
|
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
public LayoutManagerSmoothScroller(final Context context, final int orientation,
|
|
|
|
final boolean reverseLayout) {
|
2017-09-28 13:06:48 +00:00
|
|
|
super(context, orientation, reverseLayout);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 17:20:15 +00:00
|
|
|
public void smoothScrollToPosition(final RecyclerView recyclerView,
|
|
|
|
final RecyclerView.State state, final int position) {
|
2020-08-16 08:24:58 +00:00
|
|
|
final RecyclerView.SmoothScroller smoothScroller
|
2020-03-31 17:20:15 +00:00
|
|
|
= new TopSnappedSmoothScroller(recyclerView.getContext());
|
2017-09-28 13:06:48 +00:00
|
|
|
smoothScroller.setTargetPosition(position);
|
|
|
|
startSmoothScroll(smoothScroller);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TopSnappedSmoothScroller extends LinearSmoothScroller {
|
2020-03-31 17:20:15 +00:00
|
|
|
TopSnappedSmoothScroller(final Context context) {
|
2017-09-28 13:06:48 +00:00
|
|
|
super(context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 17:20:15 +00:00
|
|
|
public PointF computeScrollVectorForPosition(final int targetPosition) {
|
2017-09-28 13:06:48 +00:00
|
|
|
return LayoutManagerSmoothScroller.this
|
|
|
|
.computeScrollVectorForPosition(targetPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected int getVerticalSnapPreference() {
|
|
|
|
return SNAP_TO_START;
|
|
|
|
}
|
|
|
|
}
|
2020-03-31 17:20:15 +00:00
|
|
|
}
|