Exemplo n.º 1
0
        /// <summary>
        /// Share a item.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static async Task ShareAsync(this CommonViewItemModel model)
        {
            switch (model?.Type)
            {
            case CommonItemType.Album:
                var album = await model.InternalDbEntityId.GetAlbumByIdAsync();

                await album.ShareAsync();

                break;

            case CommonItemType.Artist:
                var artist = await model.InternalDbEntityId.GetArtistByIdAsync();

                artist.Share();
                break;

            case CommonItemType.Song:
                var fileEntity = await model.InternalDbEntityId.GetFileByIdAsync();

                await fileEntity.ShareAsync();

                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Remove an entity from existing groups. Only first occurrence will be removed.
        /// If a group has size of zero after removal, it will be removed too.
        /// </summary>
        /// <param name="item">The item to remove.</param>
        public void Remove(CommonViewItemModel item)
        {
            if (item != null)
            {
                var index = Indexer.GetIndexForGroup(item);
                // If group exists
                if (_itemsIndex.ContainsKey(index))
                {
                    var group = _itemsIndex[index];
                    group.Remove(item);
                    _entityCopies.Remove(item);
                    // Check group size. If group's size is 0, remove this group.
                    if (group.Count == 0)
                    {
                        _itemsIndex.Remove(index);
                        Items.Remove(group);
                    }
                }

                // Notify change if required (precondition: all removed)
                if (_entityCopies.Count == 0)
                {
                    IsEmpty = true;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get item index with indexer-specific logic for grouping.
        /// </summary>
        /// <param name="item">The item to be indexed.</param>
        /// <returns>Item's index.</returns>
        /// <seealso cref="GetIndex"/>
        public string GetIndexForGroup(CommonViewItemModel item)
        {
            if (string.IsNullOrEmpty(item?.Genre))
            {
                return(CommonSharedStrings.UnknownIndex);
            }

            return(item.Genre);
        }
Exemplo n.º 4
0
        public static string GetItemDateYearString(CommonViewItemModel item)
        {
            var dateString = string.Empty;

            if (!string.IsNullOrEmpty(item.ReleaseDate))
            {
                dateString = GetItemDateYearString(item.ReleaseDate);
            }
            return(dateString);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get item index with indexer-specific logic for grouping.
        /// </summary>
        /// <param name="item">The item to be indexed.</param>
        /// <returns>Item's index.</returns>
        /// <seealso cref="GetIndex"/>
        public string GetIndexForGroup(CommonViewItemModel item)
        {
            if (string.IsNullOrEmpty(item?.Title))
            {
                return(CommonSharedStrings.UnknownIndex);
            }

            // Lookup table
            return(_slg.Lookup(item.Title[0].ToString()));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get item index with indexer-specific logic for grouping.
        /// </summary>
        /// <param name="item">The item to be indexed.</param>
        /// <returns>Item's index.</returns>
        /// <seealso cref="GetIndex"/>
        public string GetIndexForGroup(CommonViewItemModel item)
        {
            if (string.IsNullOrEmpty(item?.ReleaseDate))
            {
                return(CommonSharedStrings.UnknownDate);
            }

            // Parse date.
            return(DateTimeHelper.GetItemDateYearString(item));
        }
 public ThumbnailSearchFlyout(CommonViewItemModel model)
 {
     this.InitializeComponent();
     if (model.Type == CommonItemType.Album)
     {
         DataContext = new ThumbnailSearchViewModel(model.ExtendedArtistName, model.Title);
     }
     else
     {
         DataContext = new ThumbnailSearchViewModel(model.Title);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Index, group, sort and insert an entity to the collection.
        /// If group doesn't exist, it will be created and sorted.
        /// </summary>
        /// <param name="item">The item to insert into.</param>
        /// <param name="ignoreBackendFlatList">Whether ignore backend list or not.</param>
        private void AddInternal(CommonViewItemModel item, bool ignoreBackendFlatList = false)
        {
            if (item != null)
            {
                var index = Indexer.GetIndexForGroup(item);
                // If group exists
                if (_itemsIndex.ContainsKey(index))
                {
                    _itemsIndex[index].Add(item);
                }
                // Or create group
                else
                {
                    var newCreatedGroup = new GroupedItems(index, Indexer, ItemComparer);
                    _itemsIndex.Add(index, newCreatedGroup);
                    var processed = false;
                    if (Items.Count != 0)
                    {
                        for (int i = 0; i < Items.Count; i++)
                        {
                            if (GroupComparer.Compare(Items[i].Title, index) >= 0)
                            {
                                Items.Insert(i, newCreatedGroup);
                                processed = true;
                                break;
                            }
                        }
                    }

                    if (!processed)
                    {
                        Items.Add(newCreatedGroup);
                    }

                    // Add item
                    newCreatedGroup.Add(item);
                }

                // Add backend item (optional)
                if (!ignoreBackendFlatList)
                {
                    _entityCopies.Add(item);
                }

                // Notify change if required (precondition: IsEmpty == true)
                if (IsEmpty)
                {
                    IsEmpty = false;
                }
            }
        }
Exemplo n.º 9
0
        public async void RequestCollectionChange(CommonViewItemModel newItem, CommonViewItemModel oldItem)
        {
            if (!Dispatcher.HasThreadAccess)
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => RequestCollectionChange(newItem, oldItem));

                return;
            }

            var index = ViewItems.IndexOf(oldItem);

            if (index < 0)
            {
                return;
            }
            ViewItems[index] = newItem;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Load album data from database.
        /// </summary>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>Processed albums.</returns>
        private async Task LoadAlbumData(CancellationToken cancellationToken)
        {
            if (GlobalLibraryCache.CachedDbAlbum == null)
            {
                await GlobalLibraryCache.LoadAlbumAsync();

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }
            }
            foreach (var item in GlobalLibraryCache.CachedDbAlbum)
            {
                var e = CommonViewItemModel.CreateFromDbAlbumAndCheck(item);
                GroupedItems.Add(e);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Load file data from database.
        /// </summary>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>Processed files.</returns>
        public async Task <IEnumerable <CommonViewItemModel> > LoadSongData(CancellationToken cancellationToken)
        {
            if (GlobalLibraryCache.CachedDbMediaFile == null)
            {
                await GlobalLibraryCache.LoadMediaAsync();
            }

            var result = new List <CommonViewItemModel>(GlobalLibraryCache.CachedDbMediaFile.Length);

            foreach (var item in GlobalLibraryCache.CachedDbMediaFile)
            {
                var e = new CommonViewItemModel(item);
                GroupedItems.Add(e);
                result.Add(e);
            }

            return(result);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Get item index with indexer-specific logic for grouping.
        /// </summary>
        /// <param name="item">The item to be indexed.</param>
        /// <returns>Item's index.</returns>
        /// <seealso cref="GetIndex"/>
        public string GetIndexForGroup(CommonViewItemModel item)
        {
            var ret = CommonSharedStrings.UnknownIndex;

            if (item != null)
            {
                switch (item.Type)
                {
                case CommonItemType.Album:
                    ret = CommonSharedStrings.DefaultAlbumName;
                    break;

                case CommonItemType.Artist:
                    ret = CommonSharedStrings.DefaultArtistName;
                    break;
                }
            }

            return(ret);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Get item index with indexer-specific logic for grouping.
 /// </summary>
 /// <param name="item">The item to be indexed.</param>
 /// <returns>Item's index.</returns>
 /// <seealso cref="GetIndex"/>
 public string GetIndex(CommonViewItemModel item)
 {
     return($"{item?.File?.DiscNumber}.{item?.File?.TrackNumber}");
 }
Exemplo n.º 14
0
 /// <summary>
 /// Get item index with indexer-specific logic.
 /// </summary>
 /// <param name="item">The item to be indexed.</param>
 /// <returns>Item's index.</returns>
 /// <seealso cref="GetIndexForGroup"/>
 public string GetIndexForGroup(CommonViewItemModel item)
 {
     return(!string.IsNullOrWhiteSpace(item?.File?.Album) ? item.File.Album : CommonSharedStrings.UnknownIndex);
 }
Exemplo n.º 15
0
 public string GetIndex(CommonViewItemModel item)
 {
     return(item.Title);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Get item index with indexer-specific logic.
 /// </summary>
 /// <param name="item">The item to be indexed.</param>
 /// <returns>Item's index.</returns>
 /// <seealso cref="GetIndexForGroup"/>
 public string GetIndex(CommonViewItemModel item)
 {
     // We do not that for full-text grouping, so return all
     return(!string.IsNullOrEmpty(item?.Title) ? item.Title : CommonSharedStrings.UnknownIndex);
 }
Exemplo n.º 17
0
 public string GetIndexForGroup(CommonViewItemModel item)
 {
     return(_groupName);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Get item index with indexer-specific logic for grouping.
 /// </summary>
 /// <param name="item">The item to be indexed.</param>
 /// <returns>Item's index.</returns>
 /// <seealso cref="GetIndex"/>
 public string GetIndexForGroup(CommonViewItemModel item)
 {
     return(!string.IsNullOrEmpty(item?.Title) ? item.Title.Substring(0, 1).ToUpper() : CommonSharedStrings.UnknownIndex);
 }
Exemplo n.º 19
0
 public string GetIndex(CommonViewItemModel item)
 {
     return(item?.DatabaseItemAddedDate.ToUnixTimeSeconds().ToString() ?? "0");
 }
Exemplo n.º 20
0
 public string GetIndexForGroup(CommonViewItemModel item)
 {
     return(item?.DatabaseItemAddedDate.ToString("yyyy-MM-dd") ?? CommonSharedStrings.UnknownIndex);
 }
Exemplo n.º 21
0
 /// <summary>
 /// Get item index with indexer-specific logic.
 /// </summary>
 /// <param name="item">The item to be indexed.</param>
 /// <returns>Item's index.</returns>
 /// <seealso cref="GetIndexForGroup"/>
 public string GetIndex(CommonViewItemModel item)
 {
     return(!string.IsNullOrEmpty(item?.Title) ? item.Title : CommonSharedStrings.UnknownIndex);
 }
Exemplo n.º 22
0
 /// <summary>
 /// Get item index with indexer-specific logic.
 /// </summary>
 /// <param name="item">The item to be indexed.</param>
 /// <returns>Item's index.</returns>
 /// <seealso cref="GetIndexForGroup"/>
 public string GetIndex(CommonViewItemModel item)
 {
     // Inner content will still follow alphabet-based sort.
     return(!string.IsNullOrEmpty(item?.Title) ? item.Title : CommonSharedStrings.UnknownIndex);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Index, group, sort and insert an entity to the collection.
 /// If group doesn't exist, it will be created and sorted.
 /// </summary>
 /// <param name="item">The item to insert into.</param>
 public void Add(CommonViewItemModel item)
 {
     AddInternal(item, false);
 }