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
sealed class AppFailure { | |
/** | |
* Global Failure classes | |
* These failures will be used across all over the app including Data Layer, Domain Layer, Framework Layer | |
*/ | |
class GeneralFailure(var message: String, var errorCode: Int? = null) : AppFailure() | |
class UnauthorizedFailure(var message: String = "Unauthorized", errorCode: Int? = null) : AppFailure() | |
class LoginFailure(var message: String = "Unable to login", errorCode: Int? = null) : AppFailure() | |
class ServerFailure(var message: String = "Unable to connect to the server side", errorCode: Int? = null) : AppFailure() | |
class NoInternetFailure(var message: String = "Device is not connected to the internet", errorCode: Int? = null) : AppFailure() |
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() |
OlderNewer