Skip to content

Instantly share code, notes, and snippets.

@iamhariomsharma
iamhariomsharma / ApiExt.kt
Created August 3, 2024 16:13
Retrofit Error & Response Handling Utility function
suspend fun <T : Any> executeApi(call: suspend () -> Response<T>): DataResult<T, DataError.Network> {
return try {
val response = call.invoke()
val body = response.body()
val errorBody = response.errorBody()
if (response.isSuccessful && body != null) {
DataResult.Success(body)
} else if (errorBody != null) {
val gson = Gson()
val errorResponse = gson.fromJson(String(errorBody.bytes()), ErrorResponse::class.java)
fun Modifier.bouncingClickable(
enabled: Boolean = true,
onLongClick: () -> Unit = {},
onClick: () -> Unit = {},
) = composed {
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()
val haptic = LocalHapticFeedback.current
val animationTransition = updateTransition(isPressed, label = "BouncingClickableTransition")
//Utils - Declaration
object PromptUtils {
fun alertDialog(context: Context, @StyleRes style: Int, dialogBuilder: AlertDialog.Builder.() -> Unit): Dialog {
val builder = AlertDialog.Builder(context, style).also {
it.setCancelable(false)
it.dialogBuilder()
}
return builder.create()
}
@iamhariomsharma
iamhariomsharma / build.gradle.kts
Created September 29, 2023 04:26
Useful Android Dependencies
// App Level build.gradle File
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
id("androidx.navigation.safeargs.kotlin")
id("com.google.devtools.ksp")
}