diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 120a3900..e043f310 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -35,7 +35,7 @@ android { applicationId = "ltd.grunt.brainwallet" minSdk = 29 targetSdk = 35 - versionCode = 202506331 + versionCode = 202506332 versionName = "v4.9.2" multiDexEnabled = true base.archivesName.set("${defaultConfig.versionName}(${defaultConfig.versionCode})") diff --git a/app/src/main/java/com/brainwallet/BrainwalletApp.kt b/app/src/main/java/com/brainwallet/BrainwalletApp.kt index 38ba6de7..650a1c20 100644 --- a/app/src/main/java/com/brainwallet/BrainwalletApp.kt +++ b/app/src/main/java/com/brainwallet/BrainwalletApp.kt @@ -14,6 +14,10 @@ import com.brainwallet.tools.manager.AnalyticsManager import com.brainwallet.tools.util.Utils import com.brainwallet.constants.BWConstants import com.google.firebase.crashlytics.FirebaseCrashlytics +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.cancel import org.koin.android.ext.android.inject import timber.log.Timber import timber.log.Timber.DebugTree @@ -24,6 +28,12 @@ import java.util.concurrent.atomic.AtomicInteger open class BrainwalletApp : Application() { private val notificationHandler: NotificationHandler by inject() + val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.Default) + + override fun onTerminate() { + super.onTerminate() + applicationScope.cancel() + } override fun onCreate() { super.onCreate() diff --git a/app/src/main/java/com/brainwallet/data/repository/ShopProxyRepositoryImpl.kt b/app/src/main/java/com/brainwallet/data/repository/ShopProxyRepositoryImpl.kt index ee3505db..0a53c9a9 100644 --- a/app/src/main/java/com/brainwallet/data/repository/ShopProxyRepositoryImpl.kt +++ b/app/src/main/java/com/brainwallet/data/repository/ShopProxyRepositoryImpl.kt @@ -1,18 +1,29 @@ package com.brainwallet.data.repository import com.brainwallet.data.source.RemoteConfigSource +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json import timber.log.Timber +@Serializable +data class ShopCard( + @SerialName("country_code") val countryCode: String = "", + @SerialName("country_name") val countryName: String = "", + @SerialName("product_slug") val productSlug: String = "", + @SerialName("product_name") val productName: String = "", + @SerialName("product_url") val productUrl: String = "", + @SerialName("card_image_webp") val cardImageWebp: String = "" +) @Serializable data class ShopProxy( - @SerialName("widget_url") val widget: String = "" + @SerialName("widget_url") val widget: String = "", + @SerialName("cards") val cards: List = emptyList() ) - interface ShopProxyRepository { val shopProxy: StateFlow> suspend fun refresh() @@ -21,11 +32,15 @@ interface ShopProxyRepository { class ShopProxyRepositoryImpl( private val remoteConfigSource: RemoteConfigSource, private val json: Json, + private val scope: CoroutineScope, ) : ShopProxyRepository { private val _shopProxy = MutableStateFlow>(emptyList()) override val shopProxy: StateFlow> = _shopProxy.asStateFlow() + init { + scope.launch { refresh() } + } override suspend fun refresh() { runCatching { remoteConfigSource.fetchAndActivate() } .onFailure { Timber.e(it, "RemoteConfig fetch failed") } @@ -36,12 +51,12 @@ class ShopProxyRepositoryImpl( runCatching { val wrapper = json.decodeFromString(rawJson) Timber.d("ShopProxy parsed: ${wrapper.shopProxy}") - _shopProxy.value = wrapper.shopProxy - }.onFailure { Timber.e(it, "RemoteConfig parse failed") } + _shopProxy.value = listOf(wrapper.shopProxy) + }.onFailure { Timber.e(it, "RemoteConfig parse failed: ${it.message}") } } @Serializable private data class ShopProxyWrapper( - @SerialName("shop_data") val shopProxy: List = emptyList() + @SerialName("shop_data") val shopProxy: ShopProxy = ShopProxy() ) } diff --git a/app/src/main/java/com/brainwallet/di/RemoteConfigModule.kt b/app/src/main/java/com/brainwallet/di/RemoteConfigModule.kt index 26a8a1ca..400325cc 100644 --- a/app/src/main/java/com/brainwallet/di/RemoteConfigModule.kt +++ b/app/src/main/java/com/brainwallet/di/RemoteConfigModule.kt @@ -22,5 +22,11 @@ val remoteConfigModule = module { } single { FirebaseRemoteConfigRepositoryImpl(get()) } single { HubContentRepositoryImpl(get(), get()) } - single { ShopProxyRepositoryImpl(get(), get()) } + single { + ShopProxyRepositoryImpl( + remoteConfigSource = get(), + json = get(), + scope = get(), + ) + } }