Updated on 2026-08-14
This commit is contained in:
parent
2ffe05e93a
commit
f2b49df651
9 changed files with 53 additions and 27 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package com.tangem.datasource.api.common.config
|
||||
|
||||
typealias ApiConfigs = Set<@JvmSuppressWildcards ApiConfig>
|
||||
|
||||
/**
|
||||
* Api config
|
||||
*
|
||||
|
|
@ -36,8 +38,5 @@ sealed class ApiConfig {
|
|||
internal const val MOCKED_BUILD_TYPE = "mocked"
|
||||
internal const val EXTERNAL_BUILD_TYPE = "external"
|
||||
internal const val RELEASE_BUILD_TYPE = "release"
|
||||
|
||||
/** All api configs */
|
||||
fun values() = listOf(Express(), TangemTech())
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.datasource.api.common.config.managers
|
||||
|
||||
import com.tangem.datasource.api.common.config.ApiConfig
|
||||
import com.tangem.datasource.api.common.config.ApiConfigs
|
||||
import com.tangem.datasource.api.common.config.ApiEnvironment
|
||||
import com.tangem.datasource.local.preferences.AppPreferencesStore
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys
|
||||
|
|
@ -12,17 +13,19 @@ import kotlinx.coroutines.flow.*
|
|||
/**
|
||||
* Implementation of [ApiConfigsManager] in DEV environment
|
||||
*
|
||||
* @param apiConfigs api configs
|
||||
* @property appPreferencesStore app preferences store
|
||||
* @property dispatchers coroutine dispatcher provider
|
||||
*/
|
||||
internal class DevApiConfigsManager(
|
||||
apiConfigs: ApiConfigs,
|
||||
private val appPreferencesStore: AppPreferencesStore,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) : MutableApiConfigsManager {
|
||||
|
||||
override val configs: Flow<Map<ApiConfig, ApiEnvironment>> get() = _apiConfigs
|
||||
|
||||
private val _apiConfigs = MutableStateFlow(value = ApiConfig.values().associateWith { it.defaultEnvironment })
|
||||
private val _apiConfigs = MutableStateFlow(value = apiConfigs.associateWith { it.defaultEnvironment })
|
||||
|
||||
override suspend fun initialize() {
|
||||
// We can't use appPreferencesStore.getObjectMap as base flow,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,19 @@
|
|||
package com.tangem.datasource.api.common.config.managers
|
||||
|
||||
import com.tangem.datasource.api.common.config.ApiConfig
|
||||
import com.tangem.datasource.api.common.config.ApiConfigs
|
||||
|
||||
/** Implementation of [ApiConfigsManager] in PROD environment */
|
||||
internal class ProdApiConfigsManager : ApiConfigsManager {
|
||||
/**
|
||||
* Implementation of [ApiConfigsManager] in PROD environment
|
||||
*
|
||||
* @property apiConfigs api configs
|
||||
*/
|
||||
internal class ProdApiConfigsManager(
|
||||
private val apiConfigs: ApiConfigs,
|
||||
) : ApiConfigsManager {
|
||||
|
||||
override fun getBaseUrl(id: ApiConfig.ID): String {
|
||||
val config = ApiConfig.values().firstOrNull { it.id == id }
|
||||
val config = apiConfigs.firstOrNull { it.id == id }
|
||||
?: error("Api config with id [$id] not found. Check ApiConfig implementations")
|
||||
|
||||
return config.environments[config.defaultEnvironment]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package com.tangem.datasource.di
|
||||
|
||||
import com.tangem.datasource.api.common.config.ApiConfig
|
||||
import com.tangem.datasource.api.common.config.Express
|
||||
import com.tangem.datasource.api.common.config.TangemTech
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import dagger.multibindings.IntoSet
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
internal object ApiConfigsModule {
|
||||
|
||||
@Provides
|
||||
@IntoSet
|
||||
fun provideExpressConfig(): ApiConfig = Express()
|
||||
|
||||
@Provides
|
||||
@IntoSet
|
||||
fun provideTangemTechConfig(): ApiConfig = TangemTech()
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import com.squareup.moshi.Moshi
|
||||
import com.tangem.datasource.BuildConfig
|
||||
import com.tangem.datasource.api.common.config.ApiConfig
|
||||
import com.tangem.datasource.api.common.config.ApiConfigs
|
||||
import com.tangem.datasource.api.common.config.managers.ApiConfigsManager
|
||||
import com.tangem.datasource.api.common.config.managers.DevApiConfigsManager
|
||||
import com.tangem.datasource.api.common.config.managers.ProdApiConfigsManager
|
||||
|
|
@ -42,13 +43,14 @@ class NetworkModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
fun provideApiConfigManager(
|
||||
apiConfigs: ApiConfigs,
|
||||
appPreferencesStore: AppPreferencesStore,
|
||||
dispatchers: CoroutineDispatcherProvider,
|
||||
): ApiConfigsManager {
|
||||
return if (BuildConfig.TESTER_MENU_ENABLED) {
|
||||
DevApiConfigsManager(appPreferencesStore, dispatchers)
|
||||
DevApiConfigsManager(apiConfigs, appPreferencesStore, dispatchers)
|
||||
} else {
|
||||
ProdApiConfigsManager()
|
||||
ProdApiConfigsManager(apiConfigs)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import org.junit.runners.Parameterized
|
|||
@RunWith(Parameterized::class)
|
||||
internal class ProdApiConfigsManagerTest(private val model: Model) {
|
||||
|
||||
private val manager = ProdApiConfigsManager()
|
||||
private val manager = ProdApiConfigsManager(API_CONFIGS)
|
||||
|
||||
@Test
|
||||
fun test_getBaseUrl() {
|
||||
|
|
@ -33,9 +33,16 @@ internal class ProdApiConfigsManagerTest(private val model: Model) {
|
|||
|
||||
private companion object {
|
||||
|
||||
val API_CONFIGS = setOf(
|
||||
Express(),
|
||||
TangemTech(),
|
||||
|
||||
// Don't forget to add new config
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
@Parameterized.Parameters
|
||||
fun data(): Collection<Model> = ApiConfig.values().map {
|
||||
fun data(): Collection<Model> = API_CONFIGS.map {
|
||||
when (it) {
|
||||
is Express -> createExpressModel()
|
||||
is TangemTech -> createTangemTechModel()
|
||||
|
|
|
|||
|
|
@ -10,14 +10,12 @@ import kotlinx.collections.immutable.ImmutableSet
|
|||
* @property apiInfoList environment toggles list
|
||||
* @property onEnvironmentSelect the lambda to be invoked when button is pressed
|
||||
* @property onBackClick the lambda to be invoked when back button is pressed
|
||||
* @property onApplyChangesClick the lambda to be invoked when apply changes button is pressed
|
||||
*/
|
||||
internal data class EnvironmentTogglesScreenUM(
|
||||
@StringRes val title: Int,
|
||||
val apiInfoList: ImmutableSet<ApiInfoUM>,
|
||||
val onEnvironmentSelect: (id: String, environment: String) -> Unit,
|
||||
val onBackClick: () -> Unit,
|
||||
val onApplyChangesClick: () -> Unit,
|
||||
) {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import androidx.compose.ui.res.stringResource
|
|||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.tangem.core.ui.components.PrimaryButton
|
||||
import com.tangem.core.ui.components.appbar.AppBarWithBackButton
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.core.ui.res.TangemThemePreview
|
||||
|
|
@ -63,16 +62,6 @@ internal fun EnvironmentTogglesScreen(uiModel: EnvironmentTogglesScreenUM) {
|
|||
),
|
||||
)
|
||||
}
|
||||
|
||||
item {
|
||||
PrimaryButton(
|
||||
text = stringResource(id = R.string.apply_changes),
|
||||
onClick = uiModel.onApplyChangesClick,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(TangemTheme.dimens.spacing16),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -174,7 +163,6 @@ private fun PreviewFeatureTogglesScreen() {
|
|||
),
|
||||
onEnvironmentSelect = { _: String, s1: String -> select = s1 },
|
||||
onBackClick = {},
|
||||
onApplyChangesClick = {},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ internal class EnvironmentsTogglesViewModel @Inject constructor(
|
|||
/** Setup navigation state property by router [router] */
|
||||
fun setupNavigation(router: InnerTesterRouter) {
|
||||
_uiState.update {
|
||||
it.copy(onBackClick = router::back, onApplyChangesClick = router::back)
|
||||
it.copy(onBackClick = router::back)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +85,6 @@ internal class EnvironmentsTogglesViewModel @Inject constructor(
|
|||
apiInfoList = persistentSetOf(),
|
||||
onEnvironmentSelect = ::onToggleValueChange,
|
||||
onBackClick = {},
|
||||
onApplyChangesClick = {},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue