This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ImageView.doSomething(otherArguments){ | |
//we have direct access to all image view properties (width, height, etc.) here | |
//Also this will refer to image view | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Calling Static method | |
MyUtil.doSomethingOnImage(imageView, otherArguments) | |
//Calling extension method | |
imageView.doSomething(otherArguments) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Without extension | |
Toast.makeText(this, “Hello”, Toast.LENGTH_SHORT).show() | |
//With Extension | |
showToast("Hello") | |
//Extension Method | |
fun Context.showToast(text: CharSequence, duration: Int = Toast.LENGTH_SHORT) { | |
Toast.makeText(this, text, duration).show() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Without Extension | |
view1.setOnClickListener... | |
view2.setOnClickListener... | |
viewN.setOnClickListener... | |
//With Extension | |
constraintGroup.setAllOnClickListener { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//without extension | |
liveData.value = liveData.value | |
//With extension | |
liveData.notifyObservers() | |
//Extension function | |
fun <T> MutableLiveData<T>.notifyObservers() { | |
value = value //resetting the value forces to notify observers | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Without extension | |
inputET.addTextChangedListener(object: TextWatcher { | |
override fun afterTextChanged(s: Editable?) { | |
} | |
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Withoug extension | |
Picasso.get().load(/* image url */).placeholder(/* placeholder */).into(myImageView) | |
//With extension | |
myImageView.load(/* image url */) | |
//Extension definition | |
fun ImageView.load(path: String) { | |
val placeholder = R.id.whatEver | |
var fullPath = path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Using helper methods in ViewModel is right | |
fun getAdminAccesssVisibility(): Int { | |
return if(/** some condition **/) View.VISIBLE else View.GONE | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This is right!! | |
viewModel.adminAccessVisibility.observe(this, Observer { | |
myView.visibility = it | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This is right!! | |
viewModel.adminAccessVisibility.observe(this, Observer { | |
myView.visibility = it | |
}) |