HandleAPIError in Utils class. create custom method for Snackbar for the API Error.
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public fun View.snackbar(message: String, action: (() → Unit)? = ...): Unit defined in file Utils.kt
Receiver type in Fragment in requireview(). which receiver type used for activity.
Utils.kt
fun View.snackbar(message: String, action: (() -> Unit)? = null){
val snackbar = Snackbar.make(this, message, Snackbar.LENGTH_LONG)
action?.let {
snackbar.setAction("Retry"){
it()
}
snackbar.show()
}
}
fun Fragment.handleApiError(
failure : Resource.Failure,
retry : (() -> Unit)? = null
){
when{
failure.isNetworkError -> requireView().snackbar("Please check internet Connection", retry )
}
}
fun Activity.handleApiError(
failure : Resource.Failure,
retry : (() -> Unit)? = null
){
when{
//which receiver type used for snackbar?
failure.isNetworkError -> snackbar(
"Please check internet Connection",
retry
)
}
}