Collaspe chapter sheet when touching outside of chapter sheet

Which fixes the wonky logic when switching chapters in it
This commit is contained in:
Jays2Kings 2021-04-02 00:32:29 -04:00
parent 008753e7e4
commit c43d5f01fa
4 changed files with 17 additions and 13 deletions

View File

@ -388,6 +388,14 @@ class ReaderActivity :
}
}
binding.touchView.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
if (binding.chaptersSheet.chaptersBottomSheet.sheetBehavior.isExpanded()) {
binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.collapse()
}
}
false
}
val readerNavGestureDetector = ReaderNavGestureDetector(this)
val gestureDetector = GestureDetectorCompat(this, readerNavGestureDetector)
with(binding.readerNav) {
@ -680,7 +688,7 @@ class ReaderActivity :
*/
@SuppressLint("SetTextI18n")
fun onPageSelected(page: ReaderPage) {
val newChapter = presenter.onPageSelected(page)
presenter.onPageSelected(page)
val pages = page.chapter.pages ?: return
val currentPage = page.number
@ -696,14 +704,9 @@ class ReaderActivity :
binding.readerNav.leftPageText.text = currentPage.toString()
binding.readerNav.rightPageText.text = totalPages.toString()
}
if (!newChapter && binding.chaptersSheet.chaptersBottomSheet.shouldCollapse && binding.chaptersSheet.chaptersBottomSheet.sheetBehavior.isExpanded()) {
binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.collapse()
}
if (binding.chaptersSheet.chaptersBottomSheet.selectedChapterId != page.chapter.chapter.id) {
binding.chaptersSheet.chaptersBottomSheet.refreshList()
}
binding.chaptersSheet.chaptersBottomSheet.shouldCollapse = true
// Set seekbar progress
binding.readerNav.pageSeekbar.max = pages.lastIndex
binding.readerNav.pageSeekbar.progress = page.index

View File

@ -458,8 +458,8 @@ class ReaderPresenter(
* read, update tracking services, enqueue downloaded chapter deletion, and updating the active chapter if this
* [page]'s chapter is different from the currently active.
*/
fun onPageSelected(page: ReaderPage): Boolean {
val currentChapters = viewerChaptersRelay.value ?: return false
fun onPageSelected(page: ReaderPage) {
val currentChapters = viewerChaptersRelay.value ?: return
val selectedChapter = page.chapter
@ -477,9 +477,7 @@ class ReaderPresenter(
Timber.d("Setting ${selectedChapter.chapter.url} as active")
onChapterChanged(currentChapters.currChapter)
loadNewChapter(selectedChapter)
return true
}
return false
}
/**

View File

@ -41,7 +41,6 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
lateinit var presenter: ReaderPresenter
var adapter: FastAdapter<ReaderChapterItem>? = null
private val itemAdapter = ItemAdapter<ReaderChapterItem>()
var shouldCollapse = true
var selectedChapterId = -1L
var loadingPos = 0
@ -98,7 +97,6 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
override fun onStateChanged(p0: View, state: Int) {
if (state == BottomSheetBehavior.STATE_COLLAPSED) {
shouldCollapse = true
sheetBehavior?.isHideable = false
(binding.chapterRecycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
adapter?.getPosition(presenter.getCurrentChapter()?.chapter?.id ?: 0L) ?: 0,
@ -136,7 +134,6 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
activity.binding.readerNav.leftChapter.invisible()
activity.binding.readerNav.rightChapter.invisible()
shouldCollapse = false
presenter.loadChapter(item.chapter)
loadingPos = position
val itemView = (binding.chapterRecycler.findViewHolderForAdapterPosition(position) as? ReaderChapterItem.ViewHolder)?.binding

View File

@ -63,6 +63,12 @@
</FrameLayout>
</FrameLayout>
<View
android:id="@+id/touch_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<FrameLayout
android:id="@+id/nav_layout"
android:layout_width="match_parent"