package com.aletheia.app.util

import android.graphics.BitmapFactory
import android.widget.ImageView
import androidx.annotation.DrawableRes

fun ImageView.setBookCover(bytes: ByteArray?, @DrawableRes fallbackResId: Int) {
    if (bytes == null || bytes.isEmpty()) {
        setImageResource(fallbackResId)
        return
    }

    val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
    if (bitmap != null) {
        setImageBitmap(bitmap)
    } else {
        setImageResource(fallbackResId)
    }
}
