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
/** | |
* Add an action which will be invoked when the text is changing. | |
* | |
* @return the [SearchView.OnQueryTextListener] added to the [SearchView] | |
*/ | |
inline fun SearchView.doAfterTextChanged( | |
delay: Long = 500, | |
crossinline onTextChangedDelayed: (text: String) -> Unit | |
) = doOnQueryTextListener(delay, onTextChangedDelayed) |
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
object ExecutionLocker { | |
private const val LOGGER = "ExecutionLocker:: isExecutionLocked -> " | |
// Hold the state of locking | |
private var isLockingEnabled: Boolean = false | |
// Get locking status | |
val isLocked: Boolean | |
get() = isLockingEnabled |
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
@ControllerAdvice | |
class APIExceptionHandler { | |
companion object { | |
/** | |
* Register all kind of Exceptions here | |
*/ | |
private var exceptionListHolder: MutableMap<Class<*>, HttpStatus> = HashMap<Class<*>, HttpStatus>().apply { | |
put(NullPointerException::class.java, HttpStatus.NOT_FOUND) | |
put(NoSuchElementException::class.java, HttpStatus.NOT_FOUND) | |
put(MethodArgumentTypeMismatchException::class.java, HttpStatus.BAD_REQUEST) |
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
/** | |
* Add an action which will be invoked when the text is changing. | |
* | |
* @return the [EditText.onTextChangeListener] added to the [EditText] | |
*/ | |
inline fun EditText.doAfterTextChanged( | |
delay: Long = 500, | |
crossinline onTextChangedDelayed: (text: String) -> Unit | |
) = onTextChangeListener(delay, onTextChangedDelayed) |
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
/* | |
* Copyright (c) 2017 Emil Davtyan | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining | |
* a copy of this software and associated documentation files (the | |
* "Software"), to deal in the Software without restriction, including | |
* without limitation the rights to use, copy, modify, merge, publish, | |
* distribute, sublicense, and/or sell copies of the Software, and to | |
* permit persons to whom the Software is furnished to do so, subject to | |
* the following conditions: |
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 functions that fire [CoroutineScope] (support: [Dispatchers.IO], [Dispatchers.Main], [Dispatchers.Default]) respective to [AppCompatActivity]/[Fragment]/[ViewModel]. | |
* Functions are called under the parent [CoroutineScope] of respective [AppCompatActivity]/[Fragment]/[ViewModel], | |
* So if the parent is no longer exists, cancel any ongoing operation automatically. | |
*/ | |
private suspend fun CoroutineScope.executeBody(block: suspend CoroutineScope.() -> Unit) { | |
try { | |
block.invoke(this) | |
} catch (e: Exception) { |
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
inline fun <T : Adapter> AdapterView<T>.registerForAdapterEventListener( | |
crossinline itemListener: (parent: AdapterView<*>, view: View, position: Int, id: Long) -> Unit, | |
) = doOnItemSelectedListener(itemListener, {}) | |
inline fun <T : Adapter> AdapterView<T>.registerForAdapterEventListener( | |
crossinline itemListener: (parent: AdapterView<*>, view: View, position: Int, id: Long) -> Unit, | |
crossinline nothingListener: (parent: AdapterView<*>) -> Unit = {}, | |
) = doOnItemSelectedListener(itemListener, nothingListener) | |
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
class FacadeDesignPattern { | |
companion object { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
try { | |
if (FacadeOrderManager.getInstance.createOrder("1")) { | |
println("Order Successful") | |
} | |
} catch (e: Exception) { | |
println("Error while placing order: ${e.message}") |
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
class AdapterDesignPattern { | |
companion object { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
println(CSVAdapterImpl(CSVFormatterImpl()).formatText("Hello. Romman Sabbir. How are you?.")) | |
} | |
} | |
} | |
/** |
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
class DecoratorDesignPattern { | |
companion object { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
val rose = RoseBouquet() | |
println("Without customization = ${rose.description}, ${rose.cost()}") | |
val roseWrapper = PaperWrapper(rose) | |
println("With customization = ${roseWrapper.description}, ${roseWrapper.cost()}") | |
val orchid = OrchidBouquet() |