I’m currently working through someone’s old code and I’m a little confused. How can I use the code below to populate a lazy column? Each lazyColumn item displays a Title and Description. Any help is much appreciated.
ViewModel class:
class FeatureConfigViewModel @Inject constructor(
private val featuresRepository: FeaturesRepository,
private val localFeatureConfigOverrider: LocalFeatureConfigOverrider): ViewModel() {
var featureConfigs = listOf<Feature>()
@Inject lateinit var featureConfig: FeatureConfig
init {
if (
JSON_FEATURE_FLAG_DATA_KEY.isNotEmpty()
) {
val jsonData = JSON_FEATURE_FLAG_DATA_KEY
loadFeatures(jsonData)
} else {
loadFeatures()
}
}
fun loadFeatures() {
loadFeatures(featuresRepository.getFeatures(JSON_FILE_NAME))
}
fun loadFeatures(jsonData: String) {
loadFeatures(
featuresRepository.getFeatures(JSON_FILE_NAME)
.zipWith(
featuresRepository.getFeaturesFromJson(jsonData)
) { featuresFromFile, featuresFromJson ->
for (feature in featuresFromFile) {
val overrideValue = featuresFromJson[feature.key]
if (overrideValue != null) {
localFeatureConfigOverrider.put(feature.key, overrideValue)
}
}
featuresFromFile
}
)
}
private fun loadFeatures(featuresSingle: Single<List<Feature>>) {
val d = featuresSingle.subscribe({ featureList ->
val features = featureList.toMutableList().sortedBy { it.key }
featureConfigs = features
}) { throwable ->
Logger.e(throwable)
}
}
companion object {
private const val JSON_FILE_NAME = "fileName.json"
const val JSON_FEATURE_FLAG_DATA_KEY = "keyName"
}
}
View snippet with the lazyColumn (I’m hoping to use a list containing the results from the ViewModel to populate the lazy column):
LazyColumn(modifier = Modifier
.weight(weight = 1f, fill = false)
.fillMaxSize()) {
items(items = configs) {
LazyColumnDescription(
name = it.key,
description = it.description,
)
}
}