public List<PhotoGroup> GeneratePhotoGroupsWithHeadline(List<Photo> photos, Photo headlinePhoto = null)
        {
            if (photos.Count == 0)
            {
                return new List<PhotoGroup>();
            }

            if (headlinePhoto == null)
            {
                headlinePhoto = photos[0];
            }

            List<PhotoGroup> results = new List<PhotoGroup>();
            PhotoGroup headlineGroup = GenerateHeadlinePhotoGroup(headlinePhoto);
            results.Add(headlineGroup);

            if (photos.Count > 1)
            {
                List<Photo> otherPhotos = new List<Photo>();
                otherPhotos.AddRange(photos);
                otherPhotos.Remove(headlinePhoto);

                List<PhotoGroup> groups = GeneratePhotoGroups(otherPhotos);
                results.AddRange(groups);
            }

            return results;
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string photoId = NavigationContext.QueryString["photo_id"];
            photo = Cinderella.CinderellaCore.PhotoCache[photoId];

            // Prepare data source
            dataSource = new ObservableCollection<ModelBase>();
            dataSource.Add(photo);

            foreach (var comment in photo.Comments)
            {
                dataSource.Add(comment);
            }

            CommentsListView.ItemsSource = dataSource;

            // App bar
            ApplicationBar = Resources["PhotoPageAppBar"] as ApplicationBar;

            // Background
            if (PolicyKit.ShouldUseBlurredBackground)
                BackgroundImage.PhotoSource = photo;
            else if (BackgroundImage.PhotoSource != null)
                BackgroundImage.PhotoSource = null;
        }
        private float GetHorizontalRatio(Photo leftPhoto, Photo rightPhoto)
        {
            float hRatio;
            if (leftPhoto.Width > 0 && rightPhoto.Width > 0)
            {
                hRatio = (float)leftPhoto.Width / (float)(leftPhoto.Width + rightPhoto.Width);
            }
            else
            {
                int f1 = Math.Min(leftPhoto.MediumWidth, leftPhoto.MediumHeight);
                int f2 = Math.Min(rightPhoto.MediumWidth, rightPhoto.MediumHeight);
                if (f1 != 0 && f2 != 0)
                {
                    hRatio = (float)f1 / (float)(f1 + f2);
                }
                else
                {
                    hRatio = 0.6f;
                }
            }

            if (hRatio < 0.4f)
            {
                hRatio = 0.4f;
            }

            if (hRatio > 0.75f)
            {
                hRatio = 0.75f;
            }

            return hRatio;
        }
        public static PhotoComment PhotoCommentWithJObject(JObject json, Photo photo)
        {
            // Get comment id
            string commentId = json["id"].ToString();
            PhotoComment comment = null;
            if (photo.CommentCache.ContainsKey(commentId))
            {
                comment = photo.CommentCache[commentId];
            }
            else
            {
                comment = new PhotoComment();
                comment.ResourceId = commentId;
                photo.CommentCache[commentId] = comment;
            }

            // Parse user
            comment.Author = UserFactory.UserWithPhotoCommentJObject(json);
            comment.CreationDate = json["datecreate"].ToString().ToDateTime();

            // Content
            comment.Message = json["_content"].ToString();

            return comment;
        }
        public PhotoGroup GenerateHeadlinePhotoGroup(Photo photo)
        {
            PhotoGroup group = new PhotoGroup();
            group.IsHeadline = true;
            group.Photos = new List<Photo> { photo };
            group.context = Context;
            group.contextType = ContextType;

            return group;
        }
        protected bool IsPortraitAspectRatio(Photo photo)
        {
            int w = (photo.Width == 0) ? photo.Width : photo.MediumWidth;
            int h = (photo.Height == 0) ? photo.Height : photo.MediumHeight;

            if (w == 0 || h == 0)
            {
                return false;
            }
            else
            {
                return (w < h);
            }
        }
