Updated on 2026-08-14
This commit is contained in:
parent
a3a3a4a7cb
commit
a30e44b1cf
21 changed files with 736 additions and 25 deletions
|
|
@ -1,12 +0,0 @@
|
|||
package com.tangem.core.featuretoggle
|
||||
|
||||
/**
|
||||
* Feature toggle
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
interface FeatureToggle {
|
||||
|
||||
/** Feature toggle name */
|
||||
val name: String
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.core.featuretoggle.contract
|
||||
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
|
|
@ -23,6 +24,11 @@ internal class Version private constructor(value: String) : Comparable<Version>
|
|||
fix = versions.getOrNull(index = FIX_VERSION_POSITION)
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
constructor(major: Int, minor: Int, fix: Int? = null) : this(
|
||||
value = "$major.$minor${if (fix != null) ".$fix" else ""}",
|
||||
)
|
||||
|
||||
override fun compareTo(other: Version): Int {
|
||||
var result = major.compareTo(other.major)
|
||||
if (result == 0) result = minor.compareTo(other.minor)
|
||||
|
|
@ -41,6 +47,15 @@ internal class Version private constructor(value: String) : Comparable<Version>
|
|||
return getOrNull(index) ?: error("Invalid version")
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
fun getMajorVersion() = major
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
fun getMinorVersion() = minor
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
fun getFixVersion() = fix
|
||||
|
||||
companion object {
|
||||
private const val MAJOR_VERSION_POSITION = 0
|
||||
private const val MINOR_VERSION_POSITION = 1
|
||||
|
|
@ -55,7 +70,7 @@ internal class Version private constructor(value: String) : Comparable<Version>
|
|||
return try {
|
||||
Version(value)
|
||||
} catch (exception: Exception) {
|
||||
Timber.e(exception, "Version %s is null", value)
|
||||
Timber.e(exception, "Invalid version - %s", value)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.tangem.core.featuretoggle.manager
|
||||
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.tangem.core.featuretoggle.FeatureToggle
|
||||
import com.tangem.core.featuretoggle.storage.FeatureTogglesStorage
|
||||
import com.tangem.core.featuretoggle.utils.associateToggles
|
||||
import com.tangem.core.featuretoggle.version.VersionProvider
|
||||
|
|
@ -42,7 +42,7 @@ internal class DevFeatureTogglesManager(
|
|||
.toMutableMap()
|
||||
}
|
||||
|
||||
override fun isFeatureEnabled(toggle: FeatureToggle): Boolean = featureTogglesMap.any { it.key == toggle.name }
|
||||
override fun isFeatureEnabled(name: String): Boolean = featureTogglesMap.any { it.key == name }
|
||||
|
||||
override fun getFeatureToggles(): Map<String, Boolean> = featureTogglesMap
|
||||
|
||||
|
|
@ -51,4 +51,9 @@ internal class DevFeatureTogglesManager(
|
|||
featureTogglesMap[name] = isEnabled
|
||||
appPreferenceStorage.featureToggles = jsonAdapter.toJson(featureTogglesMap)
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
fun setFeatureToggles(map: MutableMap<String, Boolean>) {
|
||||
featureTogglesMap = map
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
package com.tangem.core.featuretoggle.manager
|
||||
|
||||
import com.tangem.core.featuretoggle.FeatureToggle
|
||||
|
||||
/**
|
||||
* Component for getting information about the availability of feature toggles
|
||||
*
|
||||
|
|
@ -12,6 +10,6 @@ interface FeatureTogglesManager {
|
|||
/** Initialize manager */
|
||||
suspend fun init()
|
||||
|
||||
/** Check feature toggle [toggle] availability */
|
||||
fun isFeatureEnabled(toggle: FeatureToggle): Boolean
|
||||
/** Check feature toggle availability by name [name] */
|
||||
fun isFeatureEnabled(name: String): Boolean
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.tangem.core.featuretoggle.manager
|
||||
|
||||
import com.tangem.core.featuretoggle.FeatureToggle
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import com.tangem.core.featuretoggle.storage.FeatureTogglesStorage
|
||||
import com.tangem.core.featuretoggle.utils.associateToggles
|
||||
import com.tangem.core.featuretoggle.version.VersionProvider
|
||||
|
|
@ -25,5 +25,13 @@ internal class ProdFeatureTogglesManager(
|
|||
.associateToggles(currentVersion = versionProvider.get() ?: "")
|
||||
}
|
||||
|
||||
override fun isFeatureEnabled(toggle: FeatureToggle): Boolean = featureToggles.any { it.key == toggle.name }
|
||||
override fun isFeatureEnabled(name: String): Boolean = featureToggles.any { it.key == name }
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
fun getProdFeatureToggles() = featureToggles
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
fun setProdFeatureToggles(map: Map<String, Boolean>) {
|
||||
featureToggles = map
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.core.featuretoggle.storage
|
||||
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.tangem.core.featuretoggle.storage.LocalFeatureTogglesStorage.Companion.LOCAL_CONFIG_PATH
|
||||
import com.tangem.datasource.asset.AssetReader
|
||||
|
|
@ -29,6 +30,12 @@ internal class LocalFeatureTogglesStorage(
|
|||
.onFailure { Timber.e(LocalFeatureTogglesStorage::class.java.name, "Failed to parse $LOCAL_CONFIG_PATH") }
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
fun getConfigPath() = LOCAL_CONFIG_PATH
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
fun getFeatureToggles(): Iterable<FeatureToggle> = featureToggles
|
||||
|
||||
private companion object {
|
||||
const val LOCAL_CONFIG_PATH: String = "configs/feature_toggles_config"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue