Advertisement
Guest User

Untitled

a guest
Sep 14th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.91 KB | None | 0 0
  1. class ItemController : EpoxyController() {
  2.  
  3.     var data: List<ItemView.Item> = makeList()
  4.  
  5.     override fun buildModels() {
  6.         data.forEach { item ->
  7.             itemView {
  8.                 id(item.id)
  9.                 item(item)
  10.                 textChangeListener(object : ItemView.Listener {
  11.                     override fun onTextChanged(id: Int, text: String) {
  12.                         data =
  13.                             data.map { thisItem -> if (thisItem.id == id) getItemById(id).copy(text = text) else thisItem }
  14.                     }
  15.                 })
  16.             }
  17.         }
  18.     }
  19.  
  20.     private fun getItemById(id: Int): ItemView.Item {
  21.         return data.first { item -> item.id == id }
  22.     }
  23.  
  24.     private fun makeList(): MutableList<ItemView.Item> {
  25.         val result = mutableListOf<ItemView.Item>()
  26.         for (x in 1..50) result += ItemView.Item(x, "$x")
  27.         return result
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement