Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load Image from Firebase Storage with Picasso to ImageView in Infowindow, Picasso only shows placeholder

I try to load a image from my Firebase Storage with Picasso into an Imageview that is placed in a InfoWindowAdapter from a Marker.

I'm very desperate about it. The problem is Picasso only shows the placeholder Icon.

My code for the FirebaseStorageRefernce looks like this referring to this Firebase Blog post:

 StorageReference load = getImage(id);

 load.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
     @Override
     public void onSuccess(Uri uri) {

         downloadUri = uri;

     }
 }).addOnFailureListener(new OnFailureListener() {
     @Override
     public void onFailure(@NonNull Exception e) {
         Log.e("Failure",e.toString());
     }
 });

The downloadUri that I get is valid and works fine. Now I use this downloadUri for Picasso.

 Picasso picasso = new Picasso.Builder(getApplicationContext()).listener(new Picasso.Listener() {
    @Override
    public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
        e.printStackTrace();
    }
}).build();
picasso.setLoggingEnabled(true);
picasso.load(downloadUri).placeholder(R.drawable.toxic_bait_icon).fit().into(thump, new MarkerCallback(marker));

In reference to an answer that I found here on StackOverFlow, I made a MarkerCallback Class:

public class MarkerCallback implements Callback {

com.google.android.gms.maps.model.Marker marker = null;


MarkerCallback(Marker marker)
{

    this.marker = marker;

}


@Override
public void onError(){
    Log.e(getClass().getSimpleName(), "Error loading thumbnail!");
}

@Override
public void onSuccess(){
    Log.d("onSuccess","Picasso Callback");
    if(marker != null && marker.isInfoWindowShown()){

        Log.d("onSuccess","Picasso Callback in if");
        marker.hideInfoWindow();
        marker.showInfoWindow();

    }
}}

You can see that I added some Log.d messages on the onSuccess method to track if it's called. But it looks like the onSucess method isn't called anytime because the Log.d message never appears in LogCat.

Also Picasso doesn't show any exception, errors, failures, nor a log even though I enabled it.

picasso.setLoggingEnabled(true);

The only thing that happens is that the ImageView in the Infowindow shows the Placeholder.

I thought maybe its because the image size too large to load, but the image I try to load is only 652.86 KB.

PS: Picasso also doesn't show the ribbons in the left corner to debug the cache behaviour. I try to activate with:

picasso.setIndicatorsEnabled(true);

I use Picasso 2.5.2. I have no idea what I'm doing wrong or how to debug this if Picasso doesn't show logs nor ribbons. I hope someone can help me. I need this feature so badly.

Addendum: I have also check the permissions, referring to this post, they are OK.

 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
    android:name="android.permission.INTERNET"/>
<uses-permission
    android:name="android.permission.READ_SYNC_SETTINGS"/>
<uses-permission
    android:name="android.permission.WRITE_SYNC_SETTINGS"/>
<uses-permission
    android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Update

After some trial-and-error, I found out that Picasso shows the log, but i don't see it in logcat. After I restart my phone, I saw the log in the logcat after a while. The log disappears again, but this time even a restart doesn't help the, log doesn't reappear.

But I've also done some research and found another answer that refers to my problem.

So I changed my code but it doesn't help. The issue is still the same. Picasso shows only the placeholder.

like image 894
worl44 Avatar asked Oct 06 '16 12:10

worl44


2 Answers

Why don't you do everything at once? Inside the Firebase Storage getDownloadUrl() method:

 StorageReference load = getImage(id);

 load.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
    @Override
    public void onSuccess(Uri uri) {
        // Got the download URL for 'users/me/profile.png'
        // Pass it to Picasso to download, show in ImageView and caching
        Picasso.with(context).load(uri.toString()).into(imageView);
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // Handle any errors
    }
});
like image 161
danielrosero Avatar answered Nov 15 '22 06:11

danielrosero


Using Kotlin extension functions to Task<Uri> as receiver:

fun Task<Uri>.loadIntoPicasso(imageView: ImageView){
    addOnSuccessListener { Picasso.with(imageView.context).load(it).into(imageView) }
}
like image 44
Nikola Despotoski Avatar answered Nov 15 '22 07:11

Nikola Despotoski