convert some findViewById into ViewBinding

This commit is contained in:
Benoit Marty 2021-06-16 17:52:52 +02:00
parent 7a40841cbb
commit bae802d8dc
5 changed files with 56 additions and 71 deletions

View File

@ -18,8 +18,6 @@ package im.vector.app.features.crypto.verification.epoxy
import android.content.Context
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
@ -27,6 +25,7 @@ import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.databinding.ItemEmojiVerifBinding
import me.gujun.android.span.Span
import me.gujun.android.span.image
import me.gujun.android.span.span
@ -68,16 +67,18 @@ abstract class BottomSheetVerificationEmojisItem : VectorEpoxyModel<BottomSheetV
}
private fun bindEmojiView(view: ViewGroup, rep: EmojiRepresentation) {
rep.drawableRes?.let {
view.findViewById<TextView>(R.id.item_emoji_tv).isVisible = false
view.findViewById<ImageView>(R.id.item_emoji_image).isVisible = true
view.findViewById<ImageView>(R.id.item_emoji_image).setImageDrawable(ContextCompat.getDrawable(view.context, it))
} ?: run {
view.findViewById<TextView>(R.id.item_emoji_tv).isVisible = true
view.findViewById<ImageView>(R.id.item_emoji_image).isVisible = false
view.findViewById<TextView>(R.id.item_emoji_tv).text = rep.emoji
val views = ItemEmojiVerifBinding.bind(view)
val drawableRes = rep.drawableRes
if (drawableRes != null) {
views.itemEmojiTv.isVisible = false
views.itemEmojiImage.isVisible = true
views.itemEmojiImage.setImageDrawable(ContextCompat.getDrawable(view.context, drawableRes))
} else {
views.itemEmojiTv.isVisible = true
views.itemEmojiImage.isVisible = false
views.itemEmojiTv.text = rep.emoji
}
view.findViewById<TextView>(R.id.item_emoji_name_tv).setText(rep.nameResId)
views.itemEmojiNameTv.setText(rep.nameResId)
}
class Holder : VectorEpoxyHolder() {

View File

@ -18,11 +18,10 @@ package im.vector.app.features.popup
import android.app.Activity
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import im.vector.app.R
import im.vector.app.core.extensions.setLeftDrawable
import im.vector.app.core.glide.GlideApp
import im.vector.app.databinding.AlerterIncomingCallLayoutBinding
import im.vector.app.features.home.AvatarRenderer
import org.matrix.android.sdk.api.util.MatrixItem
@ -43,26 +42,21 @@ class IncomingCallAlert(uid: String,
private val onReject: () -> Unit) : VectorAlert.ViewBinder {
override fun bind(view: View) {
val views = AlerterIncomingCallLayoutBinding.bind(view)
val (callKindText, callKindIcon, callKindActionIcon) = if (isVideoCall) {
Triple(R.string.action_video_call, R.drawable.ic_call_video_small, R.drawable.ic_call_answer_video)
} else {
Triple(R.string.action_voice_call, R.drawable.ic_call_audio_small, R.drawable.ic_call_answer)
}
view.findViewById<TextView>(R.id.incomingCallKindView).apply {
setText(callKindText)
setLeftDrawable(callKindIcon)
views.incomingCallKindView.setText(callKindText)
views.incomingCallKindView.setLeftDrawable(callKindIcon)
views.incomingCallNameView.text = matrixItem?.getBestName()
matrixItem?.let { avatarRenderer.render(it, views.incomingCallAvatar, GlideApp.with(view.context.applicationContext)) }
views.incomingCallAcceptView.setOnClickListener {
onAccept()
}
view.findViewById<TextView>(R.id.incomingCallNameView).text = matrixItem?.getBestName()
view.findViewById<ImageView>(R.id.incomingCallAvatar)?.let { imageView ->
matrixItem?.let { avatarRenderer.render(it, imageView, GlideApp.with(view.context.applicationContext)) }
}
view.findViewById<ImageView>(R.id.incomingCallAcceptView).apply {
setOnClickListener {
onAccept()
}
setImageResource(callKindActionIcon)
}
view.findViewById<ImageView>(R.id.incomingCallRejectView).setOnClickListener {
views.incomingCallAcceptView.setImageResource(callKindActionIcon)
views.incomingCallRejectView.setOnClickListener {
onReject()
}
}

View File

@ -18,10 +18,10 @@ package im.vector.app.features.popup
import android.app.Activity
import android.view.View
import android.widget.ImageView
import androidx.annotation.DrawableRes
import im.vector.app.R
import im.vector.app.core.glide.GlideApp
import im.vector.app.databinding.AlerterVerificationLayoutBinding
import im.vector.app.features.home.AvatarRenderer
import org.matrix.android.sdk.api.util.MatrixItem
@ -40,9 +40,8 @@ class VerificationVectorAlert(uid: String,
private val avatarRenderer: AvatarRenderer) : VectorAlert.ViewBinder {
override fun bind(view: View) {
view.findViewById<ImageView>(R.id.ivUserAvatar)?.let { imageView ->
matrixItem?.let { avatarRenderer.render(it, imageView, GlideApp.with(view.context.applicationContext)) }
}
val views = AlerterVerificationLayoutBinding.bind(view)
matrixItem?.let { avatarRenderer.render(it, views.ivUserAvatar, GlideApp.with(view.context.applicationContext)) }
}
}
}

View File

@ -18,13 +18,10 @@ package im.vector.app.features.settings.troubleshoot
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import im.vector.app.R
import im.vector.app.databinding.ItemNotificationTroubleshootBinding
import im.vector.app.features.themes.ThemeUtils
class NotificationTroubleshootRecyclerViewAdapter(val tests: ArrayList<TroubleshootTest>)
@ -46,71 +43,67 @@ class NotificationTroubleshootRecyclerViewAdapter(val tests: ArrayList<Troublesh
override fun getItemCount(): Int = tests.size
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val troubleshootProgressBar = itemView.findViewById<ProgressBar>(R.id.troubleshootProgressBar)
private val troubleshootTestTitle = itemView.findViewById<TextView>(R.id.troubleshootTestTitle)
private val troubleshootTestDescription = itemView.findViewById<TextView>(R.id.troubleshootTestDescription)
private val troubleshootStatusIcon = itemView.findViewById<ImageView>(R.id.troubleshootStatusIcon)
private val troubleshootTestButton = itemView.findViewById<Button>(R.id.troubleshootTestButton)
private val views = ItemNotificationTroubleshootBinding.bind(itemView)
fun bind(test: TroubleshootTest) {
val context = itemView.context
troubleshootTestTitle.setTextColor(ThemeUtils.getColor(context, R.attr.vctr_content_primary))
troubleshootTestDescription.setTextColor(ThemeUtils.getColor(context, R.attr.vctr_content_secondary))
views.troubleshootTestTitle.setTextColor(ThemeUtils.getColor(context, R.attr.vctr_content_primary))
views.troubleshootTestDescription.setTextColor(ThemeUtils.getColor(context, R.attr.vctr_content_secondary))
when (test.status) {
TroubleshootTest.TestStatus.NOT_STARTED -> {
troubleshootTestTitle.setTextColor(ThemeUtils.getColor(context, R.attr.vctr_content_secondary))
views.troubleshootTestTitle.setTextColor(ThemeUtils.getColor(context, R.attr.vctr_content_secondary))
troubleshootProgressBar.visibility = View.INVISIBLE
troubleshootStatusIcon.visibility = View.VISIBLE
troubleshootStatusIcon.setImageResource(R.drawable.unit_test)
views.troubleshootProgressBar.visibility = View.INVISIBLE
views.troubleshootStatusIcon.visibility = View.VISIBLE
views.troubleshootStatusIcon.setImageResource(R.drawable.unit_test)
}
TroubleshootTest.TestStatus.WAITING_FOR_USER -> {
troubleshootProgressBar.visibility = View.INVISIBLE
troubleshootStatusIcon.visibility = View.VISIBLE
views.troubleshootProgressBar.visibility = View.INVISIBLE
views.troubleshootStatusIcon.visibility = View.VISIBLE
val infoColor = ContextCompat.getColor(context, R.color.vector_info_color)
val drawable = ContextCompat.getDrawable(itemView.context, R.drawable.ic_notification_privacy_warning)?.apply {
ThemeUtils.tintDrawableWithColor(this, infoColor)
}
troubleshootStatusIcon.setImageDrawable(drawable)
troubleshootTestDescription.setTextColor(infoColor)
views.troubleshootStatusIcon.setImageDrawable(drawable)
views.troubleshootTestDescription.setTextColor(infoColor)
}
TroubleshootTest.TestStatus.RUNNING -> {
troubleshootProgressBar.visibility = View.VISIBLE
troubleshootStatusIcon.visibility = View.INVISIBLE
views.troubleshootProgressBar.visibility = View.VISIBLE
views.troubleshootStatusIcon.visibility = View.INVISIBLE
}
TroubleshootTest.TestStatus.FAILED -> {
troubleshootProgressBar.visibility = View.INVISIBLE
troubleshootStatusIcon.visibility = View.VISIBLE
troubleshootStatusIcon.setImageResource(R.drawable.unit_test_ko)
troubleshootStatusIcon.imageTintList = null
troubleshootTestDescription.setTextColor(ThemeUtils.getColor(context, R.attr.colorError))
views.troubleshootProgressBar.visibility = View.INVISIBLE
views.troubleshootStatusIcon.visibility = View.VISIBLE
views.troubleshootStatusIcon.setImageResource(R.drawable.unit_test_ko)
views.troubleshootStatusIcon.imageTintList = null
views.troubleshootTestDescription.setTextColor(ThemeUtils.getColor(context, R.attr.colorError))
}
TroubleshootTest.TestStatus.SUCCESS -> {
troubleshootProgressBar.visibility = View.INVISIBLE
troubleshootStatusIcon.visibility = View.VISIBLE
troubleshootStatusIcon.setImageResource(R.drawable.unit_test_ok)
views.troubleshootProgressBar.visibility = View.INVISIBLE
views.troubleshootStatusIcon.visibility = View.VISIBLE
views.troubleshootStatusIcon.setImageResource(R.drawable.unit_test_ok)
}
}
val quickFix = test.quickFix
if (quickFix != null) {
troubleshootTestButton.setText(test.quickFix!!.title)
troubleshootTestButton.setOnClickListener {
views.troubleshootTestButton.setText(test.quickFix!!.title)
views.troubleshootTestButton.setOnClickListener {
test.quickFix!!.doFix()
}
troubleshootTestButton.visibility = View.VISIBLE
views.troubleshootTestButton.visibility = View.VISIBLE
} else {
troubleshootTestButton.visibility = View.GONE
views.troubleshootTestButton.visibility = View.GONE
}
troubleshootTestTitle.setText(test.titleResId)
views.troubleshootTestTitle.setText(test.titleResId)
val description = test.description
if (description == null) {
troubleshootTestDescription.visibility = View.GONE
views.troubleshootTestDescription.visibility = View.GONE
} else {
troubleshootTestDescription.visibility = View.VISIBLE
troubleshootTestDescription.text = description
views.troubleshootTestDescription.visibility = View.VISIBLE
views.troubleshootTestDescription.text = description
}
}
}

View File

@ -21,11 +21,9 @@ import android.content.Intent
import android.webkit.WebChromeClient
import android.webkit.WebView
import androidx.annotation.CallSuper
import im.vector.app.R
import im.vector.app.core.di.ScreenComponent
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivityVectorWebViewBinding
import org.matrix.android.sdk.api.session.Session
import javax.inject.Inject
@ -48,7 +46,7 @@ class VectorWebViewActivity : VectorBaseActivity<ActivityVectorWebViewBinding>()
override fun initUiAndData() {
configureToolbar(views.webviewToolbar)
waitingView = findViewById(R.id.simple_webview_loader)
waitingView = views.simpleWebviewLoader
views.simpleWebview.settings.apply {
// Enable Javascript