Glide Binding Adapter doesn't show the url pictures

248 Views Asked by At

So i want to have pictures show on my view from the Unsplash API. The thing is the API call is working but the pictures just don't show. All it is showing is the error placeholder.

enter image description here

Here is the Binding Adapter

@BindingAdapter("pictureOfDay")
fun CustomImage.displayPicture(carouselItem: CarouselItem?) {
    if (carouselItem?.urls == "images")
        Glide.with(context).load(carouselItem.urls)
            .error(R.drawable.glowing_x)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .into(this)
    else setImageResource(R.drawable.glowing_x)



}

Any ideas are welcome, thank you.

1

There are 1 best solutions below

0
OEThe11 On BEST ANSWER

So I ended up solving it. I had to change up my binding adapter, so that it accepted a string. Something like this...

@BindingAdapter("pictureOfDay")
fun CustomImage.setDisplayPicture(urlPic: String?)  {
    if (urlPic != null)
        Glide.with(context).load(urlPic)
            .error(R.drawable.glowing_x)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .into(this)
    else setImageResource(R.drawable.glowing_x)



}

Works perfectly fine now.