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
suspend fun <T : Any> makeRequestToApi( | |
call: suspend () -> T, | |
): ApiResult<T> { | |
return try { | |
val data = call.invoke() | |
ApiResult.Success(data) | |
} catch (throwable: Exception) { | |
return when (throwable) { | |
is HttpException -> { |
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
sealed class ApiResult<out T : Any> { | |
data class Success<out T : Any>(val response: T) : ApiResult<T>() | |
data class HttpError(val code: Int?, val message: String?) : ApiResult<Nothing>() | |
data class GenericError(val error: Exception) : ApiResult<Nothing>() | |
object InProgress : ApiResult<Nothing>() |
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
@Composable | |
fun rememberQrBitmapPainter( | |
content: String, | |
size: Dp = 150.dp, | |
padding: Dp = 0.dp | |
): BitmapPainter { | |
val density = LocalDensity.current | |
val sizePx = with(density) { size.roundToPx() } | |
val paddingPx = with(density) { padding.roundToPx() } |