@@ -114,12 +114,17 @@ class IsEnabledViewModel(initialFlag: String): ViewModel() {
114114 fun setFlagName (newFlagName : String ) {
115115 _flagName .postValue(newFlagName)
116116 _isEnabled .postValue(unleash?.isEnabled(newFlagName) ? : false )
117+ _variant .postValue(unleash?.getVariant(newFlagName)?.name ? : " " )
117118 }
118119
119120 val flagName: LiveData <String >
120121 get() = _flagName
121122
122123 private val _isEnabled = MutableLiveData (unleash?.isEnabled(initialFlag) ? : false )
124+ private val _variant = MutableLiveData (unleash?.getVariant(initialFlag)?.name ? : " " )
125+
126+ val variant: LiveData <String >
127+ get() = _variant
123128
124129 val isEnabled: LiveData <Boolean >
125130 get() = _isEnabled
@@ -138,6 +143,11 @@ class IsEnabledViewModel(initialFlag: String): ViewModel() {
138143 Log .i(" MAIN" , " Pushing value changed" )
139144 _isEnabled .postValue(newValue)
140145 }
146+ val newVariant = unleash.getVariant(flag)
147+ if (newVariant.name != _variant .value) {
148+ Log .i(" MAIN" , " Pushing variant changed" )
149+ _variant .postValue(newVariant.name)
150+ }
141151 }
142152 }
143153 unleash.addUnleashEventListener(listener)
@@ -152,14 +162,15 @@ fun Greeting(
152162 modifier : Modifier = Modifier ,
153163) {
154164 val isEnabled by isEnabledViewModel.isEnabled.observeAsState(false )
165+ val variant by isEnabledViewModel.variant.observeAsState(" " )
155166 Text (
156167 text = " Hello $name " ,
157168 fontSize = 44 .sp,
158169 modifier = modifier,
159170 color = colorResource(id = R .color.purple_500)
160171 )
161172 Text (
162- text = " ${isEnabledViewModel.getFlagName()} is ${if (isEnabled) " enabled" else " disabled" } " ,
173+ text = " ${isEnabledViewModel.getFlagName()} is ${if (isEnabled) " enabled with variant $variant " else " disabled" } " ,
163174 fontSize = 38 .sp,
164175 lineHeight = 38 .sp,
165176 color = if (isEnabled) androidx.compose.ui.graphics.Color .Green else androidx.compose.ui.graphics.Color .Red ,
0 commit comments