Skip to content

Commit

Permalink
Merge pull request #51 from google-developer-training/main-cleanup
Browse files Browse the repository at this point in the history
Fix style issues post KTS migration, update for codelab changes
  • Loading branch information
OwenScott-GDS authored Jul 21, 2023
2 parents 4ca17b9 + 1570ff1 commit 6ab9345
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 70 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Solution code for the Android Basics with Compose: Reply app.

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

Pre-requisites
--------------

* Experience with Kotlin syntax.
* How to create and run a project in Android Studio.
* Experience with Kotlin syntax
* How to create and run a project in Android Studio
* How to create composable functions
* How to create compose navigation

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
</activity>
</application>

</manifest>
</manifest>
26 changes: 16 additions & 10 deletions app/src/main/java/com/example/reply/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,34 @@ class MainActivity : ComponentActivity() {
@Composable
fun ReplyAppCompactPreview() {
ReplyTheme {
ReplyApp(
windowSize = WindowWidthSizeClass.Compact,
)
Surface {
ReplyApp(
windowSize = WindowWidthSizeClass.Compact,
)
}
}
}

@Preview(showBackground = true, widthDp = 700)
@Composable
fun ReplyAppMediumPreview() {
ReplyTheme {
ReplyApp(
windowSize = WindowWidthSizeClass.Medium,
)
Surface {
ReplyApp(
windowSize = WindowWidthSizeClass.Medium,
)
}
}
}

@Preview(showBackground = true, widthDp = 1000)
@Composable
fun ReplyAppExpandedPreview() {
ReplyTheme {
ReplyApp(
windowSize = WindowWidthSizeClass.Expanded,
)
Surface {
ReplyApp(
windowSize = WindowWidthSizeClass.Expanded,
)
}
}
}
}
12 changes: 5 additions & 7 deletions app/src/main/java/com/example/reply/data/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.example.reply.data

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes

/**
* A class which represents an account
Expand All @@ -24,14 +25,11 @@ data class Account(
/** Unique ID of a user **/
val id: Long,
/** User's first name **/
val firstName: Int,
@StringRes val firstName: Int,
/** User's last name **/
val lastName: Int,
@StringRes val lastName: Int,
/** User's email address **/
val email: Int,
@StringRes val email: Int,
/** User's avatar image resource id **/
@DrawableRes val avatar: Int
) {
/** User's full name **/
val fullName: String = "$firstName $lastName"
}
)
6 changes: 4 additions & 2 deletions app/src/main/java/com/example/reply/data/Email.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.example.reply.data

import androidx.annotation.StringRes

