diff --git a/billing/build.gradle b/billing/build.gradle index 32974fe..ced4111 100644 --- a/billing/build.gradle +++ b/billing/build.gradle @@ -8,7 +8,7 @@ apply from: '../_ktlint.gradle' ext { PUBLISH_GROUP_ID = 'de.charlex.billing' - PUBLISH_VERSION = '5.0.0.0-rc02' + PUBLISH_VERSION = '5.2.0-rc01' PUBLISH_ARTIFACT_ID = 'billing-suspend' } @@ -16,10 +16,9 @@ apply from: '../_publish.gradle' android { compileSdkVersion 33 - buildToolsVersion "31.0.0" defaultConfig { - minSdkVersion 26 + minSdkVersion 23 targetSdkVersion 33 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -47,13 +46,13 @@ dependencies { /** * Billing */ - api 'com.android.billingclient:billing:5.0.0' - api 'com.android.billingclient:billing-ktx:5.0.0' + api 'com.android.billingclient:billing:5.2.0' + api 'com.android.billingclient:billing-ktx:5.2.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.core:core-ktx:1.9.0' testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' } diff --git a/billing/src/main/java/de/charlex/billing/BillingHelper.kt b/billing/src/main/java/de/charlex/billing/BillingHelper.kt index 9601b9d..3ec8a92 100644 --- a/billing/src/main/java/de/charlex/billing/BillingHelper.kt +++ b/billing/src/main/java/de/charlex/billing/BillingHelper.kt @@ -1,6 +1,7 @@ package de.charlex.billing import android.app.Activity +import android.content.Context import android.util.Log import com.android.billingclient.api.AcknowledgePurchaseParams import com.android.billingclient.api.BillingClient @@ -35,12 +36,15 @@ import kotlin.coroutines.suspendCoroutine /** * Helps to make all necessary functions from billingClient suspendable */ -class BillingHelper(private val activity: Activity, billingClientBuilder: BillingClient.Builder.() -> Unit) : PurchasesUpdatedListener { +class BillingHelper(context: Context, billingClientBuilder: BillingClient.Builder.() -> Unit) : PurchasesUpdatedListener { + + @Deprecated(level = DeprecationLevel.ERROR, message = "Don't use the constructor with activity as param", replaceWith = ReplaceWith("BillingHelper(context, billingClientBuilder)")) + constructor(activity: Activity, billingClientBuilder: BillingClient.Builder.() -> Unit) : this(activity.applicationContext, billingClientBuilder) private var billingClient: BillingClient init { - val builder = BillingClient.newBuilder(activity) + val builder = BillingClient.newBuilder(context) billingClientBuilder.invoke(builder) builder.setListener(this) billingClient = builder.build() @@ -48,11 +52,22 @@ class BillingHelper(private val activity: Activity, billingClientBuilder: Billin private var billingContinuation: Continuation? = null + @Deprecated(level = DeprecationLevel.ERROR, message = "Use showInAppMessages with activity as param", replaceWith = ReplaceWith("showInAppMessages(activity, inAppMessageParams, resultHandler)")) private fun showInAppMessages( inAppMessageParams: InAppMessageParams = InAppMessageParams.newBuilder() .addInAppMessageCategoryToShow(InAppMessageParams.InAppMessageCategoryId.TRANSACTIONAL) .build(), resultHandler: (InAppMessageResult) -> Unit + ) { + error("Use showInAppMessages with activity as param") + } + + private fun showInAppMessages( + activity: Activity, + inAppMessageParams: InAppMessageParams = InAppMessageParams.newBuilder() + .addInAppMessageCategoryToShow(InAppMessageParams.InAppMessageCategoryId.TRANSACTIONAL) + .build(), + resultHandler: (InAppMessageResult) -> Unit ) { billingClient.showInAppMessages( activity, @@ -199,6 +214,16 @@ class BillingHelper(private val activity: Activity, billingClientBuilder: Billin } } + @Deprecated(level = DeprecationLevel.ERROR, message = "Use purchase with activity as param", replaceWith = ReplaceWith("purchase(activity, productDetails, offerToken, isOfferPersonalized, validation)")) + suspend fun purchase( + productDetails: ProductDetails, + offerToken: String? = null, + isOfferPersonalized: Boolean = false, + validation: suspend (Purchase) -> Boolean = { true } + ): PurchasesResult? { + error("Use purchase with activity as param") + } + /** * Performs a network query purchase SKUs * @@ -206,7 +231,7 @@ class BillingHelper(private val activity: Activity, billingClientBuilder: Billin * @param type String Specifies the [BillingClient.SkuType](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.SkuType) of SKUs to query. * */ - suspend fun purchase(productDetails: ProductDetails, offerToken: String? = null, isOfferPersonalized: Boolean = false, validation: suspend (Purchase) -> Boolean = { true }): PurchasesResult? { + suspend fun purchase(activity: Activity, productDetails: ProductDetails, offerToken: String? = null, isOfferPersonalized: Boolean = false, validation: suspend (Purchase) -> Boolean = { true }): PurchasesResult? { if (billingClient.startConnectionIfNecessary()) { // val skuDetails: List? = queryProductDetails(sku, type) // skuDetails?.let { diff --git a/build.gradle b/build.gradle index db22e79..c46a876 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,12 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = "1.7.0" + ext.kotlin_version = "1.8.10" repositories { google() mavenCentral() } dependencies { - classpath "com.android.tools.build:gradle:7.0.4" + classpath "com.android.tools.build:gradle:7.4.2" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0' diff --git a/gradle.properties b/gradle.properties index 98bed16..60aea38 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,4 +18,5 @@ android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": -kotlin.code.style=official \ No newline at end of file +kotlin.code.style=official +android.disableAutomaticComponentCreation=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 61472bf..63cae13 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Sep 14 01:58:53 CEST 2021 +#Sat Apr 08 09:34:25 CEST 2023 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists