【问题标题】:How can I Implement drag and drop functionality using Airbnb's Epoxy model?如何使用 Airbnb 的 Epoxy 模型实现拖放功能?
【发布时间】:2022-02-01 05:39:49
【问题描述】:

我想编写这个 todo() 部分以使用 Airbnb 的 Epoxy Library 执行拖放操作,我有这个 onModelMoved() 方法,我不知道要编写什么代码或方法需要帮助!

EpoxyTouchHelper.initDragging(controller)
        .withRecyclerView(binding.epoxyRecyclerView)
        .forVerticalList()
        .withTarget(HomeEpoxyController.ItemEntityEpoxyModel::class.java)
        .andCallbacks(object :
            EpoxyTouchHelper.DragCallbacks<HomeEpoxyController.ItemEntityEpoxyModel>() {
            override fun onModelMoved(
                fromPosition: Int,
                toPosition: Int,
                modelBeingMoved: HomeEpoxyController.ItemEntityEpoxyModel?,
                itemView: View?
            ) {
                // todo()
            }
        })

下面是我在 HomeEpoxyController 中的数据类,如果它可以帮助你的话

 data class ItemEntityEpoxyModel(
    val itemEntity: ItemEntity,
    val itemEntityInterface: ItemEntityInterface
) : ViewBindingKotlinModel<ModelItemEntityBinding>(R.layout.model_item_entity) {
    override fun ModelItemEntityBinding.bind() {
        titleTextView.text = itemEntity.title

        if(itemEntity.description == null){
            descriptionTextView.isGone = true
        }else{
            descriptionTextView.isVisible = true
            descriptionTextView.text = itemEntity.description
        }

        deleteImageView.setOnClickListener {
            itemEntityInterface.onDeleteItemEntity(itemEntity)
        }
        priorityTextView.setOnClickListener {
            itemEntityInterface.onBumpPriority(itemEntity)
        }

        val colorRes = when(itemEntity.priority){
            1 -> android.R.color.holo_green_dark
            2 -> android.R.color.holo_orange_dark
            3 -> android.R.color.holo_red_dark
            else -> R.color.purple_500
        }

        priorityTextView.setBackgroundColor(ContextCompat.getColor(root.context,colorRes))
    }

}

【问题讨论】:

    标签: kotlin epoxy


    【解决方案1】:

    您需要更新待办事项所在的列表。例如Collections.swap(yourList, fromPosition, toPosition)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-28
      • 1970-01-01
      • 1970-01-01
      • 2010-09-17
      • 1970-01-01
      相关资源
      最近更新 更多