Skip to content

Commit f3ee0f1

Browse files
authored
Merge pull request #163 from qonversion/release/4.5.0
Release 4.5.0
2 parents dca30f4 + 3f18c93 commit f3ee0f1

Some content is hidden

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

47 files changed

+739
-1708
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 4.5.0
2+
* Big refactoring of the native modules made to simplify further upgrades and make it easy to keep the SDK functionality up-to-date.
3+
14
## 4.4.0
25
* Added support of network connection lack or unexpected backend errors. Now Qonversion SDK will handle user permissions correctly even if it can't reach out to the API and will actualize them with the next successful request. Also, products and offerings become permanently available after the first successful launch - nothing will interfere user from the purchase.
36
* Added method `setPermissionsCacheLifetime` to configure the lifetime of permissions cache. It is used if we faced any error trying to get permissions from our API. Defaults to one month.

android/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ version '4.4.0'
33

44
buildscript {
55
ext.kotlin_version = '1.3.50'
6-
ext.qonversion_version = '3.3.0'
76
repositories {
87
google()
98
jcenter()
@@ -42,6 +41,6 @@ android {
4241

4342
dependencies {
4443
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
45-
implementation "io.qonversion.android.sdk:sdk:$qonversion_version"
44+
implementation 'io.qonversion.sandwich:sandwich:0.1.0'
4645
implementation 'com.google.code.gson:gson:2.8.6'
4746
}
Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package com.qonversion.flutter.sdk.qonversion_flutter_sdk
22

33
import com.google.gson.Gson
4-
import com.qonversion.android.sdk.automations.Automations
5-
import com.qonversion.android.sdk.automations.AutomationsDelegate
6-
import com.qonversion.android.sdk.automations.QActionResult
74
import io.flutter.plugin.common.BinaryMessenger
5+
import io.qonversion.sandwich.AutomationsEventListener
6+
import io.qonversion.sandwich.AutomationsSandwich
7+
import io.qonversion.sandwich.BridgeData
88

9-
class AutomationsPlugin {
9+
class AutomationsPlugin(messenger: BinaryMessenger) : AutomationsEventListener {
1010
private var shownScreensStreamHandler: BaseEventStreamHandler? = null
1111
private var startedActionsStreamHandler: BaseEventStreamHandler? = null
1212
private var failedActionsStreamHandler: BaseEventStreamHandler? = null
1313
private var finishedActionsStreamHandler: BaseEventStreamHandler? = null
1414
private var finishedAutomationsStreamHandler: BaseEventStreamHandler? = null
15-
private val automationsDelegate = getAutomationsDelegate()
15+
16+
private val automationSandwich by lazy {
17+
AutomationsSandwich()
18+
}
1619

1720
companion object {
1821
private const val EVENT_CHANNEL_SHOWN_SCREENS = "shown_screens"
@@ -22,7 +25,7 @@ class AutomationsPlugin {
2225
private const val EVENT_CHANNEL_FINISHED_AUTOMATIONS = "finished_automations"
2326
}
2427

25-
fun register(messenger: BinaryMessenger) {
28+
init {
2629
val shownScreensListener = BaseListenerWrapper(messenger, EVENT_CHANNEL_SHOWN_SCREENS)
2730
shownScreensListener.register()
2831
shownScreensStreamHandler = shownScreensListener.eventStreamHandler
@@ -44,32 +47,19 @@ class AutomationsPlugin {
4447
finishedAutomationsStreamHandler = finishedAutomationsListener.eventStreamHandler
4548
}
4649

47-
fun setAutomationsDelegate() {
48-
Automations.setDelegate(automationsDelegate)
50+
fun subscribe() {
51+
automationSandwich.subscribe(this)
4952
}
5053

51-
private fun getAutomationsDelegate() = object : AutomationsDelegate {
52-
override fun automationsDidShowScreen(screenId: String) {
53-
shownScreensStreamHandler?.eventSink?.success(screenId)
54+
override fun onAutomationEvent(event: AutomationsEventListener.Event, payload: BridgeData?) {
55+
val (data, stream) = when (event) {
56+
AutomationsEventListener.Event.ScreenShown -> Pair(Gson().toJson(payload), shownScreensStreamHandler)
57+
AutomationsEventListener.Event.ActionStarted -> Pair(Gson().toJson(payload), startedActionsStreamHandler)
58+
AutomationsEventListener.Event.ActionFinished -> Pair(Gson().toJson(payload), finishedActionsStreamHandler)
59+
AutomationsEventListener.Event.ActionFailed -> Pair(Gson().toJson(payload), failedActionsStreamHandler)
60+
AutomationsEventListener.Event.AutomationsFinished -> Pair(payload, finishedAutomationsStreamHandler)
5461
}
5562

56-
override fun automationsDidStartExecuting(actionResult: QActionResult) {
57-
val payload = Gson().toJson(actionResult.toMap())
58-
startedActionsStreamHandler?.eventSink?.success(payload)
59-
}
60-
61-
override fun automationsDidFailExecuting(actionResult: QActionResult) {
62-
val payload = Gson().toJson(actionResult.toMap())
63-
failedActionsStreamHandler?.eventSink?.success(payload)
64-
}
65-
66-
override fun automationsDidFinishExecuting(actionResult: QActionResult) {
67-
val payload = Gson().toJson(actionResult.toMap())
68-
finishedActionsStreamHandler?.eventSink?.success(payload)
69-
}
70-
71-
override fun automationsFinished() {
72-
finishedAutomationsStreamHandler?.eventSink?.success(null)
73-
}
63+
stream?.eventSink?.success(data)
7464
}
7565
}

android/src/main/kotlin/com/qonversion/flutter/sdk/qonversion_flutter_sdk/Constants.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.

android/src/main/kotlin/com/qonversion/flutter/sdk/qonversion_flutter_sdk/FlutterResult+CustomErrors.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.qonversion.flutter.sdk.qonversion_flutter_sdk
22

3-
import com.qonversion.android.sdk.QonversionError
43
import io.flutter.plugin.common.MethodChannel
4+
import io.qonversion.sandwich.SandwichError
55

66
private const val passValidValue = "Please make sure you pass a valid value"
77

@@ -37,9 +37,14 @@ fun MethodChannel.Result.noProductIdError() {
3737
return this.error("8", "Could not find productId value", "Please provide valid productId")
3838
}
3939

40-
fun MethodChannel.Result.qonversionError(error: QonversionError) {
40+
fun MethodChannel.Result.sandwichError(error: SandwichError) {
4141
val errorDetails = getErrorDetails(error)
42-
return this.error("9", error.description, errorDetails)
42+
return this.error("9", error.code, errorDetails)
43+
}
44+
45+
fun MethodChannel.Result.purchaseError(error: SandwichError, isCancelled: Boolean) {
46+
val errorDetails = getErrorDetails(error)
47+
return this.error(if (isCancelled) "PurchaseCancelledByUser" else "9", error.code, errorDetails)
4348
}
4449

4550
fun MethodChannel.Result.noNewProductIdError() {
@@ -50,10 +55,6 @@ fun MethodChannel.Result.noOldProductIdError() {
5055
return this.error("11", "Could not find old product id", passValidValue)
5156
}
5257

53-
fun MethodChannel.Result.parsingError(message: String?) {
54-
return this.error("12", "Arguments Parsing Error", message)
55-
}
56-
5758
fun MethodChannel.Result.noProperty() {
5859
return this.error("13", "Could not find property", passValidValue)
5960
}
@@ -62,7 +63,7 @@ fun MethodChannel.Result.noPropertyValue() {
6263
return this.error("14", "Could not find property value", passValidValue)
6364
}
6465

65-
fun MethodChannel.Result.offeringsError(error: QonversionError) {
66+
fun MethodChannel.Result.offeringsError(error: SandwichError) {
6667
val errorDetails = getErrorDetails(error)
6768
return this.error("Offerings", "Could not get offerings. ${error.description}.", errorDetails)
6869
}
@@ -83,8 +84,8 @@ fun MethodChannel.Result.jsonSerializationError(details: String?) {
8384
return this.error("JSONSerialization", "JSON Serialization Error", details)
8485
}
8586

86-
private fun getErrorDetails(error: QonversionError): String {
87-
var result = "Qonversion Error Code: ${error.code}"
87+
private fun getErrorDetails(error: SandwichError): String {
88+
var result = error.description
8889
if (error.additionalMessage.isNotEmpty()) {
8990
result += ". Additional Message: ${error.additionalMessage}"
9091
}

android/src/main/kotlin/com/qonversion/flutter/sdk/qonversion_flutter_sdk/Mapper.kt

Lines changed: 0 additions & 218 deletions
This file was deleted.

0 commit comments

Comments
 (0)