From 70be30fe9af75349e5ddb187c797c6d5848747fc Mon Sep 17 00:00:00 2001 From: Hristo Borisov Date: Thu, 11 May 2023 17:01:28 +0300 Subject: [PATCH] Add PE variables. (Not compilable, needs an SDK build with 5.0.0) --- RondoApp/build.gradle | 6 +- .../com/leanplum/rondo/MigrationActivity.kt | 117 ++++++++++++++---- .../main/res/layout/activity_migration.xml | 7 ++ 3 files changed, 105 insertions(+), 25 deletions(-) diff --git a/RondoApp/build.gradle b/RondoApp/build.gradle index a4f0e1d..b668f74 100644 --- a/RondoApp/build.gradle +++ b/RondoApp/build.gradle @@ -5,8 +5,8 @@ apply plugin: 'realm-android' apply plugin: 'com.google.gms.google-services' apply plugin: 'com.huawei.agconnect' -def LEANPLUM_SDK_VERSION = System.getenv("LEANPLUM_SDK_VERSION") ?: "7.1.2-beta1" -def LEANPLUM_CT_SDK_VERSION = System.getenv("LEANPLUM_CT_SDK_VERSION") ?: "4.7.4" +def LEANPLUM_SDK_VERSION = System.getenv("LEANPLUM_SDK_VERSION") ?: "7.1.2" +def LEANPLUM_CT_SDK_VERSION = System.getenv("LEANPLUM_CT_SDK_VERSION") ?: "5.0.0" ext { KEYSTORE_PATH_PROP = 'storeFilePath' @@ -132,7 +132,7 @@ dependencies { // CleverTap // implementation 'com.google.android.gms:play-services-base:18.1.0' // implementation 'com.android.installreferrer:installreferrer:2.2' - implementation "com.clevertap.android:push-templates:1.0.7" + implementation "com.clevertap.android:push-templates:1.0.9" // CleverTap Xiaomi SDK for both dev and prod flavors implementation "com.clevertap.android:clevertap-xiaomi-sdk:1.5.2" implementation files("libs/MiPush_SDK_Client_5_1_1-G_3rd.aar") diff --git a/RondoApp/src/main/java/com/leanplum/rondo/MigrationActivity.kt b/RondoApp/src/main/java/com/leanplum/rondo/MigrationActivity.kt index 21a9414..94e1241 100644 --- a/RondoApp/src/main/java/com/leanplum/rondo/MigrationActivity.kt +++ b/RondoApp/src/main/java/com/leanplum/rondo/MigrationActivity.kt @@ -1,5 +1,6 @@ package com.leanplum.rondo +import android.annotation.SuppressLint import android.os.Bundle import android.util.TypedValue import android.view.ViewGroup @@ -7,7 +8,13 @@ import android.widget.Button import android.widget.LinearLayout import android.widget.TextView import androidx.appcompat.app.AppCompatActivity +import com.clevertap.android.sdk.CleverTapAPI +import com.clevertap.android.sdk.variables.Var +import com.clevertap.android.sdk.variables.callbacks.VariablesChangedCallback +import com.leanplum.Leanplum import com.leanplum.internal.JsonConverter +import com.leanplum.internal.Log +import com.leanplum.internal.OperationQueue import com.leanplum.migration.MigrationManager import com.leanplum.migration.model.MigrationConfig import com.leanplum.utils.SizeUtil @@ -35,44 +42,108 @@ class MigrationActivity : AppCompatActivity() { } identityKeys().text = MigrationConfig.identityList.toString() + prepareVariables() prepareButtons() } + private fun prepareVariables() { + Leanplum.addCleverTapInstanceCallback { cleverTap -> + val variables = listOf( + cleverTap.defineVariable("var_string", "hello world"), + cleverTap.defineVariable("var_integer", 10), + cleverTap.defineVariable("var_decimal", 11.2), + cleverTap.defineVariable("var_boolean", true), + cleverTap.defineVariable("var_dictionary", mapOf( + "nested_string" to "hello nested", + "nested_double" to 10.5 + )), + cleverTap.defineVariable("dot_group.var_string", "hello world"), + cleverTap.defineVariable("dot_group.var_dictionary", mapOf( + "nested_float" to 0.5f, + "nested_int" to 32 + )), + ) + OperationQueue.sharedInstance().addUiOperation { + cleverTap.addVariablesChangedCallback(object : VariablesChangedCallback() { + override fun variablesChanged() { + Log.i("Rondo refreshing variables in Migration Details page") + prepareVariableViews(variables, cleverTap) + } + }) + prepareVariableViews(variables, cleverTap) + } + } + } + + @SuppressLint("SetTextI18n") + private fun prepareVariableViews(variables: List>, cleverTap: CleverTapAPI) { + val container = variableContainer() + container.removeAllViews() + + insertTextView(container, "Variables:") + + variables.forEach { + val label = it.name() + " = " + it.value() + insertTextView(container, label, 0) + } + + insertButton(container, "Fetch Variables") { + cleverTap.fetchVariables { + Log.i("Rondo fetched variables result is $it") + } + } + + insertButton(container, "Sync Variables") { + cleverTap.syncVariables() + } + } + private fun prepareButtons() { - val container = findViewById(R.id.buttonContainer) + val container = buttonContainer() + MigrationMethodsContainer.buttonEntries.forEach { val txt = it.text when (val action = it.action) { null -> { - val tv = TextView(this).apply { - text = txt - } - val lp = LinearLayout.LayoutParams( - ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ) - lp.topMargin = SizeUtil.dpToPx(this, 20) - container.addView(tv, lp) + insertTextView(container, txt) } else -> { - val button = Button(this).apply { - text = txt - transformationMethod = null - setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10F) - setOnClickListener { - action.invoke(txt) - } + insertButton(container, txt) { + action.invoke(txt) } - val lp = LinearLayout.LayoutParams( - ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ) - container.addView(button, lp) } } } } + private fun insertTextView(container: LinearLayout, label: String, topMarginPx: Int = 20) { + val tv = TextView(this).apply { + text = label + } + val lp = LinearLayout.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + lp.topMargin = SizeUtil.dpToPx(this, topMarginPx) + container.addView(tv, lp) + } + + private fun insertButton(container: LinearLayout, label: String, callback: (String) -> Unit) { + val button = Button(this).apply { + text = label + transformationMethod = null + setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10F) + setOnClickListener { + callback.invoke(label) + } + } + val lp = LinearLayout.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + container.addView(button, lp) + } + private fun state() = findViewById(R.id.state) private fun accountId() = findViewById(R.id.accountId) private fun accountToken() = findViewById(R.id.accountToken) @@ -81,4 +152,6 @@ class MigrationActivity : AppCompatActivity() { private fun attributeMappings() = findViewById