Exemplo n.º 7
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (executedOnce)
                return;

            executedOnce = true;

            string photoId = NavigationContext.QueryString["photo_id"];
            currentPhoto = Cinderella.CinderellaCore.PhotoCache[photoId];

            contextString = null;
            if(NavigationContext.QueryString.ContainsKey("context"))
                contextString = NavigationContext.QueryString["context"];

            contextTypeString = null;
            if (NavigationContext.QueryString.ContainsKey("context_type"))
                contextTypeString = NavigationContext.QueryString["context_type"];

            List<Photo> CollectionContext = null;
            if (contextString == PolicyKit.MyStream)
                CollectionContext = Cinderella.CinderellaCore.CurrentUser.Photos.ToList();
            else if (contextString == PolicyKit.DiscoveryStream)
                CollectionContext = Cinderella.CinderellaCore.DiscoveryList.ToList();
            else if (contextString == PolicyKit.FavouriteStream)
                CollectionContext = Cinderella.CinderellaCore.FavouriteList.ToList();
            else if (contextTypeString != null)
            {
                if (contextTypeString == "Group")
                {
                    CollectionContext = Cinderella.CinderellaCore.GroupCache[contextString].Photos.ToList();
                }
                else if (contextTypeString == "PhotoSet")
                {
                    CollectionContext = Cinderella.CinderellaCore.PhotoSetCache[contextString].Photos.ToList();
                }
                else if (contextTypeString == "UserPhotoStream")
                {
                    CollectionContext = Cinderella.CinderellaCore.UserCache[contextString].Photos.ToList();
                }
            }
            else
            {
                CollectionContext = new List<Photo>();
                CollectionContext.Add(currentPhoto);
            }

            PerformAppearanceAnimation();
        }
