Merge pull request #1006 from gongym12138/master

修复上下滑动会导致左右切换问题,添加了新的自定义组件RecyclerViewAtViewPager2
pull/1013/head
kunfei 4 years ago committed by GitHub
commit c22fe1e466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      app/src/main/java/io/legado/app/ui/widget/RecyclerViewAtViewPager2.kt
  2. 2
      app/src/main/res/layout/fragment_books.xml
  3. 2
      app/src/main/res/layout/fragment_explore.xml
  4. 2
      app/src/main/res/layout/fragment_rss.xml
  5. 2
      app/src/main/res/layout/fragment_rss_articles.xml

@ -0,0 +1,40 @@
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) {
parent.requestDisallowInterceptTouchEvent(false)
}
} else {
parent.requestDisallowInterceptTouchEvent(true)
}
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> parent.requestDisallowInterceptTouchEvent(false)
}
return super.dispatchTouchEvent(ev)
}
}

@ -9,7 +9,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
<io.legado.app.ui.widget.RecyclerViewAtViewPager2
android:id="@+id/rv_bookshelf"
android:layout_width="match_parent"
android:layout_height="match_parent"

@ -15,7 +15,7 @@
app:layout_constraintTop_toTopOf="parent"
app:title="@string/discovery" />
<androidx.recyclerview.widget.RecyclerView
<io.legado.app.ui.widget.RecyclerViewAtViewPager2
android:id="@+id/rv_find"
android:layout_width="match_parent"
android:layout_height="0dp"

@ -15,7 +15,7 @@
app:layout_constraintTop_toTopOf="parent"
app:title="@string/rss" />
<androidx.recyclerview.widget.RecyclerView
<io.legado.app.ui.widget.RecyclerViewAtViewPager2
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"

@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
<io.legado.app.ui.widget.RecyclerViewAtViewPager2
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Loading…
Cancel
Save