Skip to content

Commit 6ab9345

Browse files
Merge pull request #51 from google-developer-training/main-cleanup
Fix style issues post KTS migration, update for codelab changes
2 parents 4ca17b9 + 1570ff1 commit 6ab9345

19 files changed

Lines changed: 82 additions & 70 deletions

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Solution code for the Android Basics with Compose: Reply app.
44

55
Introduction
66
------------
7-
The Reply app is a simple email client that display various categories of your
8-
inbox. This app is used to illustrate the concept of adaptive layout.
7+
The Reply app is a basic email client that displays various categories of your
8+
inbox. This app is used to illustrate the concept of adaptive layouts.
99

1010
Pre-requisites
1111
--------------
1212

13-
* Experience with Kotlin syntax.
14-
* How to create and run a project in Android Studio.
13+
* Experience with Kotlin syntax
14+
* How to create and run a project in Android Studio
1515
* How to create composable functions
1616
* How to create compose navigation
1717

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@
3939
</activity>
4040
</application>
4141

42-
</manifest>
42+
</manifest>

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,34 @@ class MainActivity : ComponentActivity() {
5151
@Composable
5252
fun ReplyAppCompactPreview() {
5353
ReplyTheme {
54-
ReplyApp(
55-
windowSize = WindowWidthSizeClass.Compact,
56-
)
54+
Surface {
55+
ReplyApp(
56+
windowSize = WindowWidthSizeClass.Compact,
57+
)
58+
}
5759
}
5860
}
5961

6062
@Preview(showBackground = true, widthDp = 700)
6163
@Composable
6264
fun ReplyAppMediumPreview() {
6365
ReplyTheme {
64-
ReplyApp(
65-
windowSize = WindowWidthSizeClass.Medium,
66-
)
66+
Surface {
67+
ReplyApp(
68+
windowSize = WindowWidthSizeClass.Medium,
69+
)
70+
}
6771
}
6872
}
6973

7074
@Preview(showBackground = true, widthDp = 1000)
7175
@Composable
7276
fun ReplyAppExpandedPreview() {
7377
ReplyTheme {
74-
ReplyApp(
75-
windowSize = WindowWidthSizeClass.Expanded,
76-
)
78+
Surface {
79+
ReplyApp(
80+
windowSize = WindowWidthSizeClass.Expanded,
81+
)
82+
}
7783
}
78-
}
84+
}

app/src/main/java/com/example/reply/data/Account.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.example.reply.data
1717

1818
import androidx.annotation.DrawableRes
19+
import androidx.annotation.StringRes
1920

2021
/**
2122
* A class which represents an account
@@ -24,14 +25,11 @@ data class Account(
2425
/** Unique ID of a user **/
2526
val id: Long,
2627
/** User's first name **/
27-
val firstName: Int,
28+
@StringRes val firstName: Int,
2829
/** User's last name **/
29-
val lastName: Int,
30+
@StringRes val lastName: Int,
3031
/** User's email address **/
31-
val email: Int,
32+
@StringRes val email: Int,
3233
/** User's avatar image resource id **/
3334
@DrawableRes val avatar: Int
34-
) {
35-
/** User's full name **/
36-
val fullName: String = "$firstName $lastName"
37-
}
35+
)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.example.reply.data
1717

18+
import androidx.annotation.StringRes
19+
1820
/**
1921
* A simple data class to represent an Email
2022
*/
@@ -26,9 +28,9 @@ data class Email(
2628
/** Recipient(s) of the email **/
2729
val recipients: List<Account> = emptyList(),
2830
/** Title of the email **/
29-
val subject: Int = -1,
31+
@StringRes val subject: Int = -1,
3032
/** Content of the email **/
31-
val body: Int = -1,
33+
@StringRes val body: Int = -1,
3234
/** Which mailbox it is in **/
3335
var mailbox: MailboxType = MailboxType.Inbox,
3436
/**

app/src/main/java/com/example/reply/data/MailboxType.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ package com.example.reply.data
2020
*/
2121
enum class MailboxType {
2222
Inbox, Drafts, Sent, Spam
23-
}
23+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,4 @@ object LocalAccountsDataProvider {
114114
return allUserContactAccounts.firstOrNull { it.id == accountId }
115115
?: allUserContactAccounts.first()
116116
}
117-
}
117+
}

app/src/main/java/com/example/reply/ui/ReplyApp.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ fun ReplyApp(
7171
},
7272
modifier = modifier
7373
)
74-
}
74+
}

