diff --git a/app/src/main/java/com/gen/rxbilling/sample/MainActivity.kt b/app/src/main/java/com/gen/rxbilling/sample/MainActivity.kt index 167dbb9..373c677 100644 --- a/app/src/main/java/com/gen/rxbilling/sample/MainActivity.kt +++ b/app/src/main/java/com/gen/rxbilling/sample/MainActivity.kt @@ -7,6 +7,7 @@ import com.gen.rxbilling.client.RxBilling import com.gen.rxbilling.client.RxBillingImpl import com.gen.rxbilling.connection.BillingClientFactory import com.gen.rxbilling.lifecycle.BillingConnectionManager +import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import kotlinx.android.synthetic.main.activity_main.* import timber.log.Timber @@ -72,6 +73,7 @@ class MainActivity : AppCompatActivity() { private fun loadPurchases() { disposable.add( rxBilling.getPurchases(BillingClient.SkuType.SUBS) + .observeOn(AndroidSchedulers.mainThread()) .subscribe({ Timber.d("getPurchases $it") tvPurchases.text = it.toString() @@ -83,6 +85,7 @@ class MainActivity : AppCompatActivity() { private fun loadHistory() { disposable.add( rxBilling.getPurchaseHistory(BillingClient.SkuType.SUBS) + .observeOn(AndroidSchedulers.mainThread()) .subscribe({ Timber.d("getPurchaseHistory $it") tvHistory.text = it.toString() @@ -98,6 +101,7 @@ class MainActivity : AppCompatActivity() { .setSkusList(listOf("your_id1", "your_id2")) .setType(BillingClient.SkuType.SUBS) .build()) + .observeOn(AndroidSchedulers.mainThread()) .subscribe({ Timber.d("loadDetails $it") tvDetails.text = it.toString() diff --git a/build.gradle b/build.gradle index 95a2177..b52d508 100644 --- a/build.gradle +++ b/build.gradle @@ -3,15 +3,15 @@ apply from: 'dependencies.gradle' apply plugin: "com.hellofresh.gradle.deblibs" buildscript { - ext.kotlin_version = '1.4.10' + ext.kotlin_version = '1.5.21' ext.dokka_version = '0.9.16' repositories { maven { url 'https://plugins.gradle.org/m2/' } google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.2' + classpath 'com.android.tools.build:gradle:4.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka_version" classpath "com.hellofresh.gradle:deblibs:2.2.0" @@ -24,7 +24,7 @@ buildscript { allprojects { repositories { google() - jcenter() + mavenCentral() } } diff --git a/dependencies.gradle b/dependencies.gradle index a0779f3..6c10d9b 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -27,7 +27,7 @@ ext { rxAndroid2Ver = '2.1.1' // Billing Client - billingClientVer = '3.0.1' + billingClientVer = '4.0.0' // Developer-related timberVer = '4.7.1' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index be585da..e35dc5f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip diff --git a/rxbilling/build.gradle b/rxbilling/build.gradle index 6097645..9b71338 100644 --- a/rxbilling/build.gradle +++ b/rxbilling/build.gradle @@ -7,7 +7,7 @@ apply plugin: 'org.jetbrains.dokka-android' android { defaultConfig { - versionName "3.0.0" + versionName "4.0.0" minSdkVersion minSdkVer targetSdkVersion targetSdkVer compileSdkVersion compileSdkVer diff --git a/rxbilling/src/main/java/com/gen/rxbilling/client/RxBilling.kt b/rxbilling/src/main/java/com/gen/rxbilling/client/RxBilling.kt index e7dc286..45c5d87 100644 --- a/rxbilling/src/main/java/com/gen/rxbilling/client/RxBilling.kt +++ b/rxbilling/src/main/java/com/gen/rxbilling/client/RxBilling.kt @@ -155,11 +155,15 @@ class RxBillingImpl( private fun getBoughtItems(@BillingClient.SkuType type: String): Single> { return connectionFlowable .flatMapSingle { - val purchasesResult = it.queryPurchases(type) - return@flatMapSingle if (isSuccess(purchasesResult.responseCode)) { - Single.just(purchasesResult.purchasesList.orEmpty()) - } else { - Single.error(BillingException.fromResult(purchasesResult.billingResult)) + Single.create> { emitter -> + it.queryPurchasesAsync(type) { billingResult, mutableList -> + if (emitter.isDisposed) return@queryPurchasesAsync + if (isSuccess(billingResult.responseCode)) { + emitter.onSuccess(mutableList) + } else { + emitter.onError(BillingException.fromResult(billingResult)) + } + } } }.firstOrError() }