convert some findViewById into ViewBinding
This commit is contained in:
		
							parent
							
								
									7a40841cbb
								
							
						
					
					
						commit
						bae802d8dc
					
				| @ -18,8 +18,6 @@ package im.vector.app.features.crypto.verification.epoxy | |||||||
| 
 | 
 | ||||||
| import android.content.Context | import android.content.Context | ||||||
| import android.view.ViewGroup | import android.view.ViewGroup | ||||||
| import android.widget.ImageView |  | ||||||
| import android.widget.TextView |  | ||||||
| import androidx.core.content.ContextCompat | import androidx.core.content.ContextCompat | ||||||
| import androidx.core.view.isVisible | import androidx.core.view.isVisible | ||||||
| import com.airbnb.epoxy.EpoxyAttribute | import com.airbnb.epoxy.EpoxyAttribute | ||||||
| @ -27,6 +25,7 @@ import com.airbnb.epoxy.EpoxyModelClass | |||||||
| import im.vector.app.R | import im.vector.app.R | ||||||
| import im.vector.app.core.epoxy.VectorEpoxyHolder | import im.vector.app.core.epoxy.VectorEpoxyHolder | ||||||
| import im.vector.app.core.epoxy.VectorEpoxyModel | import im.vector.app.core.epoxy.VectorEpoxyModel | ||||||
|  | import im.vector.app.databinding.ItemEmojiVerifBinding | ||||||
| import me.gujun.android.span.Span | import me.gujun.android.span.Span | ||||||
| import me.gujun.android.span.image | import me.gujun.android.span.image | ||||||
| import me.gujun.android.span.span | import me.gujun.android.span.span | ||||||
| @ -68,16 +67,18 @@ abstract class BottomSheetVerificationEmojisItem : VectorEpoxyModel<BottomSheetV | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private fun bindEmojiView(view: ViewGroup, rep: EmojiRepresentation) { |     private fun bindEmojiView(view: ViewGroup, rep: EmojiRepresentation) { | ||||||
|         rep.drawableRes?.let { |         val views = ItemEmojiVerifBinding.bind(view) | ||||||
|             view.findViewById<TextView>(R.id.item_emoji_tv).isVisible = false |         val drawableRes = rep.drawableRes | ||||||
|             view.findViewById<ImageView>(R.id.item_emoji_image).isVisible = true |         if (drawableRes != null) { | ||||||
|             view.findViewById<ImageView>(R.id.item_emoji_image).setImageDrawable(ContextCompat.getDrawable(view.context, it)) |             views.itemEmojiTv.isVisible = false | ||||||
|         } ?: run { |             views.itemEmojiImage.isVisible = true | ||||||
|             view.findViewById<TextView>(R.id.item_emoji_tv).isVisible = true |             views.itemEmojiImage.setImageDrawable(ContextCompat.getDrawable(view.context, drawableRes)) | ||||||
|             view.findViewById<ImageView>(R.id.item_emoji_image).isVisible = false |         } else { | ||||||
|             view.findViewById<TextView>(R.id.item_emoji_tv).text = rep.emoji |             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() { |     class Holder : VectorEpoxyHolder() { | ||||||
|  | |||||||
| @ -18,11 +18,10 @@ package im.vector.app.features.popup | |||||||
| 
 | 
 | ||||||
| import android.app.Activity | import android.app.Activity | ||||||
| import android.view.View | import android.view.View | ||||||
| import android.widget.ImageView |  | ||||||
| import android.widget.TextView |  | ||||||
| import im.vector.app.R | import im.vector.app.R | ||||||
| import im.vector.app.core.extensions.setLeftDrawable | import im.vector.app.core.extensions.setLeftDrawable | ||||||
| import im.vector.app.core.glide.GlideApp | import im.vector.app.core.glide.GlideApp | ||||||
|  | import im.vector.app.databinding.AlerterIncomingCallLayoutBinding | ||||||
| import im.vector.app.features.home.AvatarRenderer | import im.vector.app.features.home.AvatarRenderer | ||||||
| import org.matrix.android.sdk.api.util.MatrixItem | import org.matrix.android.sdk.api.util.MatrixItem | ||||||
| 
 | 
 | ||||||
| @ -43,26 +42,21 @@ class IncomingCallAlert(uid: String, | |||||||
|                      private val onReject: () -> Unit) : VectorAlert.ViewBinder { |                      private val onReject: () -> Unit) : VectorAlert.ViewBinder { | ||||||
| 
 | 
 | ||||||
|         override fun bind(view: View) { |         override fun bind(view: View) { | ||||||
|  |             val views = AlerterIncomingCallLayoutBinding.bind(view) | ||||||
|             val (callKindText, callKindIcon, callKindActionIcon) = if (isVideoCall) { |             val (callKindText, callKindIcon, callKindActionIcon) = if (isVideoCall) { | ||||||
|                 Triple(R.string.action_video_call, R.drawable.ic_call_video_small, R.drawable.ic_call_answer_video) |                 Triple(R.string.action_video_call, R.drawable.ic_call_video_small, R.drawable.ic_call_answer_video) | ||||||
|             } else { |             } else { | ||||||
|                 Triple(R.string.action_voice_call, R.drawable.ic_call_audio_small, R.drawable.ic_call_answer) |                 Triple(R.string.action_voice_call, R.drawable.ic_call_audio_small, R.drawable.ic_call_answer) | ||||||
|             } |             } | ||||||
|             view.findViewById<TextView>(R.id.incomingCallKindView).apply { |             views.incomingCallKindView.setText(callKindText) | ||||||
|                 setText(callKindText) |             views.incomingCallKindView.setLeftDrawable(callKindIcon) | ||||||
|                 setLeftDrawable(callKindIcon) |             views.incomingCallNameView.text = matrixItem?.getBestName() | ||||||
|             } |             matrixItem?.let { avatarRenderer.render(it, views.incomingCallAvatar, GlideApp.with(view.context.applicationContext)) } | ||||||
|             view.findViewById<TextView>(R.id.incomingCallNameView).text = matrixItem?.getBestName() |             views.incomingCallAcceptView.setOnClickListener { | ||||||
|             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() |                 onAccept() | ||||||
|             } |             } | ||||||
|                 setImageResource(callKindActionIcon) |             views.incomingCallAcceptView.setImageResource(callKindActionIcon) | ||||||
|             } |             views.incomingCallRejectView.setOnClickListener { | ||||||
|             view.findViewById<ImageView>(R.id.incomingCallRejectView).setOnClickListener { |  | ||||||
|                 onReject() |                 onReject() | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -18,10 +18,10 @@ package im.vector.app.features.popup | |||||||
| 
 | 
 | ||||||
| import android.app.Activity | import android.app.Activity | ||||||
| import android.view.View | import android.view.View | ||||||
| import android.widget.ImageView |  | ||||||
| import androidx.annotation.DrawableRes | import androidx.annotation.DrawableRes | ||||||
| import im.vector.app.R | import im.vector.app.R | ||||||
| import im.vector.app.core.glide.GlideApp | import im.vector.app.core.glide.GlideApp | ||||||
|  | import im.vector.app.databinding.AlerterVerificationLayoutBinding | ||||||
| import im.vector.app.features.home.AvatarRenderer | import im.vector.app.features.home.AvatarRenderer | ||||||
| import org.matrix.android.sdk.api.util.MatrixItem | import org.matrix.android.sdk.api.util.MatrixItem | ||||||
| 
 | 
 | ||||||
| @ -40,9 +40,8 @@ class VerificationVectorAlert(uid: String, | |||||||
|                      private val avatarRenderer: AvatarRenderer) : VectorAlert.ViewBinder { |                      private val avatarRenderer: AvatarRenderer) : VectorAlert.ViewBinder { | ||||||
| 
 | 
 | ||||||
|         override fun bind(view: View) { |         override fun bind(view: View) { | ||||||
|             view.findViewById<ImageView>(R.id.ivUserAvatar)?.let { imageView -> |             val views = AlerterVerificationLayoutBinding.bind(view) | ||||||
|                 matrixItem?.let { avatarRenderer.render(it, imageView, GlideApp.with(view.context.applicationContext)) } |             matrixItem?.let { avatarRenderer.render(it, views.ivUserAvatar, GlideApp.with(view.context.applicationContext)) } | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -18,13 +18,10 @@ package im.vector.app.features.settings.troubleshoot | |||||||
| import android.view.LayoutInflater | import android.view.LayoutInflater | ||||||
| import android.view.View | import android.view.View | ||||||
| import android.view.ViewGroup | 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.core.content.ContextCompat | ||||||
| import androidx.recyclerview.widget.RecyclerView | import androidx.recyclerview.widget.RecyclerView | ||||||
| import im.vector.app.R | import im.vector.app.R | ||||||
|  | import im.vector.app.databinding.ItemNotificationTroubleshootBinding | ||||||
| import im.vector.app.features.themes.ThemeUtils | import im.vector.app.features.themes.ThemeUtils | ||||||
| 
 | 
 | ||||||
| class NotificationTroubleshootRecyclerViewAdapter(val tests: ArrayList<TroubleshootTest>) | class NotificationTroubleshootRecyclerViewAdapter(val tests: ArrayList<TroubleshootTest>) | ||||||
| @ -46,71 +43,67 @@ class NotificationTroubleshootRecyclerViewAdapter(val tests: ArrayList<Troublesh | |||||||
|     override fun getItemCount(): Int = tests.size |     override fun getItemCount(): Int = tests.size | ||||||
| 
 | 
 | ||||||
|     class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { |     class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||||||
|         private val troubleshootProgressBar = itemView.findViewById<ProgressBar>(R.id.troubleshootProgressBar) |         private val views = ItemNotificationTroubleshootBinding.bind(itemView) | ||||||
|         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) |  | ||||||
| 
 | 
 | ||||||
|         fun bind(test: TroubleshootTest) { |         fun bind(test: TroubleshootTest) { | ||||||
|             val context = itemView.context |             val context = itemView.context | ||||||
|             troubleshootTestTitle.setTextColor(ThemeUtils.getColor(context, R.attr.vctr_content_primary)) |             views.troubleshootTestTitle.setTextColor(ThemeUtils.getColor(context, R.attr.vctr_content_primary)) | ||||||
|             troubleshootTestDescription.setTextColor(ThemeUtils.getColor(context, R.attr.vctr_content_secondary)) |             views.troubleshootTestDescription.setTextColor(ThemeUtils.getColor(context, R.attr.vctr_content_secondary)) | ||||||
| 
 | 
 | ||||||
|             when (test.status) { |             when (test.status) { | ||||||
|                 TroubleshootTest.TestStatus.NOT_STARTED      -> { |                 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 |                     views.troubleshootProgressBar.visibility = View.INVISIBLE | ||||||
|                     troubleshootStatusIcon.visibility = View.VISIBLE |                     views.troubleshootStatusIcon.visibility = View.VISIBLE | ||||||
|                     troubleshootStatusIcon.setImageResource(R.drawable.unit_test) |                     views.troubleshootStatusIcon.setImageResource(R.drawable.unit_test) | ||||||
|                 } |                 } | ||||||
|                 TroubleshootTest.TestStatus.WAITING_FOR_USER -> { |                 TroubleshootTest.TestStatus.WAITING_FOR_USER -> { | ||||||
|                     troubleshootProgressBar.visibility = View.INVISIBLE |                     views.troubleshootProgressBar.visibility = View.INVISIBLE | ||||||
|                     troubleshootStatusIcon.visibility = View.VISIBLE |                     views.troubleshootStatusIcon.visibility = View.VISIBLE | ||||||
|                     val infoColor = ContextCompat.getColor(context, R.color.vector_info_color) |                     val infoColor = ContextCompat.getColor(context, R.color.vector_info_color) | ||||||
|                     val drawable = ContextCompat.getDrawable(itemView.context, R.drawable.ic_notification_privacy_warning)?.apply { |                     val drawable = ContextCompat.getDrawable(itemView.context, R.drawable.ic_notification_privacy_warning)?.apply { | ||||||
|                         ThemeUtils.tintDrawableWithColor(this, infoColor) |                         ThemeUtils.tintDrawableWithColor(this, infoColor) | ||||||
|                     } |                     } | ||||||
|                     troubleshootStatusIcon.setImageDrawable(drawable) |                     views.troubleshootStatusIcon.setImageDrawable(drawable) | ||||||
|                     troubleshootTestDescription.setTextColor(infoColor) |                     views.troubleshootTestDescription.setTextColor(infoColor) | ||||||
|                 } |                 } | ||||||
|                 TroubleshootTest.TestStatus.RUNNING          -> { |                 TroubleshootTest.TestStatus.RUNNING          -> { | ||||||
|                     troubleshootProgressBar.visibility = View.VISIBLE |                     views.troubleshootProgressBar.visibility = View.VISIBLE | ||||||
|                     troubleshootStatusIcon.visibility = View.INVISIBLE |                     views.troubleshootStatusIcon.visibility = View.INVISIBLE | ||||||
|                 } |                 } | ||||||
|                 TroubleshootTest.TestStatus.FAILED           -> { |                 TroubleshootTest.TestStatus.FAILED           -> { | ||||||
|                     troubleshootProgressBar.visibility = View.INVISIBLE |                     views.troubleshootProgressBar.visibility = View.INVISIBLE | ||||||
|                     troubleshootStatusIcon.visibility = View.VISIBLE |                     views.troubleshootStatusIcon.visibility = View.VISIBLE | ||||||
|                     troubleshootStatusIcon.setImageResource(R.drawable.unit_test_ko) |                     views.troubleshootStatusIcon.setImageResource(R.drawable.unit_test_ko) | ||||||
|                     troubleshootStatusIcon.imageTintList = null |                     views.troubleshootStatusIcon.imageTintList = null | ||||||
|                     troubleshootTestDescription.setTextColor(ThemeUtils.getColor(context, R.attr.colorError)) |                     views.troubleshootTestDescription.setTextColor(ThemeUtils.getColor(context, R.attr.colorError)) | ||||||
|                 } |                 } | ||||||
|                 TroubleshootTest.TestStatus.SUCCESS          -> { |                 TroubleshootTest.TestStatus.SUCCESS          -> { | ||||||
|                     troubleshootProgressBar.visibility = View.INVISIBLE |                     views.troubleshootProgressBar.visibility = View.INVISIBLE | ||||||
|                     troubleshootStatusIcon.visibility = View.VISIBLE |                     views.troubleshootStatusIcon.visibility = View.VISIBLE | ||||||
|                     troubleshootStatusIcon.setImageResource(R.drawable.unit_test_ok) |                     views.troubleshootStatusIcon.setImageResource(R.drawable.unit_test_ok) | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             val quickFix = test.quickFix |             val quickFix = test.quickFix | ||||||
|             if (quickFix != null) { |             if (quickFix != null) { | ||||||
|                 troubleshootTestButton.setText(test.quickFix!!.title) |                 views.troubleshootTestButton.setText(test.quickFix!!.title) | ||||||
|                 troubleshootTestButton.setOnClickListener { |                 views.troubleshootTestButton.setOnClickListener { | ||||||
|                     test.quickFix!!.doFix() |                     test.quickFix!!.doFix() | ||||||
|                 } |                 } | ||||||
|                 troubleshootTestButton.visibility = View.VISIBLE |                 views.troubleshootTestButton.visibility = View.VISIBLE | ||||||
|             } else { |             } else { | ||||||
|                 troubleshootTestButton.visibility = View.GONE |                 views.troubleshootTestButton.visibility = View.GONE | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             troubleshootTestTitle.setText(test.titleResId) |             views.troubleshootTestTitle.setText(test.titleResId) | ||||||
|             val description = test.description |             val description = test.description | ||||||
|             if (description == null) { |             if (description == null) { | ||||||
|                 troubleshootTestDescription.visibility = View.GONE |                 views.troubleshootTestDescription.visibility = View.GONE | ||||||
|             } else { |             } else { | ||||||
|                 troubleshootTestDescription.visibility = View.VISIBLE |                 views.troubleshootTestDescription.visibility = View.VISIBLE | ||||||
|                 troubleshootTestDescription.text = description |                 views.troubleshootTestDescription.text = description | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -21,11 +21,9 @@ import android.content.Intent | |||||||
| import android.webkit.WebChromeClient | import android.webkit.WebChromeClient | ||||||
| import android.webkit.WebView | import android.webkit.WebView | ||||||
| import androidx.annotation.CallSuper | import androidx.annotation.CallSuper | ||||||
| import im.vector.app.R |  | ||||||
| import im.vector.app.core.di.ScreenComponent | import im.vector.app.core.di.ScreenComponent | ||||||
| import im.vector.app.core.platform.VectorBaseActivity | import im.vector.app.core.platform.VectorBaseActivity | ||||||
| import im.vector.app.databinding.ActivityVectorWebViewBinding | import im.vector.app.databinding.ActivityVectorWebViewBinding | ||||||
| 
 |  | ||||||
| import org.matrix.android.sdk.api.session.Session | import org.matrix.android.sdk.api.session.Session | ||||||
| import javax.inject.Inject | import javax.inject.Inject | ||||||
| 
 | 
 | ||||||
| @ -48,7 +46,7 @@ class VectorWebViewActivity : VectorBaseActivity<ActivityVectorWebViewBinding>() | |||||||
| 
 | 
 | ||||||
|     override fun initUiAndData() { |     override fun initUiAndData() { | ||||||
|         configureToolbar(views.webviewToolbar) |         configureToolbar(views.webviewToolbar) | ||||||
|         waitingView = findViewById(R.id.simple_webview_loader) |         waitingView = views.simpleWebviewLoader | ||||||
| 
 | 
 | ||||||
|         views.simpleWebview.settings.apply { |         views.simpleWebview.settings.apply { | ||||||
|             // Enable Javascript |             // Enable Javascript | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user