subitem

mail@pastecode.io avatar
unknown
kotlin
a year ago
2.0 kB
4
Indexable
Never
class CatalogSubItem(val client: ClientGeneralData, var catalogItem: CatalogItem?): AbstractFlexibleItem<CatalogSubItem.ViewHolder>(), ISectionable<CatalogSubItem.ViewHolder, CatalogItem> {

    init {
        header = catalogItem
    }


    class ViewHolder(view: View?, adaper: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?) : ExpandableViewHolder(view, adaper) {
        var clientName : TextView?
        var clientCode : TextView?
        var clientEdino : TextView?
        init {
            clientName = view?.findViewById(R.id.client_name)
            clientCode = view?.findViewById(R.id.client_code)
            clientEdino = view?.findViewById(R.id.client_edino)
        }
    }

    override fun equals(other: Any?): Boolean {
        other?.let {
            val isEqual = (header?.equals((it as CatalogSubItem).catalogItem) ?: false)
                    && client.erpClientId == (it as CatalogSubItem).client.erpClientId

            return isEqual
        }
        return false
    }

    override fun hashCode(): Int {
        return Objects.hashCode(client.erpClientId)
    }
    override fun getLayoutRes(): Int {
        return R.layout.listitem_dynamic_checklist_catalog_client
    }

    override fun createViewHolder(
        view: View?,
        adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?
    ): ViewHolder {
        return ViewHolder(view, adapter)
    }

    override fun getHeader(): CatalogItem? {
        return catalogItem
    }

    override fun setHeader(header: CatalogItem?) {
        this.catalogItem = header
    }


    override fun bindViewHolder(
        adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?,
        holder: ViewHolder?,
        position: Int,
        payloads: MutableList<Any>?
    ) {
        (holder as ViewHolder).clientName?.text = client.name
        holder.clientCode?.text = client.code
        holder.clientEdino?.text = client.edino
    }
}