From b6565c8cb9d6b5ae62f3cb73dfd97d8c2ae05bf7 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 11 May 2021 08:43:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/main/bookshelf/RootView.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/RootView.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/RootView.kt index 938116e4e..0e8225fc0 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/RootView.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/RootView.kt @@ -23,12 +23,10 @@ class RootView : LinearLayout { private var initialX = 0f private var initialY = 0f - private val parentViewPager: ViewPager2 - get() { - return (activity as MainActivity).getViewPager() - } - - private val childViewPager: View get() = findViewById(R.id.view_pager_bookshelf) + private val parentViewPager: ViewPager2? + get() = (activity as? MainActivity)?.getViewPager() + private val childViewPager: View + get() = findViewById(R.id.view_pager_bookshelf) init { touchSlop = ViewConfiguration.get(context).scaledTouchSlop @@ -49,7 +47,7 @@ class RootView : LinearLayout { } private fun handleInterceptTouchEvent(e: MotionEvent) { - val orientation = parentViewPager.orientation + val orientation = parentViewPager?.orientation ?: return // Early return if child can't scroll in same direction as parent if (!canChildScroll(orientation, -1f) && !canChildScroll(orientation, 1f)) { return