Manga details now auto hides the fast scroll

Also more fixes to the tablet layout of manga details
This commit is contained in:
Jay 2020-04-26 17:47:32 -04:00
parent 15d2cb9f36
commit 974eb90cd5
10 changed files with 105 additions and 52 deletions

View File

@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.library
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.util.TypedValue import android.util.TypedValue
@ -17,7 +16,6 @@ import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ActionMode import androidx.appcompat.view.ActionMode
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager 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.applyWindowInsetsForRootController
import eu.kanade.tachiyomi.util.view.getItemView import eu.kanade.tachiyomi.util.view.getItemView
import eu.kanade.tachiyomi.util.view.gone 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.scrollViewWith
import eu.kanade.tachiyomi.util.view.setBackground
import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener 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.setStyle
import eu.kanade.tachiyomi.util.view.show
import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.snack
import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.util.view.updatePaddingRelative import eu.kanade.tachiyomi.util.view.updatePaddingRelative
@ -185,14 +187,11 @@ class LibraryController(
RecyclerView.SCROLL_STATE_DRAGGING -> { RecyclerView.SCROLL_STATE_DRAGGING -> {
scrollAnim?.cancel() scrollAnim?.cancel()
if (fast_scroller.translationX != 0f) { if (fast_scroller.translationX != 0f) {
fast_scroller.animate().setStartDelay(0).setDuration(100).translationX(0f) fast_scroller.show()
.start()
} }
} }
RecyclerView.SCROLL_STATE_IDLE -> { RecyclerView.SCROLL_STATE_IDLE -> {
scrollAnim = fast_scroller.animate().setStartDelay(1000).setDuration(250) scrollAnim = fast_scroller.hide()
.translationX(25f.dpToPxEnd)
scrollAnim?.start()
} }
} }
} }
@ -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) { override fun onViewCreated(view: View) {
super.onViewCreated(view) super.onViewCreated(view)
view.applyWindowInsetsForRootController(activity!!.bottom_nav) view.applyWindowInsetsForRootController(activity!!.bottom_nav)
if (!::presenter.isInitialized) presenter = LibraryPresenter(this) if (!::presenter.isInitialized) presenter = LibraryPresenter(this)
if (!alwaysShowScroller) fast_scroller.translationX = 25f.dpToPxEnd fast_scroller.setStartTranslationX(!alwaysShowScroller)
setFastScrollBackground() fast_scroller.setBackground(!alwaysShowScroller)
adapter = LibraryCategoryAdapter(this) adapter = LibraryCategoryAdapter(this)
adapter.expandItemsAtStartUp() adapter.expandItemsAtStartUp()
@ -279,7 +258,10 @@ class LibraryController(
itemPosition: Int itemPosition: Int
) { ) {
fast_scroller.translationX = 0f fast_scroller.translationX = 0f
hideScroller(2000) if (!alwaysShowScroller) {
scrollAnim?.cancel()
scrollAnim = fast_scroller.hide(2000)
}
textAnim?.cancel() textAnim?.cancel()
textAnim = text_view_m.animate().alpha(0f).setDuration(250L).setStartDelay(2000) textAnim = text_view_m.animate().alpha(0f).setDuration(250L).setStartDelay(2000)
@ -423,11 +405,11 @@ class LibraryController(
fun updateShowScrollbar(show: Boolean) { fun updateShowScrollbar(show: Boolean) {
alwaysShowScroller = show alwaysShowScroller = show
setFastScrollBackground() fast_scroller.setBackground(!show)
if (libraryLayout == 0) reattachAdapter() if (libraryLayout == 0) reattachAdapter()
scrollAnim?.cancel() scrollAnim?.cancel()
if (show) fast_scroller.translationX = 0f if (show) fast_scroller.translationX = 0f
else hideScroller() else scrollAnim = fast_scroller.hide()
setRecyclerLayout() setRecyclerLayout()
} }
@ -521,9 +503,11 @@ class LibraryController(
} else recycler_layout.alpha = 1f } else recycler_layout.alpha = 1f
if (justStarted && freshStart) { if (justStarted && freshStart) {
scrollToHeader(activeCategory) scrollToHeader(activeCategory)
fast_scroller.translationX = 0f if (!alwaysShowScroller) {
fast_scroller.show(false)
view?.post { view?.post {
hideScroller(2000) scrollAnim = fast_scroller.hide(2000)
}
} }
} }
adapter.isLongPressDragEnabled = canDrag() adapter.isLongPressDragEnabled = canDrag()

View File

@ -101,9 +101,13 @@ import eu.kanade.tachiyomi.util.system.pxToDp
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets
import eu.kanade.tachiyomi.util.view.getText 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.scrollViewWith
import eu.kanade.tachiyomi.util.view.setBackground
import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener 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.setStyle
import eu.kanade.tachiyomi.util.view.show
import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.snack
import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.util.view.updatePaddingRelative 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. // Hold a reference to the current animator, so that it can be canceled mid-way.
private var currentAnimator: Animator? = null private var currentAnimator: Animator? = null
var showScroll = false
var headerHeight = 0 var headerHeight = 0
override fun getTitle(): String? { override fun getTitle(): String? {
@ -292,11 +295,22 @@ class MangaDetailsController : BaseController,
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
val atTop = !recycler.canScrollVertically(-1) val atTop = !recycler.canScrollVertically(-1)
if (atTop) getHeader()?.backdrop?.translationY = 0f 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) recycler.updatePaddingRelative(bottom = insets.systemWindowInsetBottom)
tabletRecycler?.updatePaddingRelative(bottom = insets.systemWindowInsetBottom) tabletRecycler?.updatePaddingRelative(bottom = insets.systemWindowInsetBottom)
headerHeight = appbarHeight + insets.systemWindowInsetTop headerHeight = appbarHeight + insets.systemWindowInsetTop
@ -311,7 +325,8 @@ class MangaDetailsController : BaseController,
} }
private fun setFastScroller() { 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 -> fast_scroller.setupWithRecyclerView(recycler, { position ->
val letter = adapter?.getSectionText(position) val letter = adapter?.getSectionText(position)
when { when {
@ -328,6 +343,9 @@ class MangaDetailsController : BaseController,
indicatorCenterY: Int, indicatorCenterY: Int,
itemPosition: Int itemPosition: Int
) { ) {
scrollAnim?.cancel()
scrollAnim = fast_scroller.hide(2000)
textAnim?.cancel() textAnim?.cancel()
textAnim = text_view_m.animate().alpha(0f).setDuration(250L).setStartDelay(1000) textAnim = text_view_m.animate().alpha(0f).setDuration(250L).setStartDelay(1000)
textAnim?.start() textAnim?.start()
@ -340,10 +358,12 @@ class MangaDetailsController : BaseController,
(recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset( (recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
itemPosition, headerHeight itemPosition, headerHeight
) )
if (!isTablet) {
colorToolbar(itemPosition > 0, false) colorToolbar(itemPosition > 0, false)
} }
} }
} }
}
/** Set the toolbar to fully transparent or colored and translucent */ /** Set the toolbar to fully transparent or colored and translucent */
fun colorToolbar(isColor: Boolean, animate: Boolean = true) { fun colorToolbar(isColor: Boolean, animate: Boolean = true) {
@ -582,6 +602,12 @@ class MangaDetailsController : BaseController,
activity?.invalidateOptionsMenu() activity?.invalidateOptionsMenu()
} }
private fun showFastScroller(animate: Boolean = true) {
if (presenter.scrollType != 0) {
fast_scroller.show(animate)
}
}
private fun addMangaHeader() { private fun addMangaHeader() {
if (tabletAdapter?.scrollableHeaders?.isEmpty() == true) { if (tabletAdapter?.scrollableHeaders?.isEmpty() == true) {
tabletAdapter?.removeAllScrollableHeaders() tabletAdapter?.removeAllScrollableHeaders()

View File

@ -67,7 +67,7 @@ class MangaDetailsPresenter(
private val seasonRegex = Regex("""(Season |S)([0-9]+)?""") private val seasonRegex = Regex("""(Season |S)([0-9]+)?""")
private val loggedServices by lazy { Injekt.get<TrackManager>().services.filter { it.isLogged } } private val loggedServices by lazy { Injekt.get<TrackManager>().services.filter { it.isLogged } }
var tracks = emptyList<Track>() private var tracks = emptyList<Track>()
var trackList: List<TrackItem> = emptyList() var trackList: List<TrackItem> = emptyList()

View File

@ -5,6 +5,7 @@ import android.content.res.ColorStateList
import android.graphics.Color import android.graphics.Color
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils 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.LocalSource
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder 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.getResourceColor
import eu.kanade.tachiyomi.util.system.isLTR import eu.kanade.tachiyomi.util.system.isLTR
import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.gone
@ -61,8 +63,9 @@ class MangaHeaderHolder(
true true
false false
} }
if (!itemView.resources.isLTR) if (!itemView.resources.isLTR) {
more_bg_gradient.rotation = 180f more_bg_gradient.rotation = 180f
}
less_button.setOnClickListener { collapseDesc() } less_button.setOnClickListener { collapseDesc() }
manga_genres_tags.setOnTagClickListener { manga_genres_tags.setOnTagClickListener {
adapter.delegate.tagClicked(it) adapter.delegate.tagClicked(it)
@ -92,6 +95,10 @@ class MangaHeaderHolder(
if (startExpanded) expandDesc() if (startExpanded) expandDesc()
else collapseDesc() else collapseDesc()
if (isTablet) chapter_layout.gone() if (isTablet) chapter_layout.gone()
} else {
filter_button.updateLayoutParams<ViewGroup.MarginLayoutParams> {
marginEnd = 12.dpToPx
}
} }
} }

View File

@ -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
}

View File

@ -10,7 +10,7 @@
<size <size
android:width="25dp" android:width="25dp"
android:height="25dp" /> android:height="25dp" />
<solid android:color="@color/gray_button" /> <solid android:color="@color/md_grey_800" />
</shape> </shape>
</item> </item>
<item <item
@ -21,7 +21,7 @@
<size <size
android:width="0dp" android:width="0dp"
android:height="25dp" /> android:height="25dp" />
<solid android:color="@color/gray_button" /> <solid android:color="@color/md_grey_800" />
</shape> </shape>
</item> </item>
</layer-list> </layer-list>

View File

@ -94,7 +94,7 @@
layout="@layout/download_button" layout="@layout/download_button"
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="4dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />

View File

@ -38,7 +38,6 @@
android:elevation="10dp" android:elevation="10dp"
android:layout_gravity="end" android:layout_gravity="end"
android:background="@drawable/fast_scroll_background" android:background="@drawable/fast_scroll_background"
android:backgroundTint="@color/md_grey_800"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingBottom="8dp" android:paddingBottom="8dp"
android:paddingStart="3dp" android:paddingStart="3dp"

View File

@ -38,13 +38,14 @@
<com.reddit.indicatorfastscroll.FastScrollerView <com.reddit.indicatorfastscroll.FastScrollerView
android:id="@+id/fast_scroller" android:id="@+id/fast_scroller"
android:layout_width="25dp" android:layout_width="25dp"
android:layout_height="0dp" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="end"
android:elevation="10dp" android:elevation="10dp"
android:paddingStart="1dp" android:paddingStart="1dp"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingEnd="0dp" android:paddingEnd="0dp"
android:paddingBottom="8dp" android:paddingBottom="8dp"
app:layout_constrainedHeight="true"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
app:iconColor="?android:attr/textColorPrimary" app:iconColor="?android:attr/textColorPrimary"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"

View File

@ -225,7 +225,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:layout_marginEnd="18dp" android:layout_marginEnd="16dp"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:maxLines="3" android:maxLines="3"
@ -268,7 +268,7 @@
style="@style/Theme.Widget.Button.TextButton" style="@style/Theme.Widget.Button.TextButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="18dp" android:layout_marginEnd="16dp"
android:text="@string/more" android:text="@string/more"
android:textAlignment="viewEnd" android:textAlignment="viewEnd"
app:layout_constraintBottom_toBottomOf="@id/more_guide" app:layout_constraintBottom_toBottomOf="@id/more_guide"
@ -314,7 +314,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginEnd="18dp" android:layout_marginEnd="16dp"
android:text="@string/less" android:text="@string/less"
android:textAlignment="textEnd" android:textAlignment="textEnd"
android:visibility="gone" android:visibility="gone"
@ -331,9 +331,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:visibility="gone"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:layout_marginEnd="24dp" android:layout_marginEnd="16dp"
android:text="@string/start_reading" android:text="@string/start_reading"
app:layout_constraintBottom_toTopOf="@id/chapter_layout" app:layout_constraintBottom_toTopOf="@id/chapter_layout"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
@ -373,7 +372,7 @@
android:tint="?colorAccent" android:tint="?colorAccent"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="20dp" android:layout_marginEnd="12dp"
android:background="@null" android:background="@null"
android:padding="5dp" android:padding="5dp"
android:src="@drawable/ic_filter_list_white_24dp" android:src="@drawable/ic_filter_list_white_24dp"