Animate sort group chevrons

pull/1722/head
Alex Baker 3 years ago
parent 599faa660c
commit 45b0801158

@ -2,6 +2,7 @@ package org.tasks.tasklist
import android.content.Context import android.content.Context
import android.view.View import android.view.View
import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.todoroo.astrid.api.Filter import com.todoroo.astrid.api.Filter
@ -12,10 +13,13 @@ class HeaderViewHolder(
private val context: Context, private val context: Context,
private val locale: Locale, private val locale: Locale,
view: View, view: View,
callback: (Long) -> Unit) : RecyclerView.ViewHolder(view) { callback: (Long) -> Unit
) : RecyclerView.ViewHolder(view) {
private val header: TextView = view.findViewById(R.id.header) private val title: TextView = view.findViewById(R.id.header)
private val chevron: ImageView = view.findViewById(R.id.chevron)
private val row = view.findViewById<View>(R.id.header_row)
private var sortGroup = -1L private var sortGroup = -1L
private var rotation = 0f
fun bind(filter: Filter, sortMode: Int, alwaysDisplayFullDate: Boolean, section: AdapterSection) { fun bind(filter: Filter, sortMode: Int, alwaysDisplayFullDate: Boolean, section: AdapterSection) {
sortGroup = section.value sortGroup = section.value
@ -26,17 +30,24 @@ class HeaderViewHolder(
} }
if (header == null) { if (header == null) {
this.header.visibility = View.GONE row.visibility = View.GONE
} else { } else {
this.header.visibility = View.VISIBLE row.visibility = View.VISIBLE
this.header.text = header this.title.text = header
this.header.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, if (section.collapsed) R.drawable.ic_keyboard_arrow_down_black_18dp else R.drawable.ic_keyboard_arrow_up_black_18dp, 0) this.title.setTextColor(section.headerColor(context, sortMode))
this.header.setTextColor(section.headerColor(context, sortMode)) rotation = if (section.collapsed) 180f else 0f
chevron.rotation = rotation
} }
} }
private fun rotate() {
rotation = if (rotation == 0f) 180f else 0f
chevron.animate().rotation(rotation).setDuration(250).start()
}
init { init {
header.setOnClickListener { row.setOnClickListener {
rotate()
callback(sortGroup) callback(sortGroup)
} }
} }

@ -1,16 +1,31 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout 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"
android:id="@+id/header" android:id="@+id/header_row"
style="@style/TextAppearance" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:background="?attr/selectableItemBackground">
android:background="?attr/selectableItemBackground"
android:padding="@dimen/keyline_first"
android:gravity="start|center_vertical"
android:textColor="@color/text_secondary"
android:textSize="@dimen/sku_details_row_text_size"
android:drawableEnd="@drawable/ic_keyboard_arrow_down_black_18dp"
android:drawableTint="@color/text_tertiary"
app:fontFamily="sans-serif-medium" />
<TextView
android:id="@+id/header"
style="@style/TextAppearance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="@id/chevron"
android:gravity="start|center_vertical"
android:padding="@dimen/keyline_first"
android:textColor="@color/text_secondary"
android:textSize="@dimen/sku_details_row_text_size"
app:fontFamily="sans-serif-medium" />
<ImageView
android:id="@+id/chevron"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/keyline_first"
android:src="@drawable/ic_keyboard_arrow_down_black_24dp"
app:tint="@color/text_tertiary" />
</RelativeLayout>

Loading…
Cancel
Save