mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-04-12 18:01:23 +00:00
Improve code style to be more consistent
This commit is contained in:
@@ -10,15 +10,15 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
// check this https://stackoverflow.com/questions/56849221/recyclerview-fling-causes-laggy-while-appbarlayout-is-scrolling/57997489#57997489
|
||||
// See https://stackoverflow.com/questions/56849221#57997489
|
||||
public final class FlingBehavior extends AppBarLayout.Behavior {
|
||||
|
||||
public FlingBehavior(Context context, AttributeSet attrs) {
|
||||
public FlingBehavior(final Context context, final AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(CoordinatorLayout parent, AppBarLayout child, MotionEvent ev) {
|
||||
public boolean onInterceptTouchEvent(final CoordinatorLayout parent, final AppBarLayout child,
|
||||
final MotionEvent ev) {
|
||||
switch (ev.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
// remove reference to old nested scrolling child
|
||||
@@ -35,7 +35,8 @@ public final class FlingBehavior extends AppBarLayout.Behavior {
|
||||
@Nullable
|
||||
private OverScroller getScrollerField() {
|
||||
try {
|
||||
Class<?> headerBehaviorType = this.getClass().getSuperclass().getSuperclass().getSuperclass();
|
||||
Class<?> headerBehaviorType = this.getClass()
|
||||
.getSuperclass().getSuperclass().getSuperclass();
|
||||
if (headerBehaviorType != null) {
|
||||
Field field = headerBehaviorType.getDeclaredField("scroller");
|
||||
field.setAccessible(true);
|
||||
@@ -62,12 +63,14 @@ public final class FlingBehavior extends AppBarLayout.Behavior {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void resetNestedScrollingChild(){
|
||||
private void resetNestedScrollingChild() {
|
||||
Field field = getLastNestedScrollingChildRefField();
|
||||
if(field != null){
|
||||
if (field != null) {
|
||||
try {
|
||||
Object value = field.get(this);
|
||||
if(value != null) field.set(this, null);
|
||||
if (value != null) {
|
||||
field.set(this, null);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
// ?
|
||||
}
|
||||
@@ -76,7 +79,8 @@ public final class FlingBehavior extends AppBarLayout.Behavior {
|
||||
|
||||
private void stopAppBarLayoutFling() {
|
||||
OverScroller scroller = getScrollerField();
|
||||
if (scroller != null) scroller.forceFinished(true);
|
||||
if (scroller != null) {
|
||||
scroller.forceFinished(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user