Exemplo n.º 8
0
        public static PhotoSet PhotoSetWithJObject(JObject json)
        {
            string setId = json["id"].ToString();
            PhotoSet photoset;
            if (Cinderella.CinderellaCore.PhotoSetCache.ContainsKey(setId))
            {
                photoset = Cinderella.CinderellaCore.PhotoSetCache[setId];
            }
            else
            {
                photoset = new PhotoSet();
                photoset.ResourceId = setId;
                Cinderella.CinderellaCore.PhotoSetCache[setId] = photoset;
            }

            photoset.Primary = json["primary"].ToString();
            photoset.Secret = json["secret"].ToString();
            photoset.Server = json["server"].ToString();
            photoset.Farm = json["farm"].ToString();
            photoset.PhotoCount = int.Parse(json["photos"].ToString());
            photoset.VideoCount = int.Parse(json["videos"].ToString());
            photoset.Title = json["title"]["_content"].ToString();
            photoset.Description = json["description"]["_content"].ToString();
            photoset.IsVisible = json["visibility_can_see_set"].ToString().ParseBool();
            photoset.ViewCount = int.Parse(json["count_views"].ToString());
            photoset.CommentCount = int.Parse(json["count_comments"].ToString());
            photoset.CanComment = json["can_comment"].ToString().ParseBool();
            photoset.CreationDate = json["date_create"].ToString().ToDateTime();
            photoset.UpdatedDate = json["date_update"].ToString().ToDateTime();

            // Create the primary photo
            if (Cinderella.CinderellaCore.PhotoCache.ContainsKey(photoset.Primary))
            {
                photoset.PrimaryPhoto = Cinderella.CinderellaCore.PhotoCache[photoset.Primary];
            }
            else
            {
                Photo primaryPhoto = new Photo();
                primaryPhoto.ResourceId = photoset.Primary;
                primaryPhoto.Secret = photoset.Secret;
                primaryPhoto.Server = photoset.Server;
                primaryPhoto.Farm = photoset.Farm;

                photoset.PrimaryPhoto = primaryPhoto;
                Cinderella.CinderellaCore.PhotoCache[photoset.Primary] = primaryPhoto;
            }

            return photoset;
        }
 public static BitmapImage GetDecodedBitmapImage(Photo photo, DecodeResolutions res)
 {
     if (res == DecodeResolutions.High)
     {
         return new BitmapImage { UriSource = new Uri(photo.GetImageUrl()), DecodePixelWidth = 640 };
     }
     else if (res == DecodeResolutions.Medium)
     {
         return new BitmapImage { UriSource = new Uri(photo.GetImageUrl()), DecodePixelWidth = 480 };
     }
     else
     {
         return new BitmapImage { UriSource = new Uri(photo.GetImageUrl()), DecodePixelWidth = 240 };
     }
 }
        private float GetVerticalRatio(Photo topPhoto, Photo bottomPhoto)
        {
            float vRatio;
            if (topPhoto.Height > 0 && bottomPhoto.Height > 0)
            {
                vRatio = (float)topPhoto.Height / (float)(topPhoto.Height + bottomPhoto.Height);
            }
            else
            {
                int f1 = Math.Min(topPhoto.MediumWidth, topPhoto.MediumHeight);
                int f2 = Math.Min(bottomPhoto.MediumWidth, bottomPhoto.MediumHeight);
                if (f1 != 0 && f2 != 0)
                {
                    vRatio = (float)f1 / (float)(f1 + f2);
                }
                else
                {
                    vRatio = 0.6f;
                }
            }

            if (vRatio < 0.3f)
            {
                vRatio = 0.3f;
            }

            if (vRatio > 0.75f)
            {
                vRatio = 0.75f;
            }

            return vRatio;
        }
        private void AddDownloadRequest(Photo photo, int index)
        {
            if (BackgroundTransferService.Requests.Count() >= MAX_TILE_IMAGE_COUNT)
            {
                return;
            }

            string filename = "tile" + index.ToString() + ".jpg";

            Uri transferUri = new Uri(photo.GetImageUrl(), UriKind.Absolute);

            // Create the new transfer request, passing in the URI of the file to
            // be transferred.
            BackgroundTransferRequest transferRequest = new BackgroundTransferRequest(transferUri);

            // Set the transfer method. GET and POST are supported.
            transferRequest.Method = "GET";

            // Set download location uri
            transferRequest.DownloadLocation = new Uri("shared/transfers/" + filename, UriKind.RelativeOrAbsolute);
            transferRequest.TransferStatusChanged += new EventHandler<BackgroundTransferEventArgs>(transfer_TransferStatusChanged);
            transferRequest.Tag = filename;
            ProcessTransfer(transferRequest);

            // Start request
            try
            {
                BackgroundTransferService.Add(transferRequest);
            }
            catch (InvalidOperationException ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to add background transfer request. " + ex.Message);
            }
            catch (Exception)
            {
                System.Diagnostics.Debug.WriteLine("Unable to add background transfer request.");
            }
        }
