Skip to content

Commit

Permalink
Merge pull request #14 from apphud/APH-785
Browse files Browse the repository at this point in the history
Aph 785
  • Loading branch information
ABIvan-Tech authored Jun 4, 2021
2 parents b2235c9 + 4c36311 commit 645fac3
Show file tree
Hide file tree
Showing 29 changed files with 786 additions and 224 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official

sdkVersion=1.0.0
sdkVersion=1.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ApphudServiceTest {

private val userId = "cleaner_303"
private val deviceId = "cleaner_303"
private val API_KEY = "app_oBcXz2z9j8spKPL2T7sZwQaQN5Jzme"
private val API_KEY = "app_4sY9cLggXpMDDQMmvc5wXUPGReMp8G"
private lateinit var service: ApphudService

@Before
Expand Down
52 changes: 42 additions & 10 deletions sdk/src/main/java/com/apphud/sdk/Apphud.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package com.apphud.sdk
import android.app.Activity
import android.content.Context
import com.android.billingclient.api.SkuDetails
import com.apphud.sdk.domain.ApphudNonRenewingPurchase
import com.apphud.sdk.domain.ApphudSubscription
import com.apphud.sdk.domain.*


object Apphud {
Expand Down Expand Up @@ -125,6 +124,21 @@ object Apphud {
@kotlin.jvm.JvmStatic
fun syncPurchases() = ApphudInternal.syncPurchases()

/**
* Fetches paywalls configured in Apphud dashboard. Paywalls are automatically cached on device.
*/
fun getPaywalls(callback: (paywalls: List<ApphudPaywall>?, error: ApphudError?) -> Unit) {
ApphudInternal.getPaywalls(callback = callback)
}

/**
* Permission groups configured in Apphud dashboard. Groups are cached on device.
* Note that this method may be `null` at first launch of the app.
*/
fun permissionGroups(): List<ApphudGroup> {
return ApphudInternal.productGroups
}

/**
* Implements `Restore Purchases` mechanism. Basically it just sends current Play Market Purchase Tokens to Apphud and returns subscriptions info.
*
Expand All @@ -133,16 +147,16 @@ object Apphud {
* @param callback: Required. Returns array of subscription (or subscriptions in case you have more than one subscription group), array of standard in-app purchases and an error. All of three parameters are optional.
*/
@kotlin.jvm.JvmStatic
fun restorePurchases(callback: (subscriptions: List<ApphudSubscription>?,
purchases: List<ApphudNonRenewingPurchase>?,
error: ApphudError?) -> Unit) {
fun restorePurchases(callback: ApphudPurchasesRestoreCallback) {
ApphudInternal.restorePurchases(callback)
}

/**
* Returns an array of **SkuDetails** objects that you added in Apphud.
* Note that this method will return **null** if products are not yet fetched.
*/
@Deprecated("Use \"getPaywalls\" method instead.",
ReplaceWith("getPaywalls(callback: (paywalls: List<ApphudPaywall>?, error: ApphudError?) -> Unit)"))
@kotlin.jvm.JvmStatic
fun products(): List<SkuDetails>? {
return ApphudInternal.getSkuDetailsList()
Expand All @@ -154,7 +168,8 @@ object Apphud {
* You can use `productsDidFetchCallback` callback
* or implement `apphudFetchSkuDetailsProducts` listener method. Use whatever you like most.
*/

@Deprecated("Use \"getPaywalls\" method instead.",
ReplaceWith("getPaywalls(callback: (paywalls: List<ApphudPaywall>?, error: ApphudError?) -> Unit)"))
@kotlin.jvm.JvmStatic
fun productsFetchCallback(callback: (List<SkuDetails>) -> Unit) {
ApphudInternal.productsFetchCallback(callback)
Expand All @@ -165,6 +180,8 @@ object Apphud {
* Note that you have to add this product identifier in Apphud.
* Will return **null** if product is not yet fetched from Google Play Billing.
*/
@Deprecated("Use \"getPaywalls\" method instead.",
ReplaceWith("getPaywalls(callback: (paywalls: List<ApphudPaywall>?, error: ApphudError?) -> Unit)"))
@kotlin.jvm.JvmStatic
fun product(productIdentifier: String): SkuDetails? {
return ApphudInternal.getSkuDetailsByProductId(productIdentifier)
Expand All @@ -177,9 +194,11 @@ object Apphud {
* @param productId: The identifier of the product you wish to purchase
* @param block: Optional. Returns `ApphudPurchaseResult` object.
*/
@Deprecated("Purchase product by product identifier",
ReplaceWith("purchase(activity: Activity, product: ApphudProduct, block: ((ApphudPurchaseResult) -> Unit)?)"))
@kotlin.jvm.JvmStatic
fun purchase(activity: Activity, productId: String, block: ((ApphudPurchaseResult) -> Unit)?) =
ApphudInternal.purchase(activity, productId, true, block)
ApphudInternal.purchase(activity, productId, null, null, true, block)

/**
* Purchase sku product and automatically submit Google Play purchase token to Apphud
Expand All @@ -188,9 +207,22 @@ object Apphud {
* @param details The SkuDetails of the product you wish to purchase
* @param block Optional. Returns `ApphudPurchaseResult` object.
*/
@Deprecated("Purchase product by product identifier",
ReplaceWith("purchase(activity: Activity, product: ApphudProduct, block: ((ApphudPurchaseResult) -> Unit)?)"))
@kotlin.jvm.JvmStatic
fun purchase(activity: Activity, details: SkuDetails, block: ((ApphudPurchaseResult) -> Unit)?) =
ApphudInternal.purchase(activity, details, true, block)
ApphudInternal.purchase(activity, null, details, null, true, block)

/**
* Purchase sku product and automatically submit Google Play purchase token to Apphud
*
* @param activity current Activity for use
* @param details The SkuDetails of the product you wish to purchase
* @param block Optional. Returns `ApphudPurchaseResult` object.
*/
@kotlin.jvm.JvmStatic
fun purchase(activity: Activity, product: ApphudProduct, block: ((ApphudPurchaseResult) -> Unit)?) =
ApphudInternal.purchase(activity, null, null, product, true, block)

/**
* Purchase product by id and automatically submit Google Play purchase token to Apphud
Expand All @@ -206,7 +238,7 @@ object Apphud {
*/
@kotlin.jvm.JvmStatic
fun purchaseWithoutValidation(activity: Activity, productId: String, block: ((ApphudPurchaseResult) -> Unit)?) =
ApphudInternal.purchase(activity, productId, false, block)
ApphudInternal.purchase(activity, productId, null,null,false, block)

/**
* Purchase sku product and automatically submit Google Play purchase token to Apphud
Expand All @@ -222,7 +254,7 @@ object Apphud {
*/
@kotlin.jvm.JvmStatic
fun purchaseWithoutValidation(activity: Activity, details: SkuDetails, block: ((ApphudPurchaseResult) -> Unit)?) =
ApphudInternal.purchase(activity, details, false, block)
ApphudInternal.purchase(activity,null, details, null, false, block)

/**
* Set custom user property.
Expand Down
13 changes: 13 additions & 0 deletions sdk/src/main/java/com/apphud/sdk/ApphudExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.apphud.sdk

import android.content.Context
import android.content.pm.ApplicationInfo
import java.util.concurrent.atomic.AtomicInteger

internal fun Context.isDebuggable(): Boolean {
return 0 != this.applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE
}

internal fun AtomicInteger.isBothSkuLoaded(): Boolean {
return this.get() == 2
}
Loading

0 comments on commit 645fac3

Please sign in to comment.