Loading images in recyclerview with picasso from api - android

Add image in RecyclerView from api using picasso

Image loading using Picasso is very easy, you can do it like this way Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView); and in their website you can get every details. In your case you can parse every image URL and use RecyclerView to show them along with Picasso.

Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView)
In the new versions of Picasso you don't need the context anymore.
I'm using:
implementation 'com.squareup.picasso:picasso:2.71828'

In the new versions of Picasso used get()
Picasso latest version Picasso library: 2.71828
Picasso
.get()
.load("You Img Path Place Here")
.resize(width, height)
.noFade()
.into("Path set ImageView");
Used latest picasso version
implementation 'com.squareup.picasso:picasso:2.71828'

Try this
String img_url = "YOUR IMAGE URL";
if (!img_url.equalsIgnoreCase(""))
Picasso.with(context).load(img_url).placeholder(R.drawable.user_image)// Place holder image from drawable folder
.error(R.drawable.user_image).resize(110, 110).centerCrop()
.into("IMAGE VIEW ID WHERE YOU WANT TO SET IMAGE");
Happy coding.

You can load image using picasso like this way
Picasso.with(context).load(android_versions.get(i).getAndroid_image_url()).resize(120, 60).into(viewHolder.img_android);
https://www.learn2crack.com/2016/02/image-loading-recyclerview-picasso.html

Here ctx is context, list.getImage_full_path()) is image coming from server, in placeholder a static image is placed if image is not loaded, on error kent is name of image and into(servicecart_image) is placed in XML so image is loaded there
Picasso.with(ctx).load(list.getImage_full_path()).resize(160, 200).placeholder(R.drawable.kent)
.error(R.drawable.kent).into(servicecart_image);

Related

Getting image from firebase using glide and set into recycler view but image not load

Getting image from fire base using glide and set into recycler view but image not load
upload uploadCurrent = mUploads.get(position);
Glide.with(mContext).load(uploadCurrent.getFilePathUri()).into(holder.mimageView);
holder.textViewname.setText(uploadCurrent.getProductName());
holder.textViewcontact.setText(uploadCurrent.getContactNumber());
holder.textViewprice.setText(uploadCurrent.getPrice());
You may use picasso instead of glide,
in your build.gradle app
compile 'com.squareup.picasso:picasso:2.5.2'
then
Picasso.with(mContext).load(uploadCurrent.getFilePathUri()).into(holder.mimageView);
If it didn't work try making sure that uploadCurrent.getFilePathUri() returns a valid uri.
if it returns a valid uri then the problem is with the context maybe
try
Picasso.with(getApplicationContext()).load(uploadCurrent.getFilePathUri()).into(holder.mimageView);
if still no luck then the best way is to remove picasso and glide and write
holder.imageView.setImageUri(uploadCurrent.getFilePathUri());
That's it.

How to load updated image instead of old image in recyclerview using glide library

I'm implemented Glide library to load image in ImageView it's working fine.
Dependency:
compile "com.github.bumptech.glide:glide:4.5.0"
annotationProcessor "com.github.bumptech.glide:compiler:4.5.0"
compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0"
In Adapter:
Glide.with(context)
.load(ImageUrl)
.apply(bitmapTransform(new jp.wasabeef.glide.transformations.BlurTransformation(25)
).diskCacheStrategy(DiskCacheStrategy.ALL))
.apply(new RequestOptions()
.placeholder(R.mipmap.ic_launcher))
.into(view);
Issue is that when I'm upload image and display in recyclerview and get URL from API then it's display previously added image from cache instead of new one. I just need to add new image in first position instead of refresh whole list.
By using this:
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
Above code refresh whole list because clear whole cache data. I just need to display new uploaded image in list.
The first thing you need to verify are the response headers of your server/cdn or whatever you are using that hosts your images.
The only way for Glide to know if your image (from the same url) is updated is via cache/ETAG headers.
Now the tricky part: Glide is an image caching/loading library and it handles memory/disc caching but doesnt perform the actual networking part. It is handled by third party libraries such as OkHttp, so you will need to extend the glide modules and/or configure the network library to respect the cache headers in manner thats appropriate for your app.
Here are links to issues on glide github that will point you in the right direction:
https://github.com/bumptech/glide/issues/1257
https://github.com/bumptech/glide/issues/1847
https://github.com/bumptech/glide/issues/463
Please set like this:-
Glide.with(context)
.load(img_url)
.apply(new RequestOptions()
.placeholder(R.mipmap.personal_pic)
.diskCacheStrategy(DiskCacheStrategy.ALL))
.into(iv_profile_pic);

