From 4b9c173095a01d52ca735a19c6b6a7c90da6e751 Mon Sep 17 00:00:00 2001 From: Dmitry Brant Date: Mon, 25 Mar 2024 13:47:00 -0400 Subject: [PATCH] Follow-up to template flow. (#4546) * Follow-up to template flow. * Whoops. * Put back. * Fix deprecated. * Use correct label when available, instead of key. * Remove unnecessary ellipsize. --------- Co-authored-by: Cooltey Feng --- .../dataclient/mwapi/TemplateDataResponse.kt | 16 ++++++++++------ .../edit/templates/InsertTemplateFragment.kt | 8 +++++--- .../main/res/layout/fragment_insert_template.xml | 3 +-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/wikipedia/dataclient/mwapi/TemplateDataResponse.kt b/app/src/main/java/org/wikipedia/dataclient/mwapi/TemplateDataResponse.kt index 1004b47b7d0..f196c872058 100644 --- a/app/src/main/java/org/wikipedia/dataclient/mwapi/TemplateDataResponse.kt +++ b/app/src/main/java/org/wikipedia/dataclient/mwapi/TemplateDataResponse.kt @@ -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? get() { try { - if (noTemplateData != true && params != null && params !is JsonArray) { - return JsonUtil.json.decodeFromJsonElement>(params) + if (params != null && params !is JsonArray) { + return if (noTemplateData) { + JsonUtil.json.decodeFromJsonElement>(params).mapValues { + TemplateDataParam() + } + } else { + JsonUtil.json.decodeFromJsonElement>(params) + } } } catch (e: Exception) { L.d("Error on parsing params $e") @@ -54,8 +60,6 @@ class TemplateDataResponse : MwResponse() { val aliases: List = emptyList() private val deprecated: JsonElement? = null - private val deprecatedAsString get() = deprecated?.jsonPrimitive?.contentOrNull - - val isDeprecated get() = !deprecatedAsString.equals("false", true) + val isDeprecated get() = deprecated != null && !deprecated.jsonPrimitive.contentOrNull.equals("false", true) } } diff --git a/app/src/main/java/org/wikipedia/edit/templates/InsertTemplateFragment.kt b/app/src/main/java/org/wikipedia/edit/templates/InsertTemplateFragment.kt index 7f6c35e61e8..666f17fcd32 100644 --- a/app/src/main/java/org/wikipedia/edit/templates/InsertTemplateFragment.kt +++ b/app/src/main/java/org/wikipedia/edit/templates/InsertTemplateFragment.kt @@ -37,9 +37,11 @@ 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) + val labelText = it.value.label.orEmpty().ifEmpty { StringUtil.capitalize(it.key) } itemBinding.root.tag = false if (it.value.required) { itemBinding.textInputLayout.hint = labelText @@ -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() diff --git a/app/src/main/res/layout/fragment_insert_template.xml b/app/src/main/res/layout/fragment_insert_template.xml index 173de05a8ab..63b58f118f3 100644 --- a/app/src/main/res/layout/fragment_insert_template.xml +++ b/app/src/main/res/layout/fragment_insert_template.xml @@ -53,8 +53,7 @@ android:layout_height="wrap_content" android:textColor="?attr/primary_color" android:textSize="14sp" - android:lineSpacingExtra="6sp" - android:ellipsize="end" /> + android:lineSpacingExtra="6sp" />