Skip to content

Commit ef21d53

Browse files
feat: Display thank you message on purchase
I modified MainScreen (MenuScreen.kt) to display a "Thank you" message when the app has been purchased. Changes: - Added `isPurchased` parameter to `MenuScreen`. - `MainActivity` now passes the purchase status (`currentTrialState == TrialManager.TrialState.PURCHASED`) to `MenuScreen`. - In `MenuScreen`, if `isPurchased` is true, the donation button and related text are replaced with "Thank you for supporting the development! 🎉💛". - Added a new preview for the purchased state in `MenuScreen.kt`.
1 parent c687483 commit ef21d53

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

app/src/main/kotlin/com/google/ai/sample/MainActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ class MainActivity : ComponentActivity() {
400400
Log.d(TAG, "MenuScreen onDonationButtonClicked: Initiating subscription purchase.")
401401
initiateDonationPurchase()
402402
},
403-
isTrialExpired = currentTrialState == TrialManager.TrialState.EXPIRED_INTERNET_TIME_CONFIRMED
403+
isPurchased = (currentTrialState == TrialManager.TrialState.PURCHASED),
404+
isTrialExpired = currentTrialState == TrialManager.TrialState.EXPIRED_INTERNET_TIME_CONFIRMED
404405
)
405406
}
406407
composable("photo_reasoning") {

app/src/main/kotlin/com/google/ai/sample/MenuScreen.kt

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import androidx.compose.ui.Alignment
2424
import androidx.compose.ui.Modifier
2525
import androidx.compose.ui.platform.LocalContext
2626
import androidx.compose.ui.res.stringResource
27+
import androidx.compose.ui.text.style.TextAlign
2728
import androidx.compose.ui.tooling.preview.Preview
2829
import androidx.compose.ui.unit.dp
2930
import androidx.compose.foundation.text.ClickableText
@@ -46,7 +47,8 @@ fun MenuScreen(
4647
onItemClicked: (String) -> Unit = { },
4748
onApiKeyButtonClicked: () -> Unit = { },
4849
onDonationButtonClicked: () -> Unit = { },
49-
isTrialExpired: Boolean = false // New parameter to indicate trial status
50+
isTrialExpired: Boolean = false, // New parameter to indicate trial status
51+
isPurchased: Boolean = false
5052
) {
5153
val context = LocalContext.current
5254
val menuItems = listOf(
@@ -209,16 +211,25 @@ fun MenuScreen(
209211
.fillMaxWidth(),
210212
verticalAlignment = Alignment.CenterVertically
211213
) {
212-
Text(
213-
text = "Support more Features",
214-
style = MaterialTheme.typography.titleMedium,
215-
modifier = Modifier.weight(1f)
216-
)
217-
Button(
218-
onClick = onDonationButtonClicked, // This button should always be active
219-
modifier = Modifier.padding(start = 8.dp)
220-
) {
221-
Text(text = "Pro (2,90 €/Month)")
214+
if (isPurchased) {
215+
Text(
216+
text = "Thank you for supporting the development! 🎉💛",
217+
style = MaterialTheme.typography.titleMedium,
218+
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp),
219+
textAlign = TextAlign.Center
220+
)
221+
} else {
222+
Text(
223+
text = "Support more Features",
224+
style = MaterialTheme.typography.titleMedium,
225+
modifier = Modifier.weight(1f)
226+
)
227+
Button(
228+
onClick = onDonationButtonClicked,
229+
modifier = Modifier.padding(start = 8.dp)
230+
) {
231+
Text(text = "Pro (2,90 €/Month)")
232+
}
222233
}
223234
}
224235
}
@@ -268,13 +279,19 @@ fun MenuScreen(
268279
@Composable
269280
fun MenuScreenPreview() {
270281
// Preview with trial not expired
271-
MenuScreen(isTrialExpired = false)
282+
MenuScreen(isTrialExpired = false, isPurchased = false)
283+
}
284+
285+
@Preview(showSystemUi = true)
286+
@Composable
287+
fun MenuScreenPurchasedPreview() {
288+
MenuScreen(isTrialExpired = false, isPurchased = true)
272289
}
273290

274291
@Preview(showSystemUi = true)
275292
@Composable
276293
fun MenuScreenTrialExpiredPreview() {
277294
// Preview with trial expired
278-
MenuScreen(isTrialExpired = true)
295+
MenuScreen(isTrialExpired = true, isPurchased = false)
279296
}
280297

0 commit comments

Comments
 (0)