|
@@ -21,6 +21,7 @@ import androidx.compose.material.icons.filled.Wifi
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
import androidx.compose.runtime.Composable
|
|
|
import androidx.compose.runtime.getValue
|
|
|
+import androidx.compose.runtime.livedata.observeAsState
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
|
import androidx.compose.runtime.saveable.rememberSaveable
|
|
@@ -126,7 +127,7 @@ fun AutoConnectItem(mobileNetworkState: Boolean, basePreferenceHelper: BasePrefe
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun AutoConnectWifiItem(wifiList: AutoConnectModel, basePreferenceHelper: BasePreferenceHelper) {
|
|
|
+fun AutoConnectWifiItem(wifiList: AutoConnectModel, basePreferenceHelper: BasePreferenceHelper, connectedWifiSsid: String) {
|
|
|
Log.d("autoconnect", "AutoConnectWifiItem = ${wifiList.wifiName} ${wifiList.isAdded}")
|
|
|
|
|
|
var isAddedWifi by rememberSaveable { mutableStateOf(wifiList.isAdded) }
|
|
@@ -190,7 +191,12 @@ fun AutoConnectWifiItem(wifiList: AutoConnectModel, basePreferenceHelper: BasePr
|
|
|
detectTapGestures {
|
|
|
isAddedWifi = !isAddedWifi
|
|
|
|
|
|
- onClickAutoConnect(basePreferenceHelper, isAddedWifi, wifiList)
|
|
|
+ onClickAutoConnect(
|
|
|
+ basePreferenceHelper,
|
|
|
+ isAddedWifi,
|
|
|
+ wifiList,
|
|
|
+ connectedWifiSsid
|
|
|
+ )
|
|
|
}
|
|
|
},
|
|
|
verticalAlignment = Alignment.CenterVertically
|
|
@@ -209,7 +215,7 @@ fun AutoConnectWifiItem(wifiList: AutoConnectModel, basePreferenceHelper: BasePr
|
|
|
onClick = {
|
|
|
isAddedWifi = !isAddedWifi
|
|
|
|
|
|
- onClickAutoConnect(basePreferenceHelper, isAddedWifi, wifiList)
|
|
|
+ onClickAutoConnect(basePreferenceHelper, isAddedWifi, wifiList, connectedWifiSsid)
|
|
|
}
|
|
|
) {
|
|
|
Icon(
|
|
@@ -224,33 +230,57 @@ fun AutoConnectWifiItem(wifiList: AutoConnectModel, basePreferenceHelper: BasePr
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-fun onClickAutoConnect(basePreferenceHelper: BasePreferenceHelper, isAddedWifi: Boolean, wifiList: AutoConnectModel) {
|
|
|
+fun onClickAutoConnect(
|
|
|
+ basePreferenceHelper: BasePreferenceHelper,
|
|
|
+ isAddedWifi: Boolean,
|
|
|
+ wifiList: AutoConnectModel,
|
|
|
+ connectedWifiSsid: String
|
|
|
+) {
|
|
|
val autoConnectWifiList = basePreferenceHelper.getAutoConnectList()
|
|
|
val wifiListAdded = ArrayList<AutoConnectModel>()
|
|
|
+ val wifiListState = settingsViewModel.liveDataConnectedWifi.value
|
|
|
|
|
|
if (!isAddedWifi) {
|
|
|
Log.d("autoconnect", "isAddedWifi inside")
|
|
|
- if (autoConnectWifiList != null) {
|
|
|
- wifiListAdded.addAll(autoConnectWifiList)
|
|
|
+ if (wifiListState != null) {
|
|
|
+ wifiListAdded.addAll(wifiListState)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (wifiList.wifiName != connectedWifiSsid) {
|
|
|
wifiListAdded.remove(wifiList)
|
|
|
+ } else {
|
|
|
+ wifiListAdded.forEachIndexed { index, autoConnectModel ->
|
|
|
+ if (autoConnectModel.wifiName == wifiList.wifiName) {
|
|
|
+ wifiListAdded.set(
|
|
|
+ index,
|
|
|
+ AutoConnectModel(wifiList.wifiName, isAddedWifi)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
else {
|
|
|
Log.d("autoconnect", "isAddedWifi else")
|
|
|
- if (autoConnectWifiList != null) {
|
|
|
- wifiListAdded.addAll(autoConnectWifiList)
|
|
|
- wifiListAdded.add(
|
|
|
- 0,
|
|
|
- AutoConnectModel(wifiList.wifiName, isAddedWifi)
|
|
|
- )
|
|
|
+ if (wifiListState != null) {
|
|
|
+ wifiListAdded.addAll(wifiListState)
|
|
|
+
|
|
|
+ wifiListAdded.forEachIndexed { index, autoConnectModel ->
|
|
|
+ if (autoConnectModel.wifiName == wifiList.wifiName) {
|
|
|
+ wifiListAdded.set(
|
|
|
+ index,
|
|
|
+ AutoConnectModel(wifiList.wifiName, isAddedWifi)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
- wifiListAdded.add(AutoConnectModel(wifiList.wifiName, isAddedWifi))
|
|
|
+ wifiListAdded.set(0, AutoConnectModel(wifiList.wifiName, isAddedWifi))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Log.d("autoconnect", "wifiListAdded = ${wifiListAdded.size}")
|
|
|
|
|
|
basePreferenceHelper.setAutoConnectList(wifiListAdded)
|
|
|
-// settingsViewModel.mutableLiveDataConnectedWifi.value = wifiListAdded
|
|
|
+ settingsViewModel.mutableLiveDataConnectedWifi.value = wifiListAdded
|
|
|
}
|