Skip to content

Commit

Permalink
Merge pull request #7 from betterme-dev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
dmytro-ostapovets authored Jul 27, 2018
2 parents 58b7ec6 + d8bc363 commit 75b01a1
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 63 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# RxBilling
Rx wrapper for Billing Library with connection managment
Rx wrapper for Billing Library with connection management

# Download

[ ![Download](https://api.bintray.com/packages/betterme/rxbilling/com.betterme%3Arxbilling/images/download.svg) ](https://bintray.com/betterme/rxbilling/com.betterme%3Arxbilling/_latestVersion)

implementation 'com.betterme:rxbilling:$latestVersion'
implementation 'com.android.billingclient:billing:$billingClientVer'

# How to use

Expand Down Expand Up @@ -188,4 +189,14 @@ updates observer will not be triggered
}, {
//handle error
}))
}
}

## 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
4 changes: 2 additions & 2 deletions app/src/main/java/com/gen/rxbilling/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import com.gen.rxbilling.client.RxBilling
import com.gen.rxbilling.client.RxBillingImpl
import com.gen.rxbilling.connection.BillingClientFactory
import com.gen.rxbilling.connection.BillingServiceFactory
import com.gen.rxbilling.flow.ActivityFlowDelegate
import com.gen.rxbilling.flow.delegate.ActivityFlowDelegate
import com.gen.rxbilling.flow.BuyItemRequest
import com.gen.rxbilling.flow.RxBillingFlow
import com.gen.rxbilling.lifecycle.BillingConnectionManager
import com.gen.rxbilling.lifecycle.arch.BillingConnectionManager
import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.activity_main.*
import timber.log.Timber
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apply from: 'dependencies.gradle'

