Skip to content

Store offerings response in SharedPreferences#1028

Merged
tonidero merged 4 commits into
mainfrom
toniricodiez/sdk-3094-persist-offerings-cache-android-2
May 29, 2023
Merged

Store offerings response in SharedPreferences#1028
tonidero merged 4 commits into
mainfrom
toniricodiez/sdk-3094-persist-offerings-cache-android-2

Conversation

@tonidero

Copy link
Copy Markdown
Contributor

Description

This is the second PR in preparation of persisting offerings (SDK-3094). In this PR, we persist the backend response for offerings, but we aren't using it yet.

Main changes

  • Created OfferingsCache to abstract the caching logic for offerings and the offerings response
  • Extracted isStale helpers to extension functions so they can be used in the new offerings cache.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This currently lives in the default shared preferences... We probably want to think about having our own shared preferences file though, to avoid devs touching it accidentally.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah iOS defaults to a custom UserDefaults now.

@tonidero tonidero marked this pull request as ready for review May 26, 2023 13:13
@tonidero tonidero requested a review from a team May 26, 2023 13:13

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note that we aren't using this yet. Will use it in a followup PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note that in iOS, we added the response within the Offerings object. I thought about doing that, but due to our module setup, that would require to make it public. Didn't want to do that, so we need to keep them separate.

@codecov

codecov Bot commented May 26, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1028 (076228d) into main (50ae3dd) will increase coverage by 0.02%.
The diff coverage is 90.85%.

❗ Current head 076228d differs from pull request most recent head e767e1c. Consider uploading reports for the commit e767e1c to get more accurate results

@@            Coverage Diff             @@
##             main    #1028      +/-   ##
==========================================
+ Coverage   85.50%   85.52%   +0.02%     
==========================================
  Files         173      174       +1     
  Lines        6091     6087       -4     
  Branches      855      845      -10     
==========================================
- Hits         5208     5206       -2     
- Misses        547      548       +1     
+ Partials      336      333       -3     
Impacted Files Coverage Δ
...evenuecat/purchases/common/GoogleOfferingParser.kt 63.63% <ø> (ø)
.../com/revenuecat/purchases/OfferingParserFactory.kt 50.00% <ø> (ø)
...ava/com/revenuecat/purchases/utils/productStubs.kt 81.33% <ø> (-0.25%) ⬇️
...cat/purchases/common/offerings/OfferingsManager.kt 83.33% <83.33%> (-0.31%) ⬇️
...enuecat/purchases/common/caching/DateExtensions.kt 85.71% <85.71%> (ø)
...uecat/purchases/common/offerings/OfferingsCache.kt 92.30% <92.30%> (ø)
...cat/purchases/common/offerings/OfferingsFactory.kt 93.44% <93.44%> (ø)
...revenuecat/purchases/common/caching/DeviceCache.kt 95.83% <100.00%> (-0.28%) ⬇️
...m/revenuecat/purchases/identity/IdentityManager.kt 92.00% <100.00%> (+0.33%) ⬆️
.../main/kotlin/com/revenuecat/purchases/Purchases.kt 81.11% <100.00%> (ø)
... and 1 more

... and 7 files with indirect coverage changes

@NachoSoto NachoSoto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome 👏🏻

Comment thread common/src/main/java/com/revenuecat/purchases/common/caching/DateExtensions.kt Outdated
Comment thread common/src/main/java/com/revenuecat/purchases/common/caching/DateExtensions.kt Outdated
Comment thread common/src/main/java/com/revenuecat/purchases/common/caching/DateExtensions.kt Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah iOS defaults to a custom UserDefaults now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I really like this. I'd like to split DeviceCache in iOS as well so it's simply an implementation detail that we use in other cache classes like this one 👍🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is so much better 👏🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not for this PR, but with my idea of making DeviceCache agnostic of what it's caching, it would be nice for this to live in OfferingsCache. This is at least a step in the right direction.

Comment thread common/src/test/java/com/revenuecat/purchases/common/DeviceCacheTest.kt Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wish mocking in iOS was this easy :P

@NachoSoto NachoSoto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome 👏🏻

Base automatically changed from toniricodiez/sdk-3094-persist-offerings-cache-android to main May 29, 2023 08:22
@tonidero tonidero force-pushed the toniricodiez/sdk-3094-persist-offerings-cache-android-2 branch from 076228d to e767e1c Compare May 29, 2023 08:57
@tonidero tonidero enabled auto-merge (squash) May 29, 2023 08:58
@tonidero tonidero merged commit 3395b97 into main May 29, 2023
@tonidero tonidero deleted the toniricodiez/sdk-3094-persist-offerings-cache-android-2 branch May 29, 2023 09:15
tonidero added a commit that referenced this pull request May 29, 2023
### Description
Third and final part of persisting offerings in disk to make the system
more robust. In this final PR, we use the offerings response cached in
#1028 so, in case of a backend error getting offerings, we can calculate
the offerings (as long as Play store/Amazon store still give us the
product information) as long as we have cached the value before.
tonidero added a commit that referenced this pull request Jun 1, 2023
**This is an automatic release.**

### New Features
* Offline entitlements support (#1030) via Toni Rico (@tonidero)
### Bugfixes
* Fix billing connection error when querying purchases early in the
process lifetime (#1032) via Toni Rico (@tonidero)
### Performance Improvements
* Perform product entitlement mapping request after more critical
requests (#1017) via Toni Rico (@tonidero)
### Dependency Updates
* Bump fastlane from 2.212.2 to 2.213.0 (#1024) via dependabot[bot]
(@dependabot[bot])
### Other Changes
* Get offerings response from disk cache if available (#1029) via Toni
Rico (@tonidero)
* Improve offline entitlements logs to mention limitations of this mode
(#1039) via Toni Rico (@tonidero)
* Improve error message when backend returns internal error code (#1038)
via Toni Rico (@tonidero)
* PurchaseTester: Add new UI to configure internal proxy behavior
(#1016) via Toni Rico (@tonidero)
* Updated readme to include links to migration guides (#1021) via Marcos
Castany (@mcastany)
* Store offerings response in SharedPreferences (#1028) via Toni Rico
(@tonidero)
* Refactor offerings code out of Purchases (#1027) via Toni Rico
(@tonidero)

---------

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Co-authored-by: Toni Rico <antonio.rico.diez@revenuecat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants