More updates to move the chapter bar

This commit is contained in:
Jays2Kings 2021-03-30 23:32:28 -04:00
parent 363047a2a2
commit a6a2ef6399
3 changed files with 29 additions and 17 deletions

View File

@ -376,7 +376,8 @@ class ReaderActivity :
}
}
val gestureDetector = GestureDetectorCompat(this, ReaderNavGestureDetector(this))
val readerNavGestureDetector = ReaderNavGestureDetector(this)
val gestureDetector = GestureDetectorCompat(this, readerNavGestureDetector)
with(binding.readerNav) {
listOf(root, leftChapter, rightChapter, pageSeekbar).forEach {
it.setOnTouchListener { _, event ->
@ -384,19 +385,27 @@ class ReaderActivity :
if (event?.action == MotionEvent.ACTION_UP) {
if (!result) {
val sheetBehavior = binding.chaptersSheet.root.sheetBehavior
if (sheetBehavior?.state != BottomSheetBehavior.STATE_SETTLING && !sheetBehavior.isCollapsed()) {
binding.chaptersSheet.root.dispatchTouchEvent(event)
if (sheetBehavior?.state != BottomSheetBehavior.STATE_SETTLING && !sheetBehavior.isCollapsed()) {
sheetBehavior?.collapse()
}
}
if (readerNavGestureDetector.lockVertical) {
// event.action = MotionEvent.ACTION_CANCEL
return@setOnTouchListener true
}
} else if ((event?.action != MotionEvent.ACTION_UP || event.action != MotionEvent.ACTION_DOWN) && result) {
event.action = MotionEvent.ACTION_CANCEL
return@setOnTouchListener false
}
if (it == pageSeekbar) {
readerNavGestureDetector.lockVertical
} else {
result
}
}
}
}
// Init listeners on bottom menu
binding.readerNav.pageSeekbar.setOnSeekBarChangeListener(
@ -443,8 +452,8 @@ class ReaderActivity :
height = 280.dpToPx + insets.systemWindowInsetBottom
}
binding.navLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = 6.dpToPx + insets.systemWindowInsetLeft
rightMargin = 6.dpToPx + insets.systemWindowInsetRight
leftMargin = 12.dpToPx + insets.systemWindowInsetLeft
rightMargin = 12.dpToPx + insets.systemWindowInsetRight
}
binding.chaptersSheet.chapterRecycler.updatePaddingRelative(bottom = insets.systemWindowInsetBottom)
binding.viewerContainer.requestLayout()

View File

@ -12,8 +12,10 @@ class ReaderNavGestureDetector(private val activity: ReaderActivity) : GestureDe
private val lastPixel = 0f
private var buttonY: Float = 20f.dpToPx
private var hasScrollHorizontal = false
private var lockVertical = false
var hasScrollHorizontal = false
private set
var lockVertical = false
private set
override fun onDown(e: MotionEvent): Boolean {
lockVertical = false
@ -51,7 +53,7 @@ class ReaderNavGestureDetector(private val activity: ReaderActivity) : GestureDe
if (hasScrollHorizontal) {
activity.binding.chaptersSheet.root.sheetBehavior?.collapse()
}
return lockVertical
return !hasScrollHorizontal && lockVertical
}
override fun onFling(
@ -61,13 +63,14 @@ class ReaderNavGestureDetector(private val activity: ReaderActivity) : GestureDe
velocityY: Float
): Boolean {
var result = false
val diffY = e2.rawY - e1.rawY
val diffX = e2.rawX - e1.rawX
val diffY = e2.y - e1.y
val diffX = e2.x - e1.x
val sheetBehavior = activity.binding.chaptersSheet.root.sheetBehavior
if (!hasScrollHorizontal && abs(diffX) < abs(diffY)
&& (abs(diffY) > SWIPE_THRESHOLD || abs(velocityY) > SWIPE_VELOCITY_THRESHOLD)
&& diffY <= 0
if (!hasScrollHorizontal && abs(diffX) < abs(diffY) &&
(abs(diffY) > SWIPE_THRESHOLD || abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) &&
diffY <= 0
) {
lockVertical = true
sheetBehavior?.expand()
result = true
}
@ -84,7 +87,7 @@ class ReaderNavGestureDetector(private val activity: ReaderActivity) : GestureDe
}
private companion object {
const val SWIPE_THRESHOLD = 500
const val SWIPE_VELOCITY_THRESHOLD = 600
const val SWIPE_THRESHOLD = 50
const val SWIPE_VELOCITY_THRESHOLD = 200
}
}

View File

@ -21,7 +21,7 @@
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginStart="50dp"
android:layout_marginStart="60dp"
android:background="?selectableItemBackgroundBorderless"
android:layout_marginEnd="8dp"
android:contentDescription="@string/previous_chapter"
@ -70,7 +70,7 @@
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginEnd="50dp"
android:layout_marginEnd="60dp"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/next_chapter"
android:padding="@dimen/material_layout_keylines_screen_edge_margin"