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

refactor: minor Kt code cleanup #2886

Merged
merged 8 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 23 additions & 41 deletions android/src/amazon/java/com/dooboolab/rniap/RNIapAmazonModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,46 +57,30 @@ class RNIapAmazonModule(

@ReactMethod
fun verifyLicense(promise: Promise) {
if (BuildConfig.IS_AMAZON_DRM_ENABLED) {
Log.d(TAG, "Amazon's DRM is enabled")
try {
LicensingService.verifyLicense(reactApplicationContext) { licenseResponse ->
when (
val status: LicenseResponse.RequestStatus =
licenseResponse.requestStatus
) {
LicenseResponse.RequestStatus.LICENSED -> {
Log.d(TAG, "LicenseResponse status: $status")
promise.resolve("LICENSED")
}
LicenseResponse.RequestStatus.NOT_LICENSED -> {
Log.d(TAG, "LicenseResponse status: $status")
promise.resolve("NOT_LICENSED")
}
LicenseResponse.RequestStatus.EXPIRED -> {
Log.d(TAG, "LicenseResponse status: $status")
promise.resolve("EXPIRED")
}
LicenseResponse.RequestStatus.ERROR_VERIFICATION -> {
Log.d(TAG, "LicenseResponse status: $status")
promise.resolve("ERROR_VERIFICATION")
}
LicenseResponse.RequestStatus.ERROR_INVALID_LICENSING_KEYS -> {
Log.d(TAG, "LicenseResponse status: $status")
promise.resolve("ERROR_INVALID_LICENSING_KEYS")
}
LicenseResponse.RequestStatus.UNKNOWN_ERROR -> {
Log.d(TAG, "LicenseResponse status: $status")
promise.resolve("UNKNOWN_ERROR")
}
}
}
} catch (exception: Exception) {
promise.reject("Error while attempting to check for License", exception)
}
} else {
if (!BuildConfig.IS_AMAZON_DRM_ENABLED) {
Log.d(TAG, "Amazon's DRM is disabled")
promise.resolve("NOT_LICENSED")
return
}

Log.d(TAG, "Amazon's DRM is enabled")
try {
LicensingService.verifyLicense(reactApplicationContext) { licenseResponse ->
val status = licenseResponse.requestStatus.also {
Log.d(TAG, "LicenseResponse status: $it")
}
when (status) {
LicenseResponse.RequestStatus.LICENSED -> "LICENSED"
LicenseResponse.RequestStatus.NOT_LICENSED -> "NOT_LICENSED"
LicenseResponse.RequestStatus.EXPIRED -> "EXPIRED"
LicenseResponse.RequestStatus.ERROR_VERIFICATION -> "ERROR_VERIFICATION"
LicenseResponse.RequestStatus.ERROR_INVALID_LICENSING_KEYS -> "ERROR_INVALID_LICENSING_KEYS"
LicenseResponse.RequestStatus.UNKNOWN_ERROR -> "UNKNOWN_ERROR"
else -> null
}?.let { promise.resolve(it) }
}
} catch (exception: Exception) {
promise.reject("Error while attempting to check for License", exception)
}
}

Expand Down Expand Up @@ -130,9 +114,7 @@ class RNIapAmazonModule(
val skuSize = skuArr.size()
while (ii < skuSize) {
val sku = skuArr.getString(ii)
if (sku is String) {
productSkus.add(sku)
}
productSkus.add(sku)
ii++
}
PromiseUtils.addPromiseForKey(PROMISE_GET_PRODUCT_DATA, promise)
Expand Down
10 changes: 4 additions & 6 deletions android/src/play/java/com/dooboolab/rniap/RNIapModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class RNIapModule(
val skuList = mutableListOf<QueryProductDetailsParams.Product>()
for (i in 0 until skuArr.size()) {
if (skuArr.getType(i) == ReadableType.String) {
skuArr.getString(i)?.let { sku ->
skuArr.getString(i).let { sku ->
skuList.add(
QueryProductDetailsParams.Product
.newBuilder()
Expand Down Expand Up @@ -497,7 +497,7 @@ class RNIapModule(
}
var productDetailParams = BillingFlowParams.ProductDetailsParams.newBuilder().setProductDetails(selectedSku)
if (type == BillingClient.ProductType.SUBS) {
offerTokenArr.getString(index)?.let { offerToken ->
offerTokenArr.getString(index).let { offerToken ->
// null check for older versions of RN
productDetailParams = productDetailParams.setOfferToken(offerToken)
}
Expand All @@ -523,10 +523,8 @@ class RNIapModule(
}
subscriptionUpdateParamsBuilder.setSubscriptionReplacementMode(replacementMode)
}
if (purchaseToken != null) {
val subscriptionUpdateParams = subscriptionUpdateParamsBuilder.build()
builder.setSubscriptionUpdateParams(subscriptionUpdateParams)
}
val subscriptionUpdateParams = subscriptionUpdateParamsBuilder.build()
builder.setSubscriptionUpdateParams(subscriptionUpdateParams)
}
if (obfuscatedAccountId != null) {
builder.setObfuscatedAccountId(obfuscatedAccountId)
Expand Down
Loading