This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
data: { | |
"unreadTerm": "JP20180512" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val items = ArrayList<BaseModel>() | |
items.add(Trip().apply { from = "NewYork"; to = "Chicago"}) | |
items.add(Trip().apply { from = "London"; to = "Pennsylvania"}) | |
items.add(Progress()) | |
binding.recyclerView.adapter = Adapter(items){ holder, model -> | |
when(holder.binding){ | |
is ItemTripBinding -> holder.binding.item = model as Trip | |
is ProgressBinding -> holder.binding.item = model as Progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Trip : BaseModel(R.layout.item_trip){ | |
var from : String = "" | |
var to : String = "" | |
fun onClick(view: View){ | |
Toast.makeText(view.context,"Trip => from : $from, to : $to", Toast.LENGTH_SHORT).show() | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Adapter<T : BaseModel>(val items: List<T>, val callback : (GenericVH, T)-> Unit) : RecyclerView.Adapter<Adapter.GenericVH>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GenericVH { | |
return GenericVH(DataBindingUtil.inflate(LayoutInflater.from(parent.context), viewType, parent, false)) | |
} | |
override fun getItemCount() = items.size | |
override fun getItemViewType(position: Int) = items[position].resId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun getItemViewType(position: Int) = items[position].resId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GenericVH { | |
return GenericVH(DataBindingUtil.inflate(LayoutInflater.from(parent.context), viewType, parent, false)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class BaseModel(@LayoutRes var resId: Int) : BaseObservable() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GenericVH(val binding : ViewDataBinding): RecyclerView.ViewHolder(binding.root) |