Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
maxmiliano opened this issue Mar 12, 2017 · 12 comments
Open

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

maxmiliano opened this issue Mar 12, 2017 · 12 comments

Comments

@maxmiliano
Copy link

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

@tylerjroach
Copy link
Contributor

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.

@maxmiliano
Copy link
Author

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?

@tylerjroach
Copy link
Contributor

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

@miroslavign
Copy link

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
Copy link

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

@bagintz
Copy link

bagintz commented Oct 18, 2017

@tylerjroach any word on glide implementation?

@tylerjroach
Copy link
Contributor

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

@bagintz
Copy link

bagintz commented Oct 18, 2017

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

@tylerjroach
Copy link
Contributor

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.

@bagintz
Copy link

bagintz commented Oct 19, 2017

@miroslavign try invalidateChips on your NachoTextView after loading

@miroslavign
Copy link

@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

@bagintz
Copy link

bagintz commented Oct 19, 2017

@miroslavign I was able to accomplish url loading with this

#39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants