From b6d8fbd8e0e0ef1c6eb5cb843805a8205b8004ba Mon Sep 17 00:00:00 2001 From: Kartik Arora Date: Wed, 19 Apr 2023 08:58:44 +1000 Subject: [PATCH] Extract string resource and some cleanup --- .../android14/activities/HomeActivity.kt | 1 + .../screens/backgesture/BackGestureScreen.kt | 4 +++- .../screens/chooser/IntentChoserScreen.kt | 17 ++++++++------ .../screens/grammar/GrammarScreen.kt | 10 +++++---- .../android14/screens/home/HomeScreen.kt | 17 +------------- .../screens/mediapicker/PickerScreen.kt | 10 +++++---- .../android14/ui/composables/ButtonForDemo.kt | 22 +++++++++++++++++++ app/src/main/res/values/strings.xml | 10 +++++++++ buildSrc/src/main/kotlin/AndroidConfig.kt | 2 +- 9 files changed, 60 insertions(+), 33 deletions(-) create mode 100644 app/src/main/kotlin/me/kartikarora/android14/ui/composables/ButtonForDemo.kt diff --git a/app/src/main/kotlin/me/kartikarora/android14/activities/HomeActivity.kt b/app/src/main/kotlin/me/kartikarora/android14/activities/HomeActivity.kt index ae6304b..979755d 100644 --- a/app/src/main/kotlin/me/kartikarora/android14/activities/HomeActivity.kt +++ b/app/src/main/kotlin/me/kartikarora/android14/activities/HomeActivity.kt @@ -36,6 +36,7 @@ class HomeActivity : ComponentActivity() { paddingValues = paddingValues ) { destination -> when (destination) { + Destination.Home, Destination.CustomActionIntentChooser, Destination.RegionalPrefs, Destination.SelectedPhotoAccess -> { diff --git a/app/src/main/kotlin/me/kartikarora/android14/screens/backgesture/BackGestureScreen.kt b/app/src/main/kotlin/me/kartikarora/android14/screens/backgesture/BackGestureScreen.kt index 9992a77..59719e7 100644 --- a/app/src/main/kotlin/me/kartikarora/android14/screens/backgesture/BackGestureScreen.kt +++ b/app/src/main/kotlin/me/kartikarora/android14/screens/backgesture/BackGestureScreen.kt @@ -9,9 +9,11 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import me.kartikarora.android14.R import me.kartikarora.android14.nav.Destination import me.kartikarora.android14.ui.composables.SetupM3Scaffold import me.kartikarora.android14.ui.theme.Android14Theme @@ -34,7 +36,7 @@ fun BackGestureScreen(paddingValues: PaddingValues) { .fillMaxSize() .wrapContentHeight(), textAlign = TextAlign.Center, - text = "Do the back gesture, come on. Don't be shy.", + text = stringResource(R.string.back_gesture_title), style = MaterialTheme.typography.titleLarge ) } diff --git a/app/src/main/kotlin/me/kartikarora/android14/screens/chooser/IntentChoserScreen.kt b/app/src/main/kotlin/me/kartikarora/android14/screens/chooser/IntentChoserScreen.kt index 0520429..5561055 100644 --- a/app/src/main/kotlin/me/kartikarora/android14/screens/chooser/IntentChoserScreen.kt +++ b/app/src/main/kotlin/me/kartikarora/android14/screens/chooser/IntentChoserScreen.kt @@ -45,9 +45,9 @@ fun IntentChooserScreen( with(LocalContext.current) { val chooserIntent = Intent.createChooser( Intent(Intent.ACTION_SEND) - .setType("image/*") - .putExtra(Intent.EXTRA_TEXT, "Android 14 Demo Share"), - "Share via" + .setType(stringResource(R.string.image_mimetype)) + .putExtra(Intent.EXTRA_TEXT, stringResource(R.string.intent_chooser_extra)), + stringResource(R.string.intent_chooser_title) ).apply { val customAction = ChooserAction.Builder( Icon.createWithResource(this@with, R.drawable.baseline_android), @@ -56,7 +56,10 @@ fun IntentChooserScreen( this@with, 1234, Intent(Intent.ACTION_WEB_SEARCH).apply { - putExtra(SearchManager.QUERY, "How cool is this!") + putExtra( + SearchManager.QUERY, + stringResource(R.string.custom_action_intent_query) + ) }, PendingIntent.FLAG_IMMUTABLE ) @@ -72,7 +75,7 @@ fun IntentChooserScreen( openChooser = true } ) { - Text(text = "Share an image") + Text(text = stringResource(R.string.share_an_image_button_title)) } } } @@ -81,7 +84,7 @@ fun IntentChooserScreen( @Composable fun BackLightPreview() { Android14Theme { - SetupM3Scaffold(Destination.BackGesture) { paddingValues -> + SetupM3Scaffold(Destination.CustomActionIntentChooser) { paddingValues -> IntentChooserScreen(paddingValues) } } @@ -92,7 +95,7 @@ fun BackLightPreview() { @Composable fun BackDarkPreview() { Android14Theme(useDarkTheme = true) { - SetupM3Scaffold(Destination.BackGesture) { paddingValues -> + SetupM3Scaffold(Destination.CustomActionIntentChooser) { paddingValues -> IntentChooserScreen(paddingValues) } } diff --git a/app/src/main/kotlin/me/kartikarora/android14/screens/grammar/GrammarScreen.kt b/app/src/main/kotlin/me/kartikarora/android14/screens/grammar/GrammarScreen.kt index 00ce51b..d348db3 100644 --- a/app/src/main/kotlin/me/kartikarora/android14/screens/grammar/GrammarScreen.kt +++ b/app/src/main/kotlin/me/kartikarora/android14/screens/grammar/GrammarScreen.kt @@ -12,9 +12,11 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel +import me.kartikarora.android14.R import me.kartikarora.android14.nav.Destination import me.kartikarora.android14.ui.composables.SetupM3Scaffold import me.kartikarora.android14.ui.composables.ToggleButton @@ -74,23 +76,23 @@ fun GrammarScreen( item { Text( style = MaterialTheme.typography.titleLarge, - text = "Word" + text = stringResource(R.string.grammer_api_word_title) ) Spacer(modifier = Modifier.height(8.dp)) Text( modifier = Modifier.fillMaxWidth(), - style = MaterialTheme.typography.bodyMedium, + style = MaterialTheme.typography.bodyLarge, text = word, ) Spacer(modifier = Modifier.height(32.dp)) Text( style = MaterialTheme.typography.titleLarge, - text = "Sentence" + text = stringResource(R.string.grammar_api_sentence_title) ) Spacer(modifier = Modifier.height(8.dp)) Text( modifier = Modifier.fillMaxWidth(), - style = MaterialTheme.typography.bodyMedium, + style = MaterialTheme.typography.bodyLarge, text = sentence ) } diff --git a/app/src/main/kotlin/me/kartikarora/android14/screens/home/HomeScreen.kt b/app/src/main/kotlin/me/kartikarora/android14/screens/home/HomeScreen.kt index ef691ef..671bddf 100644 --- a/app/src/main/kotlin/me/kartikarora/android14/screens/home/HomeScreen.kt +++ b/app/src/main/kotlin/me/kartikarora/android14/screens/home/HomeScreen.kt @@ -2,12 +2,9 @@ package me.kartikarora.android14.screens.home import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.FilledTonalButton -import androidx.compose.material3.Text import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier @@ -15,6 +12,7 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import me.kartikarora.android14.nav.Destination +import me.kartikarora.android14.ui.composables.ButtonForDemoOf import me.kartikarora.android14.ui.composables.SetupM3Scaffold import me.kartikarora.android14.ui.theme.Android14Theme @@ -46,19 +44,6 @@ fun HomeScreen( } } -@Composable -fun ButtonForDemoOf( - destination: Destination, - onClick: (Destination) -> Unit -) { - FilledTonalButton( - modifier = Modifier.fillMaxWidth(), - onClick = { onClick.invoke(destination) } - ) { - Text(text = destination.title) - } -} - @Preview @Composable diff --git a/app/src/main/kotlin/me/kartikarora/android14/screens/mediapicker/PickerScreen.kt b/app/src/main/kotlin/me/kartikarora/android14/screens/mediapicker/PickerScreen.kt index 6b6336b..d9f5ce9 100644 --- a/app/src/main/kotlin/me/kartikarora/android14/screens/mediapicker/PickerScreen.kt +++ b/app/src/main/kotlin/me/kartikarora/android14/screens/mediapicker/PickerScreen.kt @@ -24,9 +24,11 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import coil.compose.AsyncImage +import me.kartikarora.android14.R import me.kartikarora.android14.activities.HomeActivity import me.kartikarora.android14.nav.Destination import me.kartikarora.android14.ui.composables.SetupM3Scaffold @@ -72,7 +74,7 @@ fun PickerScreen( ) } ) { - Text(text = "Launch permission dialog") + Text(text = stringResource(R.string.media_picker_permission_button_title)) } Spacer(modifier = Modifier.size(8.dp)) Button( @@ -85,7 +87,7 @@ fun PickerScreen( ) } ) { - Text(text = "Launch photo picker") + Text(text = stringResource(R.string.media_picker_photo_picker_button_title)) } if (showImagesFromContentResolver) { @@ -116,7 +118,7 @@ fun PickerScreen( @Composable fun BackLightPreview() { Android14Theme { - SetupM3Scaffold(Destination.BackGesture) { paddingValues -> + SetupM3Scaffold(Destination.SelectedPhotoAccess) { paddingValues -> PickerScreen(paddingValues) } } @@ -127,7 +129,7 @@ fun BackLightPreview() { @Composable fun BackDarkPreview() { Android14Theme(useDarkTheme = true) { - SetupM3Scaffold(Destination.BackGesture) { paddingValues -> + SetupM3Scaffold(Destination.SelectedPhotoAccess) { paddingValues -> PickerScreen(paddingValues) } } diff --git a/app/src/main/kotlin/me/kartikarora/android14/ui/composables/ButtonForDemo.kt b/app/src/main/kotlin/me/kartikarora/android14/ui/composables/ButtonForDemo.kt new file mode 100644 index 0000000..24e75f5 --- /dev/null +++ b/app/src/main/kotlin/me/kartikarora/android14/ui/composables/ButtonForDemo.kt @@ -0,0 +1,22 @@ +package me.kartikarora.android14.ui.composables + +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material3.FilledTonalButton +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import me.kartikarora.android14.nav.Destination + + +@Composable +fun ButtonForDemoOf( + destination: Destination, + onClick: (Destination) -> Unit +) { + FilledTonalButton( + modifier = Modifier.fillMaxWidth(), + onClick = { onClick.invoke(destination) } + ) { + Text(text = destination.title) + } +} \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4338271..bc3749c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,4 +17,14 @@ Waiter/Waitress The restaurant is hiring a new waiter/waitress for the busy season. + Do the back gesture, come on. Don\'t be shy. + Share an image + How cool is this! + Android 14 Demo Share + Share via + image/* + Word + Sentence + Launch permission dialog + Launch photo picker \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/AndroidConfig.kt b/buildSrc/src/main/kotlin/AndroidConfig.kt index dc6acaf..e8d5e48 100644 --- a/buildSrc/src/main/kotlin/AndroidConfig.kt +++ b/buildSrc/src/main/kotlin/AndroidConfig.kt @@ -3,7 +3,7 @@ object AndroidConfig { const val CompileSdk = "UpsideDownCake" const val MinSdk = "UpsideDownCake" const val TargetSdk = "UpsideDownCake" - const val VersionName = "0.1.0" + const val VersionName = "0.2.0" const val Namespace = "me.kartikarora.android14" const val KotlinCompilerExtensionVersion = "1.4.1" const val BuildTools = "34.0.0 rc3"