private void UpdateContent() { if (!GangOSClient.Livestreams.Any()) { if (Controls.OfType <TwitchItem>().Any()) { CleanUp(Controls.OfType <TwitchItem>().ToList()); } labelNoLivestreams.Visible = true; return; } Dictionary <Livestream, TwitchItem> items = Controls.OfType <TwitchItem>().ToDictionary(page => (Livestream)page.Tag); List <Livestream> livestreams = new List <Livestream>(); livestreams.AddRange(GangOSClient.Livestreams); int index = 0; List <TwitchItem> twitchItems = Controls.OfType <TwitchItem>().ToList(); foreach (var ls in livestreams) { TwitchItem currentTwitchItem = (index < twitchItems.Count ? twitchItems[index] : null); Livestream currentTag = currentTwitchItem != null ? (Livestream)currentTwitchItem.Tag : null; if (currentTag != ls) { TwitchItem twitchItem; if (items.TryGetValue(ls, out twitchItem)) { twitchItems.Remove(twitchItem); } else { twitchItem = GetTwitchItem(ls); } twitchItems.Insert(index, twitchItem); } if (ls != null) { items.Remove(ls); } index++; } CleanUp(items.Values.ToList()); foreach (var item in items.Values) { twitchItems.Remove(item); } Controls.AddRange(twitchItems.ToArray <Control>()); PerformCustomLayout(); }
private TwitchItem GetTwitchItem(Livestream livestream) { TwitchItem twitchItem; TwitchItem tempTwitchItem = null; try { tempTwitchItem = new TwitchItem(livestream); tempTwitchItem.Click += item_Click; tempTwitchItem.Clickable = true; tempTwitchItem.CreateControl(); twitchItem = tempTwitchItem; tempTwitchItem = null; } finally { if (tempTwitchItem != null) { tempTwitchItem.Dispose(); } } return(twitchItem); }
private void item_Click(object sender, EventArgs e) { TwitchItem item = sender as TwitchItem; Process.Start(((Livestream)item.Tag).URL); }