From ba37b489694999aad8d96d52045d2de35f9d67de Mon Sep 17 00:00:00 2001
From: gongym <1967988842@qq.com>
Date: Mon, 24 May 2021 12:51:47 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=B8=8B?=
=?UTF-8?q?=E6=BB=91=E5=8A=A8=E4=BC=9A=E5=AF=BC=E8=87=B4=E5=B7=A6=E5=8F=B3?=
=?UTF-8?q?=E5=88=87=E6=8D=A2=E9=97=AE=E9=A2=98=EF=BC=8C=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?=E4=BA=86=E6=96=B0=E7=9A=84=E8=87=AA=E5=AE=9A=E4=B9=89=E7=BB=84?=
=?UTF-8?q?=E4=BB=B6RecyclerViewAtViewPager2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ui/widget/RecyclerViewAtViewPager2.java | 55 +++++++++++++++++++
app/src/main/res/layout/fragment_books.xml | 2 +-
app/src/main/res/layout/fragment_explore.xml | 2 +-
app/src/main/res/layout/fragment_rss.xml | 2 +-
.../main/res/layout/fragment_rss_articles.xml | 2 +-
5 files changed, 59 insertions(+), 4 deletions(-)
create mode 100644 app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.java
diff --git a/app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.java b/app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.java
new file mode 100644
index 000000000..f701b1a14
--- /dev/null
+++ b/app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.java
@@ -0,0 +1,55 @@
+package io.legado.app.ui.widget;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.RecyclerView;
+
+public class RecyclerViewAtViewPager2 extends RecyclerView {
+
+ public RecyclerViewAtViewPager2(@NonNull Context context) {
+ super(context);
+ }
+
+ public RecyclerViewAtViewPager2(@NonNull Context context, @Nullable AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public RecyclerViewAtViewPager2(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ private int startX, startY;
+
+ @Override
+ 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 > 50) {
+ getParent().requestDisallowInterceptTouchEvent(false);
+ }
+ } else {
+ getParent().requestDisallowInterceptTouchEvent(true);
+ }
+ break;
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ getParent().requestDisallowInterceptTouchEvent(false);
+ break;
+ }
+ return super.dispatchTouchEvent(ev);
+ }
+}
diff --git a/app/src/main/res/layout/fragment_books.xml b/app/src/main/res/layout/fragment_books.xml
index 8da85f913..1e2fbe64b 100644
--- a/app/src/main/res/layout/fragment_books.xml
+++ b/app/src/main/res/layout/fragment_books.xml
@@ -9,7 +9,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
-
-
-
-
From ecd8f0391a3f307b1635d4791982223bb9641466 Mon Sep 17 00:00:00 2001
From: gongym <1967988842@qq.com>
Date: Mon, 24 May 2021 13:14:42 +0800
Subject: [PATCH 2/3] Rename .java to .kt
---
...{RecyclerViewAtViewPager2.java => RecyclerViewAtViewPager2.kt} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename app/src/main/java/io/legado/app/ui/widget/{RecyclerViewAtViewPager2.java => RecyclerViewAtViewPager2.kt} (100%)
diff --git a/app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.java b/app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.kt
similarity index 100%
rename from app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.java
rename to app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.kt
From 35ad224e5559dee0b6e705db3452de32493fdc8a Mon Sep 17 00:00:00 2001
From: gongym <1967988842@qq.com>
Date: Mon, 24 May 2021 13:14:42 +0800
Subject: [PATCH 3/3] java->kotlin
---
.../app/ui/widget/RecyclerViewAtViewPager2.kt | 81 ++++++++-----------
1 file changed, 33 insertions(+), 48 deletions(-)
diff --git a/app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.kt b/app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.kt
index f701b1a14..10abec353 100644
--- a/app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.kt
+++ b/app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.kt
@@ -1,55 +1,40 @@
-package io.legado.app.ui.widget;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.recyclerview.widget.RecyclerView;
-
-public class RecyclerViewAtViewPager2 extends RecyclerView {
-
- public RecyclerViewAtViewPager2(@NonNull Context context) {
- super(context);
- }
-
- public RecyclerViewAtViewPager2(@NonNull Context context, @Nullable AttributeSet attrs) {
- super(context, attrs);
- }
-
- public RecyclerViewAtViewPager2(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- }
-
- private int startX, startY;
-
- @Override
- 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);
+package io.legado.app.ui.widget
+
+import android.content.Context
+import androidx.recyclerview.widget.RecyclerView
+import android.util.AttributeSet
+import android.view.MotionEvent
+import kotlin.math.abs
+
+class RecyclerViewAtViewPager2 : RecyclerView {
+ constructor(context: Context) : super(context)
+ constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
+ constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
+
+ private var startX = 0
+ private var startY = 0
+ override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
+ when (ev.action) {
+ MotionEvent.ACTION_DOWN -> {
+ startX = ev.x.toInt()
+ startY = ev.y.toInt()
+ parent.requestDisallowInterceptTouchEvent(true)
+ }
+ MotionEvent.ACTION_MOVE -> {
+ val endX = ev.x.toInt()
+ val endY = ev.y.toInt()
+ val disX = abs(endX - startX)
+ val disY = abs(endY - startY)
if (disX > disY) {
if (disX > 50) {
- getParent().requestDisallowInterceptTouchEvent(false);
+ parent.requestDisallowInterceptTouchEvent(false)
}
} else {
- getParent().requestDisallowInterceptTouchEvent(true);
+ parent.requestDisallowInterceptTouchEvent(true)
}
- break;
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_CANCEL:
- getParent().requestDisallowInterceptTouchEvent(false);
- break;
+ }
+ MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> parent.requestDisallowInterceptTouchEvent(false)
}
- return super.dispatchTouchEvent(ev);
+ return super.dispatchTouchEvent(ev)
}
-}
+}
\ No newline at end of file