Skip to content

Commit 0d8164c

Browse files
authored
Release 5.0.0
Release 5.0.0
2 parents 49cc326 + 1f1ab72 commit 0d8164c

File tree

87 files changed

+1285
-1209
lines changed

Some content is hidden

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

87 files changed

+1285
-1209
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 5.0.0
2+
* New major version of Qonversion Flutter SDK. See the documentation for the changes list of changes and the migration guide.
3+
14
## 4.6.1
25
* Fixed an issue causing automation event losses on Android.
36
* Fixed a rare issue with the permissions cache on Android.

android/build.gradle

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
group 'com.qonversion.flutter.sdk.qonversion_flutter_sdk'
2-
version '4.6.0'
2+
version '5.0.0'
33

44
buildscript {
5-
ext.kotlin_version = '1.3.50'
5+
ext.kotlin_version = '1.6.10'
66
repositories {
77
google()
88
jcenter()
99
}
1010

1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:3.5.0'
12+
classpath 'com.android.tools.build:gradle:3.5.4'
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414
}
1515
}
@@ -18,20 +18,22 @@ rootProject.allprojects {
1818
repositories {
1919
google()
2020
jcenter()
21+
mavenLocal()
2122
}
2223
}
2324

2425
apply plugin: 'com.android.library'
2526
apply plugin: 'kotlin-android'
2627

