Skip to content

Commit

Permalink
Allow to store a choiceList computed for action (not decoded from JSON)
Browse files Browse the repository at this point in the history
  • Loading branch information
e-marchand committed Jan 5, 2024
1 parent e4c271f commit 94886fa
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import java.util.LinkedList
data class FieldMapping(
val binding: String?,
val choiceList: Any?, // choiceList can be a JSONObject or a JSONArray
var choiceListComputed: Map<String, Any>?,
val type: Any?, // type can be a String or a JSONArray
val name: String?,
val imageWidth: Int?, // currently not used, reading the one from layout
Expand Down Expand Up @@ -69,6 +70,7 @@ data class FieldMapping(
FieldMapping(
binding = fieldMappingJsonObject.getSafeString("binding"),
choiceList = getChoiceList(fieldMappingJsonObject),
choiceListComputed = null,
type = fieldMappingJsonObject.getSafeArray("type")
?.getStringList() // type can be a JSONArray or a String
?: fieldMappingJsonObject.getSafeString("type"),
Expand Down Expand Up @@ -147,6 +149,10 @@ data class FieldMapping(
}

fun getChoiceList(): LinkedList<Any> {
return getChoiceList (choiceList)
}

fun getChoiceList(choiceList: Any?): LinkedList<Any> {
return when (choiceList) {
is Map<*, *> -> LinkedList(choiceList.map { Pair(it.key, it.value) })
is List<*> -> LinkedList(choiceList)
Expand Down

0 comments on commit 94886fa

Please sign in to comment.