Exemplo n.º 1
0
        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;
            }
        }
        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);
            }
        }
Exemplo n.º 3
0
        private bool FilterVideoBySynced(object item)
        {
            if (added == null)
            {
                added = ChannelItems.Where(x => x.SyncState == SyncState.Added).Select(x => x.ID).ToList();
            }
            if (deleted == null)
            {
                deleted = ChannelItems.Where(x => x.SyncState == SyncState.Deleted).Select(x => x.ID).ToList();
            }
            if (!added.Any() && !deleted.Any())
            {
                return(true);
            }
            var value = (IVideoItem)item;

            if (value == null)
            {
                return(false);
            }

            bool res = added.Contains(value.ID) || deleted.Contains(value.ID);

            return(res);
        }
 private void RefreshItems()
 {
     if (ChannelItems.Any())
     {
         ChannelItems.Clear();
     }
     SelectedCountry.Value.ForEach(x => AddNewItem(x));
 }
        public void DeleteItem(IVideoItem item)
        {
            if (item == null)
            {
                throw new ArgumentException("item");
            }

            ChannelItems.Remove(item);
        }
Exemplo n.º 6
0
        public void DeleteItem(IVideoItem item)
        {
            IVideoItem el = ChannelItems.FirstOrDefault(x => x.ID == item.ID);

            if (el != null)
            {
                ChannelItems.Remove(el);
            }
        }
Exemplo n.º 7
0
 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();
         }
     }
 }
Exemplo n.º 8
0
 public void AddNewItem(IVideoItem item, bool isIncrease = true, bool isUpdateCount = true)
 {
     if (ChannelItems.Contains(item))
     {
         return;
     }
     item.IsHasLocalFileFound(DirPath);
     ChannelItems.Insert(0, item);
     if (isUpdateCount)
     {
         ChannelItemsCount += 1;
     }
 }
Exemplo n.º 9
0
 public void RestoreFullChannelItems()
 {
     if (isHasScrolled)
     {
         return;
     }
     if (ChannelItemsCount != 0 && ChannelItemsCount <= ChannelItems.Count)
     {
         return;
     }
     isHasScrolled = true;
     ChannelFactory.SetChannelCountAsync(this);
     ChannelFactory.FillChannelItemsFromDbAsync(this, 0, ChannelItems.Select(x => x.ID).ToList());
 }
Exemplo n.º 10
0
        public void DeleteItem(IVideoItem item)
        {
            if (item == null)
            {
                throw new ArgumentException("item");
            }

            ChannelItems.Remove(item);

            ChannelItemsCount -= 1;

            if (item.SyncState == SyncState.Added)
            {
                CountNew -= 1;
            }
        }
Exemplo n.º 11
0
        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;
                }
            }
        }
Exemplo n.º 12
0
        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;
                }
            }
        }