From 7875f363a8a18659d4cb59774f6ce0e3d0a428ab Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 23 May 2021 12:36:47 -0400 Subject: [PATCH] Tablet manga view --- .../tachiyomi/ui/manga/MangaController.kt | 60 +++++++++----- .../ui/manga/info/MangaInfoHeaderAdapter.kt | 22 ++++-- .../res/layout-sw600dp/manga_controller.xml | 78 +++++++++++++++++++ app/src/main/res/layout/manga_controller.xml | 3 +- 4 files changed, 135 insertions(+), 28 deletions(-) create mode 100644 app/src/main/res/layout-sw600dp/manga_controller.xml 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 d7125640a6..db4dafd800 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 @@ -206,11 +206,17 @@ class MangaController : override fun onViewCreated(view: View) { super.onViewCreated(view) - binding.recycler.applyInsetter { - type(navigationBars = true) { - padding() + listOfNotNull(binding.fullRecycler, binding.infoRecycler, binding.chaptersRecycler) + .forEach { + it.applyInsetter { + type(navigationBars = true) { + padding() + } + } + + it.layoutManager = LinearLayoutManager(view.context) + it.setHasFixedSize(true) } - } binding.actionToolbar.applyInsetter { type(navigationBars = true) { margin(bottom = true) @@ -220,33 +226,42 @@ class MangaController : if (manga == null || source == null) return // Init RecyclerView and adapter - mangaInfoAdapter = MangaInfoHeaderAdapter(this, fromSource) + mangaInfoAdapter = MangaInfoHeaderAdapter(this, fromSource, binding.infoRecycler != null) chaptersHeaderAdapter = MangaChaptersHeaderAdapter(this) chaptersAdapter = ChaptersAdapter(this, view.context) - binding.recycler.adapter = ConcatAdapter(mangaInfoAdapter, chaptersHeaderAdapter, chaptersAdapter) - binding.recycler.layoutManager = LinearLayoutManager(view.context) - binding.recycler.setHasFixedSize(true) + // Phone layout + binding.fullRecycler?.let { + it.adapter = ConcatAdapter(mangaInfoAdapter, chaptersHeaderAdapter, chaptersAdapter) + + it.scrollEvents() + .onEach { updateToolbarTitleAlpha() } + .launchIn(viewScope) + } + // Tablet layout + binding.infoRecycler?.let { + it.adapter = mangaInfoAdapter + } + binding.chaptersRecycler?.let { + it.adapter = ConcatAdapter(chaptersHeaderAdapter, chaptersAdapter) + } + chaptersAdapter?.fastScroller = binding.fastScroller - actionFabScrollListener = actionFab?.shrinkOnScroll(binding.recycler) + actionFabScrollListener = actionFab?.shrinkOnScroll(chaptersRecycler) // Skips directly to chapters list if navigated to from the library - binding.recycler.post { + chaptersRecycler.post { if (!fromSource && preferences.jumpToChapters()) { - (binding.recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(1, 0) + (chaptersRecycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(1, 0) } // Delayed in case we need to jump to chapters - binding.recycler.post { + binding.fullRecycler?.post { updateToolbarTitleAlpha() } } - binding.recycler.scrollEvents() - .onEach { updateToolbarTitleAlpha() } - .launchIn(viewScope) - binding.swipeRefresh.refreshes() .onEach { fetchMangaInfoFromSource(manualFetch = true) @@ -269,15 +284,19 @@ class MangaController : } private fun updateToolbarTitleAlpha(alpha: Int? = null) { + if (binding.fullRecycler == null) { + return + } + val calculatedAlpha = when { // Specific alpha provided alpha != null -> alpha // First item isn't in view, full opacity - ((binding.recycler.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() > 0) -> 255 + ((binding.fullRecycler!!.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() > 0) -> 255 // Based on scroll amount when first item is in view - else -> min(binding.recycler.computeVerticalScrollOffset(), 255) + else -> min(binding.fullRecycler!!.computeVerticalScrollOffset(), 255) } (activity as? MainActivity)?.binding?.toolbar?.setTitleTextColor( @@ -321,7 +340,7 @@ class MangaController : override fun cleanupFab(fab: ExtendedFloatingActionButton) { fab.setOnClickListener(null) - actionFabScrollListener?.let { binding.recycler.removeOnScrollListener(it) } + actionFabScrollListener?.let { binding.fullRecycler?.removeOnScrollListener(it) } actionFab = null } @@ -1084,6 +1103,9 @@ class MangaController : // Tracker sheet - end + private val chaptersRecycler: RecyclerView + get() = binding.fullRecycler ?: binding.chaptersRecycler!! + companion object { const val FROM_SOURCE_EXTRA = "from_source" const val MANGA_EXTRA = "manga" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt index dc5f4c37bd..8a156b4e2a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt @@ -28,7 +28,8 @@ import uy.kohesive.injekt.injectLazy class MangaInfoHeaderAdapter( private val controller: MangaController, - private val fromSource: Boolean + private val fromSource: Boolean, + private val isTablet: Boolean, ) : RecyclerView.Adapter() { @@ -194,10 +195,16 @@ class MangaInfoHeaderAdapter( */ private fun setMangaInfo(manga: Manga, source: Source?) { // Update full title TextView. - binding.mangaFullTitle.text = if (manga.title.isBlank()) { - view.context.getString(R.string.unknown) - } else { - manga.title + with(binding.mangaFullTitle) { + if (isTablet) { + isVisible = false + } else { + text = if (manga.title.isBlank()) { + view.context.getString(R.string.unknown) + } else { + manga.title + } + } } // Update author TextView. @@ -282,8 +289,9 @@ class MangaInfoHeaderAdapter( .onEach { toggleMangaInfo() } .launchIn(controller.viewScope) - // Expand manga info if navigated from source listing - if (initialLoad && fromSource) { + // Expand manga info if navigated from source listing or explicitly set to + // (e.g. on tablets) + if (initialLoad && (fromSource || isTablet)) { toggleMangaInfo() initialLoad = false } diff --git a/app/src/main/res/layout-sw600dp/manga_controller.xml b/app/src/main/res/layout-sw600dp/manga_controller.xml new file mode 100644 index 0000000000..8582e0c059 --- /dev/null +++ b/app/src/main/res/layout-sw600dp/manga_controller.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/manga_controller.xml b/app/src/main/res/layout/manga_controller.xml index 5f8ded8e5c..89d945a966 100644 --- a/app/src/main/res/layout/manga_controller.xml +++ b/app/src/main/res/layout/manga_controller.xml @@ -18,11 +18,10 @@ android:id="@+id/swipe_refresh" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_above="@+id/toolbar_bottom" android:orientation="vertical">