mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-10 20:44:04 +02:00
rewrite pollOptions json parser
This commit is contained in:
@@ -1,14 +1,12 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.actions
|
package com.vitorpamplona.amethyst.ui.actions
|
||||||
|
|
||||||
import androidx.annotation.Keep
|
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
import androidx.compose.runtime.mutableStateMapOf
|
import androidx.compose.runtime.mutableStateMapOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.google.gson.reflect.TypeToken
|
|
||||||
import com.vitorpamplona.amethyst.model.*
|
import com.vitorpamplona.amethyst.model.*
|
||||||
import com.vitorpamplona.amethyst.service.nip19.Nip19
|
import com.vitorpamplona.amethyst.service.nip19.Nip19
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
class NewPollViewModel : NewPostViewModel() {
|
class NewPollViewModel : NewPostViewModel() {
|
||||||
|
|
||||||
@@ -138,9 +136,11 @@ class NewPollViewModel : NewPostViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Keep // Do not obfuscate! Variable names are needed for parsers
|
fun jsonToPollOptions(jsonString: String): Map<Int, String> {
|
||||||
data class PollOptions(var poll_options: List<String>)
|
val jsonMap = mutableMapOf<Int, String>()
|
||||||
fun parseJsonPollOption(json: String): PollOptions {
|
val jsonObject = JSONObject(jsonString)
|
||||||
val typeToken = object : TypeToken<PollOptions>() {}.type
|
jsonObject.keys().forEach {
|
||||||
return Gson().fromJson(json, typeToken)
|
jsonMap[it.toString().toInt()] = jsonObject.getString(it)
|
||||||
|
}
|
||||||
|
return jsonMap
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user