Skip to content

Commit 3102f0b

Browse files
authored
Release 2.6.0 (#70)
1 parent 0601084 commit 3102f0b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+460
-186
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
## 2.6.0
2+
3+
- **BREAKING** [Android] `ApphudListener.apphudDidReceivePurchase` method was introduced
4+
- **BREAKING** [iOS], [Android] `paywalls` method was removed
5+
- **BREAKING** [iOS] `rawPaywalls` method was removed
6+
- [Android] `ApphudNonRenewingPurchase.purchaseToken` property was introduced
7+
- [Android] `ApphudSubscription.purchaseToken` property was introduced
8+
- [Android], [iOS] `deferPlacements` method was introduced
9+
- [Android] `refreshUserData` method was introduced
10+
- [Android], [iOS] `forceFlushUserProperties` method was introduced
11+
- [Android] `refreshUserData` now returns `ApphudUser?`
12+
- [Android] `updateUserID` now returns `ApphudUser?`
13+
- [Android], [iOS] `attributeFromWeb` method was introduced
14+
15+
- Dependencies of Native SDK's were updated to:
16+
- [Android] 2.8.3
17+
- [iOS] 3.5.6
18+
119
## 2.5.4
220

321
- [iOS],[Android] `ApphudAttributionProvider.facebook` was added.

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ android {
5353

5454
dependencies {
5555
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
56-
implementation "com.apphud:ApphudSDK-Android:2.7.0"
56+
implementation 'com.apphud:ApphudSDK-Android:2.8.3'
5757
implementation 'com.android.billingclient:billing:6.1.0'
5858
implementation 'com.google.code.gson:gson:2.8.8'
5959
}

android/src/main/kotlin/com/apphud/fluttersdk/ApphudPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class ApphudPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
128128

129129
private fun setHeaders() {
130130
HeadersInterceptor.X_SDK = "Flutter"
131-
HeadersInterceptor.X_SDK_VERSION = "2.5.4"
131+
HeadersInterceptor.X_SDK_VERSION = "2.6.0"
132132
}
133133

134134
override fun onDetachedFromActivityForConfigChanges() {

android/src/main/kotlin/com/apphud/fluttersdk/Extensions.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ fun ApphudNonRenewingPurchase.toMap(): HashMap<String, Any?> {
9797
"productId" to productId,
9898
"purchasedAt" to purchasedAt,
9999
"canceledAt" to canceledAt,
100-
"isActive" to isActive()
100+
"isActive" to isActive(),
101+
"purchaseToken" to purchaseToken
101102
)
102103
}
103104

@@ -111,14 +112,15 @@ fun ApphudSubscription.toMap(): HashMap<String, Any?> {
111112
"isAutorenewEnabled" to isAutoRenewEnabled,
112113
"isIntroductoryActivated" to isIntroductoryActivated,
113114
"isActive" to isActive(),
114-
"status" to status.name.lowercase(Locale.ROOT)
115+
"status" to status.name.lowercase(Locale.ROOT),
116+
"purchaseToken" to purchaseToken
115117
)
116118
}
117119

118120
fun ApphudGroup.toMap(): HashMap<String, Any?> {
119121
return hashMapOf(
120122
"name" to name,
121-
"productIds" to ((products?.map { it.productId }) ?: listOf()),
123+
"productIds" to productIds(),
122124
"hasAccess" to hasAccess()
123125
)
124126
}

android/src/main/kotlin/com/apphud/fluttersdk/FlutterSdkCommon.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@ package com.apphud.fluttersdk
22

33
import com.apphud.sdk.Apphud
44
import com.apphud.sdk.domain.ApphudPaywall
5-
5+
import kotlinx.coroutines.suspendCancellableCoroutine
6+
import kotlin.coroutines.resume
7+
import kotlin.coroutines.suspendCoroutine
68

79
object FlutterSdkCommon {
810
public suspend fun getPaywall(
911
paywallIdentifier: String?,
1012
placementIdentifier: String?
1113
): ApphudPaywall? {
12-
val foundPaywall: ApphudPaywall? = if (placementIdentifier != null) {
14+
return if (placementIdentifier != null) {
1315
val placements = Apphud.placements()
1416
placements.firstOrNull { it.identifier == placementIdentifier }?.paywall
1517
} else if (paywallIdentifier != null) {
16-
val paywalls = Apphud.paywalls()
17-
paywalls.firstOrNull { it.identifier == paywallIdentifier }
18+
suspendCancellableCoroutine { cont ->
19+
Apphud.paywallsDidLoadCallback { paywalls, _ ->
20+
val paywall = paywalls.firstOrNull { it.identifier == paywallIdentifier }
21+
cont.resume(paywall)
22+
}
23+
}
1824
} else null
19-
return foundPaywall
2025
}
2126
}

android/src/main/kotlin/com/apphud/fluttersdk/handlers/ApphudListenerHandler.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.apphud.fluttersdk.handlers
22

33
import com.android.billingclient.api.ProductDetails
4+
import com.android.billingclient.api.Purchase
45
import com.apphud.fluttersdk.toMap
56
import com.apphud.sdk.Apphud
67
import com.apphud.sdk.ApphudListener
@@ -25,6 +26,7 @@ class ApphudListenerHandler(handleOnMainThreadP: HandleOnMainThread) :
2526
private var subscriptionsCached: List<ApphudSubscription>? = null
2627
private var purchasesCached: List<ApphudNonRenewingPurchase>? = null
2728
private var placementsCached: List<ApphudPlacement>? = null
29+
private var purchaseCached: Purchase? = null
2830
private var handleOnMainThread = handleOnMainThreadP
2931

3032
init {
@@ -65,6 +67,7 @@ class ApphudListenerHandler(handleOnMainThreadP: HandleOnMainThread) :
6567
subscriptionsCached?.let { v -> apphudSubscriptionsUpdated(v) }
6668
purchasesCached?.let { v -> apphudNonRenewingPurchasesUpdated(v) }
6769
placementsCached?.let { v -> placementsDidFullyLoad(v) }
70+
purchaseCached?.let { v -> apphudDidReceivePurchase(v) }
6871
}
6972

7073
private fun stop() {
@@ -80,6 +83,15 @@ class ApphudListenerHandler(handleOnMainThreadP: HandleOnMainThread) :
8083
}
8184
}
8285

86+
override fun apphudDidReceivePurchase(purchase: Purchase) {
87+
purchaseCached = purchase
88+
if(isListeningStarted) {
89+
handleOnMainThread {
90+
channel?.invokeMethod("apphudDidReceivePurchase", purchase.toMap())
91+
}
92+
}
93+
}
94+
8395

8496
override fun apphudFetchProductDetails(details: List<ProductDetails>) {
8597
detailsCached = details

android/src/main/kotlin/com/apphud/fluttersdk/handlers/AttributionHandler.kt

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.apphud.fluttersdk.handlers
22

3+
import com.apphud.fluttersdk.toMap
34
import com.apphud.sdk.Apphud
45
import com.apphud.sdk.ApphudAttributionProvider
56
import io.flutter.plugin.common.MethodChannel
@@ -19,7 +20,24 @@ class AttributionHandler(
1920
AttributionRoutes.addAttribution.name -> AttributionParser(result).parse(args) { provider, data, identifier ->
2021
addAttribution(provider, data, identifier, result)
2122
}
23+
2224
AttributionRoutes.collectSearchAdsAttribution.name -> result.notImplemented()
25+
AttributionRoutes.attributeFromWeb.name -> AttributeFromWebParser(result).parse(args) { data ->
26+
attributeFromWeb(data, result)
27+
}
28+
}
29+
}
30+
31+
private fun attributeFromWeb(data: Map<String, Any>?, result: MethodChannel.Result) {
32+
if (data == null) {
33+
result.success({ "wasSuccessful" to false })
34+
return
35+
}
36+
Apphud.attributeFromWeb(data) { wasSuccessful, user ->
37+
val resultMap = hashMapOf<String, Any?>()
38+
resultMap["wasSuccessful"] = wasSuccessful
39+
resultMap["user"] = user?.toMap()
40+
handleOnMainThread { result.success(resultMap) }
2341
}
2442
}
2543

@@ -69,12 +87,33 @@ class AttributionHandler(
6987
}
7088
}
7189
}
90+
91+
class AttributeFromWebParser(val result: MethodChannel.Result) {
92+
fun parse(
93+
args: Map<String, Any>?, callback: (
94+
data: Map<String, Any>?,
95+
) -> Unit
96+
) {
97+
try {
98+
if (args == null) {
99+
callback(null)
100+
} else {
101+
val data = args as? Map<String, Any>?
102+
callback(data)
103+
}
104+
} catch (e: IllegalArgumentException) {
105+
result.error("400", e.message, "")
106+
}
107+
}
108+
}
72109
}
73110

