Skip to content

Commit

Permalink
Extract string resource and some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikarora committed Apr 18, 2023
1 parent c5377d9 commit b6d8fbd
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class HomeActivity : ComponentActivity() {
paddingValues = paddingValues
) { destination ->
when (destination) {
Destination.Home,
Destination.CustomActionIntentChooser,
Destination.RegionalPrefs,
Destination.SelectedPhotoAccess -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
)
Expand All @@ -72,7 +75,7 @@ fun IntentChooserScreen(
openChooser = true
}
) {
Text(text = "Share an image")
Text(text = stringResource(R.string.share_an_image_button_title))
}
}
}
Expand All @@ -81,7 +84,7 @@ fun IntentChooserScreen(
@Composable
fun BackLightPreview() {
Android14Theme {
SetupM3Scaffold(Destination.BackGesture) { paddingValues ->
SetupM3Scaffold(Destination.CustomActionIntentChooser) { paddingValues ->
IntentChooserScreen(paddingValues)
}
}
Expand All @@ -92,7 +95,7 @@ fun BackLightPreview() {
@Composable
fun BackDarkPreview() {
Android14Theme(useDarkTheme = true) {
SetupM3Scaffold(Destination.BackGesture) { paddingValues ->
SetupM3Scaffold(Destination.CustomActionIntentChooser) { paddingValues ->
IntentChooserScreen(paddingValues)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ 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
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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -85,7 +87,7 @@ fun PickerScreen(
)
}
) {
Text(text = "Launch photo picker")
Text(text = stringResource(R.string.media_picker_photo_picker_button_title))
}

if (showImagesFromContentResolver) {
Expand Down Expand Up @@ -116,7 +118,7 @@ fun PickerScreen(
@Composable
fun BackLightPreview() {
Android14Theme {
SetupM3Scaffold(Destination.BackGesture) { paddingValues ->
SetupM3Scaffold(Destination.SelectedPhotoAccess) { paddingValues ->
PickerScreen(paddingValues)
}
}
Expand All @@ -127,7 +129,7 @@ fun BackLightPreview() {
@Composable
fun BackDarkPreview() {
Android14Theme(useDarkTheme = true) {
SetupM3Scaffold(Destination.BackGesture) { paddingValues ->
SetupM3Scaffold(Destination.SelectedPhotoAccess) { paddingValues ->
PickerScreen(paddingValues)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@

<string name="word">Waiter/Waitress</string>
<string name="sentence">The restaurant is hiring a new waiter/waitress for the busy season.</string>
<string name="back_gesture_title">Do the back gesture, come on. Don\'t be shy.</string>
<string name="share_an_image_button_title">Share an image</string>
<string name="custom_action_intent_query">How cool is this!</string>
<string name="intent_chooser_extra">Android 14 Demo Share</string>
<string name="intent_chooser_title">Share via</string>
<string name="image_mimetype">image/*</string>
<string name="grammer_api_word_title">Word</string>
<string name="grammar_api_sentence_title">Sentence</string>
<string name="media_picker_permission_button_title">Launch permission dialog</string>
<string name="media_picker_photo_picker_button_title">Launch photo picker</string>
</resources>
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/AndroidConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b6d8fbd

Please sign in to comment.