Reinstate elevation overlay (#6243)
* Theme default elevation overlay * Fix app bar elevation overlay Elevation overlay is disabled when tabs are visible * Remove custom elevation overlay in tracking sheet item * upsi
This commit is contained in:
parent
e7d4eb1ae3
commit
845e061382
8 changed files with 24 additions and 33 deletions
|
@ -1,4 +1,4 @@
|
||||||
package eu.kanade.tachiyomi.widget
|
package com.google.android.material.appbar
|
||||||
|
|
||||||
import android.animation.AnimatorSet
|
import android.animation.AnimatorSet
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
|
@ -11,9 +11,6 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import androidx.lifecycle.coroutineScope
|
import androidx.lifecycle.coroutineScope
|
||||||
import androidx.lifecycle.findViewTreeLifecycleOwner
|
import androidx.lifecycle.findViewTreeLifecycleOwner
|
||||||
import com.google.android.material.animation.AnimationUtils
|
import com.google.android.material.animation.AnimationUtils
|
||||||
import com.google.android.material.appbar.AppBarLayout
|
|
||||||
import com.google.android.material.appbar.HideToolbarOnScrollBehavior
|
|
||||||
import com.google.android.material.appbar.MaterialToolbar
|
|
||||||
import com.google.android.material.shape.MaterialShapeDrawable
|
import com.google.android.material.shape.MaterialShapeDrawable
|
||||||
import com.google.android.material.shape.getStateAlpha
|
import com.google.android.material.shape.getStateAlpha
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
@ -23,7 +20,12 @@ import kotlinx.coroutines.flow.onEach
|
||||||
import reactivecircus.flowbinding.android.view.HierarchyChangeEvent
|
import reactivecircus.flowbinding.android.view.HierarchyChangeEvent
|
||||||
import reactivecircus.flowbinding.android.view.hierarchyChangeEvents
|
import reactivecircus.flowbinding.android.view.hierarchyChangeEvents
|
||||||
|
|
||||||
class ElevationAppBarLayout @JvmOverloads constructor(
|
/**
|
||||||
|
* [AppBarLayout] with our own lift state handler and custom title alpha.
|
||||||
|
*
|
||||||
|
* Inside this package to access some package-private methods.
|
||||||
|
*/
|
||||||
|
class TachiyomiAppBarLayout @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
attrs: AttributeSet? = null
|
attrs: AttributeSet? = null
|
||||||
) : AppBarLayout(context, attrs) {
|
) : AppBarLayout(context, attrs) {
|
||||||
|
@ -50,8 +52,8 @@ class ElevationAppBarLayout @JvmOverloads constructor(
|
||||||
private var statusBarForegroundAnimator: ValueAnimator? = null
|
private var statusBarForegroundAnimator: ValueAnimator? = null
|
||||||
private val offsetListener = OnOffsetChangedListener { appBarLayout, verticalOffset ->
|
private val offsetListener = OnOffsetChangedListener { appBarLayout, verticalOffset ->
|
||||||
// Show status bar foreground when offset
|
// Show status bar foreground when offset
|
||||||
val foreground = appBarLayout?.statusBarForeground ?: return@OnOffsetChangedListener
|
val foreground = (appBarLayout?.statusBarForeground as? MaterialShapeDrawable) ?: return@OnOffsetChangedListener
|
||||||
val start = foreground.alpha
|
val start = foreground.getStateAlpha()
|
||||||
val end = if (verticalOffset != 0) 255 else 0
|
val end = if (verticalOffset != 0) 255 else 0
|
||||||
|
|
||||||
statusBarForegroundAnimator?.cancel()
|
statusBarForegroundAnimator?.cancel()
|
||||||
|
@ -82,7 +84,7 @@ class ElevationAppBarLayout @JvmOverloads constructor(
|
||||||
override fun getBehavior(): CoordinatorLayout.Behavior<AppBarLayout> = HideToolbarOnScrollBehavior()
|
override fun getBehavior(): CoordinatorLayout.Behavior<AppBarLayout> = HideToolbarOnScrollBehavior()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disabled. Lift on scroll is handled manually with [TachiyomiCoordinatorLayout]
|
* Disabled. Lift on scroll is handled manually with [eu.kanade.tachiyomi.widget.TachiyomiCoordinatorLayout]
|
||||||
*/
|
*/
|
||||||
override fun isLiftOnScroll(): Boolean = false
|
override fun isLiftOnScroll(): Boolean = false
|
||||||
|
|
||||||
|
@ -98,6 +100,8 @@ class ElevationAppBarLayout @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun setLiftedState(lifted: Boolean, force: Boolean): Boolean = false
|
||||||
|
|
||||||
override fun onAttachedToWindow() {
|
override fun onAttachedToWindow() {
|
||||||
super.onAttachedToWindow()
|
super.onAttachedToWindow()
|
||||||
addOnOffsetChangedListener(offsetListener)
|
addOnOffsetChangedListener(offsetListener)
|
||||||
|
@ -143,6 +147,7 @@ class ElevationAppBarLayout @JvmOverloads constructor(
|
||||||
ValueAnimator.ofFloat(fromElevation, toElevation).apply {
|
ValueAnimator.ofFloat(fromElevation, toElevation).apply {
|
||||||
addUpdateListener {
|
addUpdateListener {
|
||||||
elevation = it.animatedValue as Float
|
elevation = it.animatedValue as Float
|
||||||
|
(statusBarForeground as? MaterialShapeDrawable)?.elevation = it.animatedValue as Float
|
||||||
}
|
}
|
||||||
animators.add(this)
|
animators.add(this)
|
||||||
}
|
}
|
||||||
|
@ -171,4 +176,8 @@ class ElevationAppBarLayout @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
statusBarForeground = MaterialShapeDrawable.createWithElevationOverlay(context)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -4,7 +4,6 @@ import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import eu.kanade.tachiyomi.databinding.TrackItemBinding
|
import eu.kanade.tachiyomi.databinding.TrackItemBinding
|
||||||
import eu.kanade.tachiyomi.util.view.applyElevationOverlay
|
|
||||||
|
|
||||||
class TrackAdapter(listener: OnClickListener) : RecyclerView.Adapter<TrackHolder>() {
|
class TrackAdapter(listener: OnClickListener) : RecyclerView.Adapter<TrackHolder>() {
|
||||||
|
|
||||||
|
@ -30,7 +29,6 @@ class TrackAdapter(listener: OnClickListener) : RecyclerView.Adapter<TrackHolder
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TrackHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TrackHolder {
|
||||||
binding = TrackItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
binding = TrackItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
binding.card.applyElevationOverlay()
|
|
||||||
return TrackHolder(binding, this)
|
return TrackHolder(binding, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
||||||
import eu.kanade.tachiyomi.databinding.TrackSearchItemBinding
|
import eu.kanade.tachiyomi.databinding.TrackSearchItemBinding
|
||||||
import eu.kanade.tachiyomi.util.view.applyElevationOverlay
|
|
||||||
|
|
||||||
class TrackSearchAdapter(
|
class TrackSearchAdapter(
|
||||||
private val currentTrackUrl: String?,
|
private val currentTrackUrl: String?,
|
||||||
|
@ -35,7 +34,6 @@ class TrackSearchAdapter(
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TrackSearchHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TrackSearchHolder {
|
||||||
val binding = TrackSearchItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
val binding = TrackSearchItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
binding.root.applyElevationOverlay()
|
|
||||||
return TrackSearchHolder(binding, this)
|
return TrackSearchHolder(binding, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,15 +22,12 @@ import androidx.core.view.descendants
|
||||||
import androidx.core.view.forEach
|
import androidx.core.view.forEach
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.viewpager.widget.ViewPager
|
import androidx.viewpager.widget.ViewPager
|
||||||
import com.google.android.material.card.MaterialCardView
|
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import com.google.android.material.chip.ChipGroup
|
import com.google.android.material.chip.ChipGroup
|
||||||
import com.google.android.material.elevation.ElevationOverlayProvider
|
|
||||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||||
import eu.kanade.tachiyomi.util.system.isNightMode
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns coordinates of view.
|
* Returns coordinates of view.
|
||||||
|
@ -187,16 +184,6 @@ inline fun ChipGroup.setChips(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies elevation overlay to a MaterialCardView
|
|
||||||
*/
|
|
||||||
inline fun MaterialCardView.applyElevationOverlay() {
|
|
||||||
if (context.isNightMode()) {
|
|
||||||
val provider = ElevationOverlayProvider(context)
|
|
||||||
setCardBackgroundColor(provider.compositeOverlay(cardBackgroundColor.defaultColor, cardElevation))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets TextView max lines dynamically. Can only be called when the view is already laid out.
|
* Sets TextView max lines dynamically. Can only be called when the view is already laid out.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -93,7 +93,8 @@ class TachiyomiCoordinatorLayout @JvmOverloads constructor(
|
||||||
consumed: IntArray
|
consumed: IntArray
|
||||||
) {
|
) {
|
||||||
super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type, consumed)
|
super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type, consumed)
|
||||||
if (canLiftAppBarOnScroll) {
|
// Disable elevation overlay when tabs are visible
|
||||||
|
if (canLiftAppBarOnScroll && viewPager == null) {
|
||||||
appBarLayout?.isLifted = dyConsumed != 0 || dyUnconsumed >= 0
|
appBarLayout?.isLifted = dyConsumed != 0 || dyUnconsumed >= 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<eu.kanade.tachiyomi.widget.ElevationAppBarLayout
|
<com.google.android.material.appbar.TachiyomiAppBarLayout
|
||||||
android:id="@+id/appbar"
|
android:id="@+id/appbar"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
android:theme="?attr/actionBarTheme" />
|
android:theme="?attr/actionBarTheme" />
|
||||||
|
|
||||||
</eu.kanade.tachiyomi.widget.ElevationAppBarLayout>
|
</com.google.android.material.appbar.TachiyomiAppBarLayout>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/downloaded_only"
|
android:id="@+id/downloaded_only"
|
||||||
|
|
|
@ -12,13 +12,12 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
<eu.kanade.tachiyomi.widget.ElevationAppBarLayout
|
<com.google.android.material.appbar.TachiyomiAppBarLayout
|
||||||
android:id="@+id/appbar"
|
android:id="@+id/appbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:fitsSystemWindows="true"
|
android:fitsSystemWindows="true"
|
||||||
app:elevation="0dp"
|
app:elevation="0dp">
|
||||||
app:statusBarForeground="?attr/colorToolbar">
|
|
||||||
|
|
||||||
<com.google.android.material.appbar.MaterialToolbar
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
|
@ -69,7 +68,7 @@
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</eu.kanade.tachiyomi.widget.ElevationAppBarLayout>
|
</com.google.android.material.appbar.TachiyomiAppBarLayout>
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/fab_layout"
|
android:id="@+id/fab_layout"
|
||||||
|
|
|
@ -85,7 +85,6 @@
|
||||||
<item name="switchStyle">@style/Widget.Tachiyomi.Switch</item>
|
<item name="switchStyle">@style/Widget.Tachiyomi.Switch</item>
|
||||||
<item name="sliderStyle">@style/Widget.Tachiyomi.Slider</item>
|
<item name="sliderStyle">@style/Widget.Tachiyomi.Slider</item>
|
||||||
<item name="materialCardViewStyle">@style/Widget.Material3.CardView.Elevated</item>
|
<item name="materialCardViewStyle">@style/Widget.Material3.CardView.Elevated</item>
|
||||||
<item name="elevationOverlayEnabled">false</item>
|
|
||||||
<item name="lightSystemBarsOnPrimary">false</item>
|
<item name="lightSystemBarsOnPrimary">false</item>
|
||||||
|
|
||||||
<!-- Custom Attributes-->
|
<!-- Custom Attributes-->
|
||||||
|
|
Reference in a new issue