/// <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; } }
/// <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; } } }
/// <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); }
public static string GetItemDateYearString(CommonViewItemModel item) { var dateString = string.Empty; if (!string.IsNullOrEmpty(item.ReleaseDate)) { dateString = GetItemDateYearString(item.ReleaseDate); } return(dateString); }
/// <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())); }
/// <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); } }
/// <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; } } }
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; }
/// <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); } }
/// <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); }
/// <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); }
/// <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}"); }
/// <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); }
public string GetIndex(CommonViewItemModel item) { return(item.Title); }
/// <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); }
public string GetIndexForGroup(CommonViewItemModel item) { return(_groupName); }
/// <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); }
public string GetIndex(CommonViewItemModel item) { return(item?.DatabaseItemAddedDate.ToUnixTimeSeconds().ToString() ?? "0"); }
public string GetIndexForGroup(CommonViewItemModel item) { return(item?.DatabaseItemAddedDate.ToString("yyyy-MM-dd") ?? CommonSharedStrings.UnknownIndex); }
/// <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); }
/// <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); }
/// <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); }