From 7fd794bd7adf0b6a8b88e21d4a0c5f239fc7aaa6 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 24 Sep 2021 15:44:10 +0100 Subject: [PATCH] reusing existing setTextOrHide by adding an additional parameter to hide other views --- .../java/im/vector/app/core/extensions/TextView.kt | 4 +++- .../im/vector/app/core/extensions/ViewExtensions.kt | 12 ------------ .../app/features/settings/push/PushGatewayItem.kt | 6 +++--- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/extensions/TextView.kt b/vector/src/main/java/im/vector/app/core/extensions/TextView.kt index 1c424f7071..0872edeafd 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/TextView.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/TextView.kt @@ -39,13 +39,15 @@ import im.vector.app.features.themes.ThemeUtils /** * Set a text in the TextView, or set visibility to GONE if the text is null */ -fun TextView.setTextOrHide(newText: CharSequence?, hideWhenBlank: Boolean = true) { +fun TextView.setTextOrHide(newText: CharSequence?, hideWhenBlank: Boolean = true, vararg relatedViews: View = emptyArray()) { if (newText == null || (newText.isBlank() && hideWhenBlank)) { isVisible = false + relatedViews.forEach { it.isVisible = false } } else { this.text = newText isVisible = true + relatedViews.forEach { it.isVisible = true } } } diff --git a/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt b/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt index 06aa1225c9..b28f33816b 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/ViewExtensions.kt @@ -22,7 +22,6 @@ import android.view.View import android.view.ViewGroup import android.widget.EditText import android.widget.ImageView -import android.widget.TextView import androidx.appcompat.widget.SearchView import androidx.core.view.isVisible import im.vector.app.R @@ -59,14 +58,3 @@ fun ImageView.setDrawableOrHide(drawableRes: Drawable?) { setImageDrawable(drawableRes) isVisible = drawableRes != null } - -fun TextView.setText(text: String?, nullVisibility: Int, vararg relatedViews: View) { - if (text == null) { - visibility = nullVisibility - relatedViews.forEach { it.visibility = nullVisibility } - } else { - visibility = View.VISIBLE - relatedViews.forEach { it.visibility = View.VISIBLE } - this.text = text - } -} diff --git a/vector/src/main/java/im/vector/app/features/settings/push/PushGatewayItem.kt b/vector/src/main/java/im/vector/app/features/settings/push/PushGatewayItem.kt index 2ac156d9fd..04aa2747d7 100644 --- a/vector/src/main/java/im/vector/app/features/settings/push/PushGatewayItem.kt +++ b/vector/src/main/java/im/vector/app/features/settings/push/PushGatewayItem.kt @@ -23,7 +23,7 @@ import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelWithHolder import im.vector.app.R import im.vector.app.core.epoxy.VectorEpoxyHolder -import im.vector.app.core.extensions.setText +import im.vector.app.core.extensions.setTextOrHide import org.matrix.android.sdk.api.session.pushers.Pusher @EpoxyModelClass(layout = R.layout.item_pushgateway) @@ -46,8 +46,8 @@ abstract class PushGatewayItem : EpoxyModelWithHolder() holder.appId.text = pusher.appId holder.pushKey.text = pusher.pushKey holder.appName.text = pusher.appDisplayName - holder.url.setText(pusher.data.url, nullVisibility = View.GONE, holder.urlTitle) - holder.format.setText(pusher.data.format, nullVisibility = View.GONE, holder.formatTitle) + holder.url.setTextOrHide(pusher.data.url, hideWhenBlank = true, holder.urlTitle) + holder.format.setTextOrHide(pusher.data.format, hideWhenBlank = true, holder.formatTitle) holder.deviceName.text = pusher.deviceDisplayName holder.removeButton.setOnClickListener { interactions.onRemovePushTapped(pusher)