Skip to content

Commit 1077cbc

Browse files
authored
Merge pull request #459 from android/jdk/adaptive-codelab/update-starter-code
[AdaptiveUiCodelab] update starter code
2 parents f17bec0 + eff6b7a commit 1077cbc

File tree

10 files changed

+162
-307
lines changed

10 files changed

+162
-307
lines changed

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)