wifi选择弹窗修改
This commit is contained in:
@@ -2,6 +2,7 @@ package com.ckkj.defense_device.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.ckkj.defense_device.databinding.ItemWifiBinding
|
||||
|
||||
@@ -39,14 +40,25 @@ class WifiListAdapter(
|
||||
override fun getItemCount(): Int = wifiList.size
|
||||
|
||||
fun updateData(newList: List<String>) {
|
||||
val oldList = wifiList.toList()
|
||||
val diffResult = DiffUtil.calculateDiff(object : DiffUtil.Callback() {
|
||||
override fun getOldListSize() = oldList.size
|
||||
override fun getNewListSize() = newList.size
|
||||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int) =
|
||||
oldList[oldItemPosition] == newList[newItemPosition]
|
||||
|
||||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int) =
|
||||
oldList[oldItemPosition] == newList[newItemPosition]
|
||||
})
|
||||
wifiList.clear()
|
||||
wifiList.addAll(newList)
|
||||
notifyDataSetChanged()
|
||||
diffResult.dispatchUpdatesTo(this)
|
||||
}
|
||||
|
||||
fun addData(newList: List<String>) {
|
||||
val startPosition = wifiList.size
|
||||
val newItems = newList.filter { !wifiList.contains(it) }
|
||||
if (newItems.isEmpty()) return
|
||||
wifiList.addAll(newItems)
|
||||
notifyItemRangeInserted(startPosition, newItems.size)
|
||||
}
|
||||
|
||||
@@ -144,10 +144,6 @@ class AddFamilyActivity : AppCompatActivity() {
|
||||
}
|
||||
dialogBinding.rvWifiList.adapter = wifiListAdapter
|
||||
|
||||
dialogBinding.swipeRefreshLayout.setOnRefreshListener {
|
||||
refreshWifiList(dialogBinding)
|
||||
}
|
||||
|
||||
dialogBinding.rvWifiList.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
@@ -168,16 +164,6 @@ class AddFamilyActivity : AppCompatActivity() {
|
||||
return rect.height()
|
||||
}
|
||||
|
||||
private fun refreshWifiList(dialogBinding: DialogWifiListBinding) {
|
||||
dialogBinding.swipeRefreshLayout.isRefreshing = true
|
||||
handler.postDelayed({
|
||||
wifiManager.startScan()
|
||||
val newWifiList = getWifiList()
|
||||
wifiListAdapter?.updateData(newWifiList)
|
||||
dialogBinding.swipeRefreshLayout.isRefreshing = false
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
private fun loadMoreWifiList() {
|
||||
isLoadingMore = true
|
||||
handler.postDelayed({
|
||||
@@ -204,12 +190,8 @@ class AddFamilyActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun updateWifiList() {
|
||||
popupWindow?.contentView?.findViewById<androidx.recyclerview.widget.RecyclerView>(R.id.rvWifiList)?.let { recyclerView ->
|
||||
val wifiList = getWifiList()
|
||||
recyclerView.adapter = WifiListAdapter(wifiList) { wifiName ->
|
||||
binding.etWifiName.setText(wifiName)
|
||||
popupWindow?.dismiss()
|
||||
}
|
||||
popupWindow?.contentView?.findViewById<androidx.recyclerview.widget.RecyclerView>(R.id.rvWifiList)?.let {
|
||||
wifiListAdapter?.updateData(getWifiList())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -202,14 +202,6 @@ class WiFiManagementActivity : AppCompatActivity() {
|
||||
}
|
||||
dialogBinding.rvWifiList.adapter = adapter
|
||||
|
||||
// 添加下拉刷新功能
|
||||
dialogBinding.swipeRefreshLayout.setOnRefreshListener {
|
||||
wifiManager.startScan()
|
||||
// 延迟1秒后停止刷新动画
|
||||
android.os.Handler().postDelayed({
|
||||
dialogBinding.swipeRefreshLayout.isRefreshing = false
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateBottomButtonVisibility() {
|
||||
@@ -229,9 +221,6 @@ class WiFiManagementActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun updateWifiList() {
|
||||
popupWindow?.contentView?.findViewById<androidx.swiperefreshlayout.widget.SwipeRefreshLayout>(R.id.swipeRefreshLayout)?.let { swipeRefreshLayout ->
|
||||
swipeRefreshLayout.isRefreshing = false
|
||||
}
|
||||
popupWindow?.contentView?.findViewById<androidx.recyclerview.widget.RecyclerView>(R.id.rvWifiList)?.let { recyclerView ->
|
||||
val wifiList = getWifiList()
|
||||
recyclerView.adapter = WifiListAdapter(wifiList) { wifiName ->
|
||||
@@ -253,4 +242,4 @@ class WiFiManagementActivity : AppCompatActivity() {
|
||||
unregisterReceiver(wifiScanReceiver)
|
||||
popupWindow?.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,18 +20,11 @@
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/dialog_view" />
|
||||
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipeRefreshLayout"
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvWifiList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
android:layout_weight="1"
|
||||
android:overScrollMode="never" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvWifiList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:overScrollMode="never" />
|
||||
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user