-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Custom Entitlements Sample app (#1166)
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
Showing
8 changed files
with
338 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,4 @@ | |
</activity> | ||
</application> | ||
|
||
</manifest> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...omputationSample/app/src/main/java/com/revenuecat/sample/main/CustomerInfoDetailScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
} | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...ntComputationSample/app/src/main/java/com/revenuecat/sample/main/CustomerInfoEventList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
) | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...lementComputationSample/app/src/main/java/com/revenuecat/sample/main/ExplanationScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {}) | ||
} | ||
} |
Oops, something went wrong.