Skip to content

Commit 59a7f38

Browse files
committed
DEV-3525: add demo app to test the event
1 parent 8a0865c commit 59a7f38

File tree

16 files changed

+354
-14
lines changed

16 files changed

+354
-14
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ test.key
1414
node_modules
1515
*.tgz
1616

17+
# Demo app build artifacts
18+
demo-app/build/
19+
demo-app/.gradle/
20+
demo-app/local.properties
21+

demo-app/build.gradle

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'org.jetbrains.kotlin.android'
4+
}
5+
6+
android {
7+
namespace 'com.personalization.demo'
8+
compileSdkVersion 34
9+
10+
flavorDimensions += 'default'
11+
12+
// Read shop.id from local.properties (check both root and demo-app directories)
13+
def localProperties = new Properties()
14+
def localPropertiesFile = rootProject.file('local.properties')
15+
if (!localPropertiesFile.exists()) {
16+
localPropertiesFile = project.file('local.properties')
17+
}
18+
if (localPropertiesFile.exists()) {
19+
localProperties.load(new FileInputStream(localPropertiesFile))
20+
}
21+
def shopId = localProperties.getProperty('shop.id', '357382bf66ac0ce2f1722677c59511')
22+
23+
defaultConfig {
24+
applicationId "com.personalization.demo"
25+
minSdkVersion 19
26+
targetSdkVersion 34
27+
versionCode 1
28+
versionName "1.0"
29+
multiDexEnabled true
30+
31+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
32+
33+
// Add shop ID to BuildConfig
34+
buildConfigField "String", "SHOP_ID", "\"${shopId}\""
35+
}
36+
37+
productFlavors {
38+
rees46 {
39+
dimension 'default'
40+
}
41+
}
42+
43+
buildTypes {
44+
release {
45+
minifyEnabled false
46+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
47+
}
48+
}
49+
50+
compileOptions {
51+
sourceCompatibility JavaVersion.VERSION_17
52+
targetCompatibility JavaVersion.VERSION_17
53+
}
54+
55+
kotlinOptions {
56+
jvmTarget = '17'
57+
}
58+
59+
buildFeatures {
60+
viewBinding true
61+
buildConfig true
62+
}
63+
}
64+
65+
dependencies {
66+
implementation project(':personalization-sdk')
67+
68+
implementation 'androidx.multidex:multidex:2.0.1'
69+
implementation 'androidx.core:core-ktx:1.13.1'
70+
implementation 'androidx.appcompat:appcompat:1.6.1'
71+
implementation 'com.google.android.material:material:1.12.0'
72+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
73+
implementation 'androidx.fragment:fragment-ktx:1.6.2'
74+
75+
// Firebase
76+
implementation platform('com.google.firebase:firebase-bom:32.7.0')
77+
implementation 'com.google.firebase:firebase-messaging'
78+
79+
testImplementation 'junit:junit:4.13.2'
80+
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
81+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
82+
}
83+