app/src/main/java/com/example/reply/ui/ReplyDetailsScreen.kt

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ import com.example.reply.data.MailboxType
5454
@Composable
5555
fun ReplyDetailsScreen(
5656
replyUiState: ReplyUiState,
57+
onBackPressed: () -> Unit,
5758
modifier: Modifier = Modifier,
58-
onBackPressed: () -> Unit = {},
5959
isFullScreen: Boolean = false
6060
) {
6161
BackHandler {
@@ -83,10 +83,11 @@ fun ReplyDetailsScreen(
8383
email = replyUiState.currentSelectedEmail,
8484
mailboxType = replyUiState.currentMailbox,
8585
isFullScreen = isFullScreen,
86-
modifier = if (isFullScreen)
86+
modifier = if (isFullScreen) {
8787
Modifier.padding(horizontal = dimensionResource(R.dimen.detail_card_outer_padding_horizontal))
88-
else
88+
} else {
8989
Modifier.padding(end = dimensionResource(R.dimen.detail_card_outer_padding_horizontal))
90+
}
9091
)
9192
}
9293
}
@@ -153,7 +154,9 @@ private fun ReplyEmailDetailsCard(
153154
email,
154155
Modifier.fillMaxWidth()
155156
)
156-
if (!isFullScreen) {
157+
if (isFullScreen) {
158+
Spacer(modifier = Modifier.height(dimensionResource(R.dimen.detail_content_padding_top)))
159+
} else {
157160
Text(
158161
text = stringResource(email.subject),
159162
style = MaterialTheme.typography.bodyMedium,
@@ -163,8 +166,6 @@ private fun ReplyEmailDetailsCard(
163166
bottom = dimensionResource(R.dimen.detail_expanded_subject_body_spacing)
164167
),
165168
)
166-
} else {
167-
Spacer(modifier = Modifier.height(dimensionResource(R.dimen.detail_content_padding_top)))
168169
}
169170
Text(
170171
text = stringResource(email.body),
@@ -245,7 +246,8 @@ private fun DetailsScreenHeader(email: Email, modifier: Modifier = Modifier) {
245246
Row(modifier = modifier) {
246247
ReplyProfileImage(
247248
drawableResource = email.sender.avatar,
248-
description = email.sender.fullName,
249+
description = stringResource(email.sender.firstName) + " "
250+
+ stringResource(email.sender.lastName),
249251
modifier = Modifier.size(
250252
dimensionResource(R.dimen.email_header_profile_size)
251253
)
@@ -287,17 +289,20 @@ private fun ActionButton(
287289
.padding(vertical = dimensionResource(R.dimen.detail_action_button_padding_vertical)),
288290
colors = ButtonDefaults.buttonColors(
289291
containerColor =
290-
if (!containIrreversibleAction)
292+
if (containIrreversibleAction) {
293+
MaterialTheme.colorScheme.onErrorContainer
294+
} else {
291295
MaterialTheme.colorScheme.primaryContainer
292-
else MaterialTheme.colorScheme.onErrorContainer
296+
}
293297
)
294298
) {
295299
Text(
296300
text = text,
297-
color =
298-
if (!containIrreversibleAction)
301+
color = if (containIrreversibleAction) {
302+
MaterialTheme.colorScheme.onError
303+
} else {
299304
MaterialTheme.colorScheme.onSurfaceVariant
300-
else MaterialTheme.colorScheme.onError
305+
}
301306
)
302307
}
303308
}

app/src/main/java/com/example/reply/ui/ReplyHomeContent.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,11 @@ fun ReplyEmailListItem(
130130
Card(
131131
modifier = modifier,
132132
colors = CardDefaults.cardColors(
133-
containerColor = if (selected)
133+
containerColor = if (selected) {
134134
MaterialTheme.colorScheme.primaryContainer
135-
else
135+
} else {
136136
MaterialTheme.colorScheme.secondaryContainer
137+
}
137138
),
138139
onClick = onCardClick
139140
) {
@@ -171,7 +172,8 @@ private fun ReplyEmailItemHeader(email: Email, modifier: Modifier = Modifier) {
171172
Row(modifier = modifier) {
172173
ReplyProfileImage(
173174
drawableResource = email.sender.avatar,
174-
description = email.sender.fullName,
175+
description = stringResource(email.sender.firstName) + " "
176+
+ stringResource(email.sender.lastName),
175177
modifier = Modifier.size(dimensionResource(R.dimen.email_header_profile_size))
176178
)
177179
Column(

0 commit comments

Comments
 (0)