diff --git a/demo-app/build.gradle b/demo-app/build.gradle
index 89d0b643..5c1d98ba 100644
--- a/demo-app/build.gradle
+++ b/demo-app/build.gradle
@@ -65,6 +65,14 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
+ // "Shop only" demo: launches straight into the demo shop (ShopActivity), no API / UI Kit tabs
+ // and no developer buttons — see src/shop/AndroidManifest.xml. Same SDK setup as the demo.
+ // Same applicationId as debug: google-services.json and agconnect-services.json know only it,
+ // so it replaces the full demo on the device. ./gradlew :demo-app:installRees46Shop
+ shop {
+ initWith debug
+ matchingFallbacks = ['debug']
+ }
}
compileOptions {
@@ -74,8 +82,9 @@ android {
kotlinOptions {
jvmTarget = '17'
- // Демо подключает UI-кит дизайн-системы напрямую, пока он не стал публичным API.
- freeCompilerArgs += ['-opt-in=com.personalization.ui.InternalPersonalizationUiApi']
+ // Демо подключает v3 — попапы нового конструктора и сторис на API v3 — напрямую, пока он
+ // не стал публичным API.
+ freeCompilerArgs += ['-opt-in=com.personalization.InternalPersonalizationV3Api']
}
buildFeatures {
diff --git a/demo-app/src/main/AndroidManifest.xml b/demo-app/src/main/AndroidManifest.xml
index 25a0283b..4385f93c 100644
--- a/demo-app/src/main/AndroidManifest.xml
+++ b/demo-app/src/main/AndroidManifest.xml
@@ -25,17 +25,49 @@
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/demo_notification_color" />
+
+ android:exported="true"
+ android:launchMode="singleTask">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/demo-app/src/main/assets/game/tic-tac-toe.html b/demo-app/src/main/assets/game/tic-tac-toe.html
new file mode 100644
index 00000000..73ff6374
--- /dev/null
+++ b/demo-app/src/main/assets/game/tic-tac-toe.html
@@ -0,0 +1,408 @@
+
+
+
+
+
+Крестики-нолики
+
+
+
+
+
+ Ваш ход
+
+
+
+
+ Вы — ✕, компьютер — ◯. Первый ход по очереди
+
+
+
+
+
+
+
diff --git a/demo-app/src/main/assets/uikit/stories_polls.json b/demo-app/src/main/assets/uikit/stories_polls.json
new file mode 100644
index 00000000..86199698
--- /dev/null
+++ b/demo-app/src/main/assets/uikit/stories_polls.json
@@ -0,0 +1,379 @@
+{
+ "status": "success",
+ "payload": {
+ "id": 1,
+ "settings": {
+ "avatar_size": "54",
+ "avatar_shape": "circle",
+ "border_not_viewed": "#119400",
+ "border_viewed": "#a0fdbc",
+ "pin_background": "#00cc33",
+ "pin_size": "20",
+ "background": "#ffffff",
+ "background_transparency": "100",
+ "color": "#212529",
+ "font_family": "-apple-system, Inter, system-ui, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif",
+ "font_size": "10",
+ "viewed_transparency": "0",
+ "progress_background": "#ffffff",
+ "close_color": "#ffffff",
+ "button_background": "#3b82f6",
+ "product_slide_background": "#000000",
+ "product_title_color": "#ffffff",
+ "product_price_background": "#f0f0f0",
+ "product_price_transparency": "0",
+ "product_price_color": "#18181b",
+ "product_old_price_color": "#868688",
+ "product_discount_background": "#f97316",
+ "product_status_color": "#ffffff",
+ "product_promo_code_background": "#18181b",
+ "product_promo_code_title_color": "#ffffff",
+ "product_notification_background": "#ffffff",
+ "product_notification_color": "#000000",
+ "pin_symbol": "📌",
+ "css_url": "https://storage.yandexcloud.net/r46v8/1/stories/1.css?v=1793634325-19616ad6"
+ },
+ "stories": [
+ {
+ "id": 9001,
+ "avatar": "https://cdn.stories.rees46.ru/14fcae67-551d-4a7a-828a-afc13fd5146c.jpg",
+ "name": "Опросы",
+ "pinned": false,
+ "share_url": null,
+ "shareable": false,
+ "start_position": 0,
+ "viewed": false,
+ "slides": [
+ {
+ "id": 900,
+ "background": "https://cdn.stories.rees46.ru/2e6305ca-06db-4cca-8a75-0f50a0a42a97.jpg",
+ "duration": 10,
+ "elements": [
+ {
+ "type": "poll",
+ "poll_type": "mini_poll",
+ "y_offset": 50,
+ "allow_reanswer": true,
+ "labels": {
+ "reanswer": "Ответить заново",
+ "error": "Не удалось отправить ответ. Попробуйте еще раз"
+ },
+ "poll": {
+ "code": "demo_single",
+ "kind": "single_choice",
+ "question": "Что вам больше нравится?",
+ "placeholder": null,
+ "max_length": null,
+ "submit_label": null,
+ "thanks_text": "Спасибо за ответ!",
+ "show_results": true,
+ "options": [
+ {
+ "id": 1,
+ "label": "Кроссовки"
+ },
+ {
+ "id": 2,
+ "label": "Ботинки"
+ },
+ {
+ "id": 3,
+ "label": "Сандалии"
+ }
+ ]
+ },
+ "answer": null,
+ "results": null
+ }
+ ],
+ "preview": "",
+ "type": "image",
+ "share_url": null
+ },
+ {
+ "id": 901,
+ "background": "https://cdn.stories.rees46.ru/5458c2f8-816a-4f53-82bb-89ad7995d4e1.jpg",
+ "duration": 10,
+ "elements": [
+ {
+ "type": "poll",
+ "poll_type": "mini_poll",
+ "y_offset": "40",
+ "allow_reanswer": false,
+ "labels": null,
+ "poll": {
+ "code": "demo_multi",
+ "kind": "multiple_choice",
+ "question": "Какие категории вам интересны?",
+ "placeholder": null,
+ "max_length": null,
+ "submit_label": "Отправить ответ",
+ "thanks_text": "Спасибо!",
+ "show_results": true,
+ "options": [
+ {
+ "id": 1,
+ "label": "Обувь"
+ },
+ {
+ "id": 2,
+ "label": "Одежда"
+ },
+ {
+ "id": 3,
+ "label": "Аксессуары"
+ },
+ {
+ "id": 4,
+ "label": "Спорт"
+ },
+ {
+ "id": 5,
+ "label": "Дом"
+ }
+ ]
+ },
+ "answer": null,
+ "results": null
+ }
+ ],
+ "preview": "",
+ "type": "image",
+ "share_url": null
+ },
+ {
+ "id": 902,
+ "background": "https://cdn.stories.rees46.ru/2e6305ca-06db-4cca-8a75-0f50a0a42a97.jpg",
+ "duration": 10,
+ "elements": [
+ {
+ "type": "poll",
+ "poll_type": "mini_poll",
+ "y_offset": 30,
+ "allow_reanswer": true,
+ "labels": {
+ "reanswer": "Ответить заново",
+ "error": "Не удалось отправить ответ. Попробуйте еще раз"
+ },
+ "poll": {
+ "code": "demo_text",
+ "kind": "text",
+ "question": "Что нам улучшить?",
+ "placeholder": "Ваш ответ",
+ "max_length": "120",
+ "submit_label": null,
+ "thanks_text": "Спасибо за отзыв!",
+ "show_results": false,
+ "options": []
+ },
+ "answer": null,
+ "results": null
+ }
+ ],
+ "preview": "",
+ "type": "image",
+ "share_url": null
+ },
+ {
+ "id": 903,
+ "background": "https://cdn.stories.rees46.ru/5458c2f8-816a-4f53-82bb-89ad7995d4e1.jpg",
+ "duration": 10,
+ "elements": [
+ {
+ "type": "poll",
+ "poll_type": "nps",
+ "y_offset": 60,
+ "allow_reanswer": true,
+ "labels": {
+ "reanswer": "Ответить заново",
+ "error": "Не удалось отправить ответ. Попробуйте еще раз"
+ },
+ "poll": {
+ "code": "test",
+ "channel": "test",
+ "name": "NPS",
+ "rate_min": 0,
+ "rate_max": 10,
+ "question": "Насколько вероятно, что вы порекомендуете нас друзьям?",
+ "bands": [
+ {
+ "from": 0,
+ "to": 6,
+ "success": "Спасибо, мы станем лучше"
+ },
+ {
+ "from": 7,
+ "to": 8,
+ "success": "Спасибо за оценку"
+ },
+ {
+ "from": 9,
+ "to": 10,
+ "success": "Спасибо, мы рады!"
+ }
+ ]
+ },
+ "answer": null,
+ "results": null
+ }
+ ],
+ "preview": "",
+ "type": "image",
+ "share_url": null
+ },
+ {
+ "id": 904,
+ "background": "https://cdn.stories.rees46.ru/2e6305ca-06db-4cca-8a75-0f50a0a42a97.jpg",
+ "duration": 10,
+ "elements": [
+ {
+ "type": "poll",
+ "poll_type": "csat",
+ "y_offset": 90,
+ "allow_reanswer": false,
+ "labels": null,
+ "poll": {
+ "code": "demo_csat",
+ "channel": null,
+ "name": "CSAT",
+ "rate_min": null,
+ "rate_max": null,
+ "question": "Как вам наш магазин?",
+ "bands": [
+ {
+ "from": 1,
+ "to": 3,
+ "success": "Жаль"
+ },
+ {
+ "from": 4,
+ "to": 5,
+ "success": "Ура"
+ }
+ ]
+ },
+ "answer": null,
+ "results": null
+ }
+ ],
+ "preview": "",
+ "type": "image",
+ "share_url": null
+ },
+ {
+ "id": 905,
+ "background": "https://cdn.stories.rees46.ru/5458c2f8-816a-4f53-82bb-89ad7995d4e1.jpg",
+ "duration": 10,
+ "elements": [
+ {
+ "type": "poll",
+ "poll_type": "ces",
+ "y_offset": 5,
+ "allow_reanswer": true,
+ "labels": null,
+ "poll": {
+ "code": "demo_ces",
+ "channel": "stories",
+ "name": "CES",
+ "rate_min": "1",
+ "rate_max": "7",
+ "question": "Легко ли было оформить заказ?",
+ "bands": null
+ },
+ "answer": null,
+ "results": null
+ }
+ ],
+ "preview": "",
+ "type": "image",
+ "share_url": null
+ },
+ {
+ "id": 906,
+ "background": "https://cdn.stories.rees46.ru/2e6305ca-06db-4cca-8a75-0f50a0a42a97.jpg",
+ "duration": 10,
+ "elements": [
+ {
+ "type": "poll",
+ "poll_type": "mini_poll",
+ "y_offset": 50,
+ "allow_reanswer": true,
+ "labels": {
+ "reanswer": "Ответить заново",
+ "error": "Не удалось отправить ответ. Попробуйте еще раз"
+ },
+ "poll": {
+ "code": "demo_answered",
+ "kind": "single_choice",
+ "question": "Уже отвечено: выбор с результатами",
+ "placeholder": null,
+ "max_length": null,
+ "submit_label": null,
+ "thanks_text": "Спасибо за ответ!",
+ "show_results": true,
+ "options": [
+ {
+ "id": 1,
+ "label": "Да"
+ },
+ {
+ "id": 2,
+ "label": "Нет"
+ }
+ ]
+ },
+ "answer": {
+ "id": 77,
+ "option_ids": [
+ 2
+ ],
+ "text": null
+ },
+ "results": {
+ "total": 120,
+ "options": [
+ {
+ "id": 1,
+ "percent": 40
+ },
+ {
+ "id": 2,
+ "percent": 60
+ }
+ ]
+ }
+ }
+ ],
+ "preview": "",
+ "type": "image",
+ "share_url": null
+ },
+ {
+ "id": 907,
+ "background": "https://cdn.stories.rees46.ru/5458c2f8-816a-4f53-82bb-89ad7995d4e1.jpg",
+ "duration": 10,
+ "elements": [
+ {
+ "type": "poll",
+ "poll_type": "quiz",
+ "y_offset": 50,
+ "allow_reanswer": true,
+ "labels": null,
+ "poll": {
+ "code": "demo_unknown",
+ "kind": "single_choice",
+ "question": "Неизвестный вид — не рисуется"
+ },
+ "answer": null,
+ "results": null
+ }
+ ],
+ "preview": "",
+ "type": "image",
+ "share_url": null
+ }
+ ]
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/demo-app/src/main/java/com/personalization/demo/DemoApplication.kt b/demo-app/src/main/java/com/personalization/demo/DemoApplication.kt
index 54bdb3db..034bc6fb 100644
--- a/demo-app/src/main/java/com/personalization/demo/DemoApplication.kt
+++ b/demo-app/src/main/java/com/personalization/demo/DemoApplication.kt
@@ -50,6 +50,8 @@ class DemoApplication : MultiDexApplication() {
context = applicationContext,
config = Rees46Config(shopId = BuildConfig.SHOP_ID),
)
+ // Popups v3 of the demo shop: shown on their triggers over whatever screen is open.
+ sdk.enablePopupsV3()
// Second shop for the Multi-instance tab: registered but not initialized here. It comes
// to life lazily the first time that tab resolves it (getInstance / a StoriesWidget with
// its shopId) — demonstrating per-shop lazy materialization alongside the eager default.
@@ -128,9 +130,13 @@ class DemoApplication : MultiDexApplication() {
?.notify((data.title.orEmpty() + data.body.orEmpty()).hashCode(), builder.build())
}
- /** Tapping opens MainActivity, carrying the push type/id so it can report the click to the SDK. */
+ /**
+ * Tapping opens the launcher activity — MainActivity, or ShopActivity in the "shop only" build —
+ * carrying the push type/id so it can report the click to the SDK.
+ */
private fun buildContentIntent(data: NotificationData): PendingIntent {
- val intent = Intent(this, MainActivity::class.java).apply {
+ val launcher = packageManager.getLaunchIntentForPackage(packageName)?.component
+ val intent = (if (launcher != null) Intent().setComponent(launcher) else Intent(this, MainActivity::class.java)).apply {
putExtra("NOTIFICATION_TYPE", data.type)
putExtra("NOTIFICATION_ID", data.id)
flags = Intent.FLAG_ACTIVITY_NEW_TASK or
diff --git a/demo-app/src/main/java/com/personalization/demo/DemoLink.kt b/demo-app/src/main/java/com/personalization/demo/DemoLink.kt
new file mode 100644
index 00000000..784e7da4
--- /dev/null
+++ b/demo-app/src/main/java/com/personalization/demo/DemoLink.kt
@@ -0,0 +1,90 @@
+package com.personalization.demo
+
+import android.content.Context
+import com.personalization.demo.game.GameActivity
+import java.net.URI
+import java.net.URLDecoder
+
+/**
+ * What a link that comes to the demo is — from outside (the intent filters of the manifest) or from a
+ * popup or a story of the demo:
+ * - [GAME] — the demo's mini-game: `rees46://game`, the host `game` with the scheme of any of the demos
+ * (`rees46`, `rees46flutter`, `rees46rn`), so one link in a popup or a story opens the game in each of
+ * them. `rees46://game?url=` opens a game of one's own from that address ([gameAddress]);
+ * - [STORIES] — a stories link: any scheme, host and path, the `r46_stories` parameter matters (it wins
+ * over the game host);
+ * - [OTHER] — anything else.
+ */
+internal enum class DemoLink {
+ GAME, STORIES, OTHER;
+
+ companion object {
+ /** Link schemes of the demos: this one's ([DEMO_LINK_SCHEME]), the Flutter and React Native ones. */
+ val SCHEMES = setOf(DEMO_LINK_SCHEME, "rees46flutter", "rees46rn")
+
+ const val GAME_HOST = "game"
+
+ private const val STORIES_PARAMETER = "r46_stories"
+
+ /** The parameter of a game link with the address of a game of one's own. */
+ private const val GAME_ADDRESS_PARAMETER = "url"
+
+ /** `scheme://authority` at the start of a link. */
+ private val START = Regex("^([A-Za-z][A-Za-z0-9+.-]*)://([^/?#]*)")
+
+ fun of(url: String): DemoLink {
+ val link = url.trim()
+ if (parameters(link).any { it.first == STORIES_PARAMETER }) return STORIES
+ val start = START.find(link) ?: return OTHER
+ val scheme = start.groupValues[1].lowercase()
+ // The host without a user (`user@`) and a port (`:80`).
+ val host = start.groupValues[2].substringAfterLast('@').substringBefore(':').lowercase()
+ return if (scheme in SCHEMES && host == GAME_HOST) GAME else OTHER
+ }
+
+ /**
+ * The address of a game of one's own in a game link — the `url` parameter, encoded as a query
+ * value: `rees46://game?url=https%3A%2F%2Fexample.com%2Fgame`. Only an `https` address with a host;
+ * `null` — not a game link, no address, or one that is not `https` or does not parse: the demo's
+ * own game opens.
+ */
+ fun gameAddress(url: String): String? {
+ if (of(url) != GAME) return null
+ val value = parameters(url.trim()).firstOrNull { it.first == GAME_ADDRESS_PARAMETER }?.second ?: return null
+ val address = try {
+ URLDecoder.decode(value, Charsets.UTF_8.name()).trim()
+ } catch (exception: IllegalArgumentException) {
+ return null
+ }
+ val uri = try {
+ URI(address)
+ } catch (exception: Exception) {
+ return null
+ }
+ return address.takeIf { uri.scheme.equals("https", ignoreCase = true) && !uri.host.isNullOrEmpty() }
+ }
+
+ /**
+ * The query parameters of a link — from the first `?` to a `#` after it, as the SDK reads a stories
+ * link — names with their values as they are written (not decoded).
+ */
+ private fun parameters(link: String): List> {
+ val start = link.indexOf('?')
+ if (start < 0) return emptyList()
+ val end = link.indexOf('#', start).takeIf { it >= 0 } ?: link.length
+ return link.substring(start + 1, end).split('&')
+ .map { it.substringBefore('=') to it.substringAfter('=', missingDelimiterValue = "") }
+ .filter { it.first.isNotEmpty() }
+ }
+ }
+}
+
+/**
+ * Opens the game over the screen of [context] when [url] is a game link; `false` — it is not, nothing
+ * opens.
+ */
+internal fun openGameLink(context: Context, url: String): Boolean {
+ if (DemoLink.of(url) != DemoLink.GAME) return false
+ GameActivity.start(context, url)
+ return true
+}
diff --git a/demo-app/src/main/java/com/personalization/demo/MainActivity.kt b/demo-app/src/main/java/com/personalization/demo/MainActivity.kt
index 475a0025..9666c3dd 100644
--- a/demo-app/src/main/java/com/personalization/demo/MainActivity.kt
+++ b/demo-app/src/main/java/com/personalization/demo/MainActivity.kt
@@ -14,13 +14,16 @@ import android.view.View
import android.widget.Button
import android.widget.CheckBox
import android.widget.TextView
+import android.widget.FrameLayout
import android.widget.Toast
+import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.compose.ui.platform.ComposeView
import com.google.android.material.bottomnavigation.BottomNavigationView
import androidx.core.content.ContextCompat
+import androidx.core.view.WindowCompat
import com.google.firebase.FirebaseApp
import com.google.firebase.messaging.FirebaseMessaging
import com.personalization.Params
@@ -42,6 +45,11 @@ import com.personalization.api.models.purchase.PurchaseTrackingRequest
import com.personalization.api.params.ProductItemParams
import com.personalization.api.params.PurchasePredictParams
import com.personalization.demo.BuildConfig
+import com.personalization.demo.shop.DemoShop
+import com.personalization.demo.shop.ShopRoute
+import com.personalization.demo.shop.isNight
+import com.personalization.ui.PersonalizationTheme
+import com.personalization.R as SdkR
import com.personalization.sdk.data.models.dto.popUp.Components
import org.json.JSONObject
import com.personalization.sdk.data.models.dto.popUp.PopupActions
@@ -58,9 +66,30 @@ class MainActivity : AppCompatActivity() {
/** Bottom tab currently shown, kept so it survives the activity being recreated. */
private var selectedTabId = R.id.tabApi
+ /** The "Shop" tab, see [DemoShop]. */
+ private lateinit var shop: DemoShop
+
+ /** Status bar of the theme, given back when a tab other than the shop is shown. */
+ private var themeStatusBarColor = 0
+ private var themeLightStatusBar = false
+
+ /**
+ * System back walks the shop's own stack while its tab is shown; at the shop's Home it falls
+ * through to the system.
+ */
+ private val shopBack = object : OnBackPressedCallback(false) {
+ override fun handleOnBackPressed() {
+ if (shop.back()) return
+ isEnabled = false
+ onBackPressedDispatcher.onBackPressed()
+ isEnabled = selectedTabId == R.id.tabShop
+ }
+ }
+
private companion object {
const val MAX_LOGGED_STORIES_EVENTS = 20
const val STATE_SELECTED_TAB = "selectedTabId"
+ const val STATE_SHOP = "shop"
}
private object DemoTrackingNamespaceConstants {
@@ -130,6 +159,7 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
selectedTabId = savedInstanceState?.getInt(STATE_SELECTED_TAB, R.id.tabApi) ?: R.id.tabApi
setContentView(R.layout.activity_main)
+ setupSystemBars()
// Initialize Firebase if not already initialized
try {
@@ -147,6 +177,7 @@ class MainActivity : AppCompatActivity() {
// Show the registered push provider(s) + token (FCM and/or HMS) in the header.
observePushTokens()
+ setupShop(savedInstanceState?.getBundle(STATE_SHOP))
setupStoriesTabs()
findViewById