Esempio n. 1
0
 public async Task PreloadImages(float imageWidth)
 {
     if (hasPreloadedImages)
     {
         return;
     }
     hasPreloadedImages = true;
     //Lets precach the countries too
                 #pragma warning disable 4014
     GetCountries();
                 #pragma warning restore 4014
     await Task.Factory.StartNew(() => {
         var imagUrls = products.SelectMany(x => x.ImageUrls.Select(y => Product.ImageForSize(y, imageWidth))).ToList();
         imagUrls.ForEach(async(x) => await FileCache.Download(x));
     });
 }
Esempio n. 2
0
                public async Task Update(Product product)
                {
                    NameLabel.Text  = product.Name;
                    SizeLabel.Text  = product.Size.Description;
                    ColorLabel.Text = product.Color.Name;
                    PriceLabel.Text = product.PriceDescription;
                    var imageTask = FileCache.Download(product.ImageForSize(320));

                    if (!imageTask.IsCompleted)
                    {
                        //Put default before doing the web request;
                        ImageView.Image = Image.Value;
                    }
                    var image = await imageTask;

                    ImageView.Image = UIImage.FromFile(image);
                }
        void PrecacheNextImage()
        {
            if (currentIndex + 1 >= images.Length)
            {
                cached = true;
            }
            if (cached)
            {
                return;
            }
            var next  = currentIndex + 1;
            var image = images [next];

            //No need to await the precache to finish
                        #pragma warning disable 4014
            FileCache.Download(Product.ImageForSize(image, Images.ScreenWidth));
                        #pragma warning restore 4014
        }
Esempio n. 4
0
        public static async Task <Bitmap> FromUrl(string url)
        {
            Bitmap bmp;

            if (bmpCache.TryGetValue(url, out bmp))
            {
                return(bmp);
            }
            var path = await FileCache.Download(url);

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }
            bmp = await BitmapFactory.DecodeFileAsync(path);

            bmpCache [url] = bmp;
            return(bmp);
        }
Esempio n. 5
0
        public async void LoadUrl(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return;
            }
            var t = FileCache.Download(url);

            if (t.IsCompleted)
            {
                Image = UIImage.FromFile(t.Result);
                return;
            }
            progress.StartAnimating();
            var image = UIImage.FromFile(await t);

            UIView.Animate(.3,
                           () => Image = image,
                           () => progress.StopAnimating());
        }