Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions QonversionSandwich.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
excluded_files = ['ios/sandwich/AutomationsSandwich.swift', 'ios/sandwich/AutomationsEventListener.swift', 'ios/sandwich/AutomationsMappers.swift']
s.name = 'QonversionSandwich'
s.version = '5.2.0'
s.version = '5.3.0'
s.summary = 'qonversion.io'
s.swift_version = '5.0'
s.description = <<-DESC
Expand All @@ -12,12 +12,12 @@ Pod::Spec.new do |s|
s.author = { 'Qonversion Inc.' => 'hi@qonversion.io' }
s.source = { :git => 'https://github.com/qonversion/sandwich-sdk.git', :tag => s.version.to_s }
s.framework = 'StoreKit'
s.platforms = { :ios => "9.0", :osx => "10.12" }
s.platforms = { :ios => "13.0", :osx => "10.12" }

s.osx.exclude_files = excluded_files

s.source_files = 'ios/sandwich/**/*.{h,m,swift}'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }

s.dependency "Qonversion", "5.13.0"
Comment thread
suriksarkisyan marked this conversation as resolved.
s.dependency "NoCodes", "0.0.5"
end
2 changes: 2 additions & 0 deletions android/sandwich/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
buildscript {
ext.qonversion_version = '8.2.1'
ext.nocodes_version = '0.0.1'
}

