Coder Social home page Coder Social logo

Access to cache result about ffimageloading HOT 12 CLOSED

mgorbach avatar mgorbach commented on August 20, 2024
Access to cache result

from ffimageloading.

Comments (12)

molinch avatar molinch commented on August 20, 2024

It shouldn't be complicated to add this info. I will look into it.
Therefore I'm very interested with your iOS fading logic. There is a task about it in fact #16
Would you mind sharing your fading code for iOS? We might be able to integrate that in the lib.

from ffimageloading.

mgorbach avatar mgorbach commented on August 20, 2024

Here's my fading code:

                if (imageLoadingWork != null)
                {
                    imageLoadingWork.Cancel();
                    imageLoadingWork = null;
                }

                Uri imageUrl = null;
                if (viewModel != null)
                {
                    var imageUrlViewModel = viewModel as IRemoteImage;
                    if (imageUrlViewModel != null)
                    {
                        imageUrl = imageUrlViewModel.ImageUrl;

                        if (imageUrl != null)
                        {
                            if (shownImageUrl == imageUrl)
                            {
                                // Nothing to do here, we are already showing the correct image
                                ContentImageView.Alpha = 1.0f;
                            }
                            else
                            {
                                // Clear the image and start loading the next one
                                ContentImageView.Image = null;
                                ContentImageView.Alpha = 0.0f;

                                var urlString = imageUrl.ToString();
                                imageLoadingWork = ImageService.LoadUrl(urlString)
                                    .Error(e => Console.WriteLine("Failed to load image: " + urlString + " error: " + e))
                                    .Success(() =>
                                    {
                                        shownImageUrl = imageUrl;
                                        UIView.AnimateNotify(
                                            AnimationDuration, 
                                            0.0f, 
                                            UIViewAnimationOptions.CurveEaseInOut,
                                            () =>
                                            {
                                                ContentImageView.Alpha = 1.0f;
                                            }, 
                                            null);
                                    })
                                    .Finish(work =>
                                    {
                                        // This is a special case that occurs when the image is being loaded from a disk cache. The work is not marked as either cancelled or completed.
                                        // In this case, we are going to stop to animation started by the success block and put the image onscreen without the fade
                                        bool loadedAlready = work.IsCancelled == false && work.Completed == false;
                                        if (loadedAlready && ContentImageView.Alpha == 1.0f)
                                        {
                                            ContentImageView.Layer.RemoveAllAnimations();
                                            ContentImageView.Alpha = 1.0f;
                                        }
                                    })
                                    .Into(ContentImageView);
                            }
                        }
                        else
                        {
                            ContentImageView.Alpha = 0.0f;
                            ContentImageView.Image = null;
                        }
                    }

from ffimageloading.

molinch avatar molinch commented on August 20, 2024

@mgorbach this is implemented in git now. Success callback gives both the size and a LoadingResult enum. It allows you to know if it was loaded from Internet, Disk, ApplicationBundle, DiskCache, or MemoryCache.

Could you give it a try?

from ffimageloading.

mgorbach avatar mgorbach commented on August 20, 2024

@molinch thanks for implementing this so quickly!

I can't quite try off git though, because I'm having trouble building the library. I'm trying to build the master branch on a Mac with the latest stable Xamarin Studio, and I'm getting a bunch of errors with missing references and WebP on iOS not being found, even though it seems to have restored the internal nuget packages as expected.

from ffimageloading.

molinch avatar molinch commented on August 20, 2024

Ok don't worry, I will soon make a release on NuGet so this will be included

from ffimageloading.

molinch avatar molinch commented on August 20, 2024

You can test this prerelease NuGet package: https://www.nuget.org/packages/Xamarin.FFImageLoading/1.1.6-alpha

If it works fine I'll make a release.

from ffimageloading.

mgorbach avatar mgorbach commented on August 20, 2024

@molinch thanks, I just gave it a shot. I'm getting callbacks with a loading result, but it always seems to be "internet." I haven't changed any of the disk cache settings, so I'd expect the disk cache to be enabled by default. Might be it's a bug with the result implementation?

from ffimageloading.

mgorbach avatar mgorbach commented on August 20, 2024

Also, the issue I was exploiting earlier still exists, and once the result implementation works it should probably be fixed. Specifically, when loading from the in-memory cache, the finish callback is called and both "completed" and "cancelled" are false. It seems like "completed" should be true in this case.

from ffimageloading.

molinch avatar molinch commented on August 20, 2024

Weird I tested this and got data from Internet, DiskCache and MemoryCache :(
I will give it another try

from ffimageloading.

molinch avatar molinch commented on August 20, 2024

And yes you are right it should have completed true when loading from Memory.

from ffimageloading.

molinch avatar molinch commented on August 20, 2024

@mgorbach I retested all scenarios on both iOS and Android and it works fine: Disk, DiskCache, Internet, Memory... It's always giving the correct result.

There was just one issue, affecting iOS DiskCache only, but everything else was working fine.
Now this is fixed in git too and I will make a Nuget release soon.

Could you make a separate issue regarding the callbacks?

from ffimageloading.

molinch avatar molinch commented on August 20, 2024

I pushed a new Alpha nuget https://www.nuget.org/packages/Xamarin.FFImageLoading/1.1.6-alpha1 which contains the last fix (plus other things)
I will make a release soon

from ffimageloading.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.