Skip to content

Commit

Permalink
Follow-up to template flow. (wikimedia#4546)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
dbrant and cooltey authored Mar 25, 2024
1 parent c1e8312 commit 4b9c173
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
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 @@ -54,8 +60,6 @@ class TemplateDataResponse : MwResponse() {
val aliases: List<String> = 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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
3 changes: 1 addition & 2 deletions app/src/main/res/layout/fragment_insert_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

</LinearLayout>

Expand Down

0 comments on commit 4b9c173

Please sign in to comment.