public void AddNewItem(IVideoItem item, bool isIncrease = true, bool isUpdateCount = true) { if (item == null) { throw new ArgumentException("item"); } if (item.ParentTitle == null) { item.ParentTitle = item.ParentID; } if (ChannelItems.Select(x => x.ID).Contains(item.ID)) { ChannelItems.Remove(ChannelItems.First(x => x.ID == item.ID)); } item.FileState = ItemState.LocalNo; if (item.SyncState == SyncState.Added) { ChannelItems.Insert(0, item); } else { ChannelItems.Add(item); } }
public void AddNewItem(IVideoItem item, bool isIncrease = true, bool isUpdateCount = true) { if (item == null) { throw new ArgumentException("item"); } item.ParentTitle = Title; if (item.SyncState == SyncState.Added) { ChannelItems.Insert(0, item); if (isIncrease) { CountNew += 1; } } else { ChannelItems.Add(item); } if (isUpdateCount) { ChannelItemsCount += 1; } }
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(); } } }
public void AddToStateList(object state, IVideoItem item) { if (state is WatchState) { var st = (WatchState)state; switch (st) { case WatchState.Watched: if (!watchedList.Select(x => x.ID).Contains(item.ID)) { watchedList.Add(item); if (SelectedState != null && SelectedState.State as WatchState? == st) { AddNewItem(item); } if (!watchedListIds.Contains(item.ID)) { watchedListIds.Add(item.ID); } } break; case WatchState.Planned: if (!plannedList.Select(x => x.ID).Contains(item.ID)) { plannedList.Add(item); if (SelectedState != null && SelectedState.State as WatchState? == st) { AddNewItem(item); } if (!plannedListIds.Contains(item.ID)) { plannedListIds.Add(item.ID); } IVideoItem vi = watchedList.FirstOrDefault(x => x.ID == item.ID); if (vi != null) { watchedList.Remove(vi); if (watchedListIds.Contains(item.ID)) { watchedListIds.Remove(item.ID); } } if (SelectedState != null && SelectedState.State as WatchState? == WatchState.Watched) { DeleteItem(item); } } break; case WatchState.Notset: IVideoItem vim = plannedList.FirstOrDefault(x => x.ID == item.ID); if (vim != null) { plannedList.Remove(vim); if (plannedListIds.Contains(item.ID)) { plannedListIds.Remove(item.ID); } } // if (SelectedState != null && SelectedState.State as WatchState? == WatchState.Planned) // { // DeleteItem(item); // } break; } } else if (state is SyncState) { var st = (SyncState)state; switch (st) { case SyncState.Added: if (!addedList.Select(x => x.ID).Contains(item.ID)) { addedList.Add(item); if (!addedListIds.Contains(item.ID)) { addedListIds.Add(item.ID); if (SelectedState != null && SelectedState.State as SyncState? == st) { if (!ChannelItems.Select(x => x.ID).Contains(item.ID)) { ChannelItems.Add(item); } } } } break; case SyncState.Notset: IVideoItem vi = addedList.FirstOrDefault(x => x.ID == item.ID); if (vi != null) { addedList.Remove(vi); if (addedListIds.Contains(item.ID)) { addedListIds.Remove(item.ID); if (SelectedState != null && SelectedState.State as SyncState? == SyncState.Added) { IVideoItem ite = ChannelItems.FirstOrDefault(x => x.ID == item.ID); if (ite != null) { ChannelItems.Remove(ite); } } } } break; } } }