Skip to content

Instantly share code, notes, and snippets.

@vamjakuldip
Created January 24, 2020 04:18
Show Gist options
  • Save vamjakuldip/404f180ad149168ef7ed73f8759f46e2 to your computer and use it in GitHub Desktop.
Save vamjakuldip/404f180ad149168ef7ed73f8759f46e2 to your computer and use it in GitHub Desktop.
View Biding Adapter
package com.vk.android.databinding
import android.view.View
import android.widget.EditText
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.vk.android.BuildConfig
import com.vk.android.R
object ViewBidingAdapter {
@BindingAdapter("isShow")
fun isShow(view: View, visible: Boolean) {
view.visibility = if (visible) View.VISIBLE else View.GONE
}
@BindingAdapter("imageUrl")
fun loadImage(view: ImageView, imageUrl: String) {
Glide.with(view.context)
.load(BuildConfig.BASE_URL + imageUrl).fallback(R.mipmap.ic_launcher).placeholder(R.mipmap.ic_launcher)
.into(view)
}
@BindingAdapter("clearText")
fun clearData(view: EditText, isClear: Boolean) {
if (isClear) {
view.setText("")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment