fixed elevation for app bar in stats details

This commit is contained in:
Jays2Kings 2022-08-28 21:12:10 -04:00
parent 90978665fe
commit 2139e04ab7
3 changed files with 238 additions and 165 deletions

View file

@ -1,8 +1,10 @@
package eu.kanade.tachiyomi.ui.more.stats.details package eu.kanade.tachiyomi.ui.more.stats.details
import android.animation.ValueAnimator
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.Color
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
@ -13,6 +15,7 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.github.mikephil.charting.components.MarkerView import com.github.mikephil.charting.components.MarkerView
import com.github.mikephil.charting.components.XAxis import com.github.mikephil.charting.components.XAxis
@ -40,11 +43,14 @@ import eu.kanade.tachiyomi.ui.more.stats.StatsHelper
import eu.kanade.tachiyomi.ui.more.stats.StatsHelper.getReadDuration import eu.kanade.tachiyomi.ui.more.stats.StatsHelper.getReadDuration
import eu.kanade.tachiyomi.ui.more.stats.details.StatsDetailsPresenter.Stats import eu.kanade.tachiyomi.ui.more.stats.details.StatsDetailsPresenter.Stats
import eu.kanade.tachiyomi.ui.more.stats.details.StatsDetailsPresenter.StatsSort import eu.kanade.tachiyomi.ui.more.stats.details.StatsDetailsPresenter.StatsSort
import eu.kanade.tachiyomi.util.system.ImageUtil
import eu.kanade.tachiyomi.util.system.contextCompatDrawable import eu.kanade.tachiyomi.util.system.contextCompatDrawable
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.materialAlertDialog import eu.kanade.tachiyomi.util.system.materialAlertDialog
import eu.kanade.tachiyomi.util.system.toInt import eu.kanade.tachiyomi.util.system.toInt
import eu.kanade.tachiyomi.util.system.toUtcCalendar import eu.kanade.tachiyomi.util.system.toUtcCalendar
import eu.kanade.tachiyomi.util.view.backgroundColor
import eu.kanade.tachiyomi.util.view.isControllerVisible
import eu.kanade.tachiyomi.util.view.liftAppbarWith import eu.kanade.tachiyomi.util.view.liftAppbarWith
import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener
import eu.kanade.tachiyomi.util.view.setStyle import eu.kanade.tachiyomi.util.view.setStyle
@ -81,7 +87,8 @@ class StatsDetailsController :
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
override fun onViewCreated(view: View) { override fun onViewCreated(view: View) {
super.onViewCreated(view) super.onViewCreated(view)
liftAppbarWith(binding.statsDetailsScrollView, false) liftAppbarWith(binding.statsDetailsScrollView, false, liftOnScroll = { colorToolbar(it) })
// scrollViewWith(binding.statsDetailsScrollView, liftOnScroll = { colorToolbar(it) })
setHasOptionsMenu(true) setHasOptionsMenu(true)
if (presenter.selectedStat == null) { if (presenter.selectedStat == null) {
@ -261,6 +268,42 @@ class StatsDetailsController :
} }
} }
var toolbarColorAnim: ValueAnimator? = null
var isToolbarColored = false
private var toolbarIsColored = false
private var colorAnimator: ValueAnimator? = null
/** Set the toolbar to fully transparent or colored and translucent */
private fun colorToolbar(isColor: Boolean) {
if (isColor == toolbarIsColored) return
val activity = activity ?: return
toolbarIsColored = isColor
if (isControllerVisible) setTitle()
val scrollingColor = activity.getResourceColor(R.attr.colorPrimaryVariant)
val topColor = activity.getResourceColor(R.attr.colorSurface)
colorAnimator?.cancel()
val percent = ImageUtil.getPercentOfColor(
binding.statsHorizontalScroll.backgroundColor ?: Color.TRANSPARENT,
activity.getResourceColor(R.attr.colorSurface),
activity.getResourceColor(R.attr.colorPrimaryVariant),
)
val cA = ValueAnimator.ofFloat(
percent,
toolbarIsColored.toInt().toFloat(),
)
colorAnimator = cA
colorAnimator?.addUpdateListener { animator ->
binding.statsHorizontalScroll.setBackgroundColor(
ColorUtils.blendARGB(
topColor,
scrollingColor,
animator.animatedValue as Float,
),
)
}
cA.start()
}
/** /**
* Initialize the chips state * Initialize the chips state
*/ */

