Give view pager unique ids, avoiding subtle bugs

This commit is contained in:
inorichi 2017-12-04 22:22:35 +01:00
parent 8bcb14c65d
commit 08baf798aa
6 changed files with 18 additions and 16 deletions

View File

@ -138,8 +138,8 @@ class LibraryController(
super.onViewCreated(view) super.onViewCreated(view)
adapter = LibraryAdapter(this) adapter = LibraryAdapter(this)
view_pager.adapter = adapter library_pager.adapter = adapter
view_pager.pageSelections().skip(1).subscribeUntilDestroy { library_pager.pageSelections().skip(1).subscribeUntilDestroy {
preferences.lastUsedCategory().set(it) preferences.lastUsedCategory().set(it)
activeCategory = it activeCategory = it
} }
@ -158,7 +158,7 @@ class LibraryController(
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
super.onChangeStarted(handler, type) super.onChangeStarted(handler, type)
if (type.isEnter) { if (type.isEnter) {
activity?.tabs?.setupWithViewPager(view_pager) activity?.tabs?.setupWithViewPager(library_pager)
presenter.subscribeLibrary() presenter.subscribeLibrary()
} }
} }
@ -232,7 +232,7 @@ class LibraryController(
// Get the current active category. // Get the current active category.
val activeCat = if (adapter.categories.isNotEmpty()) val activeCat = if (adapter.categories.isNotEmpty())
view_pager.currentItem library_pager.currentItem
else else
activeCategory activeCategory
@ -240,14 +240,14 @@ class LibraryController(
adapter.categories = categories adapter.categories = categories
// Restore active category. // Restore active category.
view_pager.setCurrentItem(activeCat, false) library_pager.setCurrentItem(activeCat, false)
tabsVisibilityRelay.call(categories.size > 1) tabsVisibilityRelay.call(categories.size > 1)
// Delay the scroll position to allow the view to be properly measured. // Delay the scroll position to allow the view to be properly measured.
view.post { view.post {
if (isAttached) { if (isAttached) {
activity?.tabs?.setScrollPosition(view_pager.currentItem, 0f, true) activity?.tabs?.setScrollPosition(library_pager.currentItem, 0f, true)
} }
} }
@ -292,11 +292,11 @@ class LibraryController(
private fun reattachAdapter() { private fun reattachAdapter() {
val adapter = adapter ?: return val adapter = adapter ?: return
val position = view_pager.currentItem val position = library_pager.currentItem
adapter.recycle = false adapter.recycle = false
view_pager.adapter = adapter library_pager.adapter = adapter
view_pager.currentItem = position library_pager.currentItem = position
adapter.recycle = true adapter.recycle = true
} }

View File

@ -87,11 +87,11 @@ class MangaController : RxController, TabbedController {
requestPermissionsSafe(arrayOf(WRITE_EXTERNAL_STORAGE), 301) requestPermissionsSafe(arrayOf(WRITE_EXTERNAL_STORAGE), 301)
adapter = MangaDetailAdapter() adapter = MangaDetailAdapter()
view_pager.offscreenPageLimit = 3 manga_pager.offscreenPageLimit = 3
view_pager.adapter = adapter manga_pager.adapter = adapter
if (!fromCatalogue) if (!fromCatalogue)
view_pager.currentItem = CHAPTERS_CONTROLLER manga_pager.currentItem = CHAPTERS_CONTROLLER
} }
override fun onDestroyView(view: View) { override fun onDestroyView(view: View) {
@ -102,7 +102,7 @@ class MangaController : RxController, TabbedController {
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
super.onChangeStarted(handler, type) super.onChangeStarted(handler, type)
if (type.isEnter) { if (type.isEnter) {
activity?.tabs?.setupWithViewPager(view_pager) activity?.tabs?.setupWithViewPager(manga_pager)
trackingIconSubscription = trackingIconRelay.subscribe { setTrackingIconInternal(it) } trackingIconSubscription = trackingIconRelay.subscribe { setTrackingIconInternal(it) }
} }
} }

View File

@ -118,7 +118,7 @@ abstract class PagerReader : BaseReader() {
this.pager = pager.apply { this.pager = pager.apply {
setLayoutParams(ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)) setLayoutParams(ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT))
setOffscreenPageLimit(1) setOffscreenPageLimit(1)
setId(R.id.view_pager) setId(R.id.reader_pager)
setOnChapterBoundariesOutListener(object : OnChapterBoundariesOutListener { setOnChapterBoundariesOutListener(object : OnChapterBoundariesOutListener {
override fun onFirstPageOutEvent() { override fun onFirstPageOutEvent() {
readerActivity.requestPreviousChapter() readerActivity.requestPreviousChapter()

View File

@ -8,7 +8,7 @@
<android.support.v4.view.ViewPager <android.support.v4.view.ViewPager
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/view_pager"/> android:id="@+id/library_pager"/>
<eu.kanade.tachiyomi.widget.EmptyView <eu.kanade.tachiyomi.widget.EmptyView
android:id="@+id/empty_view" android:id="@+id/empty_view"

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager <android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/view_pager" android:id="@+id/manga_pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />

View File

@ -3,4 +3,6 @@
<item name="catalogue_filter_sort_group" type="id"/> <item name="catalogue_filter_sort_group" type="id"/>
<item name="catalogue_filter_sort_item" type="id"/> <item name="catalogue_filter_sort_item" type="id"/>
<item name="reader_pager" type="id"/>
</resources> </resources>