From 59019788899f811d4158f26bddf292b1948485d7 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 13 Dec 2020 17:47:29 -0500 Subject: [PATCH] Use view binding for date headers --- .../tachiyomi/ui/recent/DateSectionItem.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/DateSectionItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/DateSectionItem.kt index 0143f39128..1eb7b56fb0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/DateSectionItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/DateSectionItem.kt @@ -2,26 +2,26 @@ package eu.kanade.tachiyomi.ui.recent import android.text.format.DateUtils import android.view.View -import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.AbstractHeaderItem import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.databinding.RecentSectionItemBinding import java.util.Date -class DateSectionItem(val date: Date) : AbstractHeaderItem() { +class DateSectionItem(val date: Date) : AbstractHeaderItem() { override fun getLayoutRes(): Int { return R.layout.recent_section_item } - override fun createViewHolder(view: View, adapter: FlexibleAdapter>): Holder { - return Holder(view, adapter) + override fun createViewHolder(view: View, adapter: FlexibleAdapter>): DateSectionItemHolder { + return DateSectionItemHolder(view, adapter) } - override fun bindViewHolder(adapter: FlexibleAdapter>, holder: Holder, position: Int, payloads: List?) { + override fun bindViewHolder(adapter: FlexibleAdapter>, holder: DateSectionItemHolder, position: Int, payloads: List?) { holder.bind(this) } @@ -37,14 +37,14 @@ class DateSectionItem(val date: Date) : AbstractHeaderItem) : FlexibleViewHolder(view, adapter, true) { + inner class DateSectionItemHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter, true) { + + private val binding = RecentSectionItemBinding.bind(view) private val now = Date().time - val section_text: TextView = view.findViewById(R.id.section_text) - fun bind(item: DateSectionItem) { - section_text.text = DateUtils.getRelativeTimeSpanString(item.date.time, now, DateUtils.DAY_IN_MILLIS) + binding.sectionText.text = DateUtils.getRelativeTimeSpanString(item.date.time, now, DateUtils.DAY_IN_MILLIS) } } }