From 974eb90cd52b98a08b00371b859d90278c15cd9d Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 26 Apr 2020 17:47:32 -0400 Subject: [PATCH] Manga details now auto hides the fast scroll Also more fixes to the tablet layout of manga details --- .../tachiyomi/ui/library/LibraryController.kt | 54 +++++++------------ .../ui/manga/MangaDetailsController.kt | 34 ++++++++++-- .../ui/manga/MangaDetailsPresenter.kt | 2 +- .../tachiyomi/ui/manga/MangaHeaderHolder.kt | 9 +++- .../util/view/FastScrollerExtensions.kt | 37 +++++++++++++ .../res/drawable/fast_scroll_background.xml | 4 +- app/src/main/res/layout/chapters_item.xml | 2 +- .../res/layout/library_list_controller.xml | 1 - .../res/layout/manga_details_controller.xml | 3 +- app/src/main/res/layout/manga_header_item.xml | 11 ++-- 10 files changed, 105 insertions(+), 52 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/util/view/FastScrollerExtensions.kt 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 b0b1582c43..3c598ba481 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 @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.library import android.app.Activity import android.content.Context -import android.content.res.ColorStateList import android.graphics.Color import android.os.Bundle import android.util.TypedValue @@ -17,7 +16,6 @@ import android.view.inputmethod.InputMethodManager import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode import androidx.appcompat.widget.SearchView -import androidx.core.content.ContextCompat import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager @@ -60,9 +58,13 @@ import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.view.applyWindowInsetsForRootController import eu.kanade.tachiyomi.util.view.getItemView import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.hide import eu.kanade.tachiyomi.util.view.scrollViewWith +import eu.kanade.tachiyomi.util.view.setBackground import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener +import eu.kanade.tachiyomi.util.view.setStartTranslationX import eu.kanade.tachiyomi.util.view.setStyle +import eu.kanade.tachiyomi.util.view.show import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative @@ -185,14 +187,11 @@ class LibraryController( RecyclerView.SCROLL_STATE_DRAGGING -> { scrollAnim?.cancel() if (fast_scroller.translationX != 0f) { - fast_scroller.animate().setStartDelay(0).setDuration(100).translationX(0f) - .start() + fast_scroller.show() } } RecyclerView.SCROLL_STATE_IDLE -> { - scrollAnim = fast_scroller.animate().setStartDelay(1000).setDuration(250) - .translationX(25f.dpToPxEnd) - scrollAnim?.start() + scrollAnim = fast_scroller.hide() } } } @@ -220,32 +219,12 @@ class LibraryController( } } - private fun hideScroller(duration: Long = 1000) { - if (alwaysShowScroller) return - scrollAnim = - fast_scroller.animate().setStartDelay(duration).setDuration(250) - .translationX(25f.dpToPxEnd) - scrollAnim?.start() - } - - private fun setFastScrollBackground() { - val context = activity ?: return - fast_scroller.background = if (!alwaysShowScroller) ContextCompat.getDrawable( - context, R.drawable.fast_scroll_background - ) else null - fast_scroller.textColor = ColorStateList.valueOf( - if (!alwaysShowScroller) Color.WHITE - else context.getResourceColor(android.R.attr.textColorPrimary) - ) - fast_scroller.iconColor = fast_scroller.textColor - } - override fun onViewCreated(view: View) { super.onViewCreated(view) view.applyWindowInsetsForRootController(activity!!.bottom_nav) if (!::presenter.isInitialized) presenter = LibraryPresenter(this) - if (!alwaysShowScroller) fast_scroller.translationX = 25f.dpToPxEnd - setFastScrollBackground() + fast_scroller.setStartTranslationX(!alwaysShowScroller) + fast_scroller.setBackground(!alwaysShowScroller) adapter = LibraryCategoryAdapter(this) adapter.expandItemsAtStartUp() @@ -279,7 +258,10 @@ class LibraryController( itemPosition: Int ) { fast_scroller.translationX = 0f - hideScroller(2000) + if (!alwaysShowScroller) { + scrollAnim?.cancel() + scrollAnim = fast_scroller.hide(2000) + } textAnim?.cancel() textAnim = text_view_m.animate().alpha(0f).setDuration(250L).setStartDelay(2000) @@ -423,11 +405,11 @@ class LibraryController( fun updateShowScrollbar(show: Boolean) { alwaysShowScroller = show - setFastScrollBackground() + fast_scroller.setBackground(!show) if (libraryLayout == 0) reattachAdapter() scrollAnim?.cancel() if (show) fast_scroller.translationX = 0f - else hideScroller() + else scrollAnim = fast_scroller.hide() setRecyclerLayout() } @@ -521,9 +503,11 @@ class LibraryController( } else recycler_layout.alpha = 1f if (justStarted && freshStart) { scrollToHeader(activeCategory) - fast_scroller.translationX = 0f - view?.post { - hideScroller(2000) + if (!alwaysShowScroller) { + fast_scroller.show(false) + view?.post { + scrollAnim = fast_scroller.hide(2000) + } } } adapter.isLongPressDragEnabled = canDrag() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt index b235b3cf9f..30d9649c01 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt @@ -101,9 +101,13 @@ import eu.kanade.tachiyomi.util.system.pxToDp import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.view.getText +import eu.kanade.tachiyomi.util.view.hide import eu.kanade.tachiyomi.util.view.scrollViewWith +import eu.kanade.tachiyomi.util.view.setBackground import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener +import eu.kanade.tachiyomi.util.view.setStartTranslationX import eu.kanade.tachiyomi.util.view.setStyle +import eu.kanade.tachiyomi.util.view.show import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative @@ -185,7 +189,6 @@ class MangaDetailsController : BaseController, // Hold a reference to the current animator, so that it can be canceled mid-way. private var currentAnimator: Animator? = null - var showScroll = false var headerHeight = 0 override fun getTitle(): String? { @@ -292,11 +295,22 @@ class MangaDetailsController : BaseController, override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { val atTop = !recycler.canScrollVertically(-1) if (atTop) getHeader()?.backdrop?.translationY = 0f + when (newState) { + RecyclerView.SCROLL_STATE_DRAGGING -> { + scrollAnim?.cancel() + if (fast_scroller.translationX != 0f) { + showFastScroller() + } + } + RecyclerView.SCROLL_STATE_IDLE -> { + scrollAnim = fast_scroller.hide() + } + } } }) } - fun setInsets(insets: WindowInsets, appbarHeight: Int, offset: Int) { + private fun setInsets(insets: WindowInsets, appbarHeight: Int, offset: Int) { recycler.updatePaddingRelative(bottom = insets.systemWindowInsetBottom) tabletRecycler?.updatePaddingRelative(bottom = insets.systemWindowInsetBottom) headerHeight = appbarHeight + insets.systemWindowInsetTop @@ -311,7 +325,8 @@ class MangaDetailsController : BaseController, } private fun setFastScroller() { - // fast_scroller.translationX = if (showScroll || isTablet) 0f else 25f.dpToPxEnd + fast_scroller.setStartTranslationX(true) + fast_scroller.setBackground(true) fast_scroller.setupWithRecyclerView(recycler, { position -> val letter = adapter?.getSectionText(position) when { @@ -328,6 +343,9 @@ class MangaDetailsController : BaseController, indicatorCenterY: Int, itemPosition: Int ) { + scrollAnim?.cancel() + scrollAnim = fast_scroller.hide(2000) + textAnim?.cancel() textAnim = text_view_m.animate().alpha(0f).setDuration(250L).setStartDelay(1000) textAnim?.start() @@ -340,7 +358,9 @@ class MangaDetailsController : BaseController, (recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset( itemPosition, headerHeight ) - colorToolbar(itemPosition > 0, false) + if (!isTablet) { + colorToolbar(itemPosition > 0, false) + } } } } @@ -582,6 +602,12 @@ class MangaDetailsController : BaseController, activity?.invalidateOptionsMenu() } + private fun showFastScroller(animate: Boolean = true) { + if (presenter.scrollType != 0) { + fast_scroller.show(animate) + } + } + private fun addMangaHeader() { if (tabletAdapter?.scrollableHeaders?.isEmpty() == true) { tabletAdapter?.removeAllScrollableHeaders() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt index 201f2011d3..6f10a63f33 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt @@ -67,7 +67,7 @@ class MangaDetailsPresenter( private val seasonRegex = Regex("""(Season |S)([0-9]+)?""") private val loggedServices by lazy { Injekt.get().services.filter { it.isLogged } } - var tracks = emptyList() + private var tracks = emptyList() var trackList: List = emptyList() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt index 63c9ea685f..3ca5804aac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt @@ -5,6 +5,7 @@ import android.content.res.ColorStateList import android.graphics.Color import android.view.MotionEvent import android.view.View +import android.view.ViewGroup import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat import androidx.core.graphics.ColorUtils @@ -19,6 +20,7 @@ import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder +import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.isLTR import eu.kanade.tachiyomi.util.view.gone @@ -61,8 +63,9 @@ class MangaHeaderHolder( true false } - if (!itemView.resources.isLTR) + if (!itemView.resources.isLTR) { more_bg_gradient.rotation = 180f + } less_button.setOnClickListener { collapseDesc() } manga_genres_tags.setOnTagClickListener { adapter.delegate.tagClicked(it) @@ -92,6 +95,10 @@ class MangaHeaderHolder( if (startExpanded) expandDesc() else collapseDesc() if (isTablet) chapter_layout.gone() + } else { + filter_button.updateLayoutParams { + marginEnd = 12.dpToPx + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/FastScrollerExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/FastScrollerExtensions.kt new file mode 100644 index 0000000000..50eb2f677d --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/FastScrollerExtensions.kt @@ -0,0 +1,37 @@ +package eu.kanade.tachiyomi.util.view + +import android.content.res.ColorStateList +import android.graphics.Color +import android.view.ViewPropertyAnimator +import androidx.core.content.ContextCompat +import com.reddit.indicatorfastscroll.FastScrollerView +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.system.dpToPxEnd +import eu.kanade.tachiyomi.util.system.getResourceColor + +fun FastScrollerView.setBackground(hasBackground: Boolean) { + background = if (hasBackground) ContextCompat.getDrawable( + context, R.drawable.fast_scroll_background + ) else null + textColor = ColorStateList.valueOf( + if (hasBackground) Color.WHITE + else context.getResourceColor(android.R.attr.textColorPrimary) + ) + iconColor = textColor +} + +fun FastScrollerView.setStartTranslationX(shouldHide: Boolean) { + translationX = if (shouldHide) 25f.dpToPxEnd else 0f +} + +fun FastScrollerView.hide(duration: Long = 1000): ViewPropertyAnimator { + val scrollAnim = animate().setStartDelay(duration).setDuration(250) + .translationX(25f.dpToPxEnd) + scrollAnim.start() + return scrollAnim +} + +fun FastScrollerView.show(animate: Boolean = true) { + if (animate) animate().setStartDelay(0).setDuration(100).translationX(0f).start() + else translationX = 0f +} diff --git a/app/src/main/res/drawable/fast_scroll_background.xml b/app/src/main/res/drawable/fast_scroll_background.xml index c004264c58..90692e419f 100644 --- a/app/src/main/res/drawable/fast_scroll_background.xml +++ b/app/src/main/res/drawable/fast_scroll_background.xml @@ -10,7 +10,7 @@ - + - + \ No newline at end of file diff --git a/app/src/main/res/layout/chapters_item.xml b/app/src/main/res/layout/chapters_item.xml index 1877774983..22e7c7bc12 100644 --- a/app/src/main/res/layout/chapters_item.xml +++ b/app/src/main/res/layout/chapters_item.xml @@ -94,7 +94,7 @@ layout="@layout/download_button" android:layout_width="50dp" android:layout_height="0dp" - android:layout_marginEnd="12dp" + android:layout_marginEnd="4dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/library_list_controller.xml b/app/src/main/res/layout/library_list_controller.xml index 75774d6363..e3090a1674 100644 --- a/app/src/main/res/layout/library_list_controller.xml +++ b/app/src/main/res/layout/library_list_controller.xml @@ -38,7 +38,6 @@ android:elevation="10dp" android:layout_gravity="end" android:background="@drawable/fast_scroll_background" - android:backgroundTint="@color/md_grey_800" android:paddingTop="8dp" android:paddingBottom="8dp" android:paddingStart="3dp" diff --git a/app/src/main/res/layout/manga_details_controller.xml b/app/src/main/res/layout/manga_details_controller.xml index df2fb4e5cd..57526938a0 100644 --- a/app/src/main/res/layout/manga_details_controller.xml +++ b/app/src/main/res/layout/manga_details_controller.xml @@ -38,13 +38,14 @@