View file

@ -125,11 +125,15 @@ fun Controller.removeQueryListener(includeSearchTB: Boolean = true) {
) )
} }
fun <T> Controller.liftAppbarWith(recyclerOrNested: T, padView: Boolean = false) { fun <T> Controller.liftAppbarWith(
recyclerOrNested: T,
padView: Boolean = false,
liftOnScroll: ((Boolean) -> Unit)? = null,
) {
val recycler = recyclerOrNested as? RecyclerView ?: recyclerOrNested as? NestedScrollView ?: return val recycler = recyclerOrNested as? RecyclerView ?: recyclerOrNested as? NestedScrollView ?: return
if (padView) { if (padView) {
var appBarHeight = ( var appBarHeight = (
if (fullAppBarHeight ?: 0 > 0) fullAppBarHeight!! if ((fullAppBarHeight ?: 0) > 0) fullAppBarHeight!!
else activityBinding?.appBar?.attrToolbarHeight ?: 0 else activityBinding?.appBar?.attrToolbarHeight ?: 0
) )
activityBinding!!.toolbar.post { activityBinding!!.toolbar.post {
@ -166,6 +170,7 @@ fun <T> Controller.liftAppbarWith(recyclerOrNested: T, padView: Boolean = false)
val colorToolbar: (Boolean) -> Unit = f@{ isColored -> val colorToolbar: (Boolean) -> Unit = f@{ isColored ->
isToolbarColored = isColored isToolbarColored = isColored
toolbarColorAnim?.cancel() toolbarColorAnim?.cancel()
liftOnScroll?.invoke(isColored)
val floatingBar = val floatingBar =
!(activityBinding?.toolbar?.isVisible == true || activityBinding?.tabsFrameLayout?.isVisible == true) !(activityBinding?.toolbar?.isVisible == true || activityBinding?.tabsFrameLayout?.isVisible == true)
val percent = ImageUtil.getPercentOfColor( val percent = ImageUtil.getPercentOfColor(
@ -196,6 +201,14 @@ fun <T> Controller.liftAppbarWith(recyclerOrNested: T, padView: Boolean = false)
activityBinding?.appBar?.updateAppBarAfterY(recycler) activityBinding?.appBar?.updateAppBarAfterY(recycler)
setAppBarBG(0f) setAppBarBG(0f)
(recycler as? NestedScrollView)?.setOnScrollChangeListener { _, _, _, _, _ ->
if (router?.backstack?.lastOrNull()
?.controller == this@liftAppbarWith && activity != null
) {
val notAtTop = recycler.canScrollVertically(-1)
if (notAtTop != isToolbarColored) colorToolbar(notAtTop)
}
}
(recycler as? RecyclerView)?.addOnScrollListener( (recycler as? RecyclerView)?.addOnScrollListener(
object : RecyclerView.OnScrollListener() { object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/stats_details_layout" android:id="@+id/stats_details_layout"
@ -11,20 +11,193 @@
android:id="@+id/progress" android:id="@+id/progress"
android:layout_width="75dp" android:layout_width="75dp"
android:layout_height="75dp" android:layout_height="75dp"
android:layout_gravity="center" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:elevation="30dp" /> android:elevation="30dp" />
<eu.kanade.tachiyomi.widget.EmptyView <eu.kanade.tachiyomi.widget.EmptyView
android:id="@+id/no_chart_data" android:id="@+id/no_chart_data"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_gravity="center" android:layout_gravity="center"
android:visibility="gone" /> android:visibility="gone" />
<HorizontalScrollView
android:id="@+id/stats_horizontal_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/stats_details_refresh_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:clipToPadding="false"
android:fadingEdgeLength="20dp"
android:requiresFadingEdge="horizontal"
android:scrollbars="none">
<LinearLayout
android:id="@+id/stats_filter_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="20dp">
<ImageView
android:id="@+id/stats_clear_button"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginEnd="10dp"
android:background="@drawable/round_clear_border"
android:clickable="true"
android:contentDescription="@string/clear"
android:focusable="true"
android:padding="3dp"
android:src="@drawable/ic_close_24dp"
app:tint="@color/gray_button" />
<com.google.android.material.chip.ChipGroup
android:id="@+id/stats_chip_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="5dp"
app:chipSpacingHorizontal="5dp"
app:singleLine="true">
<com.google.android.material.chip.Chip
android:id="@+id/chip_stat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/series_type"
android:textColor="?attr/colorOnBackground"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_query_stats_24dp"
app:chipIconEnabled="true"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_series_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/series_type"
android:textColor="?attr/colorOnBackground"
android:visibility="gone"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_style_24dp"
app:chipIconEnabled="false"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground"
tools:visibility="visible" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/source"
android:textColor="?attr/colorOnBackground"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_browse_24dp"
app:chipIconEnabled="false"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/status"
android:textColor="?attr/colorOnBackground"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_progress_clock_24dp"
app:chipIconEnabled="false"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/language"
android:textColor="?attr/colorOnBackground"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_language_24dp"
app:chipIconEnabled="false"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/category"
android:textColor="?attr/colorOnBackground"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_label_outline_24dp"
app:chipIconEnabled="false"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_sort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_count"
android:textColor="?attr/colorOnBackground"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_sort_24dp"
app:chipIconEnabled="true"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground" />
</com.google.android.material.chip.ChipGroup>
</LinearLayout>
</HorizontalScrollView>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/stats_details_refresh_layout" android:id="@+id/stats_details_refresh_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/stats_horizontal_scroll">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -32,167 +205,10 @@
android:orientation="vertical" android:orientation="vertical"
android:paddingBottom="@dimen/marginSmall"> android:paddingBottom="@dimen/marginSmall">
<HorizontalScrollView
android:id="@+id/stats_horizontal_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:fadingEdgeLength="20dp"
android:requiresFadingEdge="horizontal"
android:scrollbars="none">
<LinearLayout
android:id="@+id/stats_filter_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="10dp"
android:paddingEnd="20dp">
<ImageView
android:id="@+id/stats_clear_button"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginEnd="10dp"
android:background="@drawable/round_clear_border"
android:clickable="true"
android:contentDescription="@string/clear"
android:focusable="true"
android:padding="3dp"
android:src="@drawable/ic_close_24dp"
app:tint="@color/gray_button" />
<com.google.android.material.chip.ChipGroup
android:id="@+id/stats_chip_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="5dp"
app:chipSpacingHorizontal="5dp"
app:singleLine="true">
<com.google.android.material.chip.Chip
android:id="@+id/chip_stat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/series_type"
android:textColor="?attr/colorOnBackground"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_query_stats_24dp"
app:chipIconEnabled="true"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_series_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/series_type"
android:textColor="?attr/colorOnBackground"
android:visibility="gone"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_style_24dp"
app:chipIconEnabled="false"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground"
tools:visibility="visible" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/source"
android:textColor="?attr/colorOnBackground"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_browse_24dp"
app:chipIconEnabled="false"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/status"
android:textColor="?attr/colorOnBackground"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_progress_clock_24dp"
app:chipIconEnabled="false"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/language"
android:textColor="?attr/colorOnBackground"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_language_24dp"
app:chipIconEnabled="false"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/category"
android:textColor="?attr/colorOnBackground"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_label_outline_24dp"
app:chipIconEnabled="false"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_sort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_count"
android:textColor="?attr/colorOnBackground"
app:checkedIconEnabled="false"
app:chipIcon="@drawable/ic_sort_24dp"
app:chipIconEnabled="true"
app:chipIconTint="?attr/colorOnBackground"
app:chipStrokeColor="?attr/colorSecondary"
app:chipStrokeWidth="1dp"
app:closeIcon="@drawable/ic_arrow_drop_down_24dp"
app:closeIconEnabled="true"
app:closeIconTint="?attr/colorOnBackground" />
</com.google.android.material.chip.ChipGroup>
</LinearLayout>
</HorizontalScrollView>
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:id="@+id/stats_details_scroll_view" android:id="@+id/stats_details_scroll_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:clipToPadding="false"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<LinearLayout <LinearLayout
@ -298,6 +314,7 @@
android:id="@+id/stats_recycler_view" android:id="@+id/stats_recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clipToPadding="false"
android:layout_marginTop="@dimen/marginNormal" android:layout_marginTop="@dimen/marginNormal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" /> app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
@ -308,4 +325,4 @@
</LinearLayout> </LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</FrameLayout> </androidx.constraintlayout.widget.ConstraintLayout>