From: jjie.choi Date: Wed, 7 Jun 2017 08:08:40 +0000 (+0900) Subject: Implement MusicTab sortby X-Git-Tag: accepted/tizen/unified/20170811.133302~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a5f56fc91619a163b0738d3a7fbf0588eb08ced5;p=profile%2Ftv%2Fapps%2Fdotnet%2Fmediahub.git Implement MusicTab sortby Change-Id: I61d6a7aecceefee560d17e7a1e668e2a96467f50 Signed-off-by: jjie.choi --- diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs index fee6c63..3d21b0b 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs @@ -162,6 +162,20 @@ namespace TVMediaHub.Tizen.Models newGroupFlag = true; newTitle = mediaInformationEx.MediaContentInformation.MediaType.ToString(); } + break; + case SortOption.Album: + if (lastGroupItem == null || lastGroupItem.Title != (mediaInformationEx.MediaContentInformation as AudioInformation).Album) + { + newGroupFlag = true; + newTitle = (mediaInformationEx.MediaContentInformation as AudioInformation).Album.ToString(); + } + break; + case SortOption.Artist: + if (lastGroupItem == null || lastGroupItem.Title != (mediaInformationEx.MediaContentInformation as AudioInformation).Artist) + { + newGroupFlag = true; + newTitle = (mediaInformationEx.MediaContentInformation as AudioInformation).Artist.ToString(); + } break; default: @@ -256,6 +270,12 @@ namespace TVMediaHub.Tizen.Models case SortOption.Type: contentFilter.OrderKey = "MEDIA_TYPE"; break; + case SortOption.Album: + contentFilter.OrderKey = "MEDIA_ALBUM"; + break; + case SortOption.Artist: + contentFilter.OrderKey = "MEDIA_ARTIST"; + break; default: throw new System.ArgumentException("Invalid sorting option."); } @@ -352,6 +372,12 @@ namespace TVMediaHub.Tizen.Models case SortOption.Type: contentFilter.OrderKey = "MEDIA_TYPE"; break; + case SortOption.Album: + contentFilter.OrderKey = "MEDIA_ALBUM"; + break; + case SortOption.Artist: + contentFilter.OrderKey = "MEDIA_ARTIST"; + break; default: throw new System.ArgumentException("Invalid sorting option."); } diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs index fafed95..f05af0c 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs @@ -17,8 +17,11 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; +using System.Threading; +using System.Windows.Input; using TVMediaHub.Tizen.Models; using TVMediaHub.Tizen.Utils; +using Xamarin.Forms; namespace TVMediaHub.Tizen.ViewModels { @@ -32,9 +35,34 @@ namespace TVMediaHub.Tizen.ViewModels /// public ObservableCollection MusicList { get; set; } + /// + /// Gets or sets the SortOption list + /// + public IEnumerable SortOptions { get; set; } + + /// + /// Gets or sets the Option list + /// + public IEnumerable OptionList { get; set; } + + /// + /// A dictionary list of the source and storage id + /// + private Dictionary sourcePairList; + + /// + /// A command for executing when SortOption is changed + /// + public ICommand ChangeSortOptionCommand { get; set; } + private SortOption option = SortOption.Title; /// + /// A command for executing to get informations + /// + public ICommand GetInformationsCommand { get; set; } + + /// /// An event that is occurred when property of ViewModel is changed /// public event PropertyChangedEventHandler PropertyChanged; @@ -58,6 +86,9 @@ namespace TVMediaHub.Tizen.ViewModels public MusicTabViewModel() { MusicList = new ObservableCollection(); + InitializeFooterItemsSource(); + InitializeCommands(); + OnPropertyChanged("MusicList"); MediaHubImpl.GetInstance.MusicProviderInstance.SetContentUpdatedEventListener((s, e) => { @@ -84,9 +115,67 @@ namespace TVMediaHub.Tizen.ViewModels } } - public void TestRead() + /// + /// A method for initializing the SourceList, SortOptionList and OptionList + /// + private void InitializeFooterItemsSource() { - ReadMusicList(option); + var list = new List + { + "SONG", + "ALBUM", + "ARTIST", + "GENRE", + }; + SortOptions = list; + OnPropertyChanged("SortOptions"); + + list = new List + { + "DETAIL INFO", + "DELETE" + }; + OptionList = list; + OnPropertyChanged("OptionList"); + } + + /// + /// A method for initializing commands that are used in Image tab + /// + private void InitializeCommands() + { + ChangeSortOptionCommand = new Command((opt) => + { + var optionString = opt.ToLower(); + switch (optionString) + { + case "song": + ReadMusicList(SortOption.Title); + option = SortOption.Title; + break; + case "album": + ReadMusicList(SortOption.Album); + option = SortOption.Album; + break; + case "artist": + ReadMusicList(SortOption.Artist); + option = SortOption.Artist; + break; + case "genre": + ReadMusicList(SortOption.Genre); + option = SortOption.Genre; + break; + } + }); + + GetInformationsCommand = new Command(() => + { + SynchronizationContext.Current.Post((o) => + { + ReadMusicList(option); + }, ""); + }); + OnPropertyChanged("ChangeSortOptionCommand"); } } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs index 731d840..8ae6b99 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs @@ -235,11 +235,6 @@ namespace TVMediaHub.Tizen.Views InitializeFooter(); ItemsSource.CollectionChanged += ItemsSourceCollectionChanged; PropertyChanged += ImageTabPropertyChanged; - - SynchronizationContext.Current.Post((o) => - { - InitializePage(); - }, ""); } /// diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/MusicItem.xaml b/TVMediaHub/TVMediaHub.Tizen/Views/MusicItem.xaml index 174bf6e..9404527 100644 --- a/TVMediaHub/TVMediaHub.Tizen/Views/MusicItem.xaml +++ b/TVMediaHub/TVMediaHub.Tizen/Views/MusicItem.xaml @@ -24,12 +24,15 @@ public partial class MusicTab : ContentPageEx { + /// + /// The flag whether content is ready + /// + private bool IsContentReady = false; /// /// Identifies the ItemsSource bindable property @@ -61,6 +68,21 @@ namespace TVMediaHub.Tizen.Views get { return (ICommand)GetValue(ChangeSortOptionCommandProperty); } set { SetValue(ChangeSortOptionCommandProperty, value); } } + + /// + /// Identifies the GetInformationsCommand bindable property + /// + public static readonly BindableProperty GetInformationsCommandProperty = BindableProperty.Create("GetInformationsCommand", typeof(ICommand), typeof(MusicTab), default(ICommand)); + + /// + /// Gets or sets GetInformationsCommand + /// + public ICommand GetInformationsCommand + { + get { return (ICommand)GetValue(GetInformationsCommandProperty); } + set { SetValue(GetInformationsCommandProperty, value); } + } + /// /// A constructor /// Initializes the size of the items that are used in Music tab @@ -74,12 +96,8 @@ namespace TVMediaHub.Tizen.Views InitializeFooter(); ItemsSource.CollectionChanged += ItemsSourceCollectionChanged; - - MusicTabViewModelLocator.ViewModel.TestRead(); - // TODO : for the test } - /// /// A method for initializing the size of the items that are used in Music tab /// @@ -119,6 +137,11 @@ namespace TVMediaHub.Tizen.Views /// protected override void InitializePage() { + if (IsContentReady == false) + { + GetInformationsCommand?.Execute(""); + IsContentReady = true; + } } /// @@ -142,6 +165,7 @@ namespace TVMediaHub.Tizen.Views { } + /// /// Occurs when an item is added, removed, changed, moved, or the entire list is refreshed. /// @@ -149,7 +173,7 @@ namespace TVMediaHub.Tizen.Views /// Information about the event private void ItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { - if (e.Action.ToString().Equals("Add")) + if (e.Action.ToString().Equals(NotifyCollectionChangedAction.Add.ToString())) { if (MusicNoContents.IsVisible) { @@ -162,6 +186,15 @@ namespace TVMediaHub.Tizen.Views groupView.BindingContext = groupItem; MusicContentView.Children.Add(groupView); } + else if (e.Action.ToString().Equals(NotifyCollectionChangedAction.Reset.ToString())) + { + MusicContentView.Children.Clear(); + if (!MusicNoContents.IsVisible) + { + MusicTabScrollView.IsVisible = false; + MusicNoContents.IsVisible = true; + } + } }