Exemplo n.º 12
0
        public static Photo PhotoWithJObject(JObject json)
        {
            string photoId = json["id"].ToString();
            Photo photo = null;
            if (Cinderella.CinderellaCore.PhotoCache.ContainsKey(photoId))
            {
                photo = Cinderella.CinderellaCore.PhotoCache[photoId];
            }
            else
            {
                photo = new Photo();
                photo.ResourceId = photoId;
                Cinderella.CinderellaCore.PhotoCache[photoId] = photo;
            }

            JToken ownerValue;
            if (json.TryGetValue("owner", out ownerValue))
            {
                photo.UserId = json["owner"].ToString();

                // Parse user
                User user = UserFactory.UserWithJObject(json);
            }
            else
            {
            }

            photo.Secret = json["secret"].ToString();
            photo.Server = json["server"].ToString();
            photo.Farm = json["farm"].ToString();
            photo.ViewCount = int.Parse(json["views"].ToString());

            JToken commentCountValue;
            if(json.TryGetValue("comments", out commentCountValue))
            {
                photo.CommentCount = int.Parse(json["comments"]["_content"].ToString());
            }

            if(json["title"].GetType() == typeof(JValue))
                photo.Title = json["title"].ToString();
            else
                photo.Title = json["title"]["_content"].ToString();

            photo.Description = json["description"]["_content"].ToString();

            JToken licenseValue;
            if (json.TryGetValue("license", out licenseValue))
            {
                photo.LicenseId = json["license"].ToString();
            }

            JToken widthValue;
            if (json.TryGetValue("o_width", out widthValue))
            {
                photo.Width = int.Parse(json["o_width"].ToString());
            }

            JToken heightValue;
            if (json.TryGetValue("o_height", out heightValue))
            {
                photo.Height = int.Parse(json["o_height"].ToString());
            }

            if (json.TryGetValue("width_m", out widthValue))
            {
                photo.MediumWidth = int.Parse(json["width_m"].ToString());
            }

            if (json.TryGetValue("height_m", out heightValue))
            {
                photo.MediumHeight = int.Parse(json["height_m"].ToString());
            }

            // Tags
            photo.Tags = new List<string>();
            JToken tagsValue;
            if (json.TryGetValue("tags", out tagsValue))
            {
                string tagsString = json["tags"].ToString();
                if (tagsString.Length != 0)
                {
                    photo.Tags = new List<string>(tagsString.Split(' '));
                }

            }

            // Favourite
            JToken favValue;
            if(json.TryGetValue("isfavorite", out favValue))
            {
                photo.IsFavourite = (json["isfavorite"].ToString() == "1");
            }

            return photo;
        }
Exemplo n.º 13
0
        public static Photo PhotoWithPhotoInfoJObject(JObject json)
        {
            string photoId = json["id"].ToString();
            Photo photo = null;
            if (Cinderella.CinderellaCore.PhotoCache.ContainsKey(photoId))
            {
                photo = Cinderella.CinderellaCore.PhotoCache[photoId];
            }
            else
            {
                photo = new Photo();
                photo.ResourceId = photoId;
                Cinderella.CinderellaCore.PhotoCache[photoId] = photo;
            }

            photo.Secret = json["secret"].ToString();
            photo.Server = json["server"].ToString();
            photo.Farm = json["farm"].ToString();
            photo.ViewCount = int.Parse(json["views"].ToString());

            JToken commentCountValue;
            if (json.TryGetValue("comments", out commentCountValue))
            {
                photo.CommentCount = int.Parse(json["comments"]["_content"].ToString());
            }

            photo.Title = json["title"]["_content"].ToString();
            photo.Description = json["description"]["_content"].ToString();

            // Favourite
            JToken favValue;
            if (json.TryGetValue("isfavorite", out favValue))
            {
                photo.IsFavourite = (json["isfavorite"].ToString() == "1");
            }

            return photo;
        }
Exemplo n.º 14
0
        public static Photo PhotoWithPhotoActivityJObject(JObject json)
        {
            string photoId = json["id"].ToString();
            Photo photo = null;
            if (Cinderella.CinderellaCore.PhotoCache.ContainsKey(photoId))
            {
                photo = Cinderella.CinderellaCore.PhotoCache[photoId];
            }
            else
            {
                photo = new Photo();
                photo.ResourceId = photoId;
                Cinderella.CinderellaCore.PhotoCache[photoId] = photo;
            }

            JToken ownerValue;
            if (json.TryGetValue("owner", out ownerValue))
            {
                photo.UserId = json["owner"].ToString();

                // Parse user
                User user = UserFactory.UserWithJObject(json);
            }
            else
            {
            }

            photo.Secret = json["secret"].ToString();
            photo.Server = json["server"].ToString();
            photo.Farm = json["farm"].ToString();
            photo.ViewCount = int.Parse(json["views"].ToString());

            if (json["title"].GetType() == typeof(JValue))
                photo.Title = json["title"].ToString();
            else
                photo.Title = json["title"]["_content"].ToString();

            return photo;
        }