private void RefreshItems() { if (ChannelItems.Any()) { ChannelItems.Clear(); } SelectedCountry.Value.ForEach(x => AddNewItem(x)); }
private void FilterItems() { if (string.IsNullOrEmpty(filterVideoKey)) { IsAllItems = false; if (backupItems.Count > 0) { ChannelItems.Clear(); backupItems.ForEach(x => ChannelItems.Add(x)); ChannelItemsCount = ChannelItemsCollectionView.Cast <IVideoItem>().Count(); } else { ChannelItemsCollectionView.Filter = FilterVideoByTitle; ChannelItemsCount = ChannelItemsCollectionView.Cast <IVideoItem>().Count(); } } else { if (IsAllItems) { if (filterVideoKey.Length < 2) { return; } if (backupItems.Count == 0) { backupItems.Clear(); ChannelItems.ForEach(x => backupItems.Add(x)); } string cleared = Regex.Replace(filterVideoKey, @"\s+", " "); List <string> searchFields = cleared.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x.RemoveSpecialCharacters())).ToList(); if (searchFields.Count <= 0) { return; } List <VideoItemPOCO> res = db.GetAllItemsAsync(searchFields).Result; ChannelItems.Clear(); res.ForEach(x => ChannelItems.Add(VideoItemFactory.CreateVideoItem(x, SiteType.YouTube, true))); ChannelItemsCollectionView.Filter = null; ChannelItemsCount = ChannelItemsCollectionView.Cast <IVideoItem>().Count(); } else { if (backupItems.Count > 0) { ChannelItems.Clear(); backupItems.ForEach(x => ChannelItems.Add(x)); } ChannelItemsCollectionView.Filter = FilterVideoByTitle; ChannelItemsCount = ChannelItemsCollectionView.Cast <IVideoItem>().Count(); } } }
private async void ReloadFilteredLists(object state) { ChannelItems.Clear(); if (state is WatchState) { var st = (WatchState)state; List <IVideoItem> readyel; List <string> readyAddedIds; List <string> notreadyList; List <VideoItemPOCO> items; switch (st) { case WatchState.Watched: readyel = allchannels.SelectMany(x => x.ChannelItems).Where(y => y.WatchState == WatchState.Watched).ToList(); foreach (IVideoItem item in readyel.Where(item => !watchedList.Contains(item))) { watchedList.Add(item); } readyAddedIds = readyel.Select(x => x.ID).ToList(); foreach (string id in watchedList.Select(x => x.ID).Where(id => !readyAddedIds.Contains(id))) { readyAddedIds.Add(id); } notreadyList = watchedListIds.Except(readyAddedIds).ToList(); if (notreadyList.Any()) { items = await db.GetItemsByIdsAndState(WatchState.Watched, notreadyList).ConfigureAwait(false); foreach (VideoItemPOCO poco in items) { IChannel parent = allchannels.First(x => x.ID == poco.ParentID); IVideoItem item = VideoItemFactory.CreateVideoItem(poco, parent.Site); parent.AddNewItem(item, false); parent.IsHasNewFromSync = true; watchedList.Add(item); } } watchedList.OrderBy(x => x.Timestamp).ForEach(x => AddNewItem(x)); break; case WatchState.Planned: readyel = allchannels.SelectMany(x => x.ChannelItems).Where(y => y.WatchState == WatchState.Planned).ToList(); foreach (IVideoItem item in readyel.Where(item => !plannedList.Contains(item))) { plannedList.Add(item); } readyAddedIds = readyel.Select(x => x.ID).ToList(); foreach (string id in plannedList.Select(x => x.ID).Where(id => !readyAddedIds.Contains(id))) { readyAddedIds.Add(id); } notreadyList = plannedListIds.Except(readyAddedIds).ToList(); if (notreadyList.Any()) { items = await db.GetItemsByIdsAndState(WatchState.Planned, notreadyList).ConfigureAwait(false); foreach (VideoItemPOCO poco in items) { IChannel parent = allchannels.First(x => x.ID == poco.ParentID); IVideoItem item = VideoItemFactory.CreateVideoItem(poco, parent.Site); parent.AddNewItem(item, false); parent.IsHasNewFromSync = true; plannedList.Add(item); } } plannedList.OrderBy(x => x.Timestamp).ForEach(x => AddNewItem(x)); break; } } else if (state is SyncState) { var st = (SyncState)state; switch (st) { case SyncState.Added: List <IVideoItem> readyel = allchannels.SelectMany(x => x.ChannelItems).Where(y => y.SyncState == SyncState.Added).ToList(); foreach (IVideoItem item in readyel.Where(item => !addedList.Contains(item))) { addedList.Add(item); } List <string> readyAddedIds = readyel.Select(x => x.ID).ToList(); foreach (string id in addedList.Select(x => x.ID).Where(id => !readyAddedIds.Contains(id))) { readyAddedIds.Add(id); } List <string> notreadyList = addedListIds.Except(readyAddedIds).ToList(); if (notreadyList.Any()) { List <VideoItemPOCO> items = await db.GetItemsByIdsAndState(SyncState.Added, notreadyList).ConfigureAwait(false); foreach (VideoItemPOCO poco in items) { IChannel parent = allchannels.First(x => x.ID == poco.ParentID); IVideoItem item = VideoItemFactory.CreateVideoItem(poco, parent.Site); parent.AddNewItem(item, false); parent.IsHasNewFromSync = true; addedList.Add(item); } } addedList.OrderBy(x => x.ParentID).ThenBy(y => y.Timestamp).ForEach(x => AddNewItem(x)); break; } } }