Skip to content

Commit 3a54a3c

Browse files
authored
Merge pull request #462 from android/adaptive-codelab
[AdaptiveUiCodelab] merge codelab updates to main
2 parents f6ae4a9 + 4ee84fa commit 3a54a3c

File tree

15 files changed

+307
-318
lines changed

15 files changed

+307
-318
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
alias(libs.plugins.android.application)
19+
alias(libs.plugins.kotlin.android)
20+
}
21+
22+
android {
23+
namespace = "com.example.reply"
24+
compileSdk = 34
25+
26+
defaultConfig {
27+
applicationId = "com.example.reply"
28+
minSdk = 21
29+
targetSdk = 33
30+
versionCode = 1
31+
versionName = "1.0"
32+
33+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
34+
vectorDrawables {
35+
useSupportLibrary = true
36+
}
37+
}
38+
39+
buildTypes {
40+
release {
41+
isMinifyEnabled = false
42+
proguardFiles(
43+
getDefaultProguardFile("proguard-android-optimize.txt"),
44+
"proguard-rules.pro"
45+
)
46+
}
47+
}
48+
compileOptions {
49+
sourceCompatibility = JavaVersion.VERSION_1_8
50+
targetCompatibility = JavaVersion.VERSION_1_8
51+
}
52+
kotlinOptions {
53+
jvmTarget = "1.8"
54+
}
55+
buildFeatures {
56+
compose = true
57+
}
58+
composeOptions {
59+
kotlinCompilerExtensionVersion = "1.5.13"
60+
}
61+
packaging {
62+
resources {
63+
excludes += "/META-INF/AL2.0"
64+
excludes += "/META-INF/LGPL2.1"
65+
}
66+
}
67+
}
68+
69+
dependencies {
70+
val composeBom = platform(libs.androidx.compose.bom)
71+
implementation(composeBom)
72+
androidTestImplementation(composeBom)
73+
74+
implementation(libs.androidx.material3)
75+
implementation(libs.androidx.material.icons.extended)
76+
implementation(libs.androidx.ui.tooling.preview)
77+
androidTestImplementation(libs.androidx.ui.test.junit4)
78+
debugImplementation(libs.androidx.ui.tooling)
79+
debugImplementation(libs.androidx.ui.test.manifest)
80+
81+
implementation(libs.androidx.lifecycle.viewmodel.compose)
82+
implementation(libs.androidx.lifecycle.runtime.compose)
83+
implementation(libs.androidx.lifecycle.runtime.ktx)
84+
implementation(libs.androidx.activity.compose)
85+
implementation(libs.androidx.core.ktx)
86+
implementation(libs.androidx.window)
87+
implementation(libs.kotlinx.coroutines.android)
88+
89+
testImplementation(libs.junit)
90+
androidTestImplementation(libs.androidx.junit)
91+
androidTestImplementation(libs.androidx.espresso.core)
92+
}

AdaptiveUiCodelab/app/proguard-rules.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Add project specific ProGuard rules here.
22
# You can control the set of applied configuration files using the
3-
# proguardFiles setting in build.gradle.
3+
# proguardFiles setting in build.gradle.kts.
44
#
55
# For more details, see
66
# http://developer.android.com/guide/developing/tools/proguard.html
@@ -18,4 +18,4 @@
1818

1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
21+
#-renamesourcefileattribute SourceFile

AdaptiveUiCodelab/app/src/main/java/com/example/reply/data/Email.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ data class Email(
3333
var isStarred: Boolean = false,
3434
var mailbox: MailboxType = MailboxType.INBOX,
3535
var createAt: String,
36-
val threads: List<Email> = emptyList()
36+
val replies: List<Email> = emptyList()
3737
) {
3838
val senderPreview: String = "${sender.fullName} - 4 hrs ago"
3939
val hasBody: Boolean = body.isNotBlank()
@@ -44,5 +44,3 @@ data class Email(
4444
val nonUserAccountRecipients = recipients
4545
.filterNot { LocalAccountsDataProvider.isUserAccount(it.uid) }
4646
}
47-
48-

AdaptiveUiCodelab/app/src/main/java/com/example/reply/data/EmailsRepositoryImpl.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.example.reply.data
1818

1919
import com.example.reply.data.local.LocalEmailsDataProvider
20-
import kotlinx.coroutines.delay
2120
import kotlinx.coroutines.flow.Flow
2221
import kotlinx.coroutines.flow.flow
2322

@@ -39,4 +38,4 @@ class EmailsRepositoryImpl : EmailsRepository {
3938
override fun getEmailFromId(id: Long): Flow<Email?> = flow {
4039
val categoryEmails = LocalEmailsDataProvider.allEmails.firstOrNull { it.id == id }
4140
}
42-
}
41+
}

