For #355 - Adds history section header
parent
babe5d7d9b
commit
d8845dc524
|
@ -42,7 +42,7 @@ class HistoryUIView(
|
||||||
|
|
||||||
private class HistoryAdapter(
|
private class HistoryAdapter(
|
||||||
private val actionEmitter: Observer<HistoryAction>
|
private val actionEmitter: Observer<HistoryAction>
|
||||||
) : RecyclerView.Adapter<HistoryAdapter.HistoryListItemViewHolder>() {
|
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||||
class HistoryListItemViewHolder(
|
class HistoryListItemViewHolder(
|
||||||
view: View,
|
view: View,
|
||||||
private val actionEmitter: Observer<HistoryAction>
|
private val actionEmitter: Observer<HistoryAction>
|
||||||
|
@ -72,6 +72,20 @@ private class HistoryAdapter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class HistoryHeaderViewHolder(
|
||||||
|
view: View
|
||||||
|
) : RecyclerView.ViewHolder(view) {
|
||||||
|
private val title = view.findViewById<TextView>(R.id.history_header_title)
|
||||||
|
|
||||||
|
fun bind(title: String) {
|
||||||
|
this.title.text = title
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val LAYOUT_ID = R.layout.history_header
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var items: List<HistoryItem> = emptyList()
|
private var items: List<HistoryItem> = emptyList()
|
||||||
|
|
||||||
fun updateData(items: List<HistoryItem>) {
|
fun updateData(items: List<HistoryItem>) {
|
||||||
|
@ -79,20 +93,34 @@ private class HistoryAdapter(
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HistoryListItemViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||||
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
|
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
|
||||||
|
|
||||||
return HistoryListItemViewHolder(view, actionEmitter)
|
return when (viewType) {
|
||||||
|
HistoryHeaderViewHolder.LAYOUT_ID -> HistoryHeaderViewHolder(view)
|
||||||
|
HistoryListItemViewHolder.LAYOUT_ID -> HistoryListItemViewHolder(view, actionEmitter)
|
||||||
|
else -> throw IllegalStateException("viewType $viewType does not match to a ViewHolder")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemViewType(position: Int): Int {
|
override fun getItemViewType(position: Int): Int {
|
||||||
return HistoryListItemViewHolder.LAYOUT_ID
|
return when (position) {
|
||||||
|
0 -> HistoryHeaderViewHolder.LAYOUT_ID
|
||||||
|
else -> HistoryListItemViewHolder.LAYOUT_ID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int = items.count()
|
override fun getItemCount(): Int = items.count() + NUMBER_OF_SECTIONS
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: HistoryListItemViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||||
val item = items[position]
|
|
||||||
holder.bind(item)
|
when (holder) {
|
||||||
|
is HistoryHeaderViewHolder -> holder.bind("Today")
|
||||||
|
is HistoryListItemViewHolder -> holder.bind(items[position - NUMBER_OF_SECTIONS])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val NUMBER_OF_SECTIONS = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
<FrameLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingStart="20dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:layout_marginBottom="24dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/history_header_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="17sp"
|
||||||
|
android:textColor="@color/history_header"/>
|
||||||
|
</FrameLayout>
|
|
@ -51,6 +51,7 @@
|
||||||
<color name="library_key_icon_background">#FFF4C3</color>
|
<color name="library_key_icon_background">#FFF4C3</color>
|
||||||
<color name="library_key_icon">#C13905</color>
|
<color name="library_key_icon">#C13905</color>
|
||||||
|
|
||||||
|
<color name="history_header">#696A6A</color>
|
||||||
<color name="history_title">#000000</color>
|
<color name="history_title">#000000</color>
|
||||||
<color name="history_url">#696A6A</color>
|
<color name="history_url">#696A6A</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue