Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Custom Entitlements Sample app #1166

Merged

Conversation

aboedo
Copy link
Member

@aboedo aboedo commented Jul 21, 2023

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
Screenshot 2023-07-21 at 5 54 21 PM Screenshot 2023-07-21 at 5 54 09 PM Screenshot 2023-07-21 at 5 31 56 PM

@aboedo aboedo self-assigned this Jul 21, 2023
Comment on lines 76 to 79
implementation platform('androidx.compose:compose-bom:2022.10.00')
implementation 'androidx.compose.ui:ui-tooling-preview'
androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol what

Android studio's auto suggestions are bonkers, reverting this bit

Comment on lines 16 to 20
<activity
android:name=".main.ExplanationScreen"
android:exported="false"
android:label="@string/title_activity_explanation_screen"
android:theme="@style/Theme.CustomEntitlementComputationSample" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also an accident, reverting this bit


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CustomerInfoDetailScreen(event: CustomerInfoEvent) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shows the customer info as JSON

}

@Composable
fun CustomerInfoEventsListItem(event: CustomerInfoEvent, onEventClicked: (CustomerInfoEvent) -> Unit) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shows a list of all customer info values that have been fired from the delegate

import com.revenuecat.sample.ui.theme.CustomEntitlementComputationTheme

@Composable
fun ExplanationScreen(onDismiss: () -> Unit) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shows an explanation for what this mode is

Comment on lines 62 to 71
val navController = rememberNavController()
NavHost(navController, startDestination = "main") {
composable("main") { MainScreen(navController = navController) }
composable("customerInfoDetails/{date}") { backStackEntry ->
CustomerInfoDetailScreen(event = uiState.value.customerInfoList.find {
it.date.toString() == backStackEntry.arguments?.getString("date")
}!!)
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nav controller here is useful for being able to navigate in and out of customer info details


@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
class MainViewModel : ViewModel() {
private val previewMode = false // change this to true to be able to preview in Android Studio
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise, when we init using methods from Purchases, the preview crashes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right... I guess alternative we could move that code to an initialize method or setUpListener... But we can go with this for now.

@@ -1,3 +1,4 @@
<resources>
<string name="app_name">CustomEntitlementComputationSample</string>
<string name="title_activity_explanation_screen">ExplanationScreen</string>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another one to revert

@aboedo aboedo added the pr:feat A new feature label Jul 21, 2023
@aboedo aboedo marked this pull request as ready for review July 21, 2023 20:57
@aboedo aboedo requested review from joshdholtz and a team July 21, 2023 20:57
Comment on lines +148 to +153
Text(
text = "Tap here for more details about this mode.",
modifier = Modifier
.padding(16.dp),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried like 15 things to center the text here but Compose didn't want it centered ¯_(ツ)_/¯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I see these Text are under a Column. Not sure if you tried Column(modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally ) or something like that?

@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Merging #1166 (231a608) into main (84685a0) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #1166   +/-   ##
=======================================
  Coverage   85.59%   85.59%           
=======================================
  Files         179      179           
  Lines        6121     6121           
  Branches      918      918           
=======================================
  Hits         5239     5239           
  Misses        540      540           
  Partials      342      342           

Copy link
Member

@joshdholtz joshdholtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good to me 😇

@aboedo aboedo merged commit 3a43a81 into main Jul 21, 2023
@aboedo aboedo deleted the andy/sdk-3239-create-lazycolumn-with-stream-of-customerinfo-updates branch July 21, 2023 21:40
Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments but nothing blocking. Looks good!

Comment on lines +148 to +153
Text(
text = "Tap here for more details about this mode.",
modifier = Modifier
.padding(16.dp),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I see these Text are under a Column. Not sure if you tried Column(modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally ) or something like that?

import com.revenuecat.sample.utils.findActivity

@Composable
fun MainScreen() {
fun MainScreenNavigation() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but would be worth extracting the navigation to its own file.

val offerings: Offerings? = null,
val currentAppUserID: String = Constants.defaultAppUserID,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make it nullable here, so we make sure the user id comes from RC?


@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
class MainViewModel : ViewModel() {
private val previewMode = false // change this to true to be able to preview in Android Studio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right... I guess alternative we could move that code to an initialize method or setUpListener... But we can go with this for now.

@@ -51,6 +56,7 @@ class MainViewModel : ViewModel() {

fun switchUser(newUserID: String) {
Purchases.sharedInstance.switchUser(newUserID)
_uiState.update { it.copy(currentAppUserID = newUserID) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to help debugging, should we update it to Purchases.sharedInstance.appUserID here instead?

@@ -86,6 +92,23 @@ class MainViewModel : ViewModel() {
}

private fun updateCustomerInfoInformation(customerInfo: CustomerInfo) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FFTI. This could be renamed to updateUIState

aboedo added a commit that referenced this pull request Jul 24, 2023
**This is an automatic release.**

### New Features

Introduced Custom Entitlements Computation mode. 

This is new library intended for apps that will do their own entitlement
computation separate from RevenueCat. It's distributed as a separate
artifact in Maven.

Apps using this mode rely on webhooks to signal their backends to
refresh entitlements with RevenueCat.

See the [demo app for an example and usage
instructions](https://github.com/RevenueCat/purchases-android/tree/main/examples/CustomEntitlementComputationSample).

* Custom entitlements: add README and other improvements (#1167) via
Andy Boedo (@aboedo)
* Update Custom Entitlements Sample app (#1166) via Andy Boedo (@aboedo)
* purchase coroutine (#1142) via Andy Boedo (@aboedo)
* Add switchUser (#1156) via Cesar de la Vega (@vegaro)
* CustomEntitlementsComputation: disable first listener callback when
set (#1152) via Andy Boedo (@aboedo)
* CustomEntitlementsComputation: Prevent posting subscriber attributes
in post receipt (#1151) via Andy Boedo (@aboedo)
* Fix `customEntitlementComputation` library deployment (#1169) via Toni
Rico (@tonidero)
* CustomEntitlementComputation: Configure method for
customEntitlementComputation mode (#1168) via Toni Rico (@tonidero)
* Add publish system for customEntitlementComputation package (#1149)
via Cesar de la Vega (@vegaro)
* Use purchase coroutine in CustomEntitlementComputationSample (#1162)
via Cesar de la Vega (@vegaro)
* Adds CustomEntitlementComputationSample (#1160) via Cesar de la Vega
(@vegaro)
* Fix tests in customEntitlementComputation after merges (#1161) via
Toni Rico (@tonidero)
* CustomEntitlementComputation: Remove custom entitlement computation
flavor for amazon module (#1158) via Toni Rico (@tonidero)
* CustomEntitlementComputation: Generate dokka docs only for defaults
flavor (#1159) via Toni Rico (@tonidero)
* CustomEntitlementComputation: Create different PurchasesConfiguration
that requires an appUserId parameter (#1154) via Toni Rico (@tonidero)
* CustomEntitlementComputation: New Purchases class (#1153) via Toni
Rico (@tonidero)
* CustomEntitlementComputation: Disable automatic cache refresh (#1157)
via Toni Rico (@tonidero)
* Add `customEntitlementComputation` flavor (#1147) via Toni Rico
(@tonidero)
* Make `customEntitlementComputation` singular (#1148) via Toni Rico
(@tonidero)
* Disable offline entitlements in custom entitlements computation mode
(#1146) via Toni Rico (@tonidero)
* Remove integration test flavor (#1143) via Toni Rico (@tonidero)
* Add header to requests when in custom entitlement computation mode
(#1145) via Toni Rico (@tonidero)
* Add internal customEntitlementsComputation mode to app config (#1141)
via Toni Rico (@tonidero)

### New Coroutines
* `awaitPurchase` is available as a coroutine-friendly alternative to
`purchase()`. (#1142) via Andy Boedo (@aboedo)

### Dependency Updates
* Bump fastlane from 2.213.0 to 2.214.0 (#1140) via dependabot[bot]
(@dependabot[bot])

### Other changes
* CI: make all Codecov jobs informational (#1155) via Cesar de la Vega
(@vegaro)
* Creates PurchasesOrchestrator (#1144) via Cesar de la Vega (@vegaro)

---------

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Co-authored-by: Andy Boedo <andresboedo@gmail.com>
tonidero pushed a commit that referenced this pull request Jul 25, 2023
### New Features

Introduced Custom Entitlements Computation mode. 

This is new library intended for apps that will do their own entitlement
computation separate from RevenueCat. It's distributed as a separate
artifact in Maven.

Apps using this mode rely on webhooks to signal their backends to
refresh entitlements with RevenueCat.

See the [demo app for an example and usage
instructions](https://github.com/RevenueCat/purchases-android/tree/main/examples/CustomEntitlementComputationSample).

* Custom entitlements: add README and other improvements (#1167) via
Andy Boedo (@aboedo)
* Update Custom Entitlements Sample app (#1166) via Andy Boedo (@aboedo)
* purchase coroutine (#1142) via Andy Boedo (@aboedo)
* Add switchUser (#1156) via Cesar de la Vega (@vegaro)
* CustomEntitlementsComputation: disable first listener callback when
set (#1152) via Andy Boedo (@aboedo)
* CustomEntitlementsComputation: Prevent posting subscriber attributes
in post receipt (#1151) via Andy Boedo (@aboedo)
* Fix `customEntitlementComputation` library deployment (#1169) via Toni
Rico (@tonidero)
* CustomEntitlementComputation: Configure method for
customEntitlementComputation mode (#1168) via Toni Rico (@tonidero)
* Add publish system for customEntitlementComputation package (#1149)
via Cesar de la Vega (@vegaro)
* Use purchase coroutine in CustomEntitlementComputationSample (#1162)
via Cesar de la Vega (@vegaro)
* Adds CustomEntitlementComputationSample (#1160) via Cesar de la Vega
(@vegaro)
* Fix tests in customEntitlementComputation after merges (#1161) via
Toni Rico (@tonidero)
* CustomEntitlementComputation: Remove custom entitlement computation
flavor for amazon module (#1158) via Toni Rico (@tonidero)
* CustomEntitlementComputation: Generate dokka docs only for defaults
flavor (#1159) via Toni Rico (@tonidero)
* CustomEntitlementComputation: Create different PurchasesConfiguration
that requires an appUserId parameter (#1154) via Toni Rico (@tonidero)
* CustomEntitlementComputation: New Purchases class (#1153) via Toni
Rico (@tonidero)
* CustomEntitlementComputation: Disable automatic cache refresh (#1157)
via Toni Rico (@tonidero)
* Add `customEntitlementComputation` flavor (#1147) via Toni Rico
(@tonidero)
* Make `customEntitlementComputation` singular (#1148) via Toni Rico
(@tonidero)
* Disable offline entitlements in custom entitlements computation mode
(#1146) via Toni Rico (@tonidero)
* Remove integration test flavor (#1143) via Toni Rico (@tonidero)
* Add header to requests when in custom entitlement computation mode
(#1145) via Toni Rico (@tonidero)
* Add internal customEntitlementsComputation mode to app config (#1141)
via Toni Rico (@tonidero)

### New Coroutines
* `awaitPurchase` is available as a coroutine-friendly alternative to
`purchase()`. (#1142) via Andy Boedo (@aboedo)

### Dependency Updates
* Bump fastlane from 2.213.0 to 2.214.0 (#1140) via dependabot[bot]
(@dependabot[bot])

### Other changes
* CI: make all Codecov jobs informational (#1155) via Cesar de la Vega
(@vegaro)
* Creates PurchasesOrchestrator (#1144) via Cesar de la Vega (@vegaro)

---------

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Co-authored-by: Andy Boedo <andresboedo@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:feat A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants