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 function transform [Place] into [Address] | |
*/ | |
fun Place.toAddress(): Address { | |
val address = Address(Locale.ENGLISH) | |
this.latLng?.let { | |
address.latitude = it.latitude | |
address.longitude = it.longitude | |
} | |
when (addressComponents) { |
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
inline fun TextView.afterTextChangedDelayed(crossinline afterTextChanged: (String) -> Unit): TextWatcher { | |
val watcher = object : TextWatcher { | |
private var timer: Timer = Timer() | |
// Change the delay based on your requirement | |
private val DELAY: Long = 1000 | |
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {} | |
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {} | |
override fun afterTextChanged(editable: Editable?) { | |
timer.cancel() |
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
inline fun Spinner.onItemSelectedListenerCustom(crossinline changed: (AdapterView<*>?, View?, Int, Long) -> Unit): AdapterView.OnItemSelectedListener { | |
val listener = object : AdapterView.OnItemSelectedListener { | |
override fun onItemSelected( | |
parent: AdapterView<*>?, | |
view: View?, | |
position: Int, | |
id: Long | |
) { | |
changed.invoke(parent, view, position, id) | |
} |
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
fun Context.isMyServiceRunning(serviceClass: Class<*>): Boolean { | |
val manager = this.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager | |
return manager.getRunningServices(Integer.MAX_VALUE) | |
.any { it.service.className == serviceClass.name } | |
} |
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
@Singleton | |
class PatientUserChatAdapter @Inject constructor() : | |
RecyclerView.Adapter<PatientUserChatViewHolder>() { | |
// | |
private var dataSet: MutableList<UserChatDataModel> = mutableListOf() | |
private var callback: PatientUserChatSelectionCallback? = null | |
//Register for action callback | |
fun setActionCallback(callback: PatientUserChatSelectionCallback? = null) { |
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
// If you have a list of data to pass through intent | |
// Don't do this: | |
intent.put("first", "something") | |
intent.put("second", 100.5) | |
intent.put("third", Object) | |
// Else, do this. | |
// Create a model |
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
fun <T> MutableList<out T>.contentDeepEquals( | |
other: MutableList<out T> | |
): Boolean { | |
return Gson().toJson(this).toString() == Gson().toJson(other).toString() | |
} |
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
var handlerDelayTimer: Timer = Timer() | |
inline fun handlerPost(crossinline onSuccess: () -> Unit) { | |
Handler(Looper.getMainLooper()).post { | |
onSuccess.invoke() | |
} | |
} | |
inline fun handlerPostDelayed(delay: Long, crossinline onSuccess: () -> Unit) { | |
handlerDelayTimer.cancel() |
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
/* | |
Define all actions for a respective class/fragment/activity. | |
The reason to put all actions into a respective interface is to clear the concern. | |
So that we can easily identify the all business logic handle by this class/fragment/activity. | |
This interface will work like a blueprint of business logic for your class/fragment/activity. | |
*/ | |
interface ProfileActions { | |
fun onBMETCard() | |
fun onMyDocuments() | |
fun onSettings() |
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
/** | |
* 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) |
OlderNewer