Skip to content

Commit

Permalink
Merge pull request #22 from betterme-dev/develop
Browse files Browse the repository at this point in the history
V 2.2.0
  • Loading branch information
KChernenko authored Apr 17, 2020
2 parents 3953b2f + c94ac6c commit 60b6a6b
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 49 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ apply from: 'dependencies.gradle'
apply plugin: "com.hellofresh.gradle.deblibs"

buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.3.72'
ext.maven_version = '2.1'
ext.bintray_version = '1.8.4'
ext.bintray_version = '1.8.5'
ext.dokka_version = '0.9.16'
repositories {
maven { url 'https://plugins.gradle.org/m2/' }
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:3.6.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.github.dcendents:android-maven-gradle-plugin:$maven_version"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_version"
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka_version"
classpath "com.hellofresh.gradle:deblibs:2.0.0"
classpath "com.hellofresh.gradle:deblibs:2.2.0"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
16 changes: 8 additions & 8 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@ ext {
targetSdkVer = 28

versionCode = 1
versionName = '2.0.1'
versionName = '2.2.0'

// Kotlin
kotlinVer = '1.3.50'
kotlinVer = '1.3.72'
androidKtxVer = '1.0.2'

// Support library
constraintLayout = '1.1.3'

// AndroidX
xAppCompatVer = '1.1.0-rc01'
xLifecycleVer = '2.0.0'
xAppCompatVer = '1.1.0'
xLifecycleVer = '2.2.0'
xFragmentVer = '1.1.0-rc04'
xRulesVer = '1.1.0-rc04'
xRunnerVer = '1.1.0-rc04'
xTestVer = '1.2.0'
xExtVer = '1.1.1'

// Reactive Extensions
rxJava2Ver = '2.2.12'
rxJava2Ver = '2.2.19'
rxAndroid2Ver = '2.1.1'

// Billing Client
billingClientVer = '2.0.3'
billingClientVer = '2.2.0'

// Developer-related
timberVer = '4.7.1'

// Unit-tests
jUnitVer = '4.12'
mockitoVer = '2.28.2'
jUnitVer = '4.13'
mockitoVer = '3.3.3'
mockitoKotlinVer = '2.1.0'
jacocoVer = '0.1.2'
assertJVer = '3.9.1'
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu May 09 12:50:48 EEST 2019
#Fri Apr 17 17:32:04 EEST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.gen.rxbilling.client

import com.android.billingclient.api.Purchase


sealed class PurchasesUpdate(open val code: Int,
open val purchases: List<Purchase>) {
sealed class PurchasesUpdate(
open val code: Int,
open val purchases: List<Purchase>) {

data class Success(override val code: Int,
override val purchases: List<Purchase>) : PurchasesUpdate(code, purchases)
Expand All @@ -14,4 +14,4 @@ sealed class PurchasesUpdate(open val code: Int,

data class Failed(override val code: Int,
override val purchases: List<Purchase>) : PurchasesUpdate(code, purchases)
}
}
33 changes: 12 additions & 21 deletions rxbilling/src/main/java/com/gen/rxbilling/client/RxBilling.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.gen.rxbilling.client

import android.app.Activity
import com.android.billingclient.api.*
import com.android.billingclient.api.BillingClient.FeatureType
import com.gen.rxbilling.connection.BillingClientFactory
import com.gen.rxbilling.exception.BillingException
import com.gen.rxbilling.lifecycle.Connectable
Expand All @@ -16,6 +17,8 @@ interface RxBilling : Connectable<BillingClient> {

override fun connect(): Flowable<BillingClient>

fun isFeatureSupported(@FeatureType feature: String): Single<Boolean>

fun observeUpdates(): Flowable<PurchasesUpdate>

fun getPurchases(@BillingClient.SkuType skuType: String): Single<List<Purchase>>
Expand All @@ -29,8 +32,6 @@ interface RxBilling : Connectable<BillingClient> {
fun consumeProduct(params: ConsumeParams): Completable

fun acknowledge(params: AcknowledgePurchaseParams): Completable

fun loadRewarded(params: RewardLoadParams): Completable
}

class RxBillingImpl(
Expand All @@ -57,6 +58,15 @@ class RxBillingImpl(
return connectionFlowable
}

override fun isFeatureSupported(@FeatureType feature: String): Single<Boolean> {
return connectionFlowable.flatMapSingle {
Single.defer {
val result = it.isFeatureSupported(feature)
Single.just(result.responseCode == BillingClient.BillingResponseCode.OK)
}
}.firstOrError()
}

override fun observeUpdates(): Flowable<PurchasesUpdate> {
return connectionFlowable.flatMap {
updateSubject.toFlowable(BackpressureStrategy.LATEST)
Expand Down Expand Up @@ -142,25 +152,6 @@ class RxBillingImpl(
.ignoreElement()
}

override fun loadRewarded(params: RewardLoadParams): Completable {
return connectionFlowable
.flatMapSingle { client ->
Single.create<Int> {
client.loadRewardedSku(params) { result ->
if (it.isDisposed) return@loadRewardedSku
val responseCode = result.responseCode
if (isSuccess(responseCode)) {
it.onSuccess(result.responseCode)
} else {
it.onError(BillingException.fromResult(result))
}
}
}
}
.firstOrError()
.ignoreElement()
}

private fun getBoughtItems(@BillingClient.SkuType type: String): Single<List<Purchase>> {
return connectionFlowable
.flatMapSingle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import io.reactivex.Flowable
import io.reactivex.FlowableTransformer
import timber.log.Timber

class BillingClientFactory(private val context: Context,
private val transformer: FlowableTransformer<BillingClient, BillingClient>
= RepeatConnectionTransformer()
class BillingClientFactory(
private val context: Context,
private val transformer: FlowableTransformer<BillingClient, BillingClient>
= RepeatConnectionTransformer()
) {

fun createBillingFlowable(listener: PurchasesUpdatedListener): Flowable<BillingClient> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import io.reactivex.Flowable
import io.reactivex.FlowableTransformer
import timber.log.Timber

class BillingServiceFactory(private val context: Context,
private val transformer:
FlowableTransformer<IInAppBillingService, IInAppBillingService>
= RepeatConnectionTransformer()) {
class BillingServiceFactory(
private val context: Context,
private val transformer: FlowableTransformer<IInAppBillingService, IInAppBillingService>
= RepeatConnectionTransformer()) {

companion object {
private const val BIND_ACTION = "com.android.vending.billing.InAppBillingService.BIND"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,11 @@ class RxBillingFlow(
}

fun handleActivityResult(data: Intent?): Single<Purchase> {
return Single.create<Purchase> {
return Single.create {
if (it.isDisposed) return@create
Timber.d("onActivityResult %s", data?.extras)
val billingResult = BillingHelper.getBillingResultFromIntent(data, null)
val responseCode = billingResult.responseCode
when (responseCode) {
when (billingResult.responseCode) {
BillingClient.BillingResponseCode.OK -> {
val purchases = BillingHelper.extractPurchases(data?.extras)
it.onSuccess(purchases[0])
Expand Down

0 comments on commit 60b6a6b

Please sign in to comment.