From b3cc052612e7fa5838356b38ae39cc3d12f239b6 Mon Sep 17 00:00:00 2001 From: xuxinchao Date: Tue, 1 Nov 2022 17:03:15 +0800 Subject: [PATCH] =?UTF-8?q?BadCase=E8=87=AA=E5=AE=9A=E4=B9=89=E5=BD=95?= =?UTF-8?q?=E5=8C=85Topic=E9=80=89=E6=8B=A9=EF=BC=8C=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E5=90=8E=E8=87=AA=E5=8A=A8=E7=BD=AE=E9=A1=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../badcase/biz/adapter/TopicListAdapter.kt | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/biz/adapter/TopicListAdapter.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/biz/adapter/TopicListAdapter.kt index 7d1c810990..dc7ffabf0b 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/biz/adapter/TopicListAdapter.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/biz/adapter/TopicListAdapter.kt @@ -15,10 +15,10 @@ import com.zhjt.mogo_core_function_devatools.R */ class TopicListAdapter: RecyclerView.Adapter() { - private var data:List? = null + private var data:MutableList? = null private var topicClickListener: TopicClickListener? = null - fun setData( data: List?){ + fun setData( data: MutableList?){ this.data = data } @@ -39,13 +39,37 @@ class TopicListAdapter: RecyclerView.Adapter() holder.topic_check_box.isChecked = topicList[position].topicStatus holder.topic_check_box.tag = topicList holder.topic_check_box.isClickable = topicList[position].topicCanClick - holder.topic_check_box.setOnCheckedChangeListener { _, b -> - topicList[position].topicStatus = b - topicClickListener?.onClick(topicList[position].topicName,b) + holder.topic_check_box.setOnCheckedChangeListener { _, isChecked -> + topicList[position].topicStatus = isChecked + topicClickListener?.onClick(topicList[position].topicName,isChecked) + if(isChecked){ + //滚动到置顶 + moveItem(topicList[position],position,0) + }else{ + var lastNotCan = 0 //最后一个不能选择的 + for( i in 0 until itemCount){ + var topicEntity = data?.get(i) + if (topicEntity != null) { + if(!topicEntity.topicCanClick){ + lastNotCan = i + } + } + } + moveItem(topicList[position],position,lastNotCan) + } } } } + private fun moveItem(topicEntity: TopicEntity,removePos: Int,insertedPos: Int){ + data?.remove(topicEntity) + notifyItemRemoved(removePos) + notifyItemRangeChanged(removePos, itemCount - removePos) + data?.add(insertedPos, topicEntity) + notifyItemInserted(insertedPos) + notifyItemRangeChanged(insertedPos, itemCount) + } + override fun getItemCount() = data?.size ?: 0 class TopicListHolder(itemView: View) : RecyclerView.ViewHolder(itemView){