Skip to content

Commit

Permalink
Improve user consent dialog logic and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Nain57 committed Aug 15, 2024
1 parent 17c7e82 commit 4b386b8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal class UserConsentDataSource @Inject constructor() {
_isPrivacyOptionsRequired.value =
consentInfo.privacyOptionsRequirementStatus == ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED

Log.d(
Log.i(
TAG, "Updated user consent information, can request ads: ${consentInfo.canRequestAds()}, " +
"settings required: ${consentInfo.privacyOptionsRequirementStatus}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ internal class NewPurchaseManager @Inject constructor() {
return
}

if (purchase == null) return
if (purchase == null) {
Log.i(TAG, "Product purchase not yet available")
return
}

val purchaseState = purchase.purchaseState
if (purchaseState != Purchase.PurchaseState.PURCHASED) {
Expand All @@ -60,8 +63,13 @@ internal class NewPurchaseManager @Inject constructor() {

// If this is a new purchase, acknowledge it
if (!purchase.isAcknowledged) {
Log.i(TAG, "Product purchase state: PURCHASED")
_state.emit(InAppPurchaseState.PURCHASED)
if (ackQuery(purchase)) _state.emit(InAppPurchaseState.PURCHASED_AND_ACKNOWLEDGED)

if (ackQuery(purchase)) {
Log.i(TAG, "Product purchase state: PURCHASED_AND_ACKNOWLEDGED")
_state.emit(InAppPurchaseState.PURCHASED_AND_ACKNOWLEDGED)
}
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ internal class RevenueRepository @Inject constructor(
) { purchaseState, isConsentInit, consent ->
when {
purchaseState == InAppPurchaseState.PURCHASED -> UserConsentState.ADS_NOT_NEEDED
isConsentInit && consent -> UserConsentState.CAN_REQUEST_ADS
consent -> UserConsentState.CAN_REQUEST_ADS
isConsentInit && !consent -> UserConsentState.CANNOT_REQUEST_ADS
else -> UserConsentState.UNKNOWN
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class ScenarioViewModel @Inject constructor(
}

fun requestUserConsentIfNeeded(activity: Activity) {
revenueRepository.refreshPurchases()
revenueRepository.startUserConsentRequestUiFlowIfNeeded(activity)
}

Expand Down

0 comments on commit 4b386b8

Please sign in to comment.