1
0
Fork 0

For #355 - Adds history section header

master
Jeff Boek 2019-02-11 16:19:18 -08:00
parent babe5d7d9b
commit d8845dc524
3 changed files with 56 additions and 8 deletions

View File

@ -42,7 +42,7 @@ class HistoryUIView(
private class HistoryAdapter(
private val actionEmitter: Observer<HistoryAction>
) : RecyclerView.Adapter<HistoryAdapter.HistoryListItemViewHolder>() {
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
class HistoryListItemViewHolder(
view: View,
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()
fun updateData(items: List<HistoryItem>) {
@ -79,20 +93,34 @@ private class HistoryAdapter(
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)
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 {
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) {
val item = items[position]
holder.bind(item)
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
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
}
}

View File

@ -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>

View File

@ -51,6 +51,7 @@
<color name="library_key_icon_background">#FFF4C3</color>
<color name="library_key_icon">#C13905</color>
<color name="history_header">#696A6A</color>
<color name="history_title">#000000</color>
<color name="history_url">#696A6A</color>
</resources>