Skip to content

Commit

Permalink
#1 - Finishing touches!
Browse files Browse the repository at this point in the history
  • Loading branch information
jhg3410 committed Jan 22, 2023
1 parent 01f31e0 commit cf822a8
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 55 deletions.
8 changes: 5 additions & 3 deletions Basics_Codelab/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {

android {
namespace 'jik.compose.basicscodelab'
compileSdk 32
compileSdk 33

defaultConfig {
applicationId "jik.compose.basicscodelab"
minSdk 21
targetSdk 32
targetSdk 33
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -53,11 +53,13 @@ dependencies {
implementation 'androidx.activity:activity-compose:1.3.1'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.compose.material3:material3:1.0.0-alpha02'
implementation 'androidx.compose.material3:material3:1.1.0-alpha04'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"

implementation "androidx.compose.material:material-icons-extended:$compose_version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ExpandLess
import androidx.compose.material.icons.filled.ExpandMore
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -44,13 +48,6 @@ private fun MyApp(modifier: Modifier = Modifier) {
}
}

@Preview
@Composable
private fun MyAppPreview() {
BasicsCodelabTheme {
MyApp(Modifier.fillMaxSize())
}
}

@Composable
fun OnboardingScreen(
Expand All @@ -73,13 +70,6 @@ fun OnboardingScreen(
}
}

@Preview(showBackground = true, widthDp = 320, heightDp = 320)
@Composable
fun OnboardingPreview() {
BasicsCodelabTheme {
OnboardingScreen(onContinueClicked = {})
}
}

@Composable
private fun Greetings(
Expand All @@ -94,6 +84,82 @@ private fun Greetings(
}


@Composable
private fun Greeting(name: String) {
Card(
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.primary
),
modifier = Modifier.padding(vertical = 4.dp, horizontal = 8.dp)
) {
CardContent(name)
}
}


@Composable
private fun CardContent(name: String) {
var expanded by remember { mutableStateOf(false) }

Row(
modifier = Modifier
.padding(12.dp)
.animateContentSize(
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
)
)
) {
Column(
modifier = Modifier
.weight(1f)
.padding(12.dp)
) {
Text(text = "Hello,")
Text(
text = name, style = MaterialTheme.typography.headlineMedium.copy(
fontWeight = FontWeight.ExtraBold
)
)
if (expanded) {
Text(
text = ("Composem ipsum color sit lazy, " +
"padding theme elit, sed do bouncy. ").repeat(4)
)
}
}
IconButton(
onClick = { expanded = expanded.not() },
) {
Icon(
imageVector = if (expanded) Icons.Filled.ExpandLess else Icons.Filled.ExpandMore,
contentDescription = if (expanded) {
stringResource(id = R.string.show_less)
} else {
stringResource(id = R.string.show_more)
},
)
}
}
}

@Preview
@Composable
private fun MyAppPreview() {
BasicsCodelabTheme {
MyApp(Modifier.fillMaxSize())
}
}

@Preview(showBackground = true, widthDp = 320, heightDp = 320)
@Composable
fun OnboardingPreview() {
BasicsCodelabTheme {
OnboardingScreen(onContinueClicked = {})
}
}

@Preview(
showBackground = true,
widthDp = 320,
Expand All @@ -109,40 +175,4 @@ fun GreetingsPreview() {
BasicsCodelabTheme {
Greetings()
}
}

@Composable
fun Greeting(name: String) {
var expanded by remember { mutableStateOf(false) }

val extraPadding by animateDpAsState(
targetValue = if (expanded) 48.dp else 0.dp,
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
)
)

Surface(
color = MaterialTheme.colorScheme.primary,
modifier = Modifier.padding(vertical = 4.dp, horizontal = 8.dp)
) {
Row(modifier = Modifier.padding(24.dp)) {
Column(
modifier = Modifier
.weight(1f)
.padding(bottom = extraPadding.coerceAtLeast(0.dp))
) {
Text(text = "Hello,")
Text(
text = name, style = MaterialTheme.typography.headlineMedium.copy(
fontWeight = FontWeight.Bold
)
)
}
ElevatedButton(onClick = { expanded = expanded.not() }) {
Text(if (expanded) "Show less" else "Show more")
}
}
}
}
}
3 changes: 3 additions & 0 deletions Basics_Codelab/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<resources>
<string name="app_name">Basics Codelab</string>

<string name="show_less">Show less</string>
<string name="show_more">Show more</string>
</resources>

0 comments on commit cf822a8

Please sign in to comment.