Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 4.5.0
* Big refactoring of the native modules made to simplify further upgrades and make it easy to keep the SDK functionality up-to-date.

## 4.4.0
* 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.
* 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.
Expand Down
3 changes: 1 addition & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ version '4.4.0'

buildscript {
ext.kotlin_version = '1.3.50'
ext.qonversion_version = '3.3.0'
repositories {
google()
jcenter()
Expand Down Expand Up @@ -42,6 +41,6 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "io.qonversion.android.sdk:sdk:$qonversion_version"
implementation 'io.qonversion.sandwich:sandwich:0.1.0'
implementation 'com.google.code.gson:gson:2.8.6'
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package com.qonversion.flutter.sdk.qonversion_flutter_sdk

import com.google.gson.Gson
import com.qonversion.android.sdk.automations.Automations
import com.qonversion.android.sdk.automations.AutomationsDelegate
import com.qonversion.android.sdk.automations.QActionResult
import io.flutter.plugin.common.BinaryMessenger
import io.qonversion.sandwich.AutomationsEventListener
import io.qonversion.sandwich.AutomationsSandwich
import io.qonversion.sandwich.BridgeData

class AutomationsPlugin {
class AutomationsPlugin(messenger: BinaryMessenger) : AutomationsEventListener {
private var shownScreensStreamHandler: BaseEventStreamHandler? = null
private var startedActionsStreamHandler: BaseEventStreamHandler? = null
private var failedActionsStreamHandler: BaseEventStreamHandler? = null
private var finishedActionsStreamHandler: BaseEventStreamHandler? = null
private var finishedAutomationsStreamHandler: BaseEventStreamHandler? = null
private val automationsDelegate = getAutomationsDelegate()

private val automationSandwich by lazy {
AutomationsSandwich()
}

companion object {
private const val EVENT_CHANNEL_SHOWN_SCREENS = "shown_screens"
Expand All @@ -22,7 +25,7 @@ class AutomationsPlugin {
private const val EVENT_CHANNEL_FINISHED_AUTOMATIONS = "finished_automations"
}

fun register(messenger: BinaryMessenger) {
init {
val shownScreensListener = BaseListenerWrapper(messenger, EVENT_CHANNEL_SHOWN_SCREENS)
shownScreensListener.register()
shownScreensStreamHandler = shownScreensListener.eventStreamHandler
Expand All @@ -44,32 +47,19 @@ class AutomationsPlugin {
finishedAutomationsStreamHandler = finishedAutomationsListener.eventStreamHandler
}

fun setAutomationsDelegate() {
Automations.setDelegate(automationsDelegate)
fun subscribe() {
automationSandwich.subscribe(this)
}

private fun getAutomationsDelegate() = object : AutomationsDelegate {
override fun automationsDidShowScreen(screenId: String) {
shownScreensStreamHandler?.eventSink?.success(screenId)
override fun onAutomationEvent(event: AutomationsEventListener.Event, payload: BridgeData?) {
val (data, stream) = when (event) {
AutomationsEventListener.Event.ScreenShown -> Pair(Gson().toJson(payload), shownScreensStreamHandler)
AutomationsEventListener.Event.ActionStarted -> Pair(Gson().toJson(payload), startedActionsStreamHandler)
AutomationsEventListener.Event.ActionFinished -> Pair(Gson().toJson(payload), finishedActionsStreamHandler)
AutomationsEventListener.Event.ActionFailed -> Pair(Gson().toJson(payload), failedActionsStreamHandler)
AutomationsEventListener.Event.AutomationsFinished -> Pair(payload, finishedAutomationsStreamHandler)
}

override fun automationsDidStartExecuting(actionResult: QActionResult) {
val payload = Gson().toJson(actionResult.toMap())
startedActionsStreamHandler?.eventSink?.success(payload)
}

override fun automationsDidFailExecuting(actionResult: QActionResult) {
val payload = Gson().toJson(actionResult.toMap())
failedActionsStreamHandler?.eventSink?.success(payload)
}

override fun automationsDidFinishExecuting(actionResult: QActionResult) {
val payload = Gson().toJson(actionResult.toMap())
finishedActionsStreamHandler?.eventSink?.success(payload)
}

override fun automationsFinished() {
finishedAutomationsStreamHandler?.eventSink?.success(null)
}
stream?.eventSink?.success(data)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.qonversion.flutter.sdk.qonversion_flutter_sdk

import com.qonversion.android.sdk.QonversionError
import io.flutter.plugin.common.MethodChannel
import io.qonversion.sandwich.SandwichError

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

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

fun MethodChannel.Result.qonversionError(error: QonversionError) {
fun MethodChannel.Result.sandwichError(error: SandwichError) {
val errorDetails = getErrorDetails(error)
return this.error("9", error.description, errorDetails)
return this.error("9", error.code, errorDetails)
}

fun MethodChannel.Result.purchaseError(error: SandwichError, isCancelled: Boolean) {
val errorDetails = getErrorDetails(error)
return this.error(if (isCancelled) "PurchaseCancelledByUser" else "9", error.code, errorDetails)
}

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

fun MethodChannel.Result.parsingError(message: String?) {
return this.error("12", "Arguments Parsing Error", message)
}

fun MethodChannel.Result.noProperty() {
return this.error("13", "Could not find property", passValidValue)
}
Expand All @@ -62,7 +63,7 @@ fun MethodChannel.Result.noPropertyValue() {
return this.error("14", "Could not find property value", passValidValue)
}

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

private fun getErrorDetails(error: QonversionError): String {
var result = "Qonversion Error Code: ${error.code}"
private fun getErrorDetails(error: SandwichError): String {
var result = error.description
if (error.additionalMessage.isNotEmpty()) {
result += ". Additional Message: ${error.additionalMessage}"
}
Expand Down

This file was deleted.

Loading