2728
android {
28-
compileSdkVersion 28
29+
compileSdkVersion 33
2930

3031
sourceSets {
3132
main.java.srcDirs += 'src/main/kotlin'
3233
}
3334
defaultConfig {
3435
minSdkVersion 16
36+
targetSdkVersion 33
3537
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3638
}
3739
lintOptions {
@@ -41,6 +43,6 @@ android {
4143

4244
dependencies {
4345
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
44-
implementation "io.qonversion.sandwich:sandwich:0.2.1"
45-
implementation 'com.google.code.gson:gson:2.8.6'
46+
implementation "io.qonversion.sandwich:sandwich:1.0.0"
47+
implementation 'com.google.code.gson:gson:2.9.0'
4648
}

android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package com.qonversion.flutter.sdk.qonversion_flutter_sdk
22

33
import com.google.gson.Gson
4+
import io.flutter.embedding.engine.plugins.FlutterPlugin
45
import io.flutter.plugin.common.BinaryMessenger
6+
import io.flutter.plugin.common.MethodCall
7+
import io.flutter.plugin.common.MethodChannel
8+
import io.flutter.plugin.common.PluginRegistry
59
import io.qonversion.sandwich.AutomationsEventListener
610
import io.qonversion.sandwich.AutomationsSandwich
711
import io.qonversion.sandwich.BridgeData
812

9-
class AutomationsPlugin(messenger: BinaryMessenger) : AutomationsEventListener {
13+
class AutomationsPlugin(private val messenger: BinaryMessenger) : AutomationsEventListener {
1014
private var shownScreensStreamHandler: BaseEventStreamHandler? = null
1115
private var startedActionsStreamHandler: BaseEventStreamHandler? = null
1216
private var failedActionsStreamHandler: BaseEventStreamHandler? = null
@@ -17,6 +21,10 @@ class AutomationsPlugin(messenger: BinaryMessenger) : AutomationsEventListener {
1721
AutomationsSandwich()
1822
}
1923

24+
init {
25+
setup()
26+
}
27+
2028
companion object {
2129
private const val EVENT_CHANNEL_SHOWN_SCREENS = "shown_screens"
2230
private const val EVENT_CHANNEL_STARTED_ACTIONS = "started_actions"
@@ -25,7 +33,60 @@ class AutomationsPlugin(messenger: BinaryMessenger) : AutomationsEventListener {
2533
private const val EVENT_CHANNEL_FINISHED_AUTOMATIONS = "finished_automations"
2634
}
2735

28-
init {
36+
override fun onAutomationEvent(event: AutomationsEventListener.Event, payload: BridgeData?) {
37+
val (data, stream) = when (event) {
38+
AutomationsEventListener.Event.ScreenShown -> Pair(Gson().toJson(payload), shownScreensStreamHandler)
39+
AutomationsEventListener.Event.ActionStarted -> Pair(Gson().toJson(payload), startedActionsStreamHandler)
40+
AutomationsEventListener.Event.ActionFinished -> Pair(Gson().toJson(payload), finishedActionsStreamHandler)
41+
AutomationsEventListener.Event.ActionFailed -> Pair(Gson().toJson(payload), failedActionsStreamHandler)
42+
AutomationsEventListener.Event.AutomationsFinished -> Pair(payload, finishedAutomationsStreamHandler)
43+
}
44+
45+
stream?.eventSink?.success(data)
46+
}
47+
48+
fun subscribe() {
49+
automationSandwich.setDelegate(this)
50+
}
51+
52+
fun setNotificationsToken(token: String?, result: MethodChannel.Result) {
53+
token?.let {
54+
automationSandwich.setNotificationToken(it)
55+
result.success(null)
56+
} ?: result.noNecessaryDataError()
57+
}
58+
59+
fun handleNotification(args: Map<String, Any>, result: MethodChannel.Result) {
60+
@Suppress("UNCHECKED_CAST")
61+
val data = args["notificationData"] as? Map<String, Any> ?: return result.noNecessaryDataError()
62+
63+
if (data.isEmpty()) {
64+
return result.noNecessaryDataError()
65+
}
66+
67+
val isQonversionNotification = automationSandwich.handleNotification(data)
68+
result.success(isQonversionNotification)
69+
}
70+
71+
fun getNotificationCustomPayload(args: Map<String, Any>, result: MethodChannel.Result) {
72+
@Suppress("UNCHECKED_CAST")
73+
val data = args["notificationData"] as? Map<String, Any> ?: return result.noNecessaryDataError()
74+
75+
if (data.isEmpty()) {
76+
return result.noNecessaryDataError()
77+
}
78+
79+
val payload = automationSandwich.getNotificationCustomPayload(data)
80+
val payloadJson = Gson().toJson(payload)
81+
result.success(payloadJson)
82+
}
83+
84+
fun showScreen(screenId: String?, result: MethodChannel.Result) {
85+
screenId ?: return result.noNecessaryDataError()
86+
automationSandwich.showScreen(screenId, result.toResultListener())
87+
}
88+
89+
private fun setup() {
2990
val shownScreensListener = BaseListenerWrapper(messenger, EVENT_CHANNEL_SHOWN_SCREENS)
3091
shownScreensListener.register()
3192
shownScreensStreamHandler = shownScreensListener.eventStreamHandler
@@ -46,20 +107,4 @@ class AutomationsPlugin(messenger: BinaryMessenger) : AutomationsEventListener {
46107
finishedAutomationsListener.register()
47108
finishedAutomationsStreamHandler = finishedAutomationsListener.eventStreamHandler
48109
}
49-
50-
fun subscribe() {
51-
automationSandwich.subscribe(this)
52-
}
53-
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)
61-
}
62-
63-
stream?.eventSink?.success(data)
64-
}
65110
}

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

Lines changed: 9 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,92 +3,19 @@ package com.qonversion.flutter.sdk.qonversion_flutter_sdk
33
import io.flutter.plugin.common.MethodChannel
44
import io.qonversion.sandwich.SandwichError
55

6-
private const val passValidValue = "Please make sure you pass a valid value"
7-
8-
fun MethodChannel.Result.noArgsError() {
9-
return this.error("0", "Could not find call arguments", "Make sure you pass Map as call arguments")
10-
}
11-
12-
fun MethodChannel.Result.noApiKeyError() {
13-
return this.error("1", "Could not find API key", "Make sure you pass Map as call arguments")
14-
}
15-
16-
fun MethodChannel.Result.noUserIdError() {
17-
return this.error("2", "Could not find userID", "Make sure you pass Map as call arguments")
18-
}
19-
20-
fun MethodChannel.Result.noAutoTrackPurchasesError() {
21-
return this.error("3", "Could not find autoTrackPurchases boolean value", "Make sure you pass Map as call arguments")
22-
}
23-
24-
fun MethodChannel.Result.noDataError() {
25-
return this.error("4", "Could not find data", passValidValue)
26-
}
27-
28-
fun MethodChannel.Result.noProviderError() {
29-
return this.error("5", "Could not find provider", passValidValue)
30-
}
31-
32-
fun MethodChannel.Result.noProduct() {
33-
return this.error("ProductNotProvided", "Could not find product", "Please provide a valid product")
34-
}
35-
36-
fun MethodChannel.Result.noProductIdError() {
37-
return this.error("8", "Could not find productId value", "Please provide valid productId")
6+
fun MethodChannel.Result.noNecessaryDataError() {
7+
return error(
8+
"NoNecessaryDataError",
9+
"Could not find necessary arguments",
10+
"Make sure you pass correct call arguments"
11+
)
3812
}
3913

4014
fun MethodChannel.Result.sandwichError(error: SandwichError) {
41-
val errorDetails = getErrorDetails(error)
42-
return this.error("9", error.code, errorDetails)
15+
return error(error.code, error.description, error.additionalMessage)
4316
}
4417

4518
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)
48-
}
49-
50-
fun MethodChannel.Result.noNewProductIdError() {
51-
return this.error("10", "Could not find new product id", passValidValue)
19+
val errorCode = if (isCancelled) "PurchaseCancelledByUser" else error.code
20+
return error(errorCode, error.description, error.additionalMessage)
5221
}
53-
54-
fun MethodChannel.Result.noOldProductIdError() {
55-
return this.error("11", "Could not find old product id", passValidValue)
56-
}
57-
58-
fun MethodChannel.Result.noProperty() {
59-
return this.error("13", "Could not find property", passValidValue)
60-
}
61-
62-
fun MethodChannel.Result.noPropertyValue() {
63-
return this.error("14", "Could not find property value", passValidValue)
64-
}
65-
66-
fun MethodChannel.Result.offeringsError(error: SandwichError) {
67-
val errorDetails = getErrorDetails(error)
68-
return this.error("Offerings", "Could not get offerings. ${error.description}.", errorDetails)
69-
}
70-
71-
fun MethodChannel.Result.noSdkInfo() {
72-
return this.error("15", "Could not find sdk info", passValidValue)
73-
}
74-
75-
fun MethodChannel.Result.noLifetime() {
76-
return this.error("16", "Could not find lifetime", passValidValue)
77-
}
78-
79-
fun MethodChannel.Result.noProductIdField(details: String?) {
80-
return this.error("NoProductIdField", "Could not find qonversionId in Product", details)
81-
}
82-
83-
fun MethodChannel.Result.jsonSerializationError(details: String?) {
84-
return this.error("JSONSerialization", "JSON Serialization Error", details)
85-
}
86-
87-
private fun getErrorDetails(error: SandwichError): String {
88-
var result = error.description
89-
if (error.additionalMessage.isNotEmpty()) {
90-
result += ". Additional Message: ${error.additionalMessage}"
91-
}
92-
93-
return result
94-
}

0 commit comments

Comments
 (0)