kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
chore: add Lifecycle utilities for Compose
and replace collectAsState() with collectAsStateWithLifecycle()pull/618/head
rodzic
8e7597704b
commit
e03ab70e66
|
@ -144,6 +144,7 @@ dependencies {
|
||||||
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"
|
||||||
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
|
||||||
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
|
||||||
|
implementation "androidx.lifecycle:lifecycle-runtime-compose:$lifecycle_version"
|
||||||
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
|
||||||
implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.twotone.Check
|
import androidx.compose.material.icons.twotone.Check
|
||||||
import androidx.compose.material.icons.twotone.Close
|
import androidx.compose.material.icons.twotone.Close
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.livedata.observeAsState
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
@ -52,6 +51,7 @@ import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.geeksville.mesh.analytics.DataPair
|
import com.geeksville.mesh.analytics.DataPair
|
||||||
import com.geeksville.mesh.android.GeeksvilleApplication
|
import com.geeksville.mesh.android.GeeksvilleApplication
|
||||||
|
@ -115,7 +115,7 @@ fun ChannelScreen(viewModel: UIViewModel = viewModel()) {
|
||||||
val connectionState by viewModel.connectionState.observeAsState()
|
val connectionState by viewModel.connectionState.observeAsState()
|
||||||
val connected = connectionState == MeshService.ConnectionState.CONNECTED
|
val connected = connectionState == MeshService.ConnectionState.CONNECTED
|
||||||
|
|
||||||
val channels by viewModel.channels.collectAsState()
|
val channels by viewModel.channels.collectAsStateWithLifecycle()
|
||||||
var channelSet by remember(channels.protobuf) { mutableStateOf(channels.protobuf) }
|
var channelSet by remember(channels.protobuf) { mutableStateOf(channels.protobuf) }
|
||||||
|
|
||||||
val primaryChannel = ChannelSet(channelSet).primaryChannel
|
val primaryChannel = ChannelSet(channelSet).primaryChannel
|
||||||
|
|
|
@ -6,7 +6,6 @@ import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.Divider
|
import androidx.compose.material.Divider
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.livedata.observeAsState
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
@ -17,6 +16,7 @@ import androidx.compose.ui.platform.LocalFocusManager
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.geeksville.mesh.ConfigProtos
|
import com.geeksville.mesh.ConfigProtos
|
||||||
import com.geeksville.mesh.ConfigProtos.Config.NetworkConfig
|
import com.geeksville.mesh.ConfigProtos.Config.NetworkConfig
|
||||||
|
@ -43,8 +43,8 @@ fun DeviceSettingsItemList(viewModel: UIViewModel = viewModel()) {
|
||||||
val connectionState by viewModel.connectionState.observeAsState()
|
val connectionState by viewModel.connectionState.observeAsState()
|
||||||
val connected = connectionState == MeshService.ConnectionState.CONNECTED
|
val connected = connectionState == MeshService.ConnectionState.CONNECTED
|
||||||
|
|
||||||
val localConfig by viewModel.localConfig.collectAsState()
|
val localConfig by viewModel.localConfig.collectAsStateWithLifecycle()
|
||||||
val ourNodeInfo by viewModel.ourNodeInfo.collectAsState()
|
val ourNodeInfo by viewModel.ourNodeInfo.collectAsStateWithLifecycle()
|
||||||
var userInput by remember(ourNodeInfo?.user) { mutableStateOf(ourNodeInfo?.user) }
|
var userInput by remember(ourNodeInfo?.user) { mutableStateOf(ourNodeInfo?.user) }
|
||||||
var positionInfo by remember(ourNodeInfo?.position) { mutableStateOf(ourNodeInfo?.position) }
|
var positionInfo by remember(ourNodeInfo?.position) { mutableStateOf(ourNodeInfo?.position) }
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.Divider
|
import androidx.compose.material.Divider
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.livedata.observeAsState
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
@ -16,6 +15,7 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalFocusManager
|
import androidx.compose.ui.platform.LocalFocusManager
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.geeksville.mesh.ModuleConfigProtos.ModuleConfig
|
import com.geeksville.mesh.ModuleConfigProtos.ModuleConfig
|
||||||
import com.geeksville.mesh.copy
|
import com.geeksville.mesh.copy
|
||||||
|
@ -34,7 +34,7 @@ fun ModuleSettingsItemList(viewModel: UIViewModel = viewModel()) {
|
||||||
val connectionState by viewModel.connectionState.observeAsState()
|
val connectionState by viewModel.connectionState.observeAsState()
|
||||||
val connected = connectionState == MeshService.ConnectionState.CONNECTED
|
val connected = connectionState == MeshService.ConnectionState.CONNECTED
|
||||||
|
|
||||||
val moduleConfig by viewModel.moduleConfig.collectAsState()
|
val moduleConfig by viewModel.moduleConfig.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
// Temporary [ModuleConfigProtos.ModuleConfig] state holders
|
// Temporary [ModuleConfigProtos.ModuleConfig] state holders
|
||||||
var mqttInput by remember(moduleConfig.mqtt) { mutableStateOf(moduleConfig.mqtt) }
|
var mqttInput by remember(moduleConfig.mqtt) { mutableStateOf(moduleConfig.mqtt) }
|
||||||
|
|
Ładowanie…
Reference in New Issue