Exemplo n.º 1
0
        private void LoadSocial(string JSON)
        {
            var parsedJson = JObject.Parse(JSON);
            SocialWallpapers = new List<Wallpaper>();
            var categories = parsedJson.GetValue("entertainment");
            SocialWallpapers.AddRange(categories.Select(p => new Wallpaper
            {
                ID = (int)p["id"],
                CategoryID = (int)p["cid"],
                CategoryName = (string)p["category_name"],
                ImageURL = (string)p["wallpaper_image"],
                ThumbURL = (string)p["wallpaper_thumb"],
                Title = (string)p["title"],
                Description = (string)p["description"],
                Tags = (string)p["tag"],
                Size = (string)p["size"],
                User = (string)p["user"],
                CopyrightName = (string)p["copyright_name"],
                CopyrightURL = (string)p["copyright_link"],
                Width = (int)p["width"],
                Height = (int)p["height"],
                DownloadCount = (int)p["download_count"],
                Rating = (float)p["wallpaper_rate_avg"]
            }));

            if (SocialWallpapers.Count <= PAGE_SIZE)
            {
                foreach (Control control in PanelGetControls(pnlSocialContent))
                {
                    DisposeControl(control);
                }
                PanelClear(pnlSocialContent);

                foreach (var item in SocialWallpapers)
                {
                    var control = new WallpaperControl(item, DownloadManager);
                    PanelAddControl(pnlSocialContent, control);
                }
            }
            else
            {
                LoadSocialPage(1);
            }
        }
Exemplo n.º 2
0
        private void LoadSocialPage(int PageNumber)
        {
            var PageCount = (int)Math.Ceiling(SocialWallpapers.Count / (float)PAGE_SIZE);
            if (PageNumber <= PageCount)
            {
                lblSocialPageCount.Text = $"{PageNumber}/{PageCount}";
                btnSocialNext.Left = lblSocialPageCount.Left + TextRenderer.MeasureText(lblSocialPageCount.Text, lblSocialPageCount.Font).Width + pnlSocialTopRight.Padding.Left;
                SetControlWidth(pnlSocialTopRight, btnSocialNext.Left + btnSocialNext.Width + pnlSocialTopRight.Padding.Horizontal);

                foreach (Control control in PanelGetControls(pnlSocialContent))
                {
                    DisposeControl(control);
                }
                PanelClear(pnlSocialContent);

                var minimumIndex = PAGE_SIZE * (PageNumber - 1);
                // Includes one past index so that the loop is a fraction of a microsecond faster.
                var maximumIndex = PageNumber == PageCount ? SocialWallpapers.Count : PAGE_SIZE * PageNumber;

                for (int i = minimumIndex; i < maximumIndex; i++)
                {
                    var control = new WallpaperControl(SocialWallpapers[i], DownloadManager);
                    PanelAddControl(pnlSocialContent, control);
                }

                if (PageNumber == 1)
                {
                    btnSocialPrevious.Enabled = false;
                }
                else
                {
                    btnSocialPrevious.Enabled = true;
                }

                if (PageNumber == PageCount)
                {
                    btnSocialNext.Enabled = false;
                }
                else
                {
                    btnSocialNext.Enabled = true;
                }

                lblSocialPageCount.Tag = PageNumber;
            }
        }