Skip to content

Commit 67aeac7

Browse files
author
Manuel Vivo
authored
Update to use AndroidX collectAsStateWithLifecycle (#863)
1 parent d31721f commit 67aeac7

File tree

7 files changed

+27
-114
lines changed

7 files changed

+27
-114
lines changed

app/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ android {
8181
}
8282

8383
composeOptions {
84-
kotlinCompilerExtensionVersion "$composeVersion"
84+
kotlinCompilerExtensionVersion "$composeCompilerVersion"
8585
}
8686

8787
testOptions {
@@ -142,10 +142,12 @@ dependencies {
142142

143143
// Jetpack Compose
144144
implementation "androidx.activity:activity-compose:$activityComposeVersion"
145+
implementation "androidx.compose.compiler:compiler:$composeCompilerVersion"
145146
implementation "androidx.compose.material:material:$composeVersion"
146147
implementation "androidx.compose.animation:animation:$composeVersion"
147148
implementation "androidx.compose.ui:ui-tooling-preview:$composeVersion"
148149
implementation "androidx.navigation:navigation-compose:$navigationVersion"
150+
implementation "androidx.lifecycle:lifecycle-runtime-compose:$archLifecycleVersion"
149151
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$archLifecycleVersion"
150152
implementation "com.google.accompanist:accompanist-appcompat-theme:$accompanistVersion"
151153
implementation "com.google.accompanist:accompanist-swiperefresh:$accompanistVersion"

app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskScreen.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ import androidx.compose.ui.res.stringResource
4545
import androidx.compose.ui.text.font.FontWeight
4646
import androidx.compose.ui.unit.dp
4747
import androidx.hilt.navigation.compose.hiltViewModel
48+
import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi
49+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
4850
import com.example.android.architecture.blueprints.todoapp.R
4951
import com.example.android.architecture.blueprints.todoapp.util.AddEditTaskTopAppBar
50-
import com.example.android.architecture.blueprints.todoapp.util.collectAsStateWithLifecycle
5152
import com.google.accompanist.swiperefresh.SwipeRefresh
5253
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
5354

55+
@OptIn(ExperimentalLifecycleComposeApi::class)
5456
@Composable
5557
fun AddEditTaskScreen(
5658
@StringRes topBarTitle: Int,

app/src/main/java/com/example/android/architecture/blueprints/todoapp/statistics/StatisticsScreen.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ import androidx.compose.ui.res.dimensionResource
3333
import androidx.compose.ui.res.stringResource
3434
import androidx.compose.ui.tooling.preview.Preview
3535
import androidx.hilt.navigation.compose.hiltViewModel
36+
import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi
37+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
3638
import com.example.android.architecture.blueprints.todoapp.R
3739
import com.example.android.architecture.blueprints.todoapp.util.LoadingContent
3840
import com.example.android.architecture.blueprints.todoapp.util.StatisticsTopAppBar
39-
import com.example.android.architecture.blueprints.todoapp.util.collectAsStateWithLifecycle
4041
import com.google.accompanist.appcompattheme.AppCompatTheme
4142

43+
@OptIn(ExperimentalLifecycleComposeApi::class)
4244
@Composable
4345
fun StatisticsScreen(
4446
openDrawer: () -> Unit,
@@ -95,7 +97,12 @@ private fun StatisticsContent(
9597
) {
9698
if (!loading) {
9799
Text(stringResource(id = R.string.statistics_active_tasks, activeTasksPercent))
98-
Text(stringResource(id = R.string.statistics_completed_tasks, completedTasksPercent))
100+
Text(
101+
stringResource(
102+
id = R.string.statistics_completed_tasks,
103+
completedTasksPercent
104+
)
105+
)
99106
}
100107
}
101108
}

app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailScreen.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ import androidx.compose.ui.res.dimensionResource
4141
import androidx.compose.ui.res.stringResource
4242
import androidx.compose.ui.tooling.preview.Preview
4343
import androidx.hilt.navigation.compose.hiltViewModel
44+
import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi
45+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
4446
import com.example.android.architecture.blueprints.todoapp.R
4547
import com.example.android.architecture.blueprints.todoapp.data.Task
4648
import com.example.android.architecture.blueprints.todoapp.util.LoadingContent
4749
import com.example.android.architecture.blueprints.todoapp.util.TaskDetailTopAppBar
48-
import com.example.android.architecture.blueprints.todoapp.util.collectAsStateWithLifecycle
4950
import com.google.accompanist.appcompattheme.AppCompatTheme
5051

52+
@OptIn(ExperimentalLifecycleComposeApi::class)
5153
@Composable
5254
fun TaskDetailScreen(
5355
onEditTask: (String) -> Unit,

app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksScreen.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,18 @@ import androidx.compose.ui.text.style.TextDecoration
5353
import androidx.compose.ui.tooling.preview.Preview
5454
import androidx.compose.ui.unit.dp
5555
import androidx.hilt.navigation.compose.hiltViewModel
56+
import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi
57+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
5658
import com.example.android.architecture.blueprints.todoapp.R
5759
import com.example.android.architecture.blueprints.todoapp.data.Task
5860
import com.example.android.architecture.blueprints.todoapp.tasks.TasksFilterType.ACTIVE_TASKS
5961
import com.example.android.architecture.blueprints.todoapp.tasks.TasksFilterType.ALL_TASKS
6062
import com.example.android.architecture.blueprints.todoapp.tasks.TasksFilterType.COMPLETED_TASKS
6163
import com.example.android.architecture.blueprints.todoapp.util.LoadingContent
6264
import com.example.android.architecture.blueprints.todoapp.util.TasksTopAppBar
63-
import com.example.android.architecture.blueprints.todoapp.util.collectAsStateWithLifecycle
6465
import com.google.accompanist.appcompattheme.AppCompatTheme
6566

67+
@OptIn(ExperimentalLifecycleComposeApi::class)
6668
@Composable
6769
fun TasksScreen(
6870
@StringRes userMessage: Int,

app/src/main/java/com/example/android/architecture/blueprints/todoapp/util/CollectAsStateWithLifecycle.kt

Lines changed: 0 additions & 103 deletions
This file was deleted.

build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
buildscript {
2-
ext.kotlinVersion = '1.6.10'
3-
ext.navigationVersion = '2.4.2'
2+
ext.kotlinVersion = '1.7.0'
3+
ext.navigationVersion = '2.5.0'
44
ext.ktlintVersion = '0.44.0'
55
ext.hiltVersion = '2.42'
66

@@ -9,7 +9,7 @@ buildscript {
99
mavenCentral()
1010
}
1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:7.3.0-beta01'
12+
classpath 'com.android.tools.build:gradle:7.3.0-beta05'
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
1414
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
1515
classpath "com.google.dagger:hilt-android-gradle-plugin:$hiltVersion"
@@ -62,9 +62,10 @@ ext {
6262
androidXTestExtKotlinRunnerVersion = '1.1.4-alpha06'
6363
androidXTestRulesVersion = '1.4.1-alpha06'
6464
androidXAnnotations = '1.3.0'
65-
archLifecycleVersion = '2.5.0-rc01'
65+
archLifecycleVersion = '2.6.0-alpha01'
6666
archTestingVersion = '2.1.0'
67-
composeVersion = '1.1.1'
67+
composeVersion = '1.2.0'
68+
composeCompilerVersion = '1.2.0'
6869
coroutinesVersion = '1.6.1'
6970
dexMakerVersion = '2.12.1'
7071
espressoVersion = '3.5.0-alpha06'

0 commit comments

Comments
 (0)