You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.5 KiB
Kotlin
77 lines
2.5 KiB
Kotlin
|
|
/* 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/. */
|
|
|
|
package org.mozilla.fenix.library.history
|
|
|
|
import android.content.Context
|
|
import android.graphics.Color
|
|
import android.os.Build
|
|
import android.view.LayoutInflater
|
|
import android.view.ViewGroup
|
|
import android.widget.RelativeLayout
|
|
import android.widget.TextView
|
|
import androidx.annotation.RequiresApi
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
import io.reactivex.Observable
|
|
import io.reactivex.Observer
|
|
import io.reactivex.functions.Consumer
|
|
import org.mozilla.fenix.R
|
|
import org.mozilla.fenix.mvi.UIView
|
|
|
|
class HistoryUIView(
|
|
container: ViewGroup,
|
|
actionEmitter: Observer<HistoryAction>,
|
|
changesObservable: Observable<HistoryChange>
|
|
) :
|
|
UIView<HistoryState, HistoryAction, HistoryChange>(container, actionEmitter, changesObservable) {
|
|
|
|
override val view: RecyclerView = LayoutInflater.from(container.context)
|
|
.inflate(R.layout.component_history, container, true)
|
|
.findViewById(R.id.history_list)
|
|
|
|
init {
|
|
view.apply {
|
|
adapter = HistoryAdapter(context)
|
|
layoutManager = LinearLayoutManager(container.context)
|
|
}
|
|
}
|
|
|
|
override fun updateView() = Consumer<HistoryState> {
|
|
(view.adapter as HistoryAdapter).updateData(it.items)
|
|
}
|
|
}
|
|
|
|
private class HistoryAdapter(val context: Context) : RecyclerView.Adapter<HistoryAdapter.ViewHolder>() {
|
|
class ViewHolder(val textView: TextView) : RecyclerView.ViewHolder(textView)
|
|
|
|
private var items: List<HistoryItem> = emptyList()
|
|
|
|
fun updateData(items: List<HistoryItem>) {
|
|
this.items = items
|
|
notifyDataSetChanged()
|
|
}
|
|
|
|
@RequiresApi(Build.VERSION_CODES.M)
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
|
val textView = TextView(context).apply {
|
|
val lp = RelativeLayout.LayoutParams(
|
|
RelativeLayout.LayoutParams.WRAP_CONTENT, // Width of TextView
|
|
RelativeLayout.LayoutParams.WRAP_CONTENT
|
|
)
|
|
setLayoutParams(lp)
|
|
setText("This is a sample TextView...")
|
|
setTextColor(Color.parseColor("#ff0000"))
|
|
}
|
|
return ViewHolder(textView)
|
|
}
|
|
|
|
override fun getItemCount(): Int = items.count()
|
|
|
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
|
holder.textView.text = "Cell: ${items[position]}"
|
|
}
|
|
}
|