Updated on 2026-08-14

This commit is contained in:
Tangem 2025-02-12 17:35:12 +05:00
parent 69754e4159
commit 34cfc843ab
31 changed files with 322 additions and 170 deletions

View file

@ -4,6 +4,7 @@ import android.content.Context
import android.util.Log
import coil.ImageLoader
import coil.memory.MemoryCache
import coil.request.CachePolicy
import coil.util.Logger
import com.tangem.datasource.api.common.createNetworkLoggingInterceptor
import okhttp3.OkHttpClient
@ -24,6 +25,7 @@ fun createCoilImageLoader(context: Context, logEnabled: Boolean = false): ImageL
.build()
}
}
.memoryCachePolicy(CachePolicy.ENABLED)
.memoryCache {
MemoryCache.Builder(context)
.maxSizePercent(COIL_MEMORY_CACHE_SIZE)

View file

@ -2,6 +2,7 @@ package com.tangem.tap.common.images
import android.content.Context
import coil.imageLoader
import coil.request.CachePolicy
import coil.request.ImageRequest
import com.tangem.core.ui.coil.ImagePreloader
@ -12,6 +13,8 @@ internal class DefaultImagePreloader(
appContext.imageLoader.enqueue(
ImageRequest.Builder(appContext)
.data(url)
.memoryCacheKey(url)
.memoryCachePolicy(CachePolicy.ENABLED)
.build(),
)
}

View file

@ -27,8 +27,8 @@ internal object PromoDomainModule {
@Provides
@Singleton
fun provideShouldShowSwapStoriesUseCase(promoRepository: PromoRepository): ShouldShowSwapStoriesUseCase {
return ShouldShowSwapStoriesUseCase(promoRepository)
fun provideShouldShowSwapStoriesUseCase(promoRepository: PromoRepository): ShouldShowStoriesUseCase {
return ShouldShowStoriesUseCase(promoRepository)
}
@Provides

View file

@ -30,6 +30,7 @@ import com.tangem.domain.settings.usercountry.FetchUserCountryUseCase
import com.tangem.domain.staking.FetchStakingTokensUseCase
import com.tangem.domain.wallets.legacy.UserWalletsListManager
import com.tangem.features.onramp.OnrampFeatureToggles
import com.tangem.features.swap.SwapFeatureToggles
import com.tangem.tap.common.extensions.setContext
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.hilt.android.lifecycle.HiltViewModel
@ -58,6 +59,7 @@ internal class MainViewModel @Inject constructor(
private val getStoryContentUseCase: GetStoryContentUseCase,
private val imagePreloader: ImagePreloader,
private val fetchHotCryptoUseCase: FetchHotCryptoUseCase,
private val swapFeatureToggles: SwapFeatureToggles,
onrampFeatureToggles: OnrampFeatureToggles,
getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase,
) : ViewModel() {
@ -298,12 +300,16 @@ internal class MainViewModel @Inject constructor(
private fun preloadImages() {
try {
viewModelScope.launch {
val swapStories = getStoryContentUseCase(StoryContentIds.STORY_FIRST_TIME_SWAP.id).getOrNull()
?: return@launch
val storiesImages = swapStories.getImageUrls()
val swapStories = if (swapFeatureToggles.isPromoStoriesEnabled) {
getStoryContentUseCase.invokeSync(StoryContentIds.STORY_FIRST_TIME_SWAP.id)
.getOrNull()
} else {
null
}
val storiesImages = swapStories?.getImageUrls()
// try to preload images for stories
storiesImages.forEach(imagePreloader::preload)
storiesImages?.forEach(imagePreloader::preload)
}
} catch (ex: Exception) {
Timber.e(ex.message)