hootsuite/nachos

Is there a way to set a chip icon from a URL image?

maxmiliano opened this issue · 12 comments

Is there a way to set the icon from a URL image or maybe change it at runtime?

At the moment no. I may work on a pull request on this for the future. Essentially, you will need to manage the download/transformation of the image yourself, then pass this on to recreate the chip when the image is ready. If I do work on this, I'll work on an example that uses Glide or Picasso to do the downloading.

Thanks for the quick answer, @tylerjroach!
What do you mean by "pass this on to recreate the chip"?
Would it be a good approach to load the image (from URL) into an ImageView with Picasso and then use the ImageView.getDrawable() to create a new Chip? Then replace the old one with it?

@maxmiliano The problem with that approach is that you may not have an ImageView. If you are inserting the chip from a list, you may have already loaded in an image that you can then use getDrawable() for. Although you will need to do the bitmap transformation/sizing into the chip yourself. If the image had not yet loaded into its row (or you aren't showing an image), then you will not have the drawable to insert into the chip.

Glide has custom targets https://github.com/bumptech/glide/wiki/Custom-targets that would be useful for the purpose of downloading the images. In the callback, you could then pass the bitmap when you recreate a chip.

There are a few methods that will need to be added to Nachos to support this. Chip recreation and dynamic bitmap passing to name a few. I may work on this in the next few weeks but I can't promise I will get to it.

Nachos is pretty simple, so create a fork and see for yourself what you can come up with! The Hootsuite devs are responsive for suggested pull requests if you figure it out. :)

I implemented this one.
You set a drawable from res (for a default loading image until it remote loads), and a URL for final image.
I am having a hard time to force update chip invalidate after the image is remote loaded to bitmap.
Currently, you create a chip, and after loading it does not refresh the icon image, but after you add the next chip, it invalidates/presents the correct (remote) image on the previous chip.
Working on how to force invalidate without using tweaks like callbacks or EventBus...

If not possible without tweaks, I might try "Chip recreation" after loading url image as a last resort.

@tylerjroach any word on glide implementation?

@bagintz No, sorry, I am no longer using Nachos.

@tylerjroach are you using an alternative that does load images via url?

I ended up going with using a RecyclerView to handle chip creation since it will be more performant in the long run. See this project: https://github.com/BelooS/ChipsLayoutManager

Of course, the difference between the projects is that Nachos uses TextView spans which allow you to continue typing inline. For our ui, this wasn't a big deal having to split the EditText and the chip list to separate rows.

There is another project that I haven't tried that attempts to inline the edittext while also using a recyclerview at the same time. https://github.com/tylersuehr7/chips-input-layout This project is based on the ChipsLayouutManager project.

@miroslavign try invalidateChips on your NachoTextView after loading

@bagintz I tried that and a whole lot of other invalidate's
I will push changes i made to my fork, so maybe others could try this path as well

@miroslavign I was able to accomplish url loading with this

#39