Skip to content

Commit

Permalink
Update Custom Entitlements Sample app (#1166)
Browse files Browse the repository at this point in the history
Adds quite a few things to the Custom Entitlements Sample app: 

- A tutorial mode that when tapped, provides an explanation for what the
mode does
- Displays the current app user ID at all times
- Moved the customer info JSON into its own view, such that the main
view shows a list of all the values that have been fired from the
listener

|  |  |  |
| :-: | :-: | :-: |
| <img width="402" alt="Screenshot 2023-07-21 at 5 54 21 PM"
src="https://github.com/RevenueCat/purchases-android/assets/3922667/18f72a28-8aee-4e2e-a6de-f56fe50c3095">
| <img width="407" alt="Screenshot 2023-07-21 at 5 54 09 PM"
src="https://github.com/RevenueCat/purchases-android/assets/3922667/d1d86378-d790-48ed-b3f9-3027553a874a">
| <img width="396" alt="Screenshot 2023-07-21 at 5 31 56 PM"
src="https://github.com/RevenueCat/purchases-android/assets/3922667/54cb9961-a568-4e44-9e1c-9eb813573a1a">
|
  • Loading branch information
aboedo authored Jul 21, 2023
1 parent 84685a0 commit 3a43a81
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
</activity>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.revenuecat.sample

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.revenuecat.sample.main.MainScreen
import com.revenuecat.sample.main.MainScreenNavigation
import com.revenuecat.sample.ui.theme.CustomEntitlementComputationTheme

@Composable
fun CustomEntitlementComputationApp() {
MainScreen()
MainScreenNavigation()
}

@Preview
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CustomerInfoDetailScreen(event: CustomerInfoEvent) {
Scaffold(
topBar = {
TopAppBar(
title = {
Text(text = "Customer Info Detail")
},
)
},
) {
Box(modifier = Modifier.padding(it)) {
Column(
modifier = Modifier
.fillMaxSize()
.background(color = Color.White),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Text(
text = event.customerInfo.rawData.toString(4),
modifier = Modifier.padding(16.dp)
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.revenuecat.purchases.CustomerInfo
import com.revenuecat.sample.ui.theme.CustomEntitlementComputationTheme
import org.json.JSONObject
import java.util.Date
import java.util.UUID

data class CustomerInfoEvent(
val date: Date = Date(),
val customerInfo: CustomerInfo,
val id: UUID = UUID.randomUUID(),
)

@Composable
fun CustomerInfoEventsList(events: List<CustomerInfoEvent>, onEventClicked: (CustomerInfoEvent) -> Unit) {
LazyColumn {
items(events) { event ->
CustomerInfoEventsListItem(event = event, onEventClicked = onEventClicked)
}
}
}

@Composable
fun CustomerInfoEventsListItem(event: CustomerInfoEvent, onEventClicked: (CustomerInfoEvent) -> Unit) {
Column(
modifier = Modifier
.clickable { onEventClicked(event) }
.padding(16.dp)
) {
Text(
text = buildAnnotatedString {
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("Fired at: ")
}
append(event.date.toString())
}
)
Spacer(modifier = Modifier.height(4.dp))
Text(
text = buildAnnotatedString {
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append("App User ID: ")
}
append(event.customerInfo.originalAppUserId)
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.revenuecat.sample.ui.theme.CustomEntitlementComputationTheme

@Composable
fun ExplanationScreen(onDismiss: () -> Unit) {
Surface(color = Color.White) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Custom Entitlements Mode",
style = MaterialTheme.typography.headlineSmall,
modifier = Modifier.padding(8.dp)
)

Text(
text = "This mode is intended for apps that will do their own entitlement " +
"computation, separate from RevenueCat.",
modifier = Modifier.padding(8.dp)
)

Text(
text = "In this mode, RevenueCat will not generate anonymous user IDs, " +
"it will not refresh customerInfo cache automatically " +
"(only when a purchase goes through), and it will disallow methods " +
"other than those for configuration, switching users, " +
"getting offerings and purchases.",
modifier = Modifier.padding(8.dp)
)

Text(
text = "Use switchUser to switch to a different App User ID if needed. " +
"The SDK should only be configured once the initial appUserID is known.",
modifier = Modifier.padding(8.dp)
)

Text(
text = "Apps using this mode rely on webhooks to signal their backends to " +
"refresh entitlements with RevenueCat.",
modifier = Modifier.padding(8.dp)
)

Spacer(modifier = Modifier.weight(1f, true))
Button(
onClick = onDismiss,
content = { Text("Close") }
)
}
}

}

@Preview
@Composable
fun ExplanationScreenPreview() {
CustomEntitlementComputationTheme {
ExplanationScreen(onDismiss = {})
}
}
Loading

0 comments on commit 3a43a81

Please sign in to comment.