Skip to content

Commit

Permalink
Add PE variables. (Not compilable, needs an SDK build with 5.0.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
hborisoff committed May 11, 2023
1 parent 96dad5a commit 70be30f
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 25 deletions.
6 changes: 3 additions & 3 deletions RondoApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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")
Expand Down
117 changes: 95 additions & 22 deletions RondoApp/src/main/java/com/leanplum/rondo/MigrationActivity.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.leanplum.rondo

import android.annotation.SuppressLint
import android.os.Bundle
import android.util.TypedValue
import android.view.ViewGroup
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
Expand Down Expand Up @@ -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<Var<*>>, 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<LinearLayout>(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<TextView>(R.id.state)
private fun accountId() = findViewById<TextView>(R.id.accountId)
private fun accountToken() = findViewById<TextView>(R.id.accountToken)
Expand All @@ -81,4 +152,6 @@ class MigrationActivity : AppCompatActivity() {
private fun attributeMappings() = findViewById<Button>(R.id.attributeMappings)
private fun disableFcmForward() = findViewById<Button>(R.id.disableFcmForward)
private fun identityKeys() = findViewById<TextView>(R.id.identityKeys)
private fun buttonContainer() = findViewById<LinearLayout>(R.id.buttonContainer)
private fun variableContainer() = findViewById<LinearLayout>(R.id.variableContainer)
}
7 changes: 7 additions & 0 deletions RondoApp/src/main/res/layout/activity_migration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@
android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout
android:id="@+id/variableContainer"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>

<LinearLayout
android:id="@+id/buttonContainer"
android:orientation="vertical"
Expand Down

0 comments on commit 70be30f

Please sign in to comment.