This file contains hidden or 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
/** | |
* Create the Abstract Adapter and the ViewHolder that we need to hold the item view | |
*/ | |
abstract class AbstractAdapter<T : ViewBinding, ITEM> constructor( | |
protected var itemList: List<ITEM>, | |
private val bindingClass: (LayoutInflater, ViewGroup, Boolean) -> T | |
) : RecyclerView.Adapter<AbstractAdapter.Holder>() { | |
var binding: T? = null |
This file contains hidden or 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
/** | |
* Can you simplify this code? | |
* ================================== | |
* Assesment Point: | |
* 1. Line of code | |
* 2. Variable naming | |
* ================================== | |
* | |
* Get Data from this API to test your code: | |
* http://demo3325159.mockable.io/getBatchConfig |
This file contains hidden or 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
/** | |
* High Order Functions | |
* that execute function only in debug build variant | |
*/ | |
fun debugMode(function: () -> Unit) { | |
if (BuildConfig.DEBUG) { | |
function() | |
} | |
} |
This file contains hidden or 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
/** | |
* Extension for view visibility | |
*/ | |
fun View.visible() { | |
visibility = View.VISIBLE | |
} | |
fun View.gone() { | |
visibility = View.GONE | |
} |
This file contains hidden or 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
interface OnClickListener { | |
fun onClick(v: View) | |
} | |
interface OnLongClickListener { | |
fun onLongClick(v: View) | |
} | |
interface OnTouchListener { | |
fun onTouch(v: View, event: MotionEvent) |
This file contains hidden or 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
interface OnClickListener { | |
fun onClick(v: View) | |
fun onLongClick(v: View) | |
fun onTouch(v: View, event: MotionEvent) | |
} | |
val button = findViewById<Button>(R.id.button) | |
button.setOnClickListener(object: OnClickListener{ | |
override fun onClick(v: View) { | |
// Want to do some magic here |
This file contains hidden or 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
interface Toy { | |
var color: String? | |
} | |
open class FlyingToy : Toy { | |
override var color: String? = "Red" | |
open fun fly() { | |
println("The toy is flying...") | |
} | |
} |
This file contains hidden or 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
interface Toy { | |
var color: String? | |
fun fly() | |
} | |
class Plane : Toy { | |
override var color: String? = "Blue" | |
override fun fly() { | |
println("The plane is flying...") | |
} |
This file contains hidden or 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
/** | |
* Sample of Meaningful Names | |
*/ | |
fun saveData(data: User) { | |
//... | |
} | |
fun deleteData(id: Int) { | |
//... | |
} |
This file contains hidden or 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
// Bad variables naming | |
var a = 0 // user ages | |
var w = 0 // user weight | |
var h = 0 // user height | |
// Bad functions naming | |
fun age() | |
fun weight() | |
fun height() |
NewerOlder