java->kotlin

pull/1006/head
gongym 4 years ago
parent ecd8f0391a
commit 35ad224e55
  1. 79
      app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.kt

@ -1,55 +1,40 @@
package io.legado.app.ui.widget; package io.legado.app.ui.widget
import android.content.Context; import android.content.Context
import android.util.AttributeSet; import androidx.recyclerview.widget.RecyclerView
import android.view.MotionEvent; import android.util.AttributeSet
import android.view.MotionEvent
import androidx.annotation.NonNull; import kotlin.math.abs
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView; class RecyclerViewAtViewPager2 : RecyclerView {
constructor(context: Context) : super(context)
public class RecyclerViewAtViewPager2 extends RecyclerView { constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
public RecyclerViewAtViewPager2(@NonNull Context context) {
super(context); private var startX = 0
} private var startY = 0
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
public RecyclerViewAtViewPager2(@NonNull Context context, @Nullable AttributeSet attrs) { when (ev.action) {
super(context, attrs); MotionEvent.ACTION_DOWN -> {
} startX = ev.x.toInt()
startY = ev.y.toInt()
public RecyclerViewAtViewPager2(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { parent.requestDisallowInterceptTouchEvent(true)
super(context, attrs, defStyleAttr); }
} MotionEvent.ACTION_MOVE -> {
val endX = ev.x.toInt()
private int startX, startY; val endY = ev.y.toInt()
val disX = abs(endX - startX)
@Override val disY = abs(endY - startY)
public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
startX = (int) ev.getX();
startY = (int) ev.getY();
getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_MOVE:
int endX = (int) ev.getX();
int endY = (int) ev.getY();
int disX = Math.abs(endX - startX);
int disY = Math.abs(endY - startY);
if (disX > disY) { if (disX > disY) {
if (disX > 50) { if (disX > 50) {
getParent().requestDisallowInterceptTouchEvent(false); parent.requestDisallowInterceptTouchEvent(false)
} }
} else { } else {
getParent().requestDisallowInterceptTouchEvent(true); parent.requestDisallowInterceptTouchEvent(true)
} }
break; }
case MotionEvent.ACTION_UP: MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> parent.requestDisallowInterceptTouchEvent(false)
case MotionEvent.ACTION_CANCEL:
getParent().requestDisallowInterceptTouchEvent(false);
break;
} }
return super.dispatchTouchEvent(ev); return super.dispatchTouchEvent(ev)
} }
} }
Loading…
Cancel
Save