Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions ios/QonversionSandwich.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
701E6970280764480005C35D /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = 701E696F280764480005C35D /* Podfile */; };
701E697428082C700005C35D /* QonversionSandwich.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 701E697228082C700005C35D /* QonversionSandwich.podspec */; };
701E69BB28099E380005C35D /* LICENSE.txt in Resources */ = {isa = PBXBuildFile; fileRef = 701E69BA28099E380005C35D /* LICENSE.txt */; };
706C3C452DCCEB1F00AF131F /* NoCodesSandwich.swift in Sources */ = {isa = PBXBuildFile; fileRef = 706C3C442DCCEB1F00AF131F /* NoCodesSandwich.swift */; };
706C3C472DCCF0EE00AF131F /* NoCodesEventListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 706C3C462DCCF0EE00AF131F /* NoCodesEventListener.swift */; };
70F78C6328104E81004974DA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70F78C6228104E81004974DA /* AppDelegate.swift */; };
70F78C6528104E81004974DA /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70F78C6428104E81004974DA /* SceneDelegate.swift */; };
70F78C6728104E81004974DA /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70F78C6628104E81004974DA /* ViewController.swift */; };
Expand Down Expand Up @@ -51,6 +53,8 @@
701E696F280764480005C35D /* Podfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Podfile; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
701E697228082C700005C35D /* QonversionSandwich.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = QonversionSandwich.podspec; path = ../QonversionSandwich.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
701E69BA28099E380005C35D /* LICENSE.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = LICENSE.txt; path = ../LICENSE.txt; sourceTree = "<group>"; };
706C3C442DCCEB1F00AF131F /* NoCodesSandwich.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoCodesSandwich.swift; sourceTree = "<group>"; };
706C3C462DCCF0EE00AF131F /* NoCodesEventListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoCodesEventListener.swift; sourceTree = "<group>"; };
70F78C6028104E81004974DA /* Sample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sample.app; sourceTree = BUILT_PRODUCTS_DIR; };
70F78C6228104E81004974DA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
70F78C6428104E81004974DA /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -115,10 +119,12 @@
6A8EB5C827FD896400DCCD9E /* sandwich */ = {
isa = PBXGroup;
children = (
706C3C462DCCF0EE00AF131F /* NoCodesEventListener.swift */,
6A8EB5D028046BAA00DCCD9E /* Mappers.swift */,
70F78C7A2810658D004974DA /* AutomationsMappers.swift */,
6ACDA8FD2806D6750003AC8F /* AutomationsEventListener.swift */,
6ACDA8F5280586460003AC8F /* QonversionSandwich.swift */,
706C3C442DCCEB1F00AF131F /* NoCodesSandwich.swift */,
6ACDA8F7280587A20003AC8F /* Constants.swift */,
6ACDA8F92806D36F0003AC8F /* QonversionEventListener.swift */,
6A439CA32807112400019344 /* SandwichError.swift */,
Expand Down Expand Up @@ -368,7 +374,9 @@
70F78C7B2810658D004974DA /* AutomationsMappers.swift in Sources */,
6ACDA8FA2806D36F0003AC8F /* QonversionEventListener.swift in Sources */,
6A439CA42807112400019344 /* SandwichError.swift in Sources */,
706C3C472DCCF0EE00AF131F /* NoCodesEventListener.swift in Sources */,
6ACDA8FE2806D6750003AC8F /* AutomationsEventListener.swift in Sources */,
706C3C452DCCEB1F00AF131F /* NoCodesSandwich.swift in Sources */,
6ACDA8F6280586460003AC8F /* QonversionSandwich.swift in Sources */,
6A8EB5D128046BAA00DCCD9E /* Mappers.swift in Sources */,
6ACDA8F8280587A20003AC8F /* Constants.swift in Sources */,
Expand Down Expand Up @@ -615,7 +623,7 @@
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 15.4;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -648,7 +656,7 @@
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 15.4;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Loading
Loading