111+
74112
enum class AttributionRoutes {
75113

76114
addAttribution,
77-
collectSearchAdsAttribution;
115+
collectSearchAdsAttribution,
116+
attributeFromWeb;
78117

79118
companion object Mapper {
80119
fun stringValues(): List<String> {

android/src/main/kotlin/com/apphud/fluttersdk/handlers/HandlePurchasesHandler.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ class HandlePurchasesHandler(
2727

2828
HandlePurchasesRoutes.restorePurchases.name -> restorePurchases(result)
2929
HandlePurchasesRoutes.hasPremiumAccess.name -> hasPremiumAccess(result)
30+
HandlePurchasesRoutes.refreshUserData.name -> refreshUserData(result)
31+
}
32+
}
33+
34+
private fun refreshUserData(result: MethodChannel.Result) {
35+
Apphud.refreshUserData { user ->
36+
handleOnMainThread { result.success(user?.toMap()) }
3037
}
3138
}
3239

@@ -118,7 +125,8 @@ enum class HandlePurchasesRoutes {
118125
nonRenewingPurchases,
119126
isNonRenewingPurchaseActive,
120127
restorePurchases,
121-
hasPremiumAccess;
128+
hasPremiumAccess,
129+
refreshUserData;
122130

123131
companion object Mapper {
124132
fun stringValues(): List<String> {

android/src/main/kotlin/com/apphud/fluttersdk/handlers/InitializationHandler.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ class InitializationHandler(
6363
}
6464

6565
private fun updateUserID(userId: String, result: MethodChannel.Result) {
66-
Apphud.updateUserId(userId = userId)
67-
handleOnMainThread { result.success(null) }
66+
Apphud.updateUserId(userId = userId) { user ->
67+
handleOnMainThread { result.success(user?.toMap()) }
68+
}
6869
}
6970

7071
private fun userID(result: MethodChannel.Result) {

android/src/main/kotlin/com/apphud/fluttersdk/handlers/MakePurchaseHandler.kt

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import com.apphud.fluttersdk.FlutterSdkCommon
66
import com.apphud.fluttersdk.toApphudProduct
77
import com.apphud.fluttersdk.toMap
88
import com.apphud.sdk.Apphud
9-
import com.apphud.sdk.ApphudError
109
import com.apphud.sdk.ApphudPurchaseResult
11-
import com.apphud.sdk.domain.ApphudPaywall
1210
import com.apphud.sdk.domain.ApphudProduct
1311
import com.apphud.sdk.flutter.ApphudFlutter
1412
import io.flutter.plugin.common.MethodChannel
@@ -51,8 +49,6 @@ class MakePurchaseHandler(
5149

5250
MakePurchaseRoutes.getPaywalls.name -> result.notImplemented()
5351

54-
MakePurchaseRoutes.paywalls.name -> paywalls(result)
55-
5652
MakePurchaseRoutes.paywallsDidLoadCallback.name -> paywallsDidLoadCallback(result)
5753

5854
MakePurchaseRoutes.purchaseProduct.name -> PurchaseProductParser(result).parse(args)
@@ -66,7 +62,7 @@ class MakePurchaseHandler(
6662
)
6763
}
6864

69-
MakePurchaseRoutes.permissionGroups.name -> getPermissionGroups(result)
65+
MakePurchaseRoutes.permissionGroups.name -> permissionGroups(result)
7066

7167
MakePurchaseRoutes.rawPaywalls.name -> rawPaywalls(result)
7268

@@ -84,20 +80,20 @@ class MakePurchaseHandler(
8480
result
8581
)
8682
}
83+
84+
MakePurchaseRoutes.deferPlacements.name -> deferPlacements(result)
8785
}
8886
}
8987

90-
private fun getPermissionGroups(result: MethodChannel.Result) {
91-
val groups = Apphud.permissionGroups()
92-
handleOnMainThread { result.success(groups.map { it.toMap() }) }
88+
private fun deferPlacements(result: MethodChannel.Result) {
89+
Apphud.deferPlacements()
90+
handleOnMainThread { result.success(null) }
9391
}
9492

95-
private fun paywalls(result: MethodChannel.Result) {
93+
private fun permissionGroups(result: MethodChannel.Result) {
9694
GlobalScope.launch {
97-
val paywalls: List<ApphudPaywall> = Apphud.paywalls()
98-
val resultMap = hashMapOf<String, Any?>()
99-
resultMap["paywalls"] = paywalls.map { paywall -> paywall.toMap() }
100-
handleOnMainThread { result.success(resultMap) }
95+
val groups = Apphud.fetchPermissionGroups()
96+
handleOnMainThread { result.success(groups.map { it.toMap() }) }
10197
}
10298
}
10399

@@ -346,14 +342,14 @@ enum class MakePurchaseRoutes {
346342
syncPurchasesInObserverMode,
347343
presentOfferCodeRedemptionSheet,
348344
getPaywalls,
349-
paywalls,
350345
purchaseProduct,
351346
permissionGroups,
352347
paywallsDidLoadCallback,
353348
rawPaywalls,
354349
refreshUserData,
355350
loadFallbackPaywalls,
356-
trackPurchase;
351+
trackPurchase,
352+
deferPlacements;
357353

358354
companion object Mapper {
359355
fun stringValues(): List<String> {

0 commit comments

Comments
 (0)