buildscript {
ext.kotlin_version = '1.2.30'
ext.kotlin_version = '1.2.41'
ext.maven_version = '1.5'
ext.bintray_version = '1.7.2'
ext.dokka_version = '0.9.16'
Expand Down
38 changes: 25 additions & 13 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
ext {
compileSdkVer = 27
compileSdkVer = 28
minSdkVer = 14
targetSdkVer = 27
targetSdkVer = 28

versionCode = 1
versionName = '0.9.1'
versionName = '0.9.2'

// Kotlin
kotlinVer = '1.2.50'
androidKtxVer = '0.2'
androidKtxVer = '1.0.0-alpha1'

// Support library
supportLibraryVer = '27.1.1'
supportLibraryVer = '28.0.0-alpha1'
constraintLayout = '1.0.2'

// 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.0"
lifecycleVer = "1.1.1"

// Reactive Extensions
rxJava2Ver = '2.1.10'
Expand Down Expand Up @@ -44,9 +49,16 @@ ext {

// Dependencies
supportDependencies = [
appCompat : "com.android.support:appcompat-v7:$supportLibraryVer",
support : "com.android.support:support-v4:$supportLibraryVer",
design : "com.android.support:design:$supportLibraryVer",
appCompat: "com.android.support:appcompat-v7:$supportLibraryVer",
design : "com.android.support:design:$supportLibraryVer",
]

androidXdependencies = [
appCompat : "androidx.appcompat:appcompat:$xAppCompatVer",
fragment : "androidx.fragment:fragment:$xFragmentVer",
lifecycleRuntime : "androidx.lifecycle:lifecycle-runtime:$xLifecycleVer",
lifecycleCompiler : "androidx.lifecycle:lifecycle-compiler:$xLifecycleVer",
lifecycleExtensions: "androidx.lifecycle:lifecycle-extensions:$xLifecycleVer"
]

kotlinDependencies = [
Expand All @@ -56,7 +68,7 @@ ext {
]

developmentDependencies = [
timber : "com.jakewharton.timber:timber:$timberVer",
timber: "com.jakewharton.timber:timber:$timberVer",
]

presentationDependencies = [
Expand All @@ -68,9 +80,9 @@ ext {
]

dataDependencies = [
rxJava : "io.reactivex.rxjava2:rxjava:$rxJava2Ver",
rxAndroid : "io.reactivex.rxjava2:rxandroid:$rxAndroid2Ver",
billingClient : "com.android.billingclient:billing:$billingClientVer"
rxJava : "io.reactivex.rxjava2:rxjava:$rxJava2Ver",
rxAndroid : "io.reactivex.rxjava2:rxandroid:$rxAndroid2Ver",
billingClient: "com.android.billingclient:billing:$billingClientVer"
]

testDependencies = [
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.useAndroidX = true
android.enableJetifier = false
GROUP=com.betterme
POM_NAME=rxbilling
POM_PACKAGING=aar
Expand Down
16 changes: 10 additions & 6 deletions rxbilling/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ dokka {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation kotlinDependencies.kotlinStdLib
implementation dataDependencies.billingClient
implementation presentationDependencies.lifecycleExtensions
kapt presentationDependencies.lifecycleCompiler
implementation developmentDependencies.timber
implementation dataDependencies.rxJava
implementation dataDependencies.rxAndroid
implementation dataDependencies.billingClient
implementation kotlinDependencies.kotlinStdLib

compileOnly presentationDependencies.conductor
implementation supportDependencies.appCompat
compileOnly presentationDependencies.lifecycleExtensions
compileOnly androidXdependencies.lifecycleRuntime
compileOnly androidXdependencies.lifecycleExtensions

kapt presentationDependencies.lifecycleCompiler
kapt androidXdependencies.lifecycleCompiler

testImplementation testDependencies.jUnit
testImplementation testDependencies.mockito
Expand Down Expand Up @@ -146,7 +150,7 @@ bintray {
version {
name = libraryVersionName
desc = 'Billing library release $libraryVersionName'
released = new Date()
released = new Date()
vcsTag = libraryVersionName
}
}
Expand Down
36 changes: 0 additions & 36 deletions rxbilling/src/main/java/com/gen/rxbilling/flow/FlowDelegate.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.android.billingclient.util.BillingHelper.RESPONSE_BUY_INTENT
import com.android.vending.billing.IInAppBillingService
import com.gen.rxbilling.connection.BillingServiceFactory
import com.gen.rxbilling.exception.BillingException
import com.gen.rxbilling.flow.delegate.FlowDelegate
import com.gen.rxbilling.lifecycle.Connectable
import io.reactivex.Completable
import io.reactivex.Flowable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.gen.rxbilling.flow.delegate

import android.app.Activity
import android.app.PendingIntent
import android.content.Intent

class ActivityFlowDelegate(private val activity: Activity) : FlowDelegate {

override fun startFlow(pendingIntent: PendingIntent, requestCode: Int) {
activity.startIntentSenderForResult(
pendingIntent.intentSender, requestCode, Intent(), 0, 0, 0)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gen.rxbilling.flow.delegate

import android.app.PendingIntent

interface FlowDelegate {

fun startFlow(pendingIntent: PendingIntent, requestCode: Int)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.gen.rxbilling.flow.delegate.androidx

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 {

override fun startFlow(pendingIntent: PendingIntent, requestCode: Int) {
fragment.startIntentSenderForResult(
pendingIntent.intentSender, requestCode, Intent(), 0, 0, 0, null)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.gen.rxbilling.lifecycle.androidx

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

class BillingConnectionManager<T>(
private val connectable: Connectable<T>
) : 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()
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.gen.rxbilling.lifecycle
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<T>(private val connectable: Connectable<T>)
: LifecycleObserver {
class BillingConnectionManager<T>(
private val connectable: Connectable<T>
) : LifecycleObserver {
private var disposable: Disposable? = null

@OnLifecycleEvent(Lifecycle.Event.ON_START)
Expand Down

0 comments on commit 75b01a1

Please sign in to comment.