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

Picasso Not Loading HTTPS Facebook Links #1658

Closed
jonathansds opened this issue Jul 29, 2017 · 5 comments
Closed

Picasso Not Loading HTTPS Facebook Links #1658

jonathansds opened this issue Jul 29, 2017 · 5 comments

Comments

@jonathansds
Copy link

Hi there,
Before you set the question/issue as duplicate, please read it all first.

I know it is a known issue and there's loads of question on Stackoverflow and issues on Github but believe me I tried them all.

ISSUE
Not loading this link:

https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/13872950_1066865640060722_8272182690153279858_n.jpg?oh=66a4ff80019c1fbf79bee45d32f03468&oe=59F65F50

MY CODE

    Target target = new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            userPicture.setImageDrawable(FunctionUtil.roundBitmap(bitmap));
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            Resources resources = getContext().getResources();
            Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.ic_image_content_error);

            userPicture.setImageDrawable(FunctionUtil.roundBitmap(bitmap));
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
            Resources resources = getContext().getResources();
            Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.ic_image_placeholder);

            userPicture.setImageDrawable(FunctionUtil.roundBitmap(bitmap));
        }
    };
    Picasso.with(getContext()).load(me.getPicture().getUrl()).into(target);

WHAT I HAVE TRIED

NO CACHE:
Picasso.with(getContext()).load(me.getPicture().getUrl()).memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(target);

NEW DOWNLOADER:
new Picasso.Builder(getContext()).downloader(new OkHttpDownloader(getContext())).build().load(me.getPicture().getUrl()).into(target);

BOTH:
new Picasso.Builder(getContext()).downloader(new OkHttpDownloader(getContext())).build().load(me.getPicture().getUrl()).memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(target);

What am I doing wrong?

@NightlyNexus
Copy link
Contributor

Are you holding a reference to your Target anywhere non-locally? Picasso only holds weak references to Targets, so it looks like it's getting garbage collected here.

@jonathansds
Copy link
Author

No I'm not. This code is all inside a method. Should I declare Target as global property to hold an instance outside the method instead?

@NightlyNexus
Copy link
Contributor

Hold a reference to it for as long as your userPicture is around (like a field in the controller class). Typically, custom Views implement the Target interface.

@jonathansds
Copy link
Author

Humm... I will do it now. Give me 1 minute.

@jonathansds
Copy link
Author

It worked!! Just perfectly! So my mistake was creating the Target as a local method property then when Picasso took a little bit more time to load the image maybe the Garbage Collector cleaned the Target reference which was make it impossible to Picasso to load it into the Target. That is why it SOMETIMES worked.
Thanks so much for the support, you are the best!!

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

2 participants