diff --git a/README.md b/README.md
index 01cdedf..08d020d 100644
--- a/README.md
+++ b/README.md
@@ -90,28 +90,33 @@ The result of this operation will be delivered to your updates observer
The result of this operation will be delivered to onActivityResult() of your Activity or Fragment,
updates observer will not be triggered
- private fun startFlowWithClient() {
- disposable.add(rxBilling.launchFlow(this, BillingFlowParams.newBuilder()
- .setSku("you_id")
- .setType(BillingClient.SkuType.SUBS)
- .build())
- .subscribe({
- //flow started
- }, {
- //handle error
- }))
- }
+ private fun startFlowWithService() {
+ disposable.add(
+ rxBillingFlow.buyItem(
+ BuyItemRequest(BillingClient.SkuType.SUBS, "your_id", 101),
+ ActivityFlowDelegate(this)
+ )
+ .subscribe({
+ Timber.d("flow started")
+ }, {
+ Timber.e(it)
+ }))
+ }
+
## Handle Billing result with RxBillingFlow
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
- disposable.add(rxBillingFlow.handleActivityResult(resultCode, data)
- .subscribe({
- //handle purchase
- }, {
- //handle error
- }))
+ disposable.add(
+ rxBillingFlow.handleActivityResult(data)
+ .subscribe({
+ Timber.d("onActivityResult $it")
+ tvServiceFlow.text = it.toString()
+ }, {
+ Timber.e(it)
+ tvServiceFlow.text = it.toString()
+ }))
}
## Load owned products
@@ -125,78 +130,73 @@ updates observer will not be triggered
}))
}
-## Load owned subscriptions
+## Load owned purchases
- private fun loadSubscriptions() {
- disposable.add(rxBilling.getSubscriptions()
- .subscribe({
- //handle purchases
- }, {
- //handle error
- }))
- }
-
-## Load products history
-
- private fun loadPurchasesHistory() {
- disposable.add(rxBilling.getPurchaseHistory()
- .subscribe({
- //handle purchases
- }, {
- //handle error
- }))
- }
-
-## Load subscriptions history
-
- private fun loadPurchasesHistory() {
- disposable.add(rxBilling.getSubscriptionHistory()
- .subscribe({
- //handle purchases
- }, {
- //handle error
- }))
+ private fun loadPurchases() {
+ disposable.add(
+ rxBilling.getPurchases(BillingClient.SkuType.SUBS)
+ .subscribe({
+ Timber.d("getPurchases $it")
+ tvPurchases.text = it.toString()
+ }, {
+ Timber.e(it)
+ }))
}
-## Load product sku details
+## Load history
- private fun loadPurchasesHistory() {
- disposable.add(rxBilling.getPurchaseSkuDetails(listOf("your_id1", "your_id2"))
- .subscribe({
- //handle details
- }, {
- //handle details
- }))
+ private fun loadHistory() {
+ disposable.add(
+ rxBilling.getPurchaseHistory(BillingClient.SkuType.SUBS)
+ .subscribe({
+ Timber.d("getPurchaseHistory $it")
+ tvHistory.text = it.toString()
+ }, {
+ Timber.e(it)
+ }))
}
-## Load subscription sku details
+## Load sku details
private fun loadDetails() {
- disposable.add(rxBilling.getSubscriptionSkuDetails(listOf("your_id1", "your_id2"))
- .subscribe({
- //handle details
- }, {
- //handle details
- }))
+ disposable.add(
+ rxBilling.getSkuDetails(
+ SkuDetailsParams.newBuilder()
+ .setSkusList(listOf("your_id1", "your_id2"))
+ .setType(BillingClient.SkuType.SUBS)
+ .build())
+ .subscribe({
+ Timber.d("loadDetails $it")
+ tvDetails.text = it.toString()
+ }, {
+ Timber.e(it)
+ }))
}
## Consume product
private fun consume() {
- disposable.add(rxBilling.consumeProduct("purchase_token")
- .subscribe({
- //completed
- }, {
- //handle error
- }))
+ disposable.add(
+ rxBilling.consumeProduct(
+ ConsumeParams.newBuilder()
+ .setPurchaseToken("token")
+ .build())
+ .subscribe()
+ )
}
-
-## AndroidX
-
-If you are going to migrate on AndroidX, please use
-
- com.gen.rxbilling.lifecycle.androidx.BillingConnectionManager
-and
-
- com.gen.rxbilling.flow.delegate.androidx.FragmentFlowDelegate
\ No newline at end of file
+## Acknowledge item
+
+ private fun acknowledge() {
+ disposable.add(
+ rxBilling.acknowledge(
+ AcknowledgePurchaseParams.newBuilder()
+ .setPurchaseToken("token")
+ .setDeveloperPayload("payload")
+ .build())
+ .subscribe({
+ Timber.d("acknowledge success")
+ }, {
+ Timber.e(it)
+ }))
+ }
diff --git a/app/build.gradle b/app/build.gradle
index 15af0e6..9d6ec54 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -40,12 +40,10 @@ dependencies {
implementation developmentDependencies.timber
implementation dataDependencies.rxJava
implementation dataDependencies.rxAndroid
- implementation supportDependencies.appCompat
+ implementation presentationDependencies.appCompat
testImplementation testDependencies.jUnit
testImplementation testDependencies.mockito
testImplementation testDependencies.mockitoKotlin
- androidTestImplementation androidTestDependencies.testRunner
- androidTestImplementation androidTestDependencies.espressoCore
}
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 2f64194..c64e894 100644
--- a/app/src/main/java/com/gen/rxbilling/sample/MainActivity.kt
+++ b/app/src/main/java/com/gen/rxbilling/sample/MainActivity.kt
@@ -2,9 +2,8 @@ package com.gen.rxbilling.sample
import android.content.Intent
import android.os.Bundle
-import android.support.v7.app.AppCompatActivity
-import com.android.billingclient.api.BillingClient
-import com.android.billingclient.api.BillingFlowParams
+import androidx.appcompat.app.AppCompatActivity
+import com.android.billingclient.api.*
import com.gen.rxbilling.client.RxBilling
import com.gen.rxbilling.client.RxBillingImpl
import com.gen.rxbilling.connection.BillingClientFactory
@@ -12,7 +11,7 @@ import com.gen.rxbilling.connection.BillingServiceFactory
import com.gen.rxbilling.flow.delegate.ActivityFlowDelegate
import com.gen.rxbilling.flow.BuyItemRequest
import com.gen.rxbilling.flow.RxBillingFlow
-import com.gen.rxbilling.lifecycle.arch.BillingConnectionManager
+import com.gen.rxbilling.lifecycle.BillingConnectionManager
import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.activity_main.*
import timber.log.Timber
@@ -45,18 +44,22 @@ class MainActivity : AppCompatActivity() {
btnLoadDetails.setOnClickListener {
loadDetails()
}
+ btnAcknowledge.setOnClickListener {
+ acknowledge()
+ }
}
override fun onStart() {
super.onStart()
- disposable.add(rxBilling.observeUpdates()
- .subscribe({
- Timber.d("observeUpdates $it")
- tvClientFlow.text = it.toString()
- }, {
- Timber.e(it)
- tvClientFlow.text = it.toString()
- }))
+ disposable.add(
+ rxBilling.observeUpdates()
+ .subscribe({
+ Timber.d("observeUpdates $it")
+ tvClientFlow.text = it.toString()
+ }, {
+ Timber.e(it)
+ tvClientFlow.text = it.toString()
+ }))
}
override fun onStop() {
@@ -66,65 +69,90 @@ class MainActivity : AppCompatActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
- disposable.add(rxBillingFlow.handleActivityResult(resultCode, data)
- .subscribe({
- Timber.d("onActivityResult $it")
- tvServiceFlow.text = it.toString()
- }, {
- Timber.e(it)
- tvServiceFlow.text = it.toString()
- }))
+ disposable.add(
+ rxBillingFlow.handleActivityResult(data)
+ .subscribe({
+ Timber.d("onActivityResult $it")
+ tvServiceFlow.text = it.toString()
+ }, {
+ Timber.e(it)
+ tvServiceFlow.text = it.toString()
+ }))
}
private fun startFlowWithService() {
- disposable.add(rxBillingFlow.buyItem(BuyItemRequest(BillingClient.SkuType.SUBS, "your_id", 101),
- ActivityFlowDelegate(this))
- .subscribe({
- Timber.d("flow started")
- }, {
- Timber.e(it)
- }))
+ disposable.add(
+ rxBillingFlow.buyItem(
+ BuyItemRequest(BillingClient.SkuType.SUBS, "your_id", 101),
+ ActivityFlowDelegate(this)
+ )
+ .subscribe({
+ Timber.d("flow started")
+ }, {
+ Timber.e(it)
+ }))
}
private fun startFlowWithClient() {
- disposable.add(rxBilling.launchFlow(this, BillingFlowParams.newBuilder()
- .setSku("you_id")
- .setType(BillingClient.SkuType.SUBS)
- .build())
- .subscribe({
- Timber.d("startFlowWithClient")
- }, {
- Timber.e(it)
- }))
+ disposable.add(
+ rxBilling.launchFlow(this, BillingFlowParams.newBuilder()
+ .setSkuDetails(SkuDetails("{}"))
+ .build())
+ .subscribe({
+ Timber.d("startFlowWithClient")
+ }, {
+ Timber.e(it)
+ }))
}
private fun loadPurchases() {
- disposable.add(rxBilling.getPurchases()
- .subscribe({
- Timber.d("getPurchases $it")
- tvPurchases.text = it.toString()
- }, {
- Timber.e(it)
- }))
+ disposable.add(
+ rxBilling.getPurchases(BillingClient.SkuType.SUBS)
+ .subscribe({
+ Timber.d("getPurchases $it")
+ tvPurchases.text = it.toString()
+ }, {
+ Timber.e(it)
+ }))
}
private fun loadHistory() {
- disposable.add(rxBilling.getPurchaseHistory()
- .subscribe({
- Timber.d("getPurchaseHistory $it")
- tvHistory.text = it.toString()
- }, {
- Timber.e(it)
- }))
+ disposable.add(
+ rxBilling.getPurchaseHistory(BillingClient.SkuType.SUBS)
+ .subscribe({
+ Timber.d("getPurchaseHistory $it")
+ tvHistory.text = it.toString()
+ }, {
+ Timber.e(it)
+ }))
}
private fun loadDetails() {
- disposable.add(rxBilling.getPurchaseSkuDetails(listOf("your_id1", "your_id2"))
- .subscribe({
- Timber.d("loadDetails $it")
- tvDetails.text = it.toString()
- }, {
- Timber.e(it)
- }))
+ disposable.add(
+ rxBilling.getSkuDetails(
+ SkuDetailsParams.newBuilder()
+ .setSkusList(listOf("your_id1", "your_id2"))
+ .setType(BillingClient.SkuType.SUBS)
+ .build())
+ .subscribe({
+ Timber.d("loadDetails $it")
+ tvDetails.text = it.toString()
+ }, {
+ Timber.e(it)
+ }))
+ }
+
+ private fun acknowledge() {
+ disposable.add(
+ rxBilling.acknowledge(
+ AcknowledgePurchaseParams.newBuilder()
+ .setPurchaseToken("token")
+ .setDeveloperPayload("payload")
+ .build())
+ .subscribe({
+ Timber.d("acknowledge success")
+ }, {
+ Timber.e(it)
+ }))
}
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index cd10e23..e3720c1 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -66,7 +66,13 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
+
+
-
\ No newline at end of file
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9b44946..bd64ecf 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -5,4 +5,5 @@
Load purchases
Load history
Load details
+ Acknowledge
diff --git a/build.gradle b/build.gradle
index 06d0d7c..2090d5b 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,21 +1,24 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from: 'dependencies.gradle'
+apply plugin: "com.hellofresh.gradle.deblibs"
buildscript {
- ext.kotlin_version = '1.2.41'
- ext.maven_version = '1.5'
- ext.bintray_version = '1.7.2'
+ ext.kotlin_version = '1.3.40'
+ ext.maven_version = '2.1'
+ ext.bintray_version = '1.8.4'
ext.dokka_version = '0.9.16'
repositories {
+ maven { url 'https://plugins.gradle.org/m2/' }
google()
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.1.3'
+ classpath 'com.android.tools.build:gradle:3.4.1'
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"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@@ -32,3 +35,9 @@ allprojects {
task clean(type: Delete) {
delete rootProject.buildDir
}
+
+deblibs {
+ projectName = "RxBilling"
+ slackToken = ""
+ slackChannel = ""
+}
diff --git a/dependencies.gradle b/dependencies.gradle
index 1723bb7..d330eeb 100644
--- a/dependencies.gradle
+++ b/dependencies.gradle
@@ -4,56 +4,40 @@ ext {
targetSdkVer = 28
versionCode = 1
- versionName = '0.9.2'
+ versionName = '2.0.0'
// Kotlin
- kotlinVer = '1.2.50'
- androidKtxVer = '1.0.0-alpha1'
+ kotlinVer = '1.3.40'
+ androidKtxVer = '1.0.2'
// Support library
- supportLibraryVer = '28.0.0-alpha1'
- constraintLayout = '1.0.2'
+ constraintLayout = '1.1.3'
// AndroidX
- xAppCompatVer = '1.0.0-alpha1'
- xLifecycleVer = '2.0.0-alpha1'
- xFragmentVer = '1.0.0-alpha1'
-
- // Architecture components
- archComponentsVer = '1.1.0'
- lifecycleVer = "1.1.1"
+ xAppCompatVer = '1.1.0-alpha05'
+ xLifecycleVer = '2.0.0'
+ xFragmentVer = '1.1.0-alpha08'
// Reactive Extensions
- rxJava2Ver = '2.1.10'
- rxAndroid2Ver = '2.0.1'
-
- conductorVer = '2.1.4'
- conductorLifecycleVer = '0.1.1'
+ rxJava2Ver = '2.2.10'
+ rxAndroid2Ver = '2.1.1'
// Billing Client
- billingClientVer = '1.1'
+ billingClientVer = '2.0.1'
// Developer-related
- timberVer = '4.7.0'
+ timberVer = '4.7.1'
// Unit-tests
jUnitVer = '4.12'
- mockitoVer = '2.15.0'
- mockitoKotlinVer = '1.5.0'
+ mockitoVer = '2.28.2'
+ mockitoKotlinVer = '2.1.0'
jacocoVer = '0.1.2'
assertJVer = '3.9.0'
- // Instrumentation tests
- runnerVer = '1.0.1'
- espressoCoreVer = '3.0.1'
-
// Dependencies
- supportDependencies = [
- appCompat: "com.android.support:appcompat-v7:$supportLibraryVer",
- design : "com.android.support:design:$supportLibraryVer",
- ]
- androidXdependencies = [
+ presentationDependencies = [
appCompat : "androidx.appcompat:appcompat:$xAppCompatVer",
fragment : "androidx.fragment:fragment:$xFragmentVer",
lifecycleRuntime : "androidx.lifecycle:lifecycle-runtime:$xLifecycleVer",
@@ -71,14 +55,6 @@ ext {
timber: "com.jakewharton.timber:timber:$timberVer",
]
- presentationDependencies = [
- conductor : "com.bluelinelabs:conductor:$conductorVer",
- conductorSupport : "com.bluelinelabs:conductor-support:$conductorVer",
- conductorLifecycle : "com.bluelinelabs:conductor-archlifecycle:$conductorLifecycleVer",
- lifecycleExtensions: "android.arch.lifecycle:extensions:$lifecycleVer",
- lifecycleCompiler : "android.arch.lifecycle:compiler:$lifecycleVer",
- ]
-
dataDependencies = [
rxJava : "io.reactivex.rxjava2:rxjava:$rxJava2Ver",
rxAndroid : "io.reactivex.rxjava2:rxandroid:$rxAndroid2Ver",
@@ -88,16 +64,8 @@ ext {
testDependencies = [
jUnit : "junit:junit:$jUnitVer",
mockito : "org.mockito:mockito-core:$mockitoVer",
- mockitoKotlin: "com.nhaarman:mockito-kotlin:$mockitoKotlinVer",
+ mockitoKotlin: "com.nhaarman.mockitokotlin2:mockito-kotlin:$mockitoKotlinVer",
assertJ : "org.assertj:assertj-core:$assertJVer",
mockitoInline: "org.mockito:mockito-inline:$mockitoVer"
]
-
- androidTestDependencies = [
- testRunner : "com.android.support.test:runner:$runnerVer",
- espressoCore : "com.android.support.test.espresso:espresso-core:$espressoCoreVer",
- testRules : "com.android.support.test:rules:$runnerVer",
- supportAnnotations: "com.android.support:support-annotations:$supportLibraryVer",
- testArchCore : "android.arch.core:core-testing:$archComponentsVer"
- ]
-}
\ No newline at end of file
+}
diff --git a/gradle.properties b/gradle.properties
index 67295ad..7fa9859 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -24,4 +24,4 @@ VCS_ISSUES_URL=https://github.com/betterme-dev/RxBilling/issues
POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
-POM_LICENCE_DIST=repo
\ No newline at end of file
+POM_LICENCE_DIST=repo
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index a189bde..1021b5a 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Fri Jun 22 13:12:55 EEST 2018
+#Thu May 09 12:50:48 EEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
diff --git a/rxbilling/build.gradle b/rxbilling/build.gradle
index e24f067..a95888e 100644
--- a/rxbilling/build.gradle
+++ b/rxbilling/build.gradle
@@ -47,20 +47,16 @@ dependencies {
implementation dataDependencies.billingClient
implementation kotlinDependencies.kotlinStdLib
- compileOnly presentationDependencies.conductor
compileOnly presentationDependencies.lifecycleExtensions
- compileOnly androidXdependencies.lifecycleRuntime
- compileOnly androidXdependencies.lifecycleExtensions
+ compileOnly presentationDependencies.lifecycleRuntime
+ compileOnly presentationDependencies.lifecycleExtensions
kapt presentationDependencies.lifecycleCompiler
- kapt androidXdependencies.lifecycleCompiler
testImplementation testDependencies.jUnit
testImplementation testDependencies.mockito
testImplementation testDependencies.mockitoKotlin
- androidTestImplementation androidTestDependencies.testRunner
- androidTestImplementation androidTestDependencies.espressoCore
}
def siteUrl = 'https://github.com/betterme-dev/RxBilling' // Homepage URL of the library
@@ -108,7 +104,7 @@ install {
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
- classifier = 'sources'
+ archiveClassifier.set('sources')
}
task javadoc(type: Javadoc) {
@@ -122,7 +118,7 @@ task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
}
task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
- classifier = 'javadoc'
+ archiveClassifier.set('javadoc')
from javadoc.destinationDir
}
artifacts {
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 52af4f1..a8ac28c 100644
--- a/rxbilling/src/main/java/com/gen/rxbilling/client/RxBilling.kt
+++ b/rxbilling/src/main/java/com/gen/rxbilling/client/RxBilling.kt
@@ -11,7 +11,6 @@ import io.reactivex.Flowable
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.subjects.PublishSubject
-import timber.log.Timber
interface RxBilling : Connectable {
@@ -19,33 +18,31 @@ interface RxBilling : Connectable {
fun observeUpdates(): Flowable
- fun getPurchases(): Single>
+ fun getPurchases(@BillingClient.SkuType skuType: String): Single>
- fun getSubscriptions(): Single>
+ fun getPurchaseHistory(@BillingClient.SkuType skuType: String): Single>
- fun getPurchaseHistory(): Single>
+ fun getSkuDetails(params: SkuDetailsParams): Single>
- fun getSubscriptionHistory(): Single>
-
- fun getPurchaseSkuDetails(ids: List): Single>
+ fun launchFlow(activity: Activity, params: BillingFlowParams): Completable
- fun getSubscriptionSkuDetails(ids: List): Single>
+ fun consumeProduct(params: ConsumeParams): Completable
- fun launchFlow(activity: Activity, params: BillingFlowParams): Completable
+ fun acknowledge(params: AcknowledgePurchaseParams): Completable
- fun consumeProduct(purchaseToken: String): Completable
+ fun loadRewarded(params: RewardLoadParams): Completable
}
-class RxBillingImpl(billingFactory: BillingClientFactory)
- : RxBilling {
+class RxBillingImpl(
+ billingFactory: BillingClientFactory
+) : RxBilling {
private val updateSubject = PublishSubject.create()
- private val updatedListener = PurchasesUpdatedListener { responseCode, purchases ->
- Timber.d("$responseCode", "$purchases")
- val event = when (responseCode) {
- BillingClient.BillingResponse.OK -> PurchasesUpdate.Success(responseCode, purchases.orEmpty())
- BillingClient.BillingResponse.USER_CANCELED -> PurchasesUpdate.Canceled(responseCode, purchases.orEmpty())
+ private val updatedListener = PurchasesUpdatedListener { result, purchases ->
+ val event = when (val responseCode = result.responseCode) {
+ BillingClient.BillingResponseCode.OK -> PurchasesUpdate.Success(responseCode, purchases.orEmpty())
+ BillingClient.BillingResponseCode.USER_CANCELED -> PurchasesUpdate.Canceled(responseCode, purchases.orEmpty())
else -> PurchasesUpdate.Failed(responseCode, purchases.orEmpty())
}
updateSubject.onNext(event)
@@ -66,29 +63,29 @@ class RxBillingImpl(billingFactory: BillingClientFactory)
}
}
- override fun getPurchases(): Single> {
- return getBoughtItems(BillingClient.SkuType.INAPP)
+ override fun getPurchases(@BillingClient.SkuType skuType: String): Single> {
+ return getBoughtItems(skuType)
}
- override fun getSubscriptions(): Single> {
- return getBoughtItems(BillingClient.SkuType.SUBS)
+ override fun getPurchaseHistory(@BillingClient.SkuType skuType: String): Single> {
+ return getHistory(skuType)
}
- override fun getPurchaseHistory(): Single> {
- return getHistory(BillingClient.SkuType.INAPP)
- }
-
- override fun getSubscriptionHistory(): Single> {
- return getHistory(BillingClient.SkuType.SUBS)
- }
-
- override fun getPurchaseSkuDetails(ids: List): Single> {
- return getSkuDetails(ids, BillingClient.SkuType.INAPP)
- }
-
-
- override fun getSubscriptionSkuDetails(ids: List): Single> {
- return getSkuDetails(ids, BillingClient.SkuType.SUBS)
+ override fun getSkuDetails(params: SkuDetailsParams): Single> {
+ return connectionFlowable
+ .flatMapSingle { client ->
+ Single.create> {
+ client.querySkuDetailsAsync(params) { billingResult, skuDetailsList ->
+ if (it.isDisposed) return@querySkuDetailsAsync
+ val responseCode = billingResult.responseCode
+ if (isSuccess(responseCode)) {
+ it.onSuccess(skuDetailsList.orEmpty())
+ } else {
+ it.onError(BillingException.fromResult(billingResult))
+ }
+ }
+ }
+ }.firstOrError()
}
override fun launchFlow(activity: Activity, params: BillingFlowParams): Completable {
@@ -99,81 +96,101 @@ class RxBillingImpl(billingFactory: BillingClientFactory)
}
.firstOrError()
.flatMapCompletable {
- return@flatMapCompletable if (isSuccess(it)) {
+ return@flatMapCompletable if (isSuccess(it.responseCode)) {
Completable.complete()
} else {
- Completable.error(BillingException.fromCode(it))
+ Completable.error(BillingException.fromResult(it))
}
}
}
- override fun consumeProduct(purchaseToken: String): Completable {
+ override fun consumeProduct(params: ConsumeParams): Completable {
return connectionFlowable
- .flatMap { client ->
- Flowable.create({
- client.consumeAsync(purchaseToken) { responseCode, _ ->
- if (it.isCancelled) return@consumeAsync
+ .flatMapSingle { client ->
+ Single.create {
+ client.consumeAsync(params) { result, _ ->
+ if (it.isDisposed) return@consumeAsync
+ val responseCode = result.responseCode
if (isSuccess(responseCode)) {
- it.onNext(responseCode)
- it.onComplete()
+ it.onSuccess(responseCode)
} else {
- it.onError(BillingException.fromCode(responseCode))
+ it.onError(BillingException.fromResult(result))
}
}
- }, BackpressureStrategy.LATEST)
+ }
}
.firstOrError()
- .toCompletable()
+ .ignoreElement()
}
- private fun getBoughtItems(type: String): Single> {
+ override fun acknowledge(params: AcknowledgePurchaseParams): Completable {
return connectionFlowable
- .flatMap {
- val purchasesResult = it.queryPurchases(type)
- return@flatMap if (isSuccess(purchasesResult.responseCode)) {
- Flowable.just(purchasesResult.purchasesList.orEmpty())
- } else {
- Flowable.error>(BillingException.fromCode(purchasesResult.responseCode))
+ .flatMapSingle { client ->
+ Single.create {
+ client.acknowledgePurchase(params) { result ->
+ if (it.isDisposed) return@acknowledgePurchase
+ val responseCode = result.responseCode
+ if (isSuccess(responseCode)) {
+ it.onSuccess(responseCode)
+ } else {
+ it.onError(BillingException.fromResult(result))
+ }
+ }
}
- }.firstOrError()
+ }
+ .firstOrError()
+ .ignoreElement()
}
- private fun getHistory(type: String): Single> {
+ override fun loadRewarded(params: RewardLoadParams): Completable {
return connectionFlowable
- .flatMap { client ->
- Flowable.create>({
- client.queryPurchaseHistoryAsync(type, { responseCode: Int, mutableList: MutableList? ->
- if (it.isCancelled) return@queryPurchaseHistoryAsync
+ .flatMapSingle { client ->
+ Single.create {
+ client.loadRewardedSku(params) { result ->
+ if (it.isDisposed) return@loadRewardedSku
+ val responseCode = result.responseCode
if (isSuccess(responseCode)) {
- it.onNext(mutableList.orEmpty())
- it.onComplete()
+ it.onSuccess(result.responseCode)
} else {
- it.onError(BillingException.fromCode(responseCode))
+ it.onError(BillingException.fromResult(result))
}
- })
- }, BackpressureStrategy.LATEST)
+ }
+ }
+ }
+ .firstOrError()
+ .ignoreElement()
+ }
+
+ 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))
+ }
}.firstOrError()
}
- private fun getSkuDetails(ids: List, type: String): Single> {
- val params = SkuDetailsParams.newBuilder().setSkusList(ids).setType(type).build()
+ private fun getHistory(@BillingClient.SkuType type: String): Single> {
return connectionFlowable
- .flatMap { client ->
- Flowable.create>({
- client.querySkuDetailsAsync(params, { responseCode: Int, mutableList: MutableList? ->
- if (it.isCancelled) return@querySkuDetailsAsync
+ .flatMapSingle { client ->
+ Single.create> {
+ client.queryPurchaseHistoryAsync(type) { billingResult: BillingResult, list: MutableList? ->
+ if (it.isDisposed) return@queryPurchaseHistoryAsync
+ val responseCode = billingResult.responseCode
if (isSuccess(responseCode)) {
- it.onNext(mutableList.orEmpty())
- it.onComplete()
+ it.onSuccess(list.orEmpty())
} else {
- it.onError(BillingException.fromCode(responseCode))
+ it.onError(BillingException.fromResult(billingResult))
}
- })
- }, BackpressureStrategy.LATEST)
+ }
+ }
}.firstOrError()
}
private fun isSuccess(responseCode: Int): Boolean {
- return responseCode == BillingClient.BillingResponse.OK
+ return responseCode == BillingClient.BillingResponseCode.OK
}
-}
\ No newline at end of file
+}
diff --git a/rxbilling/src/main/java/com/gen/rxbilling/connection/BillingClientFactory.kt b/rxbilling/src/main/java/com/gen/rxbilling/connection/BillingClientFactory.kt
index 1b5f275..4d4a5d9 100644
--- a/rxbilling/src/main/java/com/gen/rxbilling/connection/BillingClientFactory.kt
+++ b/rxbilling/src/main/java/com/gen/rxbilling/connection/BillingClientFactory.kt
@@ -3,6 +3,7 @@ package com.gen.rxbilling.connection
import android.content.Context
import com.android.billingclient.api.BillingClient
import com.android.billingclient.api.BillingClientStateListener
+import com.android.billingclient.api.BillingResult
import com.android.billingclient.api.PurchasesUpdatedListener
import com.gen.rxbilling.exception.BillingException
import io.reactivex.BackpressureStrategy
@@ -11,13 +12,16 @@ import io.reactivex.FlowableTransformer
import timber.log.Timber
class BillingClientFactory(private val context: Context,
- private val transformer:
- FlowableTransformer
- = RepeatConnectionTransformer()) {
+ private val transformer: FlowableTransformer
+ = RepeatConnectionTransformer()
+) {
fun createBillingFlowable(listener: PurchasesUpdatedListener): Flowable {
val flowable = Flowable.create({
- val billingClient = BillingClient.newBuilder(context).setListener(listener).build()
+ val billingClient = BillingClient.newBuilder(context)
+ .enablePendingPurchases()
+ .setListener(listener)
+ .build()
Timber.d("startConnection")
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingServiceDisconnected() {
@@ -27,13 +31,14 @@ class BillingClientFactory(private val context: Context,
}
}
- override fun onBillingSetupFinished(responseCode: Int) {
+ override fun onBillingSetupFinished(result: BillingResult) {
+ val responseCode = result.responseCode
Timber.d("onBillingSetupFinished response $responseCode isReady ${billingClient.isReady}")
if (!it.isCancelled) {
- if (responseCode == BillingClient.BillingResponse.OK) {
+ if (responseCode == BillingClient.BillingResponseCode.OK) {
it.onNext(billingClient)
} else {
- it.onError(BillingException.fromCode(responseCode))
+ it.onError(BillingException.fromResult(result))
}
} else {
if (billingClient.isReady) {
@@ -53,4 +58,4 @@ class BillingClientFactory(private val context: Context,
return flowable.compose(transformer)
}
-}
\ No newline at end of file
+}
diff --git a/rxbilling/src/main/java/com/gen/rxbilling/connection/BillingServiceFactory.kt b/rxbilling/src/main/java/com/gen/rxbilling/connection/BillingServiceFactory.kt
index 8e51516..2fb9332 100644
--- a/rxbilling/src/main/java/com/gen/rxbilling/connection/BillingServiceFactory.kt
+++ b/rxbilling/src/main/java/com/gen/rxbilling/connection/BillingServiceFactory.kt
@@ -5,6 +5,8 @@ import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.IBinder
+import com.android.billingclient.api.BillingClient
+import com.android.billingclient.api.BillingResult
import com.android.vending.billing.IInAppBillingService
import com.gen.rxbilling.exception.BillingException
import io.reactivex.BackpressureStrategy
@@ -50,7 +52,12 @@ class BillingServiceFactory(private val context: Context,
}
val bindService = context.bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE)
if (!bindService && !emitter.isCancelled) {
- emitter.onError(BillingException.BillingUnavailableException())
+ emitter.onError(BillingException.BillingUnavailableException(
+ BillingResult.newBuilder()
+ .setResponseCode(BillingClient.BillingResponseCode.BILLING_UNAVAILABLE)
+ .setDebugMessage("")
+ .build()
+ ))
return@create
}
emitter.setCancellable {
@@ -62,4 +69,4 @@ class BillingServiceFactory(private val context: Context,
}, BackpressureStrategy.LATEST)
return flowable.compose(transformer)
}
-}
\ No newline at end of file
+}
diff --git a/rxbilling/src/main/java/com/gen/rxbilling/exception/BillingException.kt b/rxbilling/src/main/java/com/gen/rxbilling/exception/BillingException.kt
index 6089210..9842250 100644
--- a/rxbilling/src/main/java/com/gen/rxbilling/exception/BillingException.kt
+++ b/rxbilling/src/main/java/com/gen/rxbilling/exception/BillingException.kt
@@ -1,38 +1,38 @@
package com.gen.rxbilling.exception
import com.android.billingclient.api.BillingClient
+import com.android.billingclient.api.BillingResult
-sealed class BillingException(open val code: Int) :
- Exception("Billing error, code $code") {
+sealed class BillingException(result: BillingResult) :
+ Exception("Billing error, code ${result.responseCode}\n${result.debugMessage}") {
companion object {
- fun fromCode(code: Int): BillingException {
- return when (code) {
- BillingClient.BillingResponse.FEATURE_NOT_SUPPORTED -> FeatureNotSupportedException()
- BillingClient.BillingResponse.SERVICE_DISCONNECTED -> ServiceDisconnectedException()
- BillingClient.BillingResponse.USER_CANCELED -> UserCanceledException()
- BillingClient.BillingResponse.SERVICE_UNAVAILABLE -> ServiceUnavailableException()
- BillingClient.BillingResponse.BILLING_UNAVAILABLE -> BillingUnavailableException()
- BillingClient.BillingResponse.ITEM_UNAVAILABLE -> ItemUnavailableException()
- BillingClient.BillingResponse.DEVELOPER_ERROR -> DeveloperErrorException()
- BillingClient.BillingResponse.ERROR -> FatalException()
- BillingClient.BillingResponse.ITEM_ALREADY_OWNED -> AlreadyOwnedException()
- BillingClient.BillingResponse.ITEM_NOT_OWNED -> NotOwnedException()
- else -> UnknownException(code)
+ fun fromResult(result: BillingResult): BillingException {
+ return when (result.responseCode) {
+ BillingClient.BillingResponseCode.FEATURE_NOT_SUPPORTED -> FeatureNotSupportedException(result)
+ BillingClient.BillingResponseCode.SERVICE_DISCONNECTED -> ServiceDisconnectedException(result)
+ BillingClient.BillingResponseCode.USER_CANCELED -> UserCanceledException(result)
+ BillingClient.BillingResponseCode.SERVICE_UNAVAILABLE -> ServiceUnavailableException(result)
+ BillingClient.BillingResponseCode.BILLING_UNAVAILABLE -> BillingUnavailableException(result)
+ BillingClient.BillingResponseCode.ITEM_UNAVAILABLE -> ItemUnavailableException(result)
+ BillingClient.BillingResponseCode.DEVELOPER_ERROR -> DeveloperErrorException(result)
+ BillingClient.BillingResponseCode.ERROR -> FatalException(result)
+ BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED -> AlreadyOwnedException(result)
+ BillingClient.BillingResponseCode.ITEM_NOT_OWNED -> NotOwnedException(result)
+ else -> UnknownException(result)
}
}
}
-
- class FeatureNotSupportedException : BillingException(BillingClient.BillingResponse.FEATURE_NOT_SUPPORTED)
- class ServiceDisconnectedException : BillingException(BillingClient.BillingResponse.SERVICE_DISCONNECTED)
- class UserCanceledException : BillingException(BillingClient.BillingResponse.USER_CANCELED)
- class ServiceUnavailableException : BillingException(BillingClient.BillingResponse.SERVICE_UNAVAILABLE)
- class BillingUnavailableException : BillingException(BillingClient.BillingResponse.BILLING_UNAVAILABLE)
- class ItemUnavailableException : BillingException(BillingClient.BillingResponse.ITEM_UNAVAILABLE)
- class DeveloperErrorException : BillingException(BillingClient.BillingResponse.DEVELOPER_ERROR)
- class FatalException : BillingException(BillingClient.BillingResponse.ERROR)
- class AlreadyOwnedException : BillingException(BillingClient.BillingResponse.ITEM_ALREADY_OWNED)
- class NotOwnedException : BillingException(BillingClient.BillingResponse.ITEM_NOT_OWNED)
- class UnknownException(code: Int) : BillingException(code)
+ class FeatureNotSupportedException(result: BillingResult) : BillingException(result)
+ class ServiceDisconnectedException(result: BillingResult) : BillingException(result)
+ class UserCanceledException(result: BillingResult) : BillingException(result)
+ class ServiceUnavailableException(result: BillingResult) : BillingException(result)
+ class BillingUnavailableException(result: BillingResult) : BillingException(result)
+ class ItemUnavailableException(result: BillingResult) : BillingException(result)
+ class DeveloperErrorException(result: BillingResult) : BillingException(result)
+ class FatalException(result: BillingResult) : BillingException(result)
+ class AlreadyOwnedException(result: BillingResult) : BillingException(result)
+ class NotOwnedException(result: BillingResult) : BillingException(result)
+ class UnknownException(result: BillingResult) : BillingException((result))
}
diff --git a/rxbilling/src/main/java/com/gen/rxbilling/flow/RxBillingFlow.kt b/rxbilling/src/main/java/com/gen/rxbilling/flow/RxBillingFlow.kt
index c2c0e2d..8c66729 100644
--- a/rxbilling/src/main/java/com/gen/rxbilling/flow/RxBillingFlow.kt
+++ b/rxbilling/src/main/java/com/gen/rxbilling/flow/RxBillingFlow.kt
@@ -4,9 +4,10 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import com.android.billingclient.api.BillingClient
+import com.android.billingclient.api.BillingResult
import com.android.billingclient.api.Purchase
import com.android.billingclient.util.BillingHelper
-import com.android.billingclient.util.BillingHelper.RESPONSE_BUY_INTENT
+import com.android.billingclient.util.BillingHelper.RESPONSE_BUY_INTENT_KEY
import com.android.vending.billing.IInAppBillingService
import com.gen.rxbilling.connection.BillingServiceFactory
import com.gen.rxbilling.exception.BillingException
@@ -38,19 +39,23 @@ class RxBillingFlow(
request.type,
/* developerPayload */ null)
val responseCode = BillingHelper.getResponseCodeFromBundle(buyIntentBundle, null)
- if (responseCode == BillingClient.BillingResponse.OK) {
- val pendingIntent: PendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT)
+ val responseMessage = BillingHelper.getDebugMessageFromBundle(buyIntentBundle, null)
+ val billingResult = BillingResult.newBuilder()
+ .setResponseCode(responseCode)
+ .setDebugMessage(responseMessage)
+ .build()
+ if (responseCode == BillingClient.BillingResponseCode.OK) {
+ val pendingIntent: PendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT_KEY)!!
delegate.startFlow(pendingIntent, request.requestCode)
return@flatMap Flowable.just(responseCode)
} else {
- return@flatMap Flowable.error(BillingException.fromCode(responseCode))
+ return@flatMap Flowable.error(BillingException.fromResult(billingResult))
}
}
.firstOrError()
- .toCompletable()
+ .ignoreElement()
}
-
fun replaceItem(request: ReplaceItemRequest, delegate: FlowDelegate): Completable {
return connectionFlowable
.flatMap {
@@ -64,30 +69,36 @@ class RxBillingFlow(
)
val responseCode = BillingHelper.getResponseCodeFromBundle(buyIntentBundle, null)
- if (responseCode == BillingClient.BillingResponse.OK) {
- val pendingIntent: PendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT)
+ val responseMessage = BillingHelper.getDebugMessageFromBundle(buyIntentBundle, null)
+ val billingResult = BillingResult.newBuilder()
+ .setResponseCode(responseCode)
+ .setDebugMessage(responseMessage)
+ .build()
+ if (responseCode == BillingClient.BillingResponseCode.OK) {
+ val pendingIntent: PendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT_KEY)!!
delegate.startFlow(pendingIntent, request.requestCode)
return@flatMap Flowable.just(responseCode)
} else {
- return@flatMap Flowable.error(BillingException.fromCode(responseCode))
+ return@flatMap Flowable.error(BillingException.fromResult(billingResult))
}
}
.firstOrError()
- .toCompletable()
+ .ignoreElement()
}
- fun handleActivityResult(activityResultCode: Int, data: Intent?): Single {
+ fun handleActivityResult(data: Intent?): Single {
return Single.create {
if (it.isDisposed) return@create
Timber.d("onActivityResult %s", data?.extras)
- val responseCode = BillingHelper.getResponseCodeFromIntent(data, null)
+ val billingResult = BillingHelper.getBillingResultFromIntent(data, null)
+ val responseCode = billingResult.responseCode
when (responseCode) {
- BillingClient.BillingResponse.OK -> {
+ BillingClient.BillingResponseCode.OK -> {
val purchases = BillingHelper.extractPurchases(data?.extras)
it.onSuccess(purchases[0])
}
- else -> it.onError(BillingException.fromCode(responseCode))
+ else -> it.onError(BillingException.fromResult(billingResult))
}
}
}
-}
\ No newline at end of file
+}
diff --git a/rxbilling/src/main/java/com/gen/rxbilling/flow/delegate/ConductorFlowDelegate.kt b/rxbilling/src/main/java/com/gen/rxbilling/flow/delegate/ConductorFlowDelegate.kt
deleted file mode 100644
index 1b62fba..0000000
--- a/rxbilling/src/main/java/com/gen/rxbilling/flow/delegate/ConductorFlowDelegate.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.gen.rxbilling.flow.delegate
-
-import android.app.PendingIntent
-import android.content.Intent
-import com.bluelinelabs.conductor.Controller
-
-class ConductorFlowDelegate(private val controller: Controller) : FlowDelegate {
-
- override fun startFlow(pendingIntent: PendingIntent, requestCode: Int) {
- controller.startIntentSenderForResult(
- pendingIntent.intentSender, requestCode, Intent(), 0, 0, 0, null)
- }
-}
\ No newline at end of file
diff --git a/rxbilling/src/main/java/com/gen/rxbilling/flow/delegate/androidx/FragmentFlowDelegate.kt b/rxbilling/src/main/java/com/gen/rxbilling/flow/delegate/FragmentFlowDelegate.kt
similarity index 78%
rename from rxbilling/src/main/java/com/gen/rxbilling/flow/delegate/androidx/FragmentFlowDelegate.kt
rename to rxbilling/src/main/java/com/gen/rxbilling/flow/delegate/FragmentFlowDelegate.kt
index 6c96cea..b54b902 100644
--- a/rxbilling/src/main/java/com/gen/rxbilling/flow/delegate/androidx/FragmentFlowDelegate.kt
+++ b/rxbilling/src/main/java/com/gen/rxbilling/flow/delegate/FragmentFlowDelegate.kt
@@ -1,8 +1,7 @@
-package com.gen.rxbilling.flow.delegate.androidx
+package com.gen.rxbilling.flow.delegate
import android.app.PendingIntent
import android.content.Intent
-import com.gen.rxbilling.flow.delegate.FlowDelegate
class FragmentFlowDelegate(private val fragment: androidx.fragment.app.Fragment) : FlowDelegate {
@@ -10,4 +9,4 @@ class FragmentFlowDelegate(private val fragment: androidx.fragment.app.Fragment)
fragment.startIntentSenderForResult(
pendingIntent.intentSender, requestCode, Intent(), 0, 0, 0, null)
}
-}
\ No newline at end of file
+}
diff --git a/rxbilling/src/main/java/com/gen/rxbilling/flow/delegate/support/FragmentFlowDelegate.kt b/rxbilling/src/main/java/com/gen/rxbilling/flow/delegate/support/FragmentFlowDelegate.kt
deleted file mode 100644
index de7c7e8..0000000
--- a/rxbilling/src/main/java/com/gen/rxbilling/flow/delegate/support/FragmentFlowDelegate.kt
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gen.rxbilling.flow.delegate.support
-
-import android.app.PendingIntent
-import android.content.Intent
-import android.support.v4.app.Fragment
-import com.gen.rxbilling.flow.delegate.FlowDelegate
-
-class FragmentFlowDelegate(private val fragment: Fragment) : FlowDelegate {
-
- override fun startFlow(pendingIntent: PendingIntent, requestCode: Int) {
- fragment.startIntentSenderForResult(
- pendingIntent.intentSender, requestCode, Intent(), 0, 0, 0, null)
- }
-}
\ No newline at end of file
diff --git a/rxbilling/src/main/java/com/gen/rxbilling/lifecycle/androidx/BillingConnectionManager.kt b/rxbilling/src/main/java/com/gen/rxbilling/lifecycle/BillingConnectionManager.kt
similarity index 89%
rename from rxbilling/src/main/java/com/gen/rxbilling/lifecycle/androidx/BillingConnectionManager.kt
rename to rxbilling/src/main/java/com/gen/rxbilling/lifecycle/BillingConnectionManager.kt
index 44b8e4e..c5b7559 100644
--- a/rxbilling/src/main/java/com/gen/rxbilling/lifecycle/androidx/BillingConnectionManager.kt
+++ b/rxbilling/src/main/java/com/gen/rxbilling/lifecycle/BillingConnectionManager.kt
@@ -1,9 +1,8 @@
-package com.gen.rxbilling.lifecycle.androidx
+package com.gen.rxbilling.lifecycle
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
-import com.gen.rxbilling.lifecycle.Connectable
import io.reactivex.disposables.Disposable
import timber.log.Timber
@@ -30,4 +29,4 @@ class BillingConnectionManager(
Timber.d("disconnect")
disposable?.dispose()
}
-}
\ No newline at end of file
+}
diff --git a/rxbilling/src/main/java/com/gen/rxbilling/lifecycle/arch/BillingConnectionManager.kt b/rxbilling/src/main/java/com/gen/rxbilling/lifecycle/arch/BillingConnectionManager.kt
deleted file mode 100644
index 8fe152c..0000000
--- a/rxbilling/src/main/java/com/gen/rxbilling/lifecycle/arch/BillingConnectionManager.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.gen.rxbilling.lifecycle.arch
-
-import android.arch.lifecycle.Lifecycle
-import android.arch.lifecycle.LifecycleObserver
-import android.arch.lifecycle.OnLifecycleEvent
-import com.gen.rxbilling.lifecycle.Connectable
-import io.reactivex.disposables.Disposable
-import timber.log.Timber
-
-class BillingConnectionManager(
- private val connectable: Connectable
-) : LifecycleObserver {
- private var disposable: Disposable? = null
-
- @OnLifecycleEvent(Lifecycle.Event.ON_START)
- fun connect() {
- Timber.d("connect")
- disposable = connectable.connect()
- .subscribe({
- Timber.d("$it")
- }, {
- Timber.e(it)
- }, {
- Timber.d("onComplete")
- })
- }
-
- @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
- fun disconnect() {
- Timber.d("disconnect")
- disposable?.dispose()
- }
-}
\ No newline at end of file