|
| 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 | + |
0 commit comments