cache image without showing glide

Is it possible to cache image using glide without showing it in the imageView?. If it is then how?.
Right now I'm doing this code:
Glide
.with(getApplicationContext())
.load("imageUrl")
.override(windowWidth(),(int)windowWidth()*0.5))
.diskCacheStrategy(DiskCacheStrategy.ALL);
But this is not working , when app is open glide load image not from cache but from url.
Since glide 4.X:
//to save img
RequestManager rm = Glide.with(context);
rm.load(imgUrl).submit();
//to load img
Glide.with(context)
.applyDefaultRequestOptions(
new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL))
.load(imgUrl)
.into(view);
Based on this GitHub topic
i've never used it, but referring the documentation: have you tried the downloadOnly?
Glide's downloadOnly() API allows you to download the bytes of an image into the disk cache so that it will be available to be retrieved later.
https://github.com/bumptech/glide/wiki/Loading-and-Caching-on-Background-Threads#downloadonly
To preload remote images and ensure that the image is only downloaded once:
Glide.with(context)
.load(yourUrl)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.preload();

Android cannot load image from URI using Picasso

The Android app allows users to select a photo from their phone gallery which I save the URI to realm. I then retrieve this information and use Picasso to load it into the image view. For some reason the image is not loaded.
The URI is something like:
content://com.android.providers.media.documents/document/image%3A333180
I save it to realm using mCategory.icon = imageURI.toString() and then when I load it:
Picasso.with(getContext())
.load(Uri.parse(mCategory.icon)) // mCategory.icon is a string
.resize(200, 200)
.error(R.drawable.mountain) // default image to load
.into(viewHolder.categoryIcon);
The URI you got is a ContentProvider URI to show it with Picasso you try to do this:
File file = new File(Uri.parse(mCategory.icon));
Picasso.with(getContext())
.load(file)
.resize(200, 200)
.error(R.drawable.mountain)
.into(viewHolder.categoryIcon);
P.S: Though you can convert your ContentProveder path to Absolute path still it's better if you don't since Picasso support loading from the File..
Use setLoggingEnabled(true) in picasso to check the log if there is any error message.
Mentioned URI contains the encoded value of colon : i.e. %3A.
Either rename the source OR try Glide or some other library to serve the purpose.
This is working perfectly with new version of Picasso 2.71828
Picasso.get()
.load(imageUri)
.placeholder(R.drawable.placeholder)
.fit()
.centerCrop()
.into(viewHolder.categoryIcon);

Set an ImageView from photo url

How can I set an image to a ImageView from a URL?
Using Firebase authentication, I get the photo URL of the signed in user:
Uri uri = firebaseUser.getProviderData().get(0).getPhotoUrl();
You can use Picasso Library to show images in ImageView.
You just need to pass the url, uri or resource to Picasso with image view.
like
Picasso.with(this).load(/* url of image */).into(/*your imageview id*/);
To use the picasso you need to add the following in Gradle
compile 'com.squareup.picasso:picasso:2.5.2'
Read the documentation on http://square.github.io/picasso/
Also There are other libraries to display image in ImageView.
Like Fresco, Glide, Universal Image Loader etc

Categories

Resources