Skip to content

Commit f82d230

Browse files
committed
Prefetch promo resource, add various layouts and add video support
1 parent 2653641 commit f82d230

File tree

32 files changed

+803
-183
lines changed

32 files changed

+803
-183
lines changed

common/build.gradle.kts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ kotlin {
112112
api(libs.kotlinx.datetime)
113113
/** ----------------------------------------------------------------------------------------- */
114114

115+
/** --- Ktor ------------------------------------------------------------------------------- */
116+
api(libs.ktor.client.core)
117+
/** ----------------------------------------------------------------------------------------- */
118+
115119
/** --- Compose ---------------------------------------------------------------------------- */
116120
api(compose.components.resources)
117121
/** ----------------------------------------------------------------------------------------- */
@@ -145,6 +149,8 @@ kotlin {
145149
api(libs.kase64) // base64
146150
api(libs.ksoup.entites) // html entities
147151
api(libs.kable.core)
152+
api(libs.kotlincrypto.hash.md)
153+
api(libs.kotlincrypto.hash.sha2)
148154

149155
implementation(libs.tuulbox.coroutines)
150156
/** ----------------------------------------------------------------------------------------- */
@@ -165,6 +171,7 @@ kotlin {
165171
api(libs.kotlinx.coroutines.swing)
166172
implementation(compose.desktop.currentOs)
167173
implementation(libs.sqldelight.sqlite.driver)
174+
implementation(libs.ktor.client.java)
168175
}
169176

170177
androidMain.dependencies {
@@ -174,7 +181,7 @@ kotlin {
174181
api(libs.androidx.biometric)
175182

176183
api(libs.androidx.preference.ktx)
177-
184+
implementation(libs.ktor.client.android)
178185

179186
/** --- Breez FDroid ----------------------------------------------------------------------- */
180187
// Temp fix for FDroid breez dependencies
@@ -197,6 +204,7 @@ kotlin {
197204

198205
iosMain.dependencies {
199206
implementation(libs.sqldelight.native.driver)
207+
implementation(libs.ktor.client.darwin)
200208
}
201209
}
202210
}

common/src/androidUnitTest/kotlin/com/blockstream/common/models/TestViewModel.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package com.blockstream.common.models
22

33
import com.blockstream.common.CountlyBase
44
import com.blockstream.common.data.AppInfo
5+
import com.blockstream.common.managers.PromoManager
56
import com.blockstream.common.managers.SessionManager
67
import io.mockk.every
78
import io.mockk.mockkClass
89
import kotlinx.coroutines.Dispatchers
910
import kotlinx.coroutines.ExperimentalCoroutinesApi
1011
import kotlinx.coroutines.flow.MutableSharedFlow
12+
import kotlinx.coroutines.flow.MutableStateFlow
1113
import kotlinx.coroutines.test.UnconfinedTestDispatcher
1214
import kotlinx.coroutines.test.resetMain
1315
import kotlinx.coroutines.test.setMain
@@ -48,6 +50,10 @@ abstract class TestViewModel<VM : GreenViewModel>: KoinTest {
4850
declareMock<SessionManager> {
4951

5052
}
53+
54+
declareMock<PromoManager> {
55+
every { promos } returns MutableStateFlow(listOf())
56+
}
5157
}
5258
)
5359
}

common/src/commonMain/kotlin/com/blockstream/common/data/NavData.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ data class NavData(
66
val title: String? = null,
77
val subtitle: String? = null,
88
val isVisible: Boolean = true,
9+
val showNavigationIcon: Boolean = true,
910
val onBackPressed: () -> Boolean = { true },
1011
val actions: List<NavAction> = listOf()
1112
)

common/src/commonMain/kotlin/com/blockstream/common/data/Promo.kt

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,33 @@ package com.blockstream.common.data
33
import cafe.adriel.voyager.core.lifecycle.JavaSerializable
44
import com.blockstream.common.gdk.GreenJson
55
import com.blockstream.common.serializers.HtmlEntitiesSerializer
6+
import kotlinx.serialization.KSerializer
67
import kotlinx.serialization.SerialName
78
import kotlinx.serialization.Serializable
9+
import org.kotlincrypto.hash.md.MD5
10+
11+
@Serializable
12+
data class PromoFile(val url: String, val file: String, val filePath: String) : GreenJson<PromoFile>(), JavaSerializable {
13+
14+
companion object{
15+
@OptIn(ExperimentalStdlibApi::class)
16+
fun create(id: String, url: String?, type: String, dir: String): PromoFile? {
17+
return url?.let {
18+
val file = "${id}_${type}_${
19+
MD5().digest(it.encodeToByteArray()).toHexString().substring(0..6)
20+
}"
21+
22+
PromoFile(
23+
url = it,
24+
file = file,
25+
filePath = "$dir/$file"
26+
)
27+
}
28+
}
29+
}
30+
31+
override fun kSerializer(): KSerializer<PromoFile> = serializer()
32+
}
833

