0

我试图在epoxyrecyclerview 中制作剥离行。我已经嵌套了epoxyrecycler 视图,这是父级的epoxymodel

    EpoxyModelWithHolder<AccountClassificationEpoxyModel.Holder>(),
    PopupMenu.OnMenuItemClickListener {

    @EpoxyAttribute
    lateinit var data: ClassificationDto

    @EpoxyAttribute
    var dataAccount: HashMap<Int, ArrayList<AccountDto>>? = null

    @EpoxyAttribute
    lateinit var parentFragment: AccountFragment

    private lateinit var dialogState: DialogState

    var isEven = false

    @RequiresApi(Build.VERSION_CODES.M)
    override fun bind(holder: Holder) {
        super.bind(holder)

        if (!this::dialogState.isInitialized) {
            dialogState = ViewModelProviders.of(parentFragment).get(DialogState::class.java)
        }

        fillValues(holder)
        holder.btnEdit.setOnClickListener {
            val popUp = PopupMenu(parentFragment.requireContext(), it)
            popUp.setOnMenuItemClickListener(this)
            popUp.inflate(R.menu.menu_popup)
            popUp.show()
        }
    }


    inner class Holder : KotlinEpoxyHolder() {
        val tvName by bind<TextView>(R.id.tvClassificationName)
        val tvCode by bind<TextView>(R.id.tvClassificationCode)
        val rvAccount by bind<EpoxyRecyclerView>(R.id.rvAccount)
        val btnEdit by bind<AppCompatImageButton>(R.id.btnEdit)
    }

    override fun onMenuItemClick(item: MenuItem?): Boolean {
        when (item?.itemId) {
            R.id.actionUpdate -> {
                val dialog = AddClassificationFragment(data).newInstance()
                dialog.setTargetFragment(parentFragment, 1)
                parentFragment.fragmentManager?.let { it1 -> dialog.show(it1, "Dialog") }
            }
            R.id.actionDelete -> {
                dialogState.deleteClassification(data)
            }
        }
        return true
    }

    private fun fillValues(holder: Holder) {
        holder.tvName.text = data.classificationName
        holder.tvCode.text = data.classificationCode
        holder.rvAccount.layoutManager = GridLayoutManager(holder.rvAccount.context, 1)
        holder.rvAccount.clear()
        holder.rvAccount.withModels {
            data.id?.let {
                val filteredData = dataAccount?.get(it)
                filteredData?.forEach {
                    accountAccount {
                        id(hashCode())
                        data(it)
                        even(isEven)
                        parentFragment(parentFragment)
                    }
                    isEven = !isEven
                }
            }
        }
    }
}

这是我的孩子环氧树脂模型

    EpoxyModelWithHolder<AccountAccountEpoxyModel.Holder>(), PopupMenu.OnMenuItemClickListener {

    @EpoxyAttribute
    lateinit var data: AccountDto

    @EpoxyAttribute
    var even: Boolean = false

    @EpoxyAttribute
    lateinit var parentFragment: AccountFragment

    private lateinit var dialogState: DialogState

    @RequiresApi(Build.VERSION_CODES.M)
    override fun bind(holder: Holder) {
        super.bind(holder)

        if (!this::dialogState.isInitialized) {
            dialogState = ViewModelProviders.of(parentFragment).get(DialogState::class.java)
        }

        if (even) holder.background.toGone()

        holder.tvAccountName.text = data.accountName
        holder.tvAccountCode.text = data.accountCode
        holder.tvPosition.text = data.position?.capitalize(Locale.getDefault())
        holder.btnEdit.setOnClickListener {
            val popUp = PopupMenu(parentFragment.requireContext(), it)
            popUp.setOnMenuItemClickListener(this)
            popUp.inflate(R.menu.menu_popup)
            popUp.show()
        }
    }

    inner class Holder : KotlinEpoxyHolder() {
        val tvAccountName by bind<TextView>(R.id.tvAccountName)
        val tvAccountCode by bind<TextView>(R.id.tvAccountCode)
        val tvPosition by bind<TextView>(R.id.tvPosition)
        val background by bind<View>(R.id.background)
        val btnEdit by bind<AppCompatImageButton>(R.id.btnEdit)
    }

    override fun onMenuItemClick(item: MenuItem?): Boolean {
        when (item?.itemId) {
            R.id.actionUpdate -> {
                val dialog = AddAccountDialog(data).newInstance()
                dialog.setTargetFragment(parentFragment, 1)
                parentFragment.fragmentManager?.let { it1 -> dialog.show(it1, "Dialog") }
            }
            R.id.actionDelete -> {
                dialogState.deleteAccount(data)
            }
        }
        return true
    }
}

所以我使用变量 isEven 来制作条形行。当行位置甚至突出显示背景消失时。问题是当我更新数据时,条带变得凌乱。

4

0 回答 0