demo-app/proguard-rules.pro

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
5+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:name=".DemoApplication"
9+
android:allowBackup="true"
10+
android:icon="@android:drawable/ic_dialog_info"
11+
android:label="@string/app_name"
12+
android:roundIcon="@android:drawable/ic_dialog_info"
13+
android:supportsRtl="true"
14+
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
15+
tools:targetApi="31">
16+
<activity
17+
android:name=".MainActivity"
18+
android:exported="true">
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
26+
</manifest>
27+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.personalization.demo
2+
3+
import android.content.Context
4+
import androidx.multidex.MultiDexApplication
5+
import com.google.firebase.FirebaseApp
6+
7+
class DemoApplication : MultiDexApplication() {
8+
9+
override fun onCreate() {
10+
super.onCreate()
11+
// Initialize Firebase if not already initialized
12+
if (FirebaseApp.getApps(this).isEmpty()) {
13+
FirebaseApp.initializeApp(this)
14+
}
15+
}
16+
}
17+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.personalization.demo
2+
3+
import android.os.Bundle
4+
import androidx.appcompat.app.AppCompatActivity
5+
import com.google.firebase.FirebaseApp
6+
import com.personalization.SDK
7+
import com.personalization.demo.BuildConfig
8+
import com.personalization.sdk.data.models.dto.popUp.Components
9+
import com.personalization.sdk.data.models.dto.popUp.PopupActions
10+
import com.personalization.sdk.data.models.dto.popUp.PopupDto
11+
import com.personalization.sdk.data.models.dto.popUp.Position
12+
13+
class MainActivity : AppCompatActivity() {
14+
15+
private lateinit var sdk: SDK
16+
17+
override fun onCreate(savedInstanceState: Bundle?) {
18+
super.onCreate(savedInstanceState)
19+
setContentView(R.layout.activity_main)
20+
21+
// Initialize Firebase if not already initialized
22+
try {
23+
if (FirebaseApp.getApps(this).isEmpty()) {
24+
FirebaseApp.initializeApp(this)
25+
}
26+
} catch (e: Exception) {
27+
e.printStackTrace()
28+
}
29+
30+
// Initialize SDK
31+
try {
32+
sdk = SDK()
33+
sdk.initialize(
34+
context = this,
35+
shopId = BuildConfig.SHOP_ID,
36+
apiDomain = "api.rees46.ru",
37+
autoSendPushToken = false
38+
)
39+
} catch (e: Exception) {
40+
e.printStackTrace()
41+
// Continue even if SDK initialization fails for demo purposes
42+
}
43+
44+
// Initialize fragment manager for popups
45+
sdk.inAppNotificationManager.initFragmentManager(supportFragmentManager)
46+
47+
// Setup button
48+
findViewById<android.widget.Button>(R.id.btnShowTestPopup).setOnClickListener {
49+
showTestPopup()
50+
}
51+
}
52+
53+
private fun showTestPopup() {
54+
val testPopup = PopupDto(
55+
id = 999,
56+
channels = listOf("email"),
57+
position = Position.CENTERED,
58+
delay = 0,
59+
html = """
60+
<div class="popup-title">Test Popup</div>
61+
<p class="popup-999__intro">This is a test popup for Android SDK</p>
62+
""".trimIndent(),
63+
components = Components(
64+
header = "Test Popup",
65+
text = "This is a test popup for Android SDK",
66+
image = "",
67+
button = "",
68+
textEnabled = "",
69+
imageEnabled = "",
70+
headerEnabled = ""
71+
),
72+
webPushSystem = false,
73+
popupActions = PopupActions(
74+
link = null,
75+
close = null,
76+
pushSubscribe = null
77+
)
78+
)
79+
80+
sdk.inAppNotificationManager.shopPopUp(testPopup)
81+
}
82+
}
83+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical"
6+
android:padding="16dp"
7+
android:gravity="center">
8+
9+
<Button
10+
android:id="@+id/btnShowTestPopup"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:text="@string/show_test_popup"
14+
android:layout_marginTop="32dp" />
15+
16+
</LinearLayout>
17+
18+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="app_name">Personalization SDK Demo</string>
4+
<string name="show_test_popup">Show Test Popup</string>
5+
</resources>
6+
7+

personalization-sdk/build.gradle

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ android {
3434
}
3535

3636
compileOptions {
37-
sourceCompatibility JavaVersion.VERSION_20
38-
targetCompatibility JavaVersion.VERSION_20
37+
sourceCompatibility JavaVersion.VERSION_17
38+
targetCompatibility JavaVersion.VERSION_17
3939
}
4040

4141
kotlinOptions {
42-
jvmTarget = '20'
42+
jvmTarget = '17'
4343
}
4444

4545
sourceSets {
@@ -75,6 +75,12 @@ android {
7575
dependencies {
7676
implementation fileTree(dir: 'libs', include: ['*.jar'])
7777

78+
// Explicitly exclude demo-app from SDK dependencies
79+
// demo-app is a separate application module and should not be included in SDK artifacts
80+
configurations.all {
81+
exclude group: 'com.personalization.demo', module: 'demo-app'
82+
}
83+
7884
implementation 'androidx.multidex:multidex:2.0.1'
7985
implementation 'androidx.recyclerview:recyclerview:1.3.2'
8086
implementation 'com.google.android.material:material:1.12.0'

personalization-sdk/src/main/kotlin/com/personalization/api/managers/TrackEventManager.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,12 @@ interface TrackEventManager {
5151
value: Int? = null,
5252
listener: OnApiCallbackListener? = null
5353
)
54+
55+
/**
56+
* Track popup shown event
57+
*
58+
* @param popupId Popup ID
59+
* @param listener Callback
60+
*/
61+
fun trackPopupShown(popupId: Int, listener: OnApiCallbackListener? = null)
5462
}

0 commit comments

Comments
 (0)