Skip to content

Commit

Permalink
billing client v4
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-ostapovets committed Aug 5, 2021
1 parent 9e14017 commit e7a1aab
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/gen/rxbilling/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -24,7 +24,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion rxbilling/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions rxbilling/src/main/java/com/gen/rxbilling/client/RxBilling.kt
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,15 @@ class RxBillingImpl(
private fun getBoughtItems(@BillingClient.SkuType type: String): Single<List<Purchase>> {
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<List<Purchase>> { 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()
}
Expand Down

0 comments on commit e7a1aab

Please sign in to comment.