-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from qonversion/release/4.3.0
Release 4.3.0
- Loading branch information
Showing
31 changed files
with
772 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...id/src/main/kotlin/com/qonversion/flutter/sdk/qonversion_flutter_sdk/AutomationsPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
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 | ||
|
||
class AutomationsPlugin { | ||
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() | ||
|
||
companion object { | ||
private const val EVENT_CHANNEL_SHOWN_SCREENS = "shown_screens" | ||
private const val EVENT_CHANNEL_STARTED_ACTIONS = "started_actions" | ||
private const val EVENT_CHANNEL_FAILED_ACTIONS = "failed_actions" | ||
private const val EVENT_CHANNEL_FINISHED_ACTIONS = "finished_actions" | ||
private const val EVENT_CHANNEL_FINISHED_AUTOMATIONS = "finished_automations" | ||
} | ||
|
||
fun register(messenger: BinaryMessenger) { | ||
val shownScreensListener = BaseListenerWrapper(messenger, EVENT_CHANNEL_SHOWN_SCREENS) | ||
shownScreensListener.register() | ||
shownScreensStreamHandler = shownScreensListener.eventStreamHandler | ||
|
||
val startedActionsListener = BaseListenerWrapper(messenger, EVENT_CHANNEL_STARTED_ACTIONS) | ||
startedActionsListener.register() | ||
startedActionsStreamHandler = startedActionsListener.eventStreamHandler | ||
|
||
val failedActionsListener = BaseListenerWrapper(messenger, EVENT_CHANNEL_FAILED_ACTIONS) | ||
failedActionsListener.register() | ||
failedActionsStreamHandler = failedActionsListener.eventStreamHandler | ||
|
||
val finishedActionsListener = BaseListenerWrapper(messenger, EVENT_CHANNEL_FINISHED_ACTIONS) | ||
finishedActionsListener.register() | ||
finishedActionsStreamHandler = finishedActionsListener.eventStreamHandler | ||
|
||
val finishedAutomationsListener = BaseListenerWrapper(messenger, EVENT_CHANNEL_FINISHED_AUTOMATIONS) | ||
finishedAutomationsListener.register() | ||
finishedAutomationsStreamHandler = finishedAutomationsListener.eventStreamHandler | ||
} | ||
|
||
fun setAutomationsDelegate() { | ||
Automations.setDelegate(automationsDelegate) | ||
} | ||
|
||
private fun getAutomationsDelegate() = object : AutomationsDelegate { | ||
override fun automationsDidShowScreen(screenId: String) { | ||
shownScreensStreamHandler?.eventSink?.success(screenId) | ||
} | ||
|
||
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// AutomationsPlugin.swift | ||
// qonversion_flutter | ||
// | ||
// Created by Maria on 18.11.2021. | ||
// | ||
|
||
import Qonversion | ||
|
||
public class AutomationsPlugin: NSObject { | ||
private let eventChannelShownScreens = "shown_screens" | ||
private let eventChannelStartedActions = "started_actions" | ||
private let eventChannelFailedActions = "failed_actions" | ||
private let eventChannelFinishedActions = "finished_actions" | ||
private let eventChannelFinishedAutomations = "finished_automations" | ||
|
||
private var shownScreensStreamHandler: BaseEventStreamHandler? | ||
private var startedActionsStreamHandler: BaseEventStreamHandler? | ||
private var failedActionsStreamHandler: BaseEventStreamHandler? | ||
private var finishedActionsStreamHandler: BaseEventStreamHandler? | ||
private var finishedAutomationsStreamHandler: BaseEventStreamHandler? | ||
|
||
public func register(_ registrar: FlutterPluginRegistrar) { | ||
let shownScreensListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: eventChannelShownScreens) | ||
shownScreensListener.register() { self.shownScreensStreamHandler = $0 } | ||
|
||
let startedActionsListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: eventChannelStartedActions) | ||
startedActionsListener.register() { self.startedActionsStreamHandler = $0 } | ||
|
||
let failedActionsListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: eventChannelFailedActions) | ||
failedActionsListener.register() { self.failedActionsStreamHandler = $0 } | ||
|
||
let finishedActionsListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: eventChannelFinishedActions) | ||
finishedActionsListener.register() { self.finishedActionsStreamHandler = $0 } | ||
|
||
let finishedAutomationsListener = FlutterListenerWrapper<BaseEventStreamHandler>(registrar, postfix: eventChannelFinishedAutomations) | ||
finishedAutomationsListener.register() { self.finishedAutomationsStreamHandler = $0 } | ||
|
||
Qonversion.Automations.setDelegate(self) | ||
} | ||
} | ||
|
||
extension AutomationsPlugin: Qonversion.AutomationsDelegate { | ||
public func automationsDidShowScreen(_ screenID: String) { | ||
shownScreensStreamHandler?.eventSink?(screenID) | ||
} | ||
|
||
public func automationsDidStartExecuting(actionResult: Qonversion.ActionResult) { | ||
let payload = actionResult.toMap().toJson() | ||
startedActionsStreamHandler?.eventSink?(payload) | ||
} | ||
|
||
public func automationsDidFailExecuting(actionResult: Qonversion.ActionResult) { | ||
let payload = actionResult.toMap().toJson() | ||
failedActionsStreamHandler?.eventSink?(payload) | ||
} | ||
|
||
public func automationsDidFinishExecuting(actionResult: Qonversion.ActionResult) { | ||
let payload = actionResult.toMap().toJson() | ||
finishedActionsStreamHandler?.eventSink?(payload) | ||
} | ||
|
||
public func automationsFinished() { | ||
finishedAutomationsStreamHandler?.eventSink?(nil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.