/**
* A simple data class to represent an Email
*/
Expand All @@ -26,9 +28,9 @@ data class Email(
/** Recipient(s) of the email **/
val recipients: List<Account> = emptyList(),
/** Title of the email **/
val subject: Int = -1,
@StringRes val subject: Int = -1,
/** Content of the email **/
val body: Int = -1,
@StringRes val body: Int = -1,
/** Which mailbox it is in **/
var mailbox: MailboxType = MailboxType.Inbox,
/**
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/reply/data/MailboxType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ package com.example.reply.data
*/
enum class MailboxType {
Inbox, Drafts, Sent, Spam
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ object LocalAccountsDataProvider {
return allUserContactAccounts.firstOrNull { it.id == accountId }
?: allUserContactAccounts.first()
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/reply/ui/ReplyApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ fun ReplyApp(
},
modifier = modifier
)
}
}
29 changes: 17 additions & 12 deletions app/src/main/java/com/example/reply/ui/ReplyDetailsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ import com.example.reply.data.MailboxType
@Composable
fun ReplyDetailsScreen(
replyUiState: ReplyUiState,
onBackPressed: () -> Unit,
modifier: Modifier = Modifier,
onBackPressed: () -> Unit = {},
isFullScreen: Boolean = false
) {
BackHandler {
Expand Down Expand Up @@ -83,10 +83,11 @@ fun ReplyDetailsScreen(
email = replyUiState.currentSelectedEmail,
mailboxType = replyUiState.currentMailbox,
isFullScreen = isFullScreen,
modifier = if (isFullScreen)
modifier = if (isFullScreen) {
Modifier.padding(horizontal = dimensionResource(R.dimen.detail_card_outer_padding_horizontal))
else
} else {
Modifier.padding(end = dimensionResource(R.dimen.detail_card_outer_padding_horizontal))
}
)
}
}
Expand Down Expand Up @@ -153,7 +154,9 @@ private fun ReplyEmailDetailsCard(
email,
Modifier.fillMaxWidth()
)
if (!isFullScreen) {
if (isFullScreen) {
Spacer(modifier = Modifier.height(dimensionResource(R.dimen.detail_content_padding_top)))
} else {
Text(
text = stringResource(email.subject),
style = MaterialTheme.typography.bodyMedium,
Expand All @@ -163,8 +166,6 @@ private fun ReplyEmailDetailsCard(
bottom = dimensionResource(R.dimen.detail_expanded_subject_body_spacing)
),
)
} else {
Spacer(modifier = Modifier.height(dimensionResource(R.dimen.detail_content_padding_top)))
}
Text(
text = stringResource(email.body),
Expand Down Expand Up @@ -245,7 +246,8 @@ private fun DetailsScreenHeader(email: Email, modifier: Modifier = Modifier) {
Row(modifier = modifier) {
ReplyProfileImage(
drawableResource = email.sender.avatar,
description = email.sender.fullName,
description = stringResource(email.sender.firstName) + " "
+ stringResource(email.sender.lastName),
modifier = Modifier.size(
dimensionResource(R.dimen.email_header_profile_size)
)
Expand Down Expand Up @@ -287,17 +289,20 @@ private fun ActionButton(
.padding(vertical = dimensionResource(R.dimen.detail_action_button_padding_vertical)),
colors = ButtonDefaults.buttonColors(
containerColor =
if (!containIrreversibleAction)
if (containIrreversibleAction) {
MaterialTheme.colorScheme.onErrorContainer
} else {
MaterialTheme.colorScheme.primaryContainer
else MaterialTheme.colorScheme.onErrorContainer
}
)
) {
Text(
text = text,
color =
if (!containIrreversibleAction)
color = if (containIrreversibleAction) {
MaterialTheme.colorScheme.onError
} else {
MaterialTheme.colorScheme.onSurfaceVariant
else MaterialTheme.colorScheme.onError
}
)
}
}
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/example/reply/ui/ReplyHomeContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ fun ReplyEmailListItem(
Card(
modifier = modifier,
colors = CardDefaults.cardColors(
containerColor = if (selected)
containerColor = if (selected) {
MaterialTheme.colorScheme.primaryContainer
else
} else {
MaterialTheme.colorScheme.secondaryContainer
}
),
onClick = onCardClick
) {
Expand Down Expand Up @@ -171,7 +172,8 @@ private fun ReplyEmailItemHeader(email: Email, modifier: Modifier = Modifier) {
Row(modifier = modifier) {
ReplyProfileImage(
drawableResource = email.sender.avatar,
description = email.sender.fullName,
description = stringResource(email.sender.firstName) + " "
+ stringResource(email.sender.lastName),
modifier = Modifier.size(dimensionResource(R.dimen.email_header_profile_size))
)
Column(
Expand Down
12 changes: 4 additions & 8 deletions app/src/main/java/com/example/reply/ui/ReplyHomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import androidx.compose.material.icons.filled.Drafts
import androidx.compose.material.icons.filled.Inbox
import androidx.compose.material.icons.filled.Report
import androidx.compose.material.icons.filled.Send
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
Expand All @@ -60,7 +59,6 @@ import com.example.reply.data.local.LocalAccountsDataProvider
import com.example.reply.ui.utils.ReplyContentType
import com.example.reply.ui.utils.ReplyNavigationType

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ReplyHomeScreen(
navigationType: ReplyNavigationType,
Expand Down Expand Up @@ -136,9 +134,9 @@ fun ReplyHomeScreen(
} else {
ReplyDetailsScreen(
replyUiState = replyUiState,
isFullScreen = true,
onBackPressed = onDetailScreenBackPressed,
modifier = modifier,
onBackPressed = onDetailScreenBackPressed
isFullScreen = true
)
}
}
Expand Down Expand Up @@ -190,8 +188,7 @@ private fun ReplyAppContent(
AnimatedVisibility(
visible = navigationType == ReplyNavigationType.BOTTOM_NAVIGATION
) {
val bottomNavigationContentDescription =
stringResource(R.string.navigation_bottom)
val bottomNavigationContentDescription = stringResource(R.string.navigation_bottom)
ReplyBottomNavigationBar(
currentTab = replyUiState.currentMailbox,
onTabPressed = onTabPressed,
Expand Down Expand Up @@ -252,7 +249,6 @@ private fun ReplyBottomNavigationBar(
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun NavigationDrawerContent(
selectedDestination: MailboxType,
Expand Down Expand Up @@ -313,4 +309,4 @@ private data class NavigationItemContent(
val mailboxType: MailboxType,
val icon: ImageVector,
val text: String
)
)
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/reply/ui/ReplyViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ class ReplyViewModel : ViewModel() {
)
}
}
}
}
1 change: 0 additions & 1 deletion app/src/main/java/com/example/reply/ui/theme/Color.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,3 @@ val md_theme_dark_inversePrimary = Color(0xFF006879)
val md_theme_dark_surfaceTint = Color(0xFF54D7F3)
val md_theme_dark_outlineVariant = Color(0xFF3F484B)
val md_theme_dark_scrim = Color(0xFF000000)

9 changes: 6 additions & 3 deletions app/src/main/java/com/example/reply/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ private val LightColorScheme = lightColorScheme(
scrim = md_theme_light_scrim,
)


private val DarkColorScheme = darkColorScheme(
primary = md_theme_dark_primary,
onPrimary = md_theme_dark_onPrimary,
Expand Down Expand Up @@ -105,7 +104,11 @@ fun ReplyTheme(
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
if (darkTheme) {
dynamicDarkColorScheme(context)
} else {
dynamicLightColorScheme(context)
}
}

darkTheme -> DarkColorScheme
Expand All @@ -125,4 +128,4 @@ fun ReplyTheme(
typography = Typography,
content = content
)
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/reply/ui/theme/Type.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ val Typography = Typography(
lineHeight = 24.sp,
letterSpacing = 0.5.sp
)
)
)
2 changes: 1 addition & 1 deletion app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
</adaptive-icon>
2 changes: 1 addition & 1 deletion app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
</adaptive-icon>
Loading

0 comments on commit 6ab9345

Please sign in to comment.