Example #1
0
        private void UpdateItem(UpdateModel updateModel)
        {
            Grouping <string, ItemPreview> currentItems = null;

            if (Items != null)
            {
                currentItems = Items.Where(k => k.Key == updateModel.ItemPreview.ItemType.ToPluralString())
                               .FirstOrDefault();
            }
            else if (Items is null)
            {
                Items = new ObservableCollection <Grouping <string, ItemPreview> >();
            }
            if (currentItems is null)//that means no items of that type are in list
            {
                //add new item
                DisplayMsg("", false);//make sure there is no msg
                Items.Add(new Grouping <string, ItemPreview>(updateModel.ItemPreview.ItemType.ToPluralString(), new List <ItemPreview>()
                {
                    updateModel.ItemPreview
                }));
            }
            else if (updateModel.UpdateType == TypeOfUpdates.Create)
            {
                currentItems.Add(updateModel.ItemPreview);
            }
            else if (updateModel.UpdateType == TypeOfUpdates.Modify)
            {//get current item that will be modified later
                var itemToBeModified = currentItems.FirstOrDefault(s => s.Id == updateModel.ItemPreview.Id);
                if (itemToBeModified != null)
                {
                    int index = currentItems.IndexOf(itemToBeModified);//get index of the item from the list
                    currentItems.SetNewItem(index, updateModel.ItemPreview);
                }
            }
            else if (updateModel.UpdateType == TypeOfUpdates.Delete)
            {
                Delete(updateModel.ItemPreview.Id);
            }
            if (IsUwp)
            {
                Items = UpdateItems(Items);//update the list with itself(bug: (when updating an item it will not be displayed so i updated the current list))
            }
        }
Example #2
0
 public static int GetPlayingSongIndexInGroup(this Grouping <IGroupKey, Mediafile> group)
 {
     return(group?.IndexOf(group.FirstOrDefault(t => t.State == Core.Common.PlayerState.Playing)) ?? 0);
 }