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