Codelab updates

This commit is contained in:
Android dev 2023-05-01 19:23:11 -07:00
parent 43a9e25e24
commit 9e2aa0ad69
5 changed files with 14 additions and 26 deletions

View File

@ -65,18 +65,18 @@ android {
dependencies { dependencies {
implementation platform('androidx.compose:compose-bom:2023.01.00') implementation platform('androidx.compose:compose-bom:2023.04.01')
implementation 'androidx.activity:activity-compose:1.6.1' implementation 'androidx.activity:activity-compose:1.7.1'
implementation 'androidx.compose.material3:material3' implementation 'androidx.compose.material3:material3'
implementation 'androidx.compose.ui:ui' implementation 'androidx.compose.ui:ui'
implementation "androidx.compose.ui:ui-tooling" implementation "androidx.compose.ui:ui-tooling"
implementation 'androidx.compose.ui:ui-tooling-preview' implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.core:core-ktx:1.9.0' implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.0' implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation platform('androidx.compose:compose-bom:2023.01.00') androidTestImplementation platform('androidx.compose:compose-bom:2023.04.01')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4' androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.ext:junit:1.1.5'

View File

@ -31,8 +31,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
@ -48,11 +46,9 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
@ -96,7 +92,6 @@ fun TipTimeLayout() {
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center verticalArrangement = Arrangement.Center
) { ) {
val largePadding = 32.dp
Text( Text(
text = stringResource(R.string.calculate_tip), text = stringResource(R.string.calculate_tip),
modifier = Modifier modifier = Modifier
@ -110,12 +105,9 @@ fun TipTimeLayout() {
keyboardType = KeyboardType.Number, keyboardType = KeyboardType.Number,
imeAction = ImeAction.Next imeAction = ImeAction.Next
), ),
keyboardActions = KeyboardActions(
onNext = { focusManager.moveFocus(FocusDirection.Down) }
),
value = amountInput, value = amountInput,
onValueChanged = { amountInput = it }, onValueChanged = { amountInput = it },
modifier = Modifier.padding(bottom = largePadding).fillMaxWidth(), modifier = Modifier.padding(bottom = 32.dp).fillMaxWidth(),
) )
EditNumberField( EditNumberField(
label = R.string.how_was_the_service, label = R.string.how_was_the_service,
@ -124,17 +116,14 @@ fun TipTimeLayout() {
keyboardType = KeyboardType.Number, keyboardType = KeyboardType.Number,
imeAction = ImeAction.Done imeAction = ImeAction.Done
), ),
keyboardActions = KeyboardActions(
onDone = { focusManager.clearFocus() }
),
value = tipInput, value = tipInput,
onValueChanged = { tipInput = it }, onValueChanged = { tipInput = it },
modifier = Modifier.padding(bottom = largePadding).fillMaxWidth(), modifier = Modifier.padding(bottom = 32.dp).fillMaxWidth(),
) )
RoundTheTipRow( RoundTheTipRow(
roundUp = roundUp, roundUp = roundUp,
onRoundUpChanged = { roundUp = it }, onRoundUpChanged = { roundUp = it },
modifier = Modifier.padding(bottom = largePadding) modifier = Modifier.padding(bottom = 32.dp)
) )
Text( Text(
text = stringResource(R.string.tip_amount, tip), text = stringResource(R.string.tip_amount, tip),
@ -149,7 +138,6 @@ fun EditNumberField(
@StringRes label: Int, @StringRes label: Int,
@DrawableRes leadingIcon: Int, @DrawableRes leadingIcon: Int,
keyboardOptions: KeyboardOptions, keyboardOptions: KeyboardOptions,
keyboardActions: KeyboardActions,
value: String, value: String,
onValueChanged: (String) -> Unit, onValueChanged: (String) -> Unit,
modifier: Modifier = Modifier modifier: Modifier = Modifier
@ -159,11 +147,9 @@ fun EditNumberField(
singleLine = true, singleLine = true,
leadingIcon = { Icon(painter = painterResource(id = leadingIcon), null) }, leadingIcon = { Icon(painter = painterResource(id = leadingIcon), null) },
modifier = modifier, modifier = modifier,
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),
onValueChange = onValueChanged, onValueChange = onValueChanged,
label = { Text(stringResource(label)) }, label = { Text(stringResource(label)) },
keyboardOptions = keyboardOptions, keyboardOptions = keyboardOptions
keyboardActions = keyboardActions
) )
} }

View File

@ -21,7 +21,7 @@ buildscript {
} }
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins { plugins {
id 'com.android.application' version '7.4.2' apply false id 'com.android.application' version '8.0.0' apply false
id 'com.android.library' version '7.4.2' apply false id 'com.android.library' version '8.0.0' apply false
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
} }

View File

@ -21,3 +21,5 @@ kotlin.code.style=official
# resources declared in the library itself and none from the library's dependencies, # resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library # thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false

View File

@ -1,6 +1,6 @@
#Fri Nov 12 13:07:13 PST 2021 #Fri Nov 12 13:07:13 PST 2021
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME