From 59a7f389800cbea2988fc71efccc51931b60de5a Mon Sep 17 00:00:00 2001 From: xyzcancer Date: Mon, 1 Dec 2025 11:43:45 +0400 Subject: [PATCH] DEV-3525: add demo app to test the event --- .gitignore | 5 ++ demo-app/build.gradle | 83 +++++++++++++++++++ demo-app/proguard-rules.pro | 5 ++ demo-app/src/main/AndroidManifest.xml | 27 ++++++ .../personalization/demo/DemoApplication.kt | 17 ++++ .../com/personalization/demo/MainActivity.kt | 83 +++++++++++++++++++ .../src/main/res/layout/activity_main.xml | 18 ++++ demo-app/src/main/res/values/strings.xml | 7 ++ personalization-sdk/build.gradle | 12 ++- .../api/managers/TrackEventManager.kt | 8 ++ .../com/personalization/di/SdkModule.kt | 14 +++- .../impl/InAppNotificationManagerImpl.kt | 31 ++++++- .../trackEvent/impl/TrackEventManagerImpl.kt | 20 ++++- .../network/NetworkRepositoryImpl.kt | 35 ++++++-- .../GetUserSettingsValueUseCase.kt | 2 + settings.gradle | 1 + 16 files changed, 354 insertions(+), 14 deletions(-) create mode 100644 demo-app/build.gradle create mode 100644 demo-app/proguard-rules.pro create mode 100644 demo-app/src/main/AndroidManifest.xml create mode 100644 demo-app/src/main/java/com/personalization/demo/DemoApplication.kt create mode 100644 demo-app/src/main/java/com/personalization/demo/MainActivity.kt create mode 100644 demo-app/src/main/res/layout/activity_main.xml create mode 100644 demo-app/src/main/res/values/strings.xml diff --git a/.gitignore b/.gitignore index 0e50d914..e5f0a728 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,8 @@ test.key node_modules *.tgz +# Demo app build artifacts +demo-app/build/ +demo-app/.gradle/ +demo-app/local.properties + diff --git a/demo-app/build.gradle b/demo-app/build.gradle new file mode 100644 index 00000000..16927520 --- /dev/null +++ b/demo-app/build.gradle @@ -0,0 +1,83 @@ +plugins { + id 'com.android.application' + id 'org.jetbrains.kotlin.android' +} + +android { + namespace 'com.personalization.demo' + compileSdkVersion 34 + + flavorDimensions += 'default' + + // Read shop.id from local.properties (check both root and demo-app directories) + def localProperties = new Properties() + def localPropertiesFile = rootProject.file('local.properties') + if (!localPropertiesFile.exists()) { + localPropertiesFile = project.file('local.properties') + } + if (localPropertiesFile.exists()) { + localProperties.load(new FileInputStream(localPropertiesFile)) + } + def shopId = localProperties.getProperty('shop.id', '357382bf66ac0ce2f1722677c59511') + + defaultConfig { + applicationId "com.personalization.demo" + minSdkVersion 19 + targetSdkVersion 34 + versionCode 1 + versionName "1.0" + multiDexEnabled true + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + // Add shop ID to BuildConfig + buildConfigField "String", "SHOP_ID", "\"${shopId}\"" + } + + productFlavors { + rees46 { + dimension 'default' + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = '17' + } + + buildFeatures { + viewBinding true + buildConfig true + } +} + +dependencies { + implementation project(':personalization-sdk') + + implementation 'androidx.multidex:multidex:2.0.1' + implementation 'androidx.core:core-ktx:1.13.1' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.12.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'androidx.fragment:fragment-ktx:1.6.2' + + // Firebase + implementation platform('com.google.firebase:firebase-bom:32.7.0') + implementation 'com.google.firebase:firebase-messaging' + + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' +} + diff --git a/demo-app/proguard-rules.pro b/demo-app/proguard-rules.pro new file mode 100644 index 00000000..a6775bd0 --- /dev/null +++ b/demo-app/proguard-rules.pro @@ -0,0 +1,5 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. + + diff --git a/demo-app/src/main/AndroidManifest.xml b/demo-app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..a8abb8a0 --- /dev/null +++ b/demo-app/src/main/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + diff --git a/demo-app/src/main/java/com/personalization/demo/DemoApplication.kt b/demo-app/src/main/java/com/personalization/demo/DemoApplication.kt new file mode 100644 index 00000000..3c888d51 --- /dev/null +++ b/demo-app/src/main/java/com/personalization/demo/DemoApplication.kt @@ -0,0 +1,17 @@ +package com.personalization.demo + +import android.content.Context +import androidx.multidex.MultiDexApplication +import com.google.firebase.FirebaseApp + +class DemoApplication : MultiDexApplication() { + + override fun onCreate() { + super.onCreate() + // Initialize Firebase if not already initialized + if (FirebaseApp.getApps(this).isEmpty()) { + FirebaseApp.initializeApp(this) + } + } +} + diff --git a/demo-app/src/main/java/com/personalization/demo/MainActivity.kt b/demo-app/src/main/java/com/personalization/demo/MainActivity.kt new file mode 100644 index 00000000..a211f1aa --- /dev/null +++ b/demo-app/src/main/java/com/personalization/demo/MainActivity.kt @@ -0,0 +1,83 @@ +package com.personalization.demo + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import com.google.firebase.FirebaseApp +import com.personalization.SDK +import com.personalization.demo.BuildConfig +import com.personalization.sdk.data.models.dto.popUp.Components +import com.personalization.sdk.data.models.dto.popUp.PopupActions +import com.personalization.sdk.data.models.dto.popUp.PopupDto +import com.personalization.sdk.data.models.dto.popUp.Position + +class MainActivity : AppCompatActivity() { + + private lateinit var sdk: SDK + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + // Initialize Firebase if not already initialized + try { + if (FirebaseApp.getApps(this).isEmpty()) { + FirebaseApp.initializeApp(this) + } + } catch (e: Exception) { + e.printStackTrace() + } + + // Initialize SDK + try { + sdk = SDK() + sdk.initialize( + context = this, + shopId = BuildConfig.SHOP_ID, + apiDomain = "api.rees46.ru", + autoSendPushToken = false + ) + } catch (e: Exception) { + e.printStackTrace() + // Continue even if SDK initialization fails for demo purposes + } + + // Initialize fragment manager for popups + sdk.inAppNotificationManager.initFragmentManager(supportFragmentManager) + + // Setup button + findViewById(R.id.btnShowTestPopup).setOnClickListener { + showTestPopup() + } + } + + private fun showTestPopup() { + val testPopup = PopupDto( + id = 999, + channels = listOf("email"), + position = Position.CENTERED, + delay = 0, + html = """ + + + """.trimIndent(), + components = Components( + header = "Test Popup", + text = "This is a test popup for Android SDK", + image = "", + button = "", + textEnabled = "", + imageEnabled = "", + headerEnabled = "" + ), + webPushSystem = false, + popupActions = PopupActions( + link = null, + close = null, + pushSubscribe = null + ) + ) + + sdk.inAppNotificationManager.shopPopUp(testPopup) + } +} + diff --git a/demo-app/src/main/res/layout/activity_main.xml b/demo-app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..395cd9d2 --- /dev/null +++ b/demo-app/src/main/res/layout/activity_main.xml @@ -0,0 +1,18 @@ + + + +