Skip to content

Commit

Permalink
Activity: Collect UI-reated states using a lifecycle-aware method
Browse files Browse the repository at this point in the history
This patch changes the method for collecting the StateFlow of the
OffloadingServiceUiStates to the one that is lifecycle-aware.

Signed-off-by: Wook Song <[email protected]>
  • Loading branch information
wooksong authored and niley7464 committed Sep 24, 2024
1 parent 2877793 commit 86db353
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ junitVersion = "1.1.5"
kotlin = "1.9.23"
kotlinPluginSerialization = "2.0.20"
kotlinxSerializationJson = "1.6.3"
lifecycleRuntimeKtx = "2.7.0"
lifecycleRuntime = "2.7.0"
recyclerview = "1.3.2"
robolectric = "4.12.2"
room = "2.6.1"
Expand Down Expand Up @@ -49,7 +49,8 @@ androidx-datastore-core-android = { group = "androidx.datastore", name = "datast
androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastore" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-lifecycle-runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "lifecycleRuntime" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntime" }
androidx-material-icons-core = { module = "androidx.compose.material:material-icons-core", version.ref = "composeMaterial" }
androidx-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "composeMaterial" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
Expand Down
1 change: 1 addition & 0 deletions ml_inference_offloading/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ dependencies {
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.material.icons.core)
implementation(libs.androidx.material.icons.extended)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
Expand Down Expand Up @@ -230,8 +231,9 @@ class MainActivity : ComponentActivity() {
)
}
)
val offloadingServiceUiStates by mViewModel.services.collectAsStateWithLifecycle()
ServiceList(
mViewModel.services.collectAsState().value,
offloadingServiceUiStates,
onClickStart = { id ->
mService?.send(
Message.obtain(
Expand Down

0 comments on commit 86db353

Please sign in to comment.