Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow-up to template flow. #4546

Merged
merged 10 commits into from
Mar 25, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ class TemplateDataResponse : MwResponse() {
val description: String? = null
private val params: JsonElement? = null
val format: String? = null
@SerialName("notemplatedata") val noTemplateData: Boolean? = null
@SerialName("notemplatedata") val noTemplateData: Boolean = false

val getParams: Map<String, TemplateDataParam>? get() {
try {
if (noTemplateData != true && params != null && params !is JsonArray) {
return JsonUtil.json.decodeFromJsonElement<Map<String, TemplateDataParam>>(params)
if (params != null && params !is JsonArray) {
return if (noTemplateData) {
JsonUtil.json.decodeFromJsonElement<Map<String, JsonArray>>(params).mapValues {
TemplateDataParam()
}
} else {
JsonUtil.json.decodeFromJsonElement<Map<String, TemplateDataParam>>(params)
}
}
} catch (e: Exception) {
L.d("Error on parsing params $e")
Expand All @@ -56,6 +62,6 @@ class TemplateDataResponse : MwResponse() {

private val deprecatedAsString get() = deprecated?.jsonPrimitive?.contentOrNull

val isDeprecated get() = !deprecatedAsString.equals("false", true)
val isDeprecated get() = deprecatedAsString.equals("true", true)
dbrant marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class InsertTemplateFragment : Fragment() {
private fun buildParamsInputFields(templateData: TemplateDataResponse.TemplateData) {
activity.updateInsertButton(true)
binding.templateDataParamsContainer.removeAllViews()
templateData.getParams?.filter { !it.value.isDeprecated }?.forEach {
templateData.getParams?.filter {
!it.value.isDeprecated
}?.forEach {
val itemBinding = ItemInsertTemplateBinding.inflate(layoutInflater)
val labelText = StringUtil.capitalize(it.key)
itemBinding.root.tag = false
Expand Down Expand Up @@ -77,7 +79,7 @@ class InsertTemplateFragment : Fragment() {
binding.templateDataTitle.text = StringUtil.removeNamespace(pageTitle.displayText)
binding.templateDataDescription.text = StringUtil.fromHtml(getTemplateDescription(templateData))
binding.templateDataDescription.isVisible = !binding.templateDataDescription.text.isNullOrEmpty()
binding.templateDataMissing.isVisible = templateData.noTemplateData == true
binding.templateDataMissing.isVisible = templateData.noTemplateData
binding.templateDataMissingText.text = StringUtil.fromHtml(getString(R.string.templates_description_missing_data,
getString(R.string.template_parameters_url), getString(R.string.autogenerated_parameters_url)))
binding.templateDataMissingText.movementMethod = LinkMovementMethodExt.getExternalLinkMovementMethod()
Expand Down