This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MarkAccountAsBetaFeatureToggleCompanion @Inject constructor( | |
featureToggleSet: Set<@JvmSuppressWildcards FeatureToggle<*>>, | |
private val accountRepository: AccountRepository | |
) : FeatureToggleCompanion<Boolean>(featureToggleSet, MarkAccountAsBetaFeature) { | |
override fun executeUpdate(value: Boolean): Completable = | |
accountRepository.markAccountAsBeta(value) | |
.ignoreElement() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class FeatureToggleCompanion<T : Any>( | |
featureToggleSet: Set<@JvmSuppressWildcards FeatureToggle<*>>, | |
associatedFeature: Feature<T> | |
) { | |
protected val toggle = featureToggleSet.first { it.feature == associatedFeature } | |
val feature = toggle.feature | |
val featureValue = toggle.value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AveragesCardViewModel( | |
private val showAveragesCardFeatureToggle: ShowAveragesCardFeatureToggle | |
) { | |
val isVisible: Boolean = showAveragesCardFeatureToggle.value | |
class Factory @Inject constructor( | |
private val showAveragesCardFeatureToggle: ShowAveragesCardFeatureToggle | |
) : ViewModelProvider.Factory() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
class ShowAveragesCardToggleModule { | |
@Provides | |
fun provideShowAveragesCardFeatureToggle(context: Context) = | |
ShowAveragesCardFeatureToggle(context) | |
@Provides | |
@IntoSet | |
fun addShowAveragesCardFeatureToggleIntoSet( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ShowAveragesCardFeature : Feature<Boolean> { | |
override val initialValue = false | |
override val name = "Show Averages Card" | |
} | |
class ShowAveragesCardFeatureToggle(context: Context) : | |
PersistentFeatureToggle(context, ShowAveragesCardFeature) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface FeatureToggle<T : Any> { | |
val feature: Feature<T> | |
var value: T | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Feature<T : Any> { | |
val initialValue: T | |
val name: String | |
fun validate(newValue: T): Boolean = true | |
fun type(): KClass<out T> = initialValue::class | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am lookashc on github. | |
* I am lookashc (https://keybase.io/lookashc) on keybase. | |
* I have a public key ASDgSVReUo1hxm2WGfzp5ExrTzJBeazfcdhnT7aHBJnI3Qo | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <T> dependantLiveData(vararg dependencies: LiveData<*>, crossinline mapper: () -> T?) = | |
MediatorLiveData<T>().also { mediatorLiveData -> | |
val observer = Observer<Any> { mediatorLiveData.value = mapper() } | |
dependencies.forEach { dependencyLiveData -> | |
mediatorLiveData.addSource(dependencyLiveData, observer) | |
} | |
} | |
//Example usage |