Skip to content

Commit

Permalink
Avoid duplicate LazyColumn SSID keys (#4976)
Browse files Browse the repository at this point in the history
* Avoid duplicate LazyColumn SSID keys

* Don't allow adding the same SSID twice
  • Loading branch information
jpelgrom authored Jan 15, 2025
1 parent 2a9dab5 commit e9fb3b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class SsidViewModel @Inject constructor(
*/
fun addHomeWifiSsid(ssid: String): Boolean {
if (ssid.isEmpty()) return false
if (wifiSsids.contains(ssid)) return false
setHomeWifiSsids((wifiSsids + ssid).sorted())
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Button
Expand Down Expand Up @@ -131,7 +131,12 @@ fun SsidView(
}
}
}
items(wifiSsids, key = { "ssid.item.$it" }) {
itemsIndexed(
items = wifiSsids,
key = { index: Int, item: String ->
if (wifiSsids.count { it == item } == 1) "ssid.item.$item" else "ssid.index.$index"
}
) { _, it ->
val connected = remember(it, activeSsid, activeBssid, usingWifi) {
usingWifi &&
(
Expand Down

0 comments on commit e9fb3b0

Please sign in to comment.