mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-27 20:09:27 +03:00
reusing existing setTextOrHide by adding an additional parameter to hide other views
This commit is contained in:
parent
95b4f99970
commit
7fd794bd7a
3 changed files with 6 additions and 16 deletions
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<PushGatewayItem.Holder>()
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue