BadCase自定义录包Topic选择,选中后自动置顶
This commit is contained in:
@@ -15,10 +15,10 @@ import com.zhjt.mogo_core_function_devatools.R
|
||||
*/
|
||||
class TopicListAdapter: RecyclerView.Adapter<TopicListAdapter.TopicListHolder>() {
|
||||
|
||||
private var data:List<TopicEntity>? = null
|
||||
private var data:MutableList<TopicEntity>? = null
|
||||
private var topicClickListener: TopicClickListener? = null
|
||||
|
||||
fun setData( data: List<TopicEntity>?){
|
||||
fun setData( data: MutableList<TopicEntity>?){
|
||||
this.data = data
|
||||
}
|
||||
|
||||
@@ -39,13 +39,37 @@ class TopicListAdapter: RecyclerView.Adapter<TopicListAdapter.TopicListHolder>()
|
||||
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){
|
||||
|
||||
Reference in New Issue
Block a user