重构添加设备流程
This commit is contained in:
@@ -6,10 +6,12 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.defenseapplication.databinding.ItemWifiBinding
|
||||
|
||||
class WifiListAdapter(
|
||||
private val wifiList: List<String>,
|
||||
wifiList: List<String>,
|
||||
private val onItemClick: (String) -> Unit
|
||||
) : RecyclerView.Adapter<WifiListAdapter.ViewHolder>() {
|
||||
|
||||
private val wifiList = mutableListOf<String>().apply { addAll(wifiList) }
|
||||
|
||||
inner class ViewHolder(val binding: ItemWifiBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
init {
|
||||
itemView.setOnClickListener {
|
||||
@@ -35,4 +37,17 @@ class WifiListAdapter(
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = wifiList.size
|
||||
|
||||
fun updateData(newList: List<String>) {
|
||||
wifiList.clear()
|
||||
wifiList.addAll(newList)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun addData(newList: List<String>) {
|
||||
val startPosition = wifiList.size
|
||||
val newItems = newList.filter { !wifiList.contains(it) }
|
||||
wifiList.addAll(newItems)
|
||||
notifyItemRangeInserted(startPosition, newItems.size)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user