Commit 5a4f238c authored by Anon's avatar Anon
Browse files

ScannerListAdapter: Fix jumpy UI.

parent 4258ca6a
......@@ -26,10 +26,12 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import java.util.*
import kotlin.collections.HashSet
class ScannerListAdapter(val clickListener: (Device) -> Unit) : RecyclerView.Adapter<DeviceViewHolder>() {
private val list = LinkedList<Device>()
private val foundDevices = mutableSetOf<String>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DeviceViewHolder {
val inflater = LayoutInflater.from(parent.context)
......@@ -44,6 +46,12 @@ class ScannerListAdapter(val clickListener: (Device) -> Unit) : RecyclerView.Ada
override fun getItemCount(): Int = list.size
fun put(device: Device) {
if (foundDevices.contains(device.btMac)) {
return
} else {
foundDevices.add(device.btMac)
}
list.remove(device)
list.add(device)
notifyDataSetChanged()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment