-
Notifications
You must be signed in to change notification settings - Fork 5
mvvm: move network node actions to NetworkScreenViewModel #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -32,8 +32,10 @@ data class NetworkScreenModel( | |||||
| class NetworkScreenViewModel(di:DI, savedStateHandle: SavedStateHandle): ViewModel() { | ||||||
| // _uiState will be updated whenever there is a change in the UI state | ||||||
| private val _uiState = MutableStateFlow(NetworkScreenModel()) | ||||||
|
|
||||||
| // uiState is a read-only property that shows the current UI state | ||||||
| val uiState: Flow<NetworkScreenModel> = _uiState.asStateFlow() | ||||||
|
|
||||||
| // di is used to get the AndroidVirtualNode instance | ||||||
| private val node: AndroidVirtualNode by di.instance() | ||||||
| private val appServer: AppServer by di.instance() | ||||||
|
|
@@ -54,7 +56,8 @@ class NetworkScreenViewModel(di:DI, savedStateHandle: SavedStateHandle): ViewMod | |||||
|
|
||||||
| // For each disconnected node, notify DeviceStatusManager | ||||||
| disconnectedNodes.forEach { nodeAddress -> | ||||||
| val ipAddress = InetAddress.getByAddress(nodeAddress.addressToByteArray()).hostAddress | ||||||
| val ipAddress = | ||||||
| InetAddress.getByAddress(nodeAddress.addressToByteArray()).hostAddress | ||||||
| DeviceStatusManager.handleNetworkDisconnect(ipAddress) | ||||||
| Log.d("NetworkScreenViewModel", "Detected disconnection of node: $ipAddress") | ||||||
| } | ||||||
|
|
@@ -77,11 +80,11 @@ class NetworkScreenViewModel(di:DI, savedStateHandle: SavedStateHandle): ViewMod | |||||
| allNodes = allNodesWithTest, | ||||||
| // update the ssid of the connecting station | ||||||
| connectingInProgressSsid = | ||||||
| if (nodeState.wifiState.wifiStationState.status == WifiStationState.Status.CONNECTING) { | ||||||
| nodeState.wifiState.wifiStationState.config?.ssid | ||||||
| } else { | ||||||
| null | ||||||
| } | ||||||
| if (nodeState.wifiState.wifiStationState.status == WifiStationState.Status.CONNECTING) { | ||||||
| nodeState.wifiState.wifiStationState.config?.ssid | ||||||
| } else { | ||||||
| null | ||||||
| } | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -187,13 +190,30 @@ class NetworkScreenViewModel(di:DI, savedStateHandle: SavedStateHandle): ViewMod | |||||
| delay(30000) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| */ | ||||||
| fun getDeviceName(wifiAddress: Int) { | ||||||
| viewModelScope.launch { | ||||||
| val inetAddress = InetAddress.getByAddress(wifiAddress.addressToByteArray()) | ||||||
| appServer.sendDeviceName(inetAddress) | ||||||
| } | ||||||
|
|
||||||
| fun onNodeSelected(ipAddress: String) { | ||||||
| viewModelScope.launch { | ||||||
| try { | ||||||
| val addr = InetAddress.getByName(ipAddress) | ||||||
|
||||||
| val addr = InetAddress.getByName(ipAddress) | |
| val addr = withContext(Dispatchers.IO) { InetAddress.getByName(ipAddress) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved InetAddress.getByName(ipAddress) to Dispatchers.IO using withContext to avoid running on the main thread.
Uh oh!
There was an error while loading. Please reload this page.