From 845e06138299c0333ca90ed9578422567779a9ac Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Thu, 18 Nov 2021 22:47:24 +0700 Subject: [PATCH] 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 --- .../material/appbar/TachiyomiAppBarLayout.kt} | 25 +++++++++++++------ .../tachiyomi/ui/manga/track/TrackAdapter.kt | 2 -- .../ui/manga/track/TrackSearchAdapter.kt | 2 -- .../tachiyomi/util/view/ViewExtensions.kt | 13 ---------- .../widget/TachiyomiCoordinatorLayout.kt | 3 ++- .../main/res/layout-sw720dp/main_activity.xml | 4 +-- app/src/main/res/layout/main_activity.xml | 7 +++--- app/src/main/res/values/themes.xml | 1 - 8 files changed, 24 insertions(+), 33 deletions(-) rename app/src/main/java/{eu/kanade/tachiyomi/widget/ElevationAppBarLayout.kt => com/google/android/material/appbar/TachiyomiAppBarLayout.kt} (87%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/ElevationAppBarLayout.kt b/app/src/main/java/com/google/android/material/appbar/TachiyomiAppBarLayout.kt similarity index 87% rename from app/src/main/java/eu/kanade/tachiyomi/widget/ElevationAppBarLayout.kt rename to app/src/main/java/com/google/android/material/appbar/TachiyomiAppBarLayout.kt index 2a730fc376..6cc8239b39 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/ElevationAppBarLayout.kt +++ b/app/src/main/java/com/google/android/material/appbar/TachiyomiAppBarLayout.kt @@ -1,4 +1,4 @@ -package eu.kanade.tachiyomi.widget +package com.google.android.material.appbar import android.animation.AnimatorSet import android.animation.ValueAnimator @@ -11,9 +11,6 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.lifecycle.coroutineScope import androidx.lifecycle.findViewTreeLifecycleOwner 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.getStateAlpha 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.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, attrs: AttributeSet? = null ) : AppBarLayout(context, attrs) { @@ -50,8 +52,8 @@ class ElevationAppBarLayout @JvmOverloads constructor( private var statusBarForegroundAnimator: ValueAnimator? = null private val offsetListener = OnOffsetChangedListener { appBarLayout, verticalOffset -> // Show status bar foreground when offset - val foreground = appBarLayout?.statusBarForeground ?: return@OnOffsetChangedListener - val start = foreground.alpha + val foreground = (appBarLayout?.statusBarForeground as? MaterialShapeDrawable) ?: return@OnOffsetChangedListener + val start = foreground.getStateAlpha() val end = if (verticalOffset != 0) 255 else 0 statusBarForegroundAnimator?.cancel() @@ -82,7 +84,7 @@ class ElevationAppBarLayout @JvmOverloads constructor( override fun getBehavior(): CoordinatorLayout.Behavior = 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 @@ -98,6 +100,8 @@ class ElevationAppBarLayout @JvmOverloads constructor( } } + override fun setLiftedState(lifted: Boolean, force: Boolean): Boolean = false + override fun onAttachedToWindow() { super.onAttachedToWindow() addOnOffsetChangedListener(offsetListener) @@ -143,6 +147,7 @@ class ElevationAppBarLayout @JvmOverloads constructor( ValueAnimator.ofFloat(fromElevation, toElevation).apply { addUpdateListener { elevation = it.animatedValue as Float + (statusBarForeground as? MaterialShapeDrawable)?.elevation = it.animatedValue as Float } animators.add(this) } @@ -171,4 +176,8 @@ class ElevationAppBarLayout @JvmOverloads constructor( } } } + + init { + statusBarForeground = MaterialShapeDrawable.createWithElevationOverlay(context) + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackAdapter.kt index 05eca06989..67a866e6c1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackAdapter.kt @@ -4,7 +4,6 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import eu.kanade.tachiyomi.databinding.TrackItemBinding -import eu.kanade.tachiyomi.util.view.applyElevationOverlay class TrackAdapter(listener: OnClickListener) : RecyclerView.Adapter() { @@ -30,7 +29,6 @@ class TrackAdapter(listener: OnClickListener) : RecyclerView.Adapter= 0 } } diff --git a/app/src/main/res/layout-sw720dp/main_activity.xml b/app/src/main/res/layout-sw720dp/main_activity.xml index adc1e8ff31..2d7463fd33 100644 --- a/app/src/main/res/layout-sw720dp/main_activity.xml +++ b/app/src/main/res/layout-sw720dp/main_activity.xml @@ -11,7 +11,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - + - + app:elevation="0dp"> - + @style/Widget.Tachiyomi.Switch @style/Widget.Tachiyomi.Slider @style/Widget.Material3.CardView.Elevated - false false