934
@Serializable
1035
data class Promo(
@@ -13,6 +38,11 @@ data class Promo(
1338
val isVisible: Boolean = true,
1439
@SerialName("is_small")
1540
val isSmall: Boolean = false,
41+
@SerialName("layout_small")
42+
val layoutSmall: Int = 0,
43+
@SerialName("layout_large")
44+
val layoutLarge: Int = 0,
45+
1646
@Serializable(with = HtmlEntitiesSerializer::class)
1747
val title: String? = null,
1848
@Serializable(with = HtmlEntitiesSerializer::class)
@@ -28,6 +58,12 @@ data class Promo(
2858
@SerialName("text_large")
2959
val textLarge: String? = null,
3060
@Serializable(with = HtmlEntitiesSerializer::class)
61+
@SerialName("overline_small")
62+
val overlineSmall: String? = null,
63+
@Serializable(with = HtmlEntitiesSerializer::class)
64+
@SerialName("overline_large")
65+
val overlineLarge: String? = null,
66+
@Serializable(with = HtmlEntitiesSerializer::class)
3167
@SerialName("cta_small")
3268
val ctaSmall: String? = null,
3369
@Serializable(with = HtmlEntitiesSerializer::class)
@@ -38,13 +74,30 @@ data class Promo(
3874
val imageSmall: String? = null,
3975
@SerialName("image_large")
4076
val imageLarge: String? = null,
77+
@SerialName("video_large")
78+
val videoLarge: String? = null,
4179

4280
val link: String? = null,
4381
val screens: List<String>? = null,
44-
): GreenJson<Promo>(), JavaSerializable{
82+
) : GreenJson<Promo>(), JavaSerializable {
4583
override fun kSerializer() = serializer()
4684

47-
companion object{
85+
val imageSmallFile by lazy {
86+
PromoFile.create(id, imageSmall, "imageSmall", CacheDir)
87+
}
88+
89+
val imageLargeFile by lazy {
90+
PromoFile.create(id, imageLarge, "imageLarge", CacheDir)
91+
}
92+
93+
val videoLargeFile by lazy {
94+
PromoFile.create(id, videoLarge, "videoLarge", CacheDir)
95+
}
96+
97+
companion object {
98+
99+
var CacheDir :String = ""
100+
48101
val preview1 = Promo(
49102
id = "jade_upsell_10",
50103
title = "Jade Discount",
@@ -54,10 +107,12 @@ data class Promo(
54107
textLarge = "Don’t leave your wallet security to chance, seize this limited time opportunity to get a discount on Jade.\\nUnlike general devices, Jade is specifically crafted to protect your keys from remote hackers and thieves. Pair it with 2FA-protected accounts for defense against even the most sophisticated attacks.",
55108
ctaSmall = "Get Discount Now",
56109
ctaLarge = "Claim Your Offer Now",
110+
layoutSmall = 0
57111
)
58112

59113
val preview2 = Promo(
60114
id = "jade_upsell_10",
115+
imageSmall = "https://blockstream.com/img/jade/jade-page-virtual-secure-element.svg",
61116
titleSmall = "The Ultimate Cyber Defense No Image",
62117
titleLarge = "Exclusive Jade Wallet Savings—Unlock Yours Now!",
63118
ctaSmall = "Get Discount Now"
@@ -70,7 +125,42 @@ data class Promo(
70125

71126
val preview4 = Promo(
72127
id = "jade_upsell_10",
73-
textSmall = "The Ultimate Cyber Defense 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0",
128+
title = "Layout 1 : Jade Discount",
129+
imageSmall = "https://jade.blockstream.com/assets/jade-image-layout2small.png",
130+
titleSmall = "Layout 1 : Keep the keys to your bitcoin and LBTC assets safely offline.",
131+
titleLarge = "Exclusive Jade Wallet Savings—Unlock Yours Now!",
132+
textSmall = "Upgrade your wallet security today, and enjoy a special discount on your purchase.",
133+
textLarge = "Don’t leave your wallet security to chance, seize this limited time opportunity to get a discount on Jade.\\nUnlike general devices, Jade is specifically crafted to protect your keys from remote hackers and thieves. Pair it with 2FA-protected accounts for defense against even the most sophisticated attacks.",
134+
ctaSmall = "Get Discount Now",
135+
ctaLarge = "Claim Your Offer Now",
136+
layoutSmall = 0
137+
)
138+
139+
val preview5 = Promo(
140+
id = "jade_upsell_10",
141+
title = "Layout 1 : Jade Discount",
142+
imageSmall = "https://jade.blockstream.com/assets/jade-image-layout2small.png",
143+
titleSmall = "Layout 1 : Keep the keys to your bitcoin and LBTC assets safely offline.",
144+
titleLarge = "Exclusive Jade Wallet Savings—Unlock Yours Now!",
145+
textSmall = "Upgrade your wallet security today, and enjoy a special discount on your purchase.",
146+
textLarge = "Don’t leave your wallet security to chance, seize this limited time opportunity to get a discount on Jade.\\nUnlike general devices, Jade is specifically crafted to protect your keys from remote hackers and thieves. Pair it with 2FA-protected accounts for defense against even the most sophisticated attacks.",
147+
ctaSmall = "Get Discount Now",
148+
ctaLarge = "Claim Your Offer Now",
149+
layoutSmall = 1
150+
)
151+
152+
val preview6 = Promo(
153+
id = "jade_upsell_10",
154+
title = "Layout 2 : Jade Discount",
155+
overlineSmall = "MEET JADE BLE",
156+
imageSmall = "https://jade.blockstream.com/assets/jade-image-layout2small.png",
157+
titleSmall = "Layout 2 : Keep the keys to your bitcoin and LBTC assets safely offline.",
158+
titleLarge = "Exclusive Jade Wallet Savings—Unlock Yours Now!",
159+
textSmall = "Upgrade your wallet security today, and enjoy a special discount on your purchase.",
160+
textLarge = "Don’t leave your wallet security to chance, seize this limited time opportunity to get a discount on Jade.\\nUnlike general devices, Jade is specifically crafted to protect your keys from remote hackers and thieves. Pair it with 2FA-protected accounts for defense against even the most sophisticated attacks.",
161+
ctaSmall = "Get Discount Now",
162+
ctaLarge = "Claim Your Offer Now",
163+
layoutSmall = 2
74164
)
75165
}
76166
}

common/src/commonMain/kotlin/com/blockstream/common/di/Koin.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.blockstream.common.di
22

3-
import co.touchlab.kermit.chunked
43
import co.touchlab.kermit.Logger
54
import co.touchlab.kermit.Severity
5+
import co.touchlab.kermit.chunked
66
import co.touchlab.kermit.platformLogWriter
77
import com.blockstream.common.data.AppConfig
88
import com.blockstream.common.data.AppInfo
@@ -15,6 +15,7 @@ import com.blockstream.common.lightning.GreenlightKeys
1515
import com.blockstream.common.lightning.LightningManager
1616
import com.blockstream.common.managers.AssetManager
1717
import com.blockstream.common.managers.LifecycleManager
18+
import com.blockstream.common.managers.PromoManager
1819
import com.blockstream.common.managers.SessionManager
1920
import com.blockstream.common.managers.SettingsManager
2021
import kotlinx.coroutines.MainScope
@@ -84,6 +85,9 @@ private fun commonModules(appConfig: AppConfig): List<Module> {
8485
single {
8586
Database(get(), get())
8687
}
88+
single {
89+
PromoManager(get(), get(), get())
90+
}
8791
single {
8892
SettingsManager(
8993
settings = get(),

0 commit comments

Comments
 (0)