nachos icon indicating copy to clipboard operation
nachos copied to clipboard

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

Open maxmiliano opened this issue 7 years ago • 12 comments

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

maxmiliano avatar Mar 12 '17 14:03 maxmiliano

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.

tylerjroach avatar Mar 12 '17 14:03 tylerjroach

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 avatar Mar 12 '17 22:03 maxmiliano

@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. :)

tylerjroach avatar Mar 13 '17 15:03 tylerjroach

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...

miroslavign avatar Oct 15 '17 11:10 miroslavign

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

miroslavign avatar Oct 15 '17 11:10 miroslavign

@tylerjroach any word on glide implementation?

bagintz avatar Oct 18 '17 18:10 bagintz

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

tylerjroach avatar Oct 18 '17 18:10 tylerjroach

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

bagintz avatar Oct 18 '17 18:10 bagintz

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.

tylerjroach avatar Oct 18 '17 18:10 tylerjroach

@miroslavign try invalidateChips on your NachoTextView after loading

bagintz avatar Oct 19 '17 01:10 bagintz

@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 avatar Oct 19 '17 08:10 miroslavign

@miroslavign I was able to accomplish url loading with this

https://github.com/hootsuite/nachos/pull/39

bagintz avatar Oct 19 '17 09:10 bagintz