public void GetSticker (IceCream iceCream, Action<MSSticker> completion)
		{
			if (iceCream.Base == null || iceCream.Scoops == null || iceCream.Topping == null)
				throw new Exception ("Stickers can only be created for completed ice creams");

			// Determine the URL for the sticker.
			var fileName = $"{iceCream.Base.RawValue}{iceCream.Scoops.RawValue}{iceCream.Topping.RawValue}.png";
			var url = Path.Combine (cacheURL, fileName);

			// Check if the sticker already exists at the URL
			if (!NSFileManager.DefaultManager.FileExists (url)) {
				
				// Create the sticker image and write it to disk.
				var image = iceCream.RenderSticker (false);
				var imageData = image?.AsPNG ();
				if (image == null || imageData == null)
					throw new Exception ("Unable to build image for ice cream");

				try {
					File.WriteAllBytes (url, imageData.ToArray ());
				} catch {
					throw new Exception ("Failed to write sticker image to cach");
				}
			}

			NSError error;
			var sticker = new MSSticker (new NSUrl ($"file://{url}"), "Ice Cream", out error);

			if (error != null)
				throw new Exception ($"Failed to write image to cache, error: {error.LocalizedDescription}");

			completion?.Invoke (sticker);
		}
예제 #2
0
        UICollectionViewCell DequeueArcherStickerCell(MSSticker sticker, NSIndexPath indexPath)
        {
            var cell = CollectionView.DequeueReusableCell(ArcherStickerCell.ReuseIdentifier, indexPath) as ArcherStickerCell;

            if (cell == null)
            {
                throw new Exception("Unable to dequeue an ArcherStickerCell");
            }

            cell.StickerView.Sticker = sticker;
            cell.StickerView.StartAnimating();

            return(cell);
        }
예제 #3
0
        private MSSticker GetArcherSticker(string fileName, string fileType)
        {
            var bundle  = NSBundle.MainBundle;
            var testUrl = bundle.GetUrlForResource(fileName, fileType);

            if (testUrl == null)
            {
                throw new Exception("Unable to find archer sticker image");
            }

            var description = "An Archer sticker";

            NSError error;
            var     sticker = new MSSticker(testUrl, description, out error);

            if (error != null)
            {
                throw new Exception($"Failed to create placeholder sticker: {error.LocalizedDescription}");
            }

            return(sticker);
        }
예제 #4
0
        public void GetSticker(IceCream iceCream, Action <MSSticker> completion)
        {
            if (iceCream.Base == null || iceCream.Scoops == null || iceCream.Topping == null)
            {
                throw new Exception("Stickers can only be created for completed ice creams");
            }

            // Determine the URL for the sticker.
            var fileName = $"{iceCream.Base.RawValue}{iceCream.Scoops.RawValue}{iceCream.Topping.RawValue}.png";
            var url      = Path.Combine(cacheURL, fileName);

            // Check if the sticker already exists at the URL
            if (!NSFileManager.DefaultManager.FileExists(url))
            {
                // Create the sticker image and write it to disk.
                var image     = iceCream.RenderSticker(false);
                var imageData = image?.AsPNG();
                if (image == null || imageData == null)
                {
                    throw new Exception("Unable to build image for ice cream");
                }

                try {
                    File.WriteAllBytes(url, imageData.ToArray());
                } catch {
                    throw new Exception("Failed to write sticker image to cach");
                }
            }

            NSError error;
            var     sticker = new MSSticker(new NSUrl($"file://{url}"), "Ice Cream", out error);

            if (error != null)
            {
                throw new Exception($"Failed to write image to cache, error: {error.LocalizedDescription}");
            }

            completion?.Invoke(sticker);
        }