AdaptiveUiCodelab/app/src/main/java/com/example/reply/data/local/LocalEmailsDataProvider.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import com.example.reply.data.MailboxType
2727

2828
object LocalEmailsDataProvider {
2929

30-
private val threads = listOf(
30+
private val replies = listOf(
3131
Email(
3232
4L,
3333
LocalAccountsDataProvider.getContactAccountByUid(11L),
@@ -116,7 +116,7 @@ object LocalEmailsDataProvider {
116116
""".trimIndent(),
117117
createAt = "20 mins ago",
118118
isStarred = true,
119-
threads = threads,
119+
replies = replies,
120120
),
121121
Email(
122122
1L,
@@ -133,7 +133,7 @@ object LocalEmailsDataProvider {
133133
Ali
134134
""".trimIndent(),
135135
createAt = "40 mins ago",
136-
threads = threads,
136+
replies = replies,
137137
),
138138
Email(
139139
2L,
@@ -149,7 +149,7 @@ object LocalEmailsDataProvider {
149149
),
150150
true,
151151
createAt = "1 hour ago",
152-
threads = threads,
152+
replies = replies,
153153
),
154154
Email(
155155
3L,
@@ -311,4 +311,3 @@ object LocalEmailsDataProvider {
311311
"Grocery coupons"
312312
)
313313
}
314-

AdaptiveUiCodelab/app/src/main/java/com/example/reply/ui/MainActivity.kt

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import androidx.activity.ComponentActivity
2121
import androidx.activity.compose.setContent
2222
import androidx.activity.viewModels
2323
import androidx.compose.runtime.Composable
24-
import androidx.compose.runtime.collectAsState
24+
import androidx.compose.runtime.getValue
2525
import androidx.compose.ui.tooling.preview.Preview
26+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
2627
import com.example.reply.data.local.LocalEmailsDataProvider
2728
import com.example.reply.ui.theme.ReplyTheme
2829

@@ -35,8 +36,11 @@ class MainActivity : ComponentActivity() {
3536

3637
setContent {
3738
ReplyTheme {
38-
val uiState = viewModel.uiState.collectAsState().value
39-
ReplyApp(uiState)
39+
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
40+
ReplyApp(
41+
replyHomeUIState = uiState,
42+
onEmailClick = viewModel::setSelectedEmail
43+
)
4044
}
4145
}
4246
}
@@ -46,28 +50,37 @@ class MainActivity : ComponentActivity() {
4650
@Composable
4751
fun ReplyAppPreview() {
4852
ReplyTheme {
49-
ReplyApp(replyHomeUIState = ReplyHomeUIState(
50-
emails = LocalEmailsDataProvider.allEmails
51-
))
53+
ReplyApp(
54+
replyHomeUIState = ReplyHomeUIState(
55+
emails = LocalEmailsDataProvider.allEmails
56+
),
57+
onEmailClick = {}
58+
)
5259
}
5360
}
5461

5562
@Preview(showBackground = true, widthDp = 700)
5663
@Composable
5764
fun ReplyAppPreviewTablet() {
5865
ReplyTheme {
59-
ReplyApp(replyHomeUIState = ReplyHomeUIState(
60-
emails = LocalEmailsDataProvider.allEmails
61-
))
66+
ReplyApp(
67+
replyHomeUIState = ReplyHomeUIState(
68+
emails = LocalEmailsDataProvider.allEmails
69+
),
70+
onEmailClick = {}
71+
)
6272
}
6373
}
6474

6575
@Preview(showBackground = true, widthDp = 1000)
6676
@Composable
6777
fun ReplyAppPreviewDesktop() {
6878
ReplyTheme {
69-
ReplyApp(replyHomeUIState = ReplyHomeUIState(
70-
emails = LocalEmailsDataProvider.allEmails
71-
))
79+
ReplyApp(
80+
replyHomeUIState = ReplyHomeUIState(
81+
emails = LocalEmailsDataProvider.allEmails
82+
),
83+
onEmailClick = {}
84+
)
7285
}
73-
}
86+
}

0 commit comments

Comments
 (0)