plugins {
Expand Down Expand Up @@ -44,6 +45,7 @@ ext {

dependencies {
api "io.qonversion.android.sdk:sdk:$qonversion_version"
api "io.qonversion:no-codes:$nocodes_version"
implementation 'androidx.preference:preference:1.2.0'
}

Expand Down
32 changes: 32 additions & 0 deletions android/sandwich/src/main/kotlin/io/qonversion/sandwich/Mappers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import com.qonversion.android.sdk.dto.products.QProductPricingPhase
import com.qonversion.android.sdk.dto.products.QProductStoreDetails
import com.qonversion.android.sdk.dto.properties.QUserProperties
import com.qonversion.android.sdk.dto.properties.QUserProperty
import io.qonversion.nocodes.dto.QAction
import io.qonversion.nocodes.error.NoCodesError

fun QonversionError.toSandwichError(): SandwichError {
return SandwichError(this)
Expand Down Expand Up @@ -339,3 +341,33 @@ fun Map<String, Any?>.toScreenPresentationConfig(): QScreenPresentationConfig {

return presentationStyle?.let { QScreenPresentationConfig(it) } ?: QScreenPresentationConfig()
}

fun QAction.toMap(): BridgeData {
val parametersMap = parameters?.mapKeys { it.key.key }?.mapValues { it.value }
return mapOf(
"type" to type.type,
"parameters" to parametersMap,
"error" to error?.toMap()
)
}

fun Map<String, Any?>.toNoCodesScreenPresentationConfig(): io.qonversion.nocodes.dto.QScreenPresentationConfig {
Comment thread
SpertsyanKM marked this conversation as resolved.
Outdated
val presentationStyle = try {
get("presentationStyle")?.takeIf { it is String }?.let {
io.qonversion.nocodes.dto.QScreenPresentationStyle.valueOf(it as String)
}
} catch (e: IllegalArgumentException) {
null
}

return presentationStyle?.let { io.qonversion.nocodes.dto.QScreenPresentationConfig(it) }
?: io.qonversion.nocodes.dto.QScreenPresentationConfig()
}

fun NoCodesError.toMap(): BridgeData {
return mapOf(
"code" to code.toString(),
"description" to details,
"additionalMessage" to qonversionError?.additionalMessage
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.qonversion.sandwich

interface NoCodesEventListener {
fun onNoCodesEvent(event: Event, payload: BridgeData? = null)

enum class Event(val key: String) {
ScreenShown("nocodes_screen_shown"),
ScreenClosed("nocodes_screen_closed"),
ActionStarted("nocodes_action_started"),
ActionFinished("nocodes_action_finished"),
ActionFailed("nocodes_action_failed"),
ScreenFailedToLoad("nocodes_screen_failed_to_load")
Comment thread
suriksarkisyan marked this conversation as resolved.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package io.qonversion.sandwich

import android.app.Application
import android.content.Context
import io.qonversion.nocodes.NoCodes
import io.qonversion.nocodes.NoCodesConfig
import io.qonversion.nocodes.dto.LogLevel
import io.qonversion.nocodes.interfaces.NoCodesDelegate
import io.qonversion.nocodes.interfaces.ScreenCustomizationDelegate
import io.qonversion.nocodes.dto.QScreenPresentationConfig
import io.qonversion.nocodes.dto.QScreenPresentationStyle
import io.qonversion.nocodes.dto.QAction
import io.qonversion.nocodes.error.NoCodesError
import io.qonversion.nocodes.error.NoCodesException

class NoCodesSandwich(
private val application: Application,
private val activityProvider: ActivityProvider
) {

private var defaultPresentationConfig: QScreenPresentationConfig? = null
private val screenPresentationConfigs = mutableMapOf<String, QScreenPresentationConfig>()
private var isCustomizationDelegateSet = false
private val screenCustomizationDelegate = object : ScreenCustomizationDelegate {
override fun getPresentationConfigurationForScreen(screenId: String): QScreenPresentationConfig {
return screenPresentationConfigs[screenId] ?: defaultPresentationConfig ?: QScreenPresentationConfig()
}
}

// region Initialization

fun initialize(
context: Context,
projectKey: String,
proxyUrl: String? = null,
logLevelKey: String? = null,
logTag: String? = null
) {
val configBuilder = NoCodesConfig.Builder(context, projectKey)

proxyUrl?.let {
configBuilder.setProxyURL(it)
}

logLevelKey?.let {
try {
val logLevel = LogLevel.valueOf(it)
configBuilder.setLogLevel(logLevel)
} catch (e: IllegalArgumentException) {
// Ignore invalid log level
Comment thread
suriksarkisyan marked this conversation as resolved.
Outdated
}
}

logTag?.let {
configBuilder.setLogTag(it)
}

NoCodes.initialize(configBuilder.build())
}

// endregion

// region Delegate

fun setDelegate(eventListener: NoCodesEventListener) {
NoCodes.shared.setDelegate(createNoCodesDelegate(eventListener))
}

fun setScreenCustomizationDelegate() {
if (!isCustomizationDelegateSet) {
isCustomizationDelegateSet = true
NoCodes.shared.setScreenCustomizationDelegate(screenCustomizationDelegate)
}
}

fun setScreenPresentationConfig(configData: Map<String, Any?>, screenId: String? = null) {
val config = configData.toNoCodesScreenPresentationConfig()

if (!isCustomizationDelegateSet) {
isCustomizationDelegateSet = true
NoCodes.shared.setScreenCustomizationDelegate(screenCustomizationDelegate)
}

screenId?.let {
screenPresentationConfigs[screenId] = config
} ?: run {
screenPresentationConfigs.clear()
defaultPresentationConfig = config
}
}

// endregion

// region Screen Management

fun showScreen(screenId: String) {
NoCodes.shared.showScreen(screenId)
}

fun close() {
NoCodes.shared.close()
}

// endregion

// region Configuration

fun setLogLevel(logLevelKey: String) {
val logLevel = LogLevel.valueOf(logLevelKey)
NoCodes.shared.setLogLevel(logLevel)
}

fun setLogTag(logTag: String) {
NoCodes.shared.setLogTag(logTag)
}

// endregion

// region Private

private fun createNoCodesDelegate(eventListener: NoCodesEventListener): NoCodesDelegate {
return object : NoCodesDelegate {
override fun onScreenShown(screenId: String) {
val payload = mapOf("screenId" to screenId)
eventListener.onNoCodesEvent(NoCodesEventListener.Event.ScreenShown, payload)
}

override fun onActionStartedExecuting(action: QAction) {
val payload = mapOf("action" to action.toMap())
eventListener.onNoCodesEvent(NoCodesEventListener.Event.ActionStarted, payload)
}

override fun onActionFailedToExecute(action: QAction) {
val payload = mapOf("action" to action.toMap())
eventListener.onNoCodesEvent(NoCodesEventListener.Event.ActionFailed, payload)
}

override fun onActionFinishedExecuting(action: QAction) {
val payload = mapOf("action" to action.toMap())
eventListener.onNoCodesEvent(NoCodesEventListener.Event.ActionFinished, payload)
}

override fun onFinished() {
eventListener.onNoCodesEvent(NoCodesEventListener.Event.ScreenClosed)
}

override fun onScreenFailedToLoad(error: NoCodesError) {
val payload = mapOf(
"code" to error.code.toString(),
"description" to error.details,
"additionalMessage" to error.qonversionError?.additionalMessage
)
Comment thread
suriksarkisyan marked this conversation as resolved.
Outdated
eventListener.onNoCodesEvent(NoCodesEventListener.Event.ScreenFailedToLoad, payload)
}
}
}

// endregion
}
4 changes: 2 additions & 2 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
source 'https://github.com/CocoaPods/Specs.git'

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
platform :ios, '13.0'

use_frameworks!

target 'QonversionSandwich' do
pod 'Qonversion', '5.13.0'
Comment thread
suriksarkisyan marked this conversation as resolved.
pod 'NoCodes', '0.0.5'
end

Comment on lines +7 to 11
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed?

target 'Sample' do
Expand Down
24 changes: 14 additions & 10 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
PODS:
- Qonversion (5.13.0):
- Qonversion/Main (= 5.13.0)
- Qonversion/Main (5.13.0)
- QonversionSandwich (5.1.7):
- Qonversion (= 5.13.0)
- NoCodes (0.0.5):
- Qonversion (= 5.13.3)
- Qonversion (5.13.3):
- Qonversion/Main (= 5.13.3)
- Qonversion/Main (5.13.3)
- QonversionSandwich (5.3.0):
- NoCodes (= 0.0.5)

DEPENDENCIES:
- Qonversion (= 5.13.0)
- NoCodes (= 0.0.5)
- QonversionSandwich (from `../`)

SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
- NoCodes
- Qonversion

EXTERNAL SOURCES:
QonversionSandwich:
:path: "../"

SPEC CHECKSUMS:
Qonversion: 37addeba74c5b328de9e1173b580c971b6d764ec
QonversionSandwich: 6aa0afcf15dc79817eef20bf5dfe475b32bcff9a
NoCodes: 40aab24087b8e27f1f9da901ab023a64a0d35d15
Qonversion: 2b32ae8681de3ba02db5b5ed69c8f213ac4a28fa
QonversionSandwich: fdf2cc9b254bbbb6bf5e9ba545d570de9be013ac

PODFILE CHECKSUM: ea5d129345e5e6f263575a7a6d165488b50b6991
PODFILE CHECKSUM: bf8d60259bbb4b0784fe7e49fb6de90eada0700c

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
Loading
Loading