Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No-Codes SDK #650

Open
wants to merge 4 commits into
base: feature/noCodesCore
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ dependencies {
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation project(':sdk')
implementation project(':nocodes')
}

apply plugin: 'com.google.gms.google-services'
9 changes: 9 additions & 0 deletions app/src/main/java/com/qonversion/android/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import java.util.Map;

import io.qonversion.nocodes.NoCodes;
import io.qonversion.nocodes.NoCodesConfig;

public class App extends MultiDexApplication {
public static final String CHANNEL_ID = "qonversion";

Expand All @@ -36,6 +39,12 @@ public void onCreate() {
.build();
Qonversion.initialize(qonversionConfig);

final NoCodesConfig noCodesConfig = new NoCodesConfig.Builder(
this,
"PV77YHL7qnGvsdmpTs7gimsxUvY-Znl2"
).build();
NoCodes.initialize(noCodesConfig);

Qonversion.getSharedInstance().syncHistoricalData();

AppsFlyerConversionListener conversionListener = new AppsFlyerConversionListener() {
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/java/com/qonversion/android/app/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ import com.qonversion.android.sdk.dto.products.QProduct
import com.qonversion.android.sdk.listeners.QEntitlementsUpdateListener
import com.qonversion.android.sdk.listeners.QonversionEntitlementsCallback
import com.qonversion.android.sdk.listeners.QonversionProductsCallback
import io.qonversion.nocodes.NoCodes
import io.qonversion.nocodes.dto.QAction
import io.qonversion.nocodes.error.NoCodesError
import io.qonversion.nocodes.interfaces.NoCodesDelegate
import io.qonversion.nocodes.interfaces.NoCodesShowScreenCallback
import io.qonversion.nocodes.showScreen

private const val TAG = "HomeFragment"

Expand Down Expand Up @@ -66,6 +72,28 @@ class HomeFragment : Fragment() {
}
})

NoCodes.shared.setDelegate(object : NoCodesDelegate {
override fun onScreenShown(screenId: String) {
super.onScreenShown(screenId)
}

override fun onActionStartedExecuting(action: QAction) {
super.onActionStartedExecuting(action)
}

override fun onActionFailedExecuting(action: QAction) {
super.onActionFailedExecuting(action)
}

override fun onActionFinishedExecuting(action: QAction) {
super.onActionFinishedExecuting(action)
}

override fun onFinished() {
super.onFinished()
}
})

binding.buttonSubscribe.setOnClickListener {
purchase(productIdSubs)
}
Expand Down
16 changes: 16 additions & 0 deletions config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<ID>MagicNumber:ApiErrorMapper.kt$ApiErrorMapper$20300</ID>
<ID>MagicNumber:ApiErrorMapper.kt$ApiErrorMapper$20303</ID>
<ID>MagicNumber:ApiErrorMapper.kt$ApiErrorMapper$20399</ID>
<ID>MagicNumber:ApiInteractorImpl.kt$418</ID>
<ID>MagicNumber:LogLevel.kt$LogLevel.Error$30</ID>
<ID>MagicNumber:LogLevel.kt$LogLevel.Info$10</ID>
<ID>MagicNumber:LogLevel.kt$LogLevel.Warning$20</ID>
<ID>MagicNumber:QEntitlementsCacheLifetime.kt$QEntitlementsCacheLifetime.Month$30</ID>
<ID>MagicNumber:QEntitlementsCacheLifetime.kt$QEntitlementsCacheLifetime.SixMonths$180</ID>
<ID>MagicNumber:QEntitlementsCacheLifetime.kt$QEntitlementsCacheLifetime.ThreeMonths$90</ID>
Expand Down Expand Up @@ -265,22 +269,33 @@
<ID>SwallowedException:EnvironmentProvider.kt$EnvironmentProvider$catch (throwable: Throwable) { UNKNOWN }</ID>
<ID>SwallowedException:ExceptionHandler.kt$ExceptionHandler$catch (e: Exception) { "" }</ID>
<ID>SwallowedException:FacebookAttribution.kt$FacebookAttribution$catch (e: Exception) { null }</ID>
<ID>SwallowedException:NoCodesInternal.kt$NoCodesInternal$catch (e: Exception) { // todo converting between NoCodesError / NoCodesException }</ID>
<ID>SwallowedException:PurchasesCache.kt$PurchasesCache$catch (e: IOException) { setOf() }</ID>
<ID>SwallowedException:QAutomationsManager.kt$QAutomationsManager$catch (e: JSONException) { null }</ID>
<ID>SwallowedException:ScreenFragment.kt$ScreenFragment$catch (e: ActivityNotFoundException) { logger.error("Couldn't find any Activity to handle the Intent with deeplink $url") automationsManager.automationsDidFailExecuting(actionResult) }</ID>
<ID>SwallowedException:ScreenFragment.kt$ScreenFragment$catch (e: ActivityNotFoundException) { logger.error("Couldn't find any Activity to handle the Intent with url $url") automationsManager.automationsDidFailExecuting(actionResult) }</ID>
<ID>SwallowedException:ScreenFragment.kt$ScreenFragment$catch (e: ActivityNotFoundException) { logger.error("ScreenActivity -&gt; Couldn't find any Activity to handle the Intent with deeplink $url") delegate?.onActionFailedExecuting(action) }</ID>
<ID>SwallowedException:ScreenFragment.kt$ScreenFragment$catch (e: ActivityNotFoundException) { logger.error("ScreenActivity -&gt; Couldn't find any Activity to handle the Intent with url $url") delegate?.onActionFailedExecuting(action) }</ID>
<ID>SwallowedException:ScreenFragment.kt$ScreenFragment$catch (e: Exception) { automationsManager.automationsDidFailExecuting(actionResult) }</ID>
<ID>SwallowedException:ScreenFragment.kt$ScreenFragment$catch (e: Exception) { delegate?.onActionFailedExecuting(action) }</ID>
<ID>SwallowedException:ScreenPresenter.kt$ScreenPresenter$catch (e: Exception) { logger.error("ScreenPresenter -&gt; failed to open the screen with id $screenId") view.onError("Something went wrong while loading the next screen") }</ID>
<ID>SwallowedException:SharedPreferencesCache.kt$SharedPreferencesCache$catch (e: IOException) { null }</ID>
<ID>ThrowingExceptionsWithoutMessageOrCause:AdvertisingProvider.kt$AdvertisingProvider.AdvertisingConnection$IllegalStateException()</ID>
<ID>ThrowsCount:ApiInteractorImpl.kt$ApiInteractorImpl$private suspend fun execute( request: Request, retryPolicy: RetryPolicy, attemptIndex: Int ): Response</ID>
<ID>TooGenericExceptionCaught:AdvertisingProvider.kt$AdvertisingProvider$e: Exception</ID>
<ID>TooGenericExceptionCaught:EnvironmentProvider.kt$EnvironmentProvider$throwable: Throwable</ID>
<ID>TooGenericExceptionCaught:ExceptionHandler.kt$ExceptionHandler$cause: Exception</ID>
<ID>TooGenericExceptionCaught:ExceptionHandler.kt$ExceptionHandler$e: Exception</ID>
<ID>TooGenericExceptionCaught:FacebookAttribution.kt$FacebookAttribution$e: Exception</ID>
<ID>TooGenericExceptionCaught:JsonSerializer.kt$JsonSerializer$cause: NullPointerException</ID>
<ID>TooGenericExceptionCaught:NetworkClientImpl.kt$NetworkClientImpl$cause: Exception</ID>
<ID>TooGenericExceptionCaught:NoCodesInternal.kt$NoCodesInternal$e: Exception</ID>
<ID>TooGenericExceptionCaught:QAutomationsManager.kt$QAutomationsManager$e: Exception</ID>
<ID>TooGenericExceptionCaught:QExceptionManager.kt$QExceptionManager$cause: Exception</ID>
<ID>TooGenericExceptionCaught:QFallbacksService.kt$QFallbacksService$e: Exception</ID>
<ID>TooGenericExceptionCaught:ScreenControllerImpl.kt$ScreenControllerImpl$e: Exception</ID>
<ID>TooGenericExceptionCaught:ScreenFragment.kt$ScreenFragment$e: Exception</ID>
<ID>TooGenericExceptionCaught:ScreenPresenter.kt$ScreenPresenter$e: Exception</ID>
<ID>TooManyFunctions:Api.kt$Api</ID>
<ID>TooManyFunctions:AppComponent.kt$AppComponent</ID>
<ID>TooManyFunctions:BillingClientWrapper.kt$BillingClientWrapper : BillingClientWrapperBaseIBillingClientWrapper</ID>
Expand All @@ -299,6 +314,7 @@
<ID>TooManyFunctions:ScreenFragment.kt$ScreenFragment : FragmentView</ID>
<ID>TooManyFunctions:SharedPreferencesCache.kt$SharedPreferencesCache : Cache</ID>
<ID>TooManyFunctions:extensions.kt$com.qonversion.android.sdk.internal.extensions.kt</ID>
<ID>UnnecessaryAbstractClass:BaseClass.kt$BaseClass</ID>
<ID>UnnecessaryAbstractClass:BillingClientWrapperBase.kt$BillingClientWrapperBase</ID>
<ID>UnnecessaryAbstractClass:RequestData.kt$RequestData</ID>
<ID>UnusedPrivateMember:AutomationsEvent.kt$AutomationsEvent$private val productId: String? // Temporarily inaccessible</ID>
Expand Down
1 change: 1 addition & 0 deletions nocodes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
46 changes: 46 additions & 0 deletions nocodes/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

android {
namespace 'io.qonversion.nocodes'
compileSdk 34

defaultConfig {
minSdk 21
targetSdk 34
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
buildTypes.each {
it.buildConfigField("String","VERSION_NAME", "\"${defaultConfig.versionName}\"")
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
buildFeatures {
viewBinding true
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1"
implementation project(':sdk')
}
21 changes: 21 additions & 0 deletions nocodes/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
11 changes: 11 additions & 0 deletions nocodes/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<activity
android:name=".internal.screen.view.ScreenActivity"
android:screenOrientation="portrait"
/>
</application>

</manifest>
110 changes: 110 additions & 0 deletions nocodes/src/main/java/io/qonversion/nocodes/NoCodes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package io.qonversion.nocodes

import android.util.Log
import io.qonversion.nocodes.dto.LogLevel
import io.qonversion.nocodes.interfaces.NoCodesDelegate
import io.qonversion.nocodes.internal.NoCodesInternal
import io.qonversion.nocodes.internal.di.DependenciesAssembly
import io.qonversion.nocodes.internal.dto.config.InternalConfig
import io.qonversion.nocodes.interfaces.NoCodesShowScreenCallback
import io.qonversion.nocodes.interfaces.ScreenCustomizationDelegate

interface NoCodes {

companion object {

private var backingInstance: NoCodes? = null

/**
* Use this variable to get a current initialized instance of the Qonversion No-Codes SDK.
* Please, use the property only after calling [NoCodes.initialize].
* Otherwise, trying to access the variable will cause an exception.
*
* @return Current initialized instance of the Qonversion No-Codes SDK.
* @throws UninitializedPropertyAccessException if the instance has not been initialized
*/
@JvmStatic
@get:JvmName("getSharedInstance")
val shared: NoCodes
get() = backingInstance ?: throw UninitializedPropertyAccessException(
"Qonversion No-Codes has not been initialized. You should call " +
"the initialize method before accessing the shared instance of Qonversion No-Codes."
)

/**
* An entry point to use Qonversion No-Codes SDK.
* Call to initialize Qonversion No-Codes SDK with the required data.
*
* @param config a config that contains key SDK settings.
* @return Initialized instance of the Qonversion No-Codes SDK.
*/
@JvmStatic
fun initialize(config: NoCodesConfig): NoCodes {
backingInstance?.let {
Log.e(
"Qonversion No-Codes", "Qonversion No-Codes has been initialized already. " +
"Multiple instances of Qonversion No-Codes are not supported now."
)
return it
}

val internalConfig = InternalConfig(config)
val dependenciesAssembly = DependenciesAssembly.Builder(
config.application,
internalConfig
).build()
return NoCodesInternal(internalConfig, dependenciesAssembly).also {
backingInstance = it
}
}
}

/**
* The delegate is receiving events from the No-Code screens.
* Make sure the method is called before [NoCodes.showScreen].
* You can also provide it during the initialization via [NoCodesConfig.Builder.setDelegate].
*
* @param delegate delegate to be called when any no-code screen event occurs.
*/
fun setDelegate(delegate: NoCodesDelegate)

/**
* The delegate is responsible for customizing screens representation.
* You can also provide it during the initialization via [NoCodesConfig.Builder.setScreenCustomizationDelegate].
*
* @param delegate delegate that would be called before opening Qonversion No-Code screens.
*/
fun setScreenCustomizationDelegate(delegate: ScreenCustomizationDelegate)

/**
* Show the screen using its ID.
* @param screenId identifier of the screen which must be shown.
* @param callback callback that is called when the screen is shown to a user.
*/
fun showScreen(screenId: String, callback: NoCodesShowScreenCallback)

/**
* Define the level of the logs that the SDK prints.
* The more strict the level is, the less logs will be written.
* For example, setting the log level as Warning will disable all info and verbose logs.
*
* You may set log level both *after* Qonversion No-Codes SDK initializing with [NoCodes.setLogLevel]
* and *while* Qonversion No-Codes initializing with [NoCodes.initialize]
*
* See [LogLevel] for details.
*
* @param logLevel the desired allowed log level.
*/
fun setLogLevel(logLevel: LogLevel)

/**
* Define the log tag that the Qonversion No-Codes SDK will print with every log message.
* For example, you can use it to filter the Qonversion SDK logs and your app own logs together.
*
* You may set log tag both *after* Qonversion No-Codes SDK initializing with [NoCodes.setLogTag]
* and *while* Qonversion No-Codes initializing with [NoCodes.initialize]
*
* @param logTag the desired log tag.
*/
fun setLogTag(logTag: String)
}
Loading
Loading