Updates to manga header margins + tablet layout fixes for the controller

This commit is contained in:
Jay 2020-04-25 18:17:41 -04:00
parent 09a24bd9f2
commit 1c51a4c499
2 changed files with 30 additions and 33 deletions

View File

@ -26,6 +26,7 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.ViewPropertyAnimator
import android.view.WindowInsets
import android.view.animation.DecelerateInterpolator
import android.view.inputmethod.InputMethodManager
import android.widget.LinearLayout
@ -93,11 +94,11 @@ import eu.kanade.tachiyomi.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.ThemeUtil
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.dpToPxEnd
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.launchUI
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.scrollViewWith
import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener
@ -264,7 +265,37 @@ class MangaDetailsController : BaseController,
swipe_refresh.setDistanceToTriggerSync(70.dpToPx)
activity!!.appbar.elevation = 0f
if (isTablet) {
recycler.doOnApplyWindowInsets { _, insets, _ ->
setInsets(insets, appbarHeight, offset)
}
} else {
scrollViewWith(recycler, padBottom = true, customPadding = true, afterInsets = { insets ->
setInsets(insets, appbarHeight, offset)
}, liftOnScroll = {
colorToolbar(it)
})
}
recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if (!isTablet) {
val atTop = !recycler.canScrollVertically(-1)
val tY = getHeader()?.backdrop?.translationY ?: 0f
getHeader()?.backdrop?.translationY = max(0f, tY + dy * 0.25f)
if (atTop) getHeader()?.backdrop?.translationY = 0f
}
}
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
val atTop = !recycler.canScrollVertically(-1)
if (atTop) getHeader()?.backdrop?.translationY = 0f
}
})
}
fun setInsets(insets: WindowInsets, appbarHeight: Int, offset: Int) {
recycler.updatePaddingRelative(bottom = insets.systemWindowInsetBottom)
tabletRecycler?.updatePaddingRelative(bottom = insets.systemWindowInsetBottom)
headerHeight = appbarHeight + insets.systemWindowInsetTop
@ -276,44 +307,10 @@ class MangaDetailsController : BaseController,
topMargin = headerHeight
bottomMargin = insets.systemWindowInsetBottom
}
}, liftOnScroll = {
colorToolbar(it)
})
recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if (!isTablet) {
val atTop = !recycler.canScrollVertically(-1)
val tY = getHeader()?.backdrop?.translationY ?: 0f
getHeader()?.backdrop?.translationY = max(0f, tY + dy * 0.25f)
if (atTop) getHeader()?.backdrop?.translationY = 0f
val fPosition =
(recycler.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition()
val scrollFunc: (Boolean) -> Unit = { show ->
showScroll = show
scrollAnim?.cancel()
scrollAnim = fast_scroller.animate().setDuration(100).translationX(
if (show) 0f else 25f.dpToPxEnd)
scrollAnim?.start()
}
if (fPosition > 0 && !showScroll) {
scrollFunc(true)
} else if (fPosition <= 0 && showScroll) {
scrollFunc(false)
}
}
}
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
val atTop = !recycler.canScrollVertically(-1)
if (atTop) getHeader()?.backdrop?.translationY = 0f
}
})
}
private fun setFastScroller() {
fast_scroller.translationX = if (showScroll || isTablet) 0f else 25f.dpToPxEnd
// fast_scroller.translationX = if (showScroll || isTablet) 0f else 25f.dpToPxEnd
fast_scroller.setupWithRecyclerView(recycler, { position ->
val letter = adapter?.getSectionText(position)
when {

View File

@ -223,7 +223,7 @@
style="@style/TextAppearance.Regular.Body1.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="18dp"
android:clickable="true"
@ -314,7 +314,7 @@
style="@style/Theme.Widget.Button.TextButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="18dp"
android:text="@string/less"
android:textAlignment="textEnd"
@ -331,7 +331,7 @@
style="@style/Theme.Widget.Button.Primary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="24dp"
android:text="@string/start_reading"