From 08baf798aa6bd49ae0f61d84b2a670f36f67bdd7 Mon Sep 17 00:00:00 2001 From: inorichi Date: Mon, 4 Dec 2017 22:22:35 +0100 Subject: [PATCH] Give view pager unique ids, avoiding subtle bugs --- .../tachiyomi/ui/library/LibraryController.kt | 18 +++++++++--------- .../tachiyomi/ui/manga/MangaController.kt | 8 ++++---- .../ui/reader/viewer/pager/PagerReader.kt | 2 +- app/src/main/res/layout/library_controller.xml | 2 +- app/src/main/res/layout/manga_controller.xml | 2 +- app/src/main/res/values/ids.xml | 2 ++ 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index b699069b7c..806b31b9e1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -138,8 +138,8 @@ class LibraryController( super.onViewCreated(view) adapter = LibraryAdapter(this) - view_pager.adapter = adapter - view_pager.pageSelections().skip(1).subscribeUntilDestroy { + library_pager.adapter = adapter + library_pager.pageSelections().skip(1).subscribeUntilDestroy { preferences.lastUsedCategory().set(it) activeCategory = it } @@ -158,7 +158,7 @@ class LibraryController( override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { super.onChangeStarted(handler, type) if (type.isEnter) { - activity?.tabs?.setupWithViewPager(view_pager) + activity?.tabs?.setupWithViewPager(library_pager) presenter.subscribeLibrary() } } @@ -232,7 +232,7 @@ class LibraryController( // Get the current active category. val activeCat = if (adapter.categories.isNotEmpty()) - view_pager.currentItem + library_pager.currentItem else activeCategory @@ -240,14 +240,14 @@ class LibraryController( adapter.categories = categories // Restore active category. - view_pager.setCurrentItem(activeCat, false) + library_pager.setCurrentItem(activeCat, false) tabsVisibilityRelay.call(categories.size > 1) // Delay the scroll position to allow the view to be properly measured. view.post { 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() { val adapter = adapter ?: return - val position = view_pager.currentItem + val position = library_pager.currentItem adapter.recycle = false - view_pager.adapter = adapter - view_pager.currentItem = position + library_pager.adapter = adapter + library_pager.currentItem = position adapter.recycle = true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index 467848aac9..ed9636f6ba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -87,11 +87,11 @@ class MangaController : RxController, TabbedController { requestPermissionsSafe(arrayOf(WRITE_EXTERNAL_STORAGE), 301) adapter = MangaDetailAdapter() - view_pager.offscreenPageLimit = 3 - view_pager.adapter = adapter + manga_pager.offscreenPageLimit = 3 + manga_pager.adapter = adapter if (!fromCatalogue) - view_pager.currentItem = CHAPTERS_CONTROLLER + manga_pager.currentItem = CHAPTERS_CONTROLLER } override fun onDestroyView(view: View) { @@ -102,7 +102,7 @@ class MangaController : RxController, TabbedController { override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { super.onChangeStarted(handler, type) if (type.isEnter) { - activity?.tabs?.setupWithViewPager(view_pager) + activity?.tabs?.setupWithViewPager(manga_pager) trackingIconSubscription = trackingIconRelay.subscribe { setTrackingIconInternal(it) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.kt index a5a4e71d49..1bd7b0b80f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.kt @@ -118,7 +118,7 @@ abstract class PagerReader : BaseReader() { this.pager = pager.apply { setLayoutParams(ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)) setOffscreenPageLimit(1) - setId(R.id.view_pager) + setId(R.id.reader_pager) setOnChapterBoundariesOutListener(object : OnChapterBoundariesOutListener { override fun onFirstPageOutEvent() { readerActivity.requestPreviousChapter() diff --git a/app/src/main/res/layout/library_controller.xml b/app/src/main/res/layout/library_controller.xml index 24e3d9af43..e315b9b920 100644 --- a/app/src/main/res/layout/library_controller.xml +++ b/app/src/main/res/layout/library_controller.xml @@ -8,7 +8,7 @@ + android:id="@+id/library_pager"/> \ No newline at end of file diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml index 912dfd017d..a28b6bb7ee 100644 --- a/app/src/main/res/values/ids.xml +++ b/app/src/main/res/values/ids.xml @@ -3,4 +3,6 @@ + + \ No newline at end of file