Skip to content

Instantly share code, notes, and snippets.

@ha-yi
Created June 12, 2017 19:20
Show Gist options
  • Save ha-yi/6b10b960e3b5e9dcaa83de74cda8ce91 to your computer and use it in GitHub Desktop.
Save ha-yi/6b10b960e3b5e9dcaa83de74cda8ce91 to your computer and use it in GitHub Desktop.
class ListJiwaPresenter (context: Context, val recyclerView: RecyclerView?):BasePresenter<MutableList<Jiwa>>(context) {
override fun onSuccess(data: MutableList<Jiwa>?) {
recyclerView?.layoutManager = LinearLayoutManager(recyclerView?.context, LinearLayoutManager.VERTICAL, false)
recyclerView?.adapter = ListJiwaAdapter(data)
}
override fun onError(message: String?) {
Terpaksa error "Gagal mengambil data Jiwa"
}
class ListJiwaAdapter(val data:MutableList<Jiwa>?) : RecyclerView.Adapter<ListJiwaAdapter.JiwaHolder>() {
override fun onBindViewHolder(holder: JiwaHolder?, position: Int) {
holder?.setJiwa(data?.get(position))
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): JiwaHolder =
JiwaHolder(LayoutInflater.from(parent?.context).inflate(R.layout.list_jiwa_item, parent, false))
override fun getItemCount(): Int = data?.size?:0
class JiwaHolder(view:View):RecyclerView.ViewHolder(view) {
fun setJiwa(jiwa: Jiwa?) {
// initialize view
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment