Updated on 2026-08-14
This commit is contained in:
commit
c2ee146ed0
29 changed files with 295 additions and 135 deletions
64
app/src/main/java/com/tangem/tap/common/Throttling.kt
Normal file
64
app/src/main/java/com/tangem/tap/common/Throttling.kt
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package com.tangem.tap.common
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
open class Throttler<T>(
|
||||
private val duration: Long,
|
||||
) : Throttle<T> {
|
||||
|
||||
private val items: MutableMap<T, Long> = mutableMapOf()
|
||||
|
||||
override fun isStillThrottled(item: T): Boolean {
|
||||
val inThrottlingUpTo = items[item] ?: return false
|
||||
val diff = System.currentTimeMillis() - inThrottlingUpTo
|
||||
return diff < 0
|
||||
}
|
||||
|
||||
override fun updateThrottlingTo(item: T): T {
|
||||
val now = System.currentTimeMillis()
|
||||
val throttledUpTo = items[item] ?: 0L
|
||||
if (throttledUpTo == 0L || throttledUpTo < now) {
|
||||
val newTime = now + duration
|
||||
items[item] = newTime
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
open fun clear() {
|
||||
items.clear()
|
||||
}
|
||||
}
|
||||
|
||||
class ThrottlerWithValues<T, V>(
|
||||
duration: Long
|
||||
) : Throttler<T>(duration), ValuesHolder<T, V> {
|
||||
|
||||
private val valuesHolder: MutableMap<T, V?> = mutableMapOf()
|
||||
|
||||
override fun setValue(item: T, value: V) {
|
||||
valuesHolder[item] = value
|
||||
}
|
||||
|
||||
override fun geValue(item: T): V? = valuesHolder[item]
|
||||
|
||||
override fun remove(item: T) {
|
||||
valuesHolder.remove(item)
|
||||
}
|
||||
|
||||
override fun clear() {
|
||||
valuesHolder.clear()
|
||||
super.clear()
|
||||
}
|
||||
}
|
||||
|
||||
interface Throttle<T> {
|
||||
fun isStillThrottled(item: T): Boolean
|
||||
fun updateThrottlingTo(item: T): T
|
||||
}
|
||||
|
||||
interface ValuesHolder<K, V> {
|
||||
fun setValue(item: K, value: V)
|
||||
fun geValue(item: K): V?
|
||||
fun remove(item: K)
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ enum class AnalyticsEvent(val event: String) {
|
|||
CARD_IS_SCANNED("card_is_scanned"),
|
||||
TRANSACTION_IS_SENT("transaction_is_sent"),
|
||||
READY_TO_SCAN("ready_to_scan"),
|
||||
DEMO_MODE_ACTIVATED("demo_mode_activated"),
|
||||
|
||||
APP_RATING_DISPLAYED("rate_app_warning_displayed"),
|
||||
APP_RATING_DISMISS("dismiss_rate_app_warning"),
|
||||
|
|
@ -20,6 +21,7 @@ enum class AnalyticsEvent(val event: String) {
|
|||
|
||||
enum class AnalyticsParam(val param: String) {
|
||||
BLOCKCHAIN("blockchain"),
|
||||
CARD_ID("cardId"),
|
||||
BATCH_ID("batch_id"),
|
||||
FIRMWARE("firmware"),
|
||||
ACTION("action"),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class GlobalAnalyticsHandler(val analyticsHandlers: List<AnalyticsHandler>) :
|
|||
blockchain: String?,
|
||||
params: Map<String, String>
|
||||
) {
|
||||
analyticsHandlers.forEach { it.triggerEvent(event, card, blockchain) }
|
||||
analyticsHandlers.forEach { it.triggerEvent(event, card, blockchain, params) }
|
||||
}
|
||||
|
||||
override fun triggerEvent(event: String, params: Map<String, String>) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.tangem.tap.common.images
|
|||
import android.app.Application
|
||||
import com.squareup.picasso.OkHttp3Downloader
|
||||
import com.squareup.picasso.Picasso
|
||||
import com.tangem.tap.logConfig
|
||||
import com.tangem.wallet.BuildConfig
|
||||
import okhttp3.Cache
|
||||
import okhttp3.CacheControl
|
||||
|
|
@ -18,42 +19,45 @@ class PicassoHelper {
|
|||
|
||||
fun initPicassoWithCaching(application: Application) {
|
||||
val picasso = Picasso.Builder(application)
|
||||
.downloader(OkHttp3Downloader(getOkHttpForPicasso(application)))
|
||||
.build()
|
||||
picasso.isLoggingEnabled = BuildConfig.DEBUG
|
||||
.downloader(OkHttp3Downloader(getOkHttpForPicasso(application)))
|
||||
.build()
|
||||
picasso.isLoggingEnabled = logIsEnabled()
|
||||
picasso.setIndicatorsEnabled(BuildConfig.DEBUG)
|
||||
Picasso.setSingletonInstance(picasso)
|
||||
}
|
||||
|
||||
private fun getOkHttpForPicasso(application: Application): OkHttpClient {
|
||||
val okHttpBuilder = OkHttpClient.Builder()
|
||||
okHttpBuilder.cache(Cache(File(application.filesDir, "artworks"), Long.MAX_VALUE))
|
||||
okHttpBuilder.callTimeout(15000, TimeUnit.MILLISECONDS)
|
||||
return OkHttpClient.Builder().apply {
|
||||
cache(Cache(File(application.filesDir, "artworks"), Long.MAX_VALUE))
|
||||
callTimeout(15000, TimeUnit.MILLISECONDS)
|
||||
|
||||
okHttpBuilder.addInterceptor { chain ->
|
||||
val cacheControl = CacheControl.Builder()
|
||||
if (logIsEnabled()) {
|
||||
addDebugInterceptors(this)
|
||||
}
|
||||
|
||||
addInterceptor { chain ->
|
||||
val cacheControl = CacheControl.Builder()
|
||||
.maxStale(KEEP_CACHE_MAX_DAYS, TimeUnit.DAYS)
|
||||
.build()
|
||||
val origRequest = chain.request()
|
||||
val neverExpireRequest = origRequest.newBuilder()
|
||||
val origRequest = chain.request()
|
||||
val neverExpireRequest = origRequest.newBuilder()
|
||||
.cacheControl(cacheControl)
|
||||
.build()
|
||||
chain.proceed(neverExpireRequest)
|
||||
}
|
||||
addDebugInterceptors(okHttpBuilder)
|
||||
chain.proceed(neverExpireRequest)
|
||||
}
|
||||
}.build()
|
||||
|
||||
return okHttpBuilder.build()
|
||||
}
|
||||
|
||||
private fun addDebugInterceptors(okHttpBuilder: OkHttpClient.Builder) {
|
||||
if (!BuildConfig.DEBUG) return
|
||||
|
||||
val picassoInterceptor = HttpLoggingInterceptor(PicassoOkHttpLogger()).apply {
|
||||
level = HttpLoggingInterceptor.Level.BODY
|
||||
}
|
||||
okHttpBuilder.addInterceptor(picassoInterceptor)
|
||||
}
|
||||
|
||||
private fun logIsEnabled(): Boolean = BuildConfig.DEBUG && logConfig.picasso
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.tap.common.redux
|
||||
|
||||
import com.tangem.tap.logConfig
|
||||
import org.rekotlin.Middleware
|
||||
import timber.log.Timber
|
||||
|
||||
|
|
@ -9,7 +10,7 @@ import timber.log.Timber
|
|||
val logMiddleware: Middleware<AppState> = { dispatch, appState ->
|
||||
{ nextDispatch ->
|
||||
{ action ->
|
||||
Timber.d("Dispatch action: $action")
|
||||
if (logConfig.storeAction) Timber.d("Dispatch action: $action")
|
||||
nextDispatch(action)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
package com.tangem.tap.common.shop.shopify
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class ShopifyShop(
|
||||
val domain: String,
|
||||
@Json(name = "storefrontApiKeyAndroid")
|
||||
val storefrontApiKey: String,
|
||||
val merchantID: String,
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue