Implement MusicTab sortby
authorjjie.choi <jjie.choi@samsung.com>
Wed, 7 Jun 2017 08:08:40 +0000 (17:08 +0900)
committerJiHee Choi <jjie.choi@samsung.com>
Wed, 7 Jun 2017 09:15:47 +0000 (18:15 +0900)
Change-Id: I61d6a7aecceefee560d17e7a1e668e2a96467f50
Signed-off-by: jjie.choi <jjie.choi@samsung.com>
TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs
TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs
TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/MusicItem.xaml
TVMediaHub/TVMediaHub.Tizen/Views/MusicItem.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/MusicTab.xaml
TVMediaHub/TVMediaHub.Tizen/Views/MusicTab.xaml.cs

index fee6c63..3d21b0b 100755 (executable)
@@ -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.");
             }
index fafed95..f05af0c 100755 (executable)
 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
         /// </summary>
         public ObservableCollection<GroupItem> MusicList { get; set; }
 
+        /// <summary>
+        /// Gets or sets the SortOption list
+        /// </summary>
+        public IEnumerable<string> SortOptions { get; set; }
+
+        /// <summary>
+        /// Gets or sets the Option list
+        /// </summary>
+        public IEnumerable<string> OptionList { get; set; }
+
+        /// <summary>
+        /// A dictionary list of the source and storage id
+        /// </summary>
+        private Dictionary<string, string> sourcePairList;
+
+        /// <summary>
+        /// A command for executing when SortOption is changed
+        /// </summary>
+        public ICommand ChangeSortOptionCommand { get; set; }
+
         private SortOption option = SortOption.Title;
 
         /// <summary>
+        /// A command for executing to get informations
+        /// </summary>
+        public ICommand GetInformationsCommand { get; set; }
+
+        /// <summary>
         /// An event that is occurred when property of ViewModel is changed
         /// </summary>
         public event PropertyChangedEventHandler PropertyChanged;
@@ -58,6 +86,9 @@ namespace TVMediaHub.Tizen.ViewModels
         public MusicTabViewModel()
         {
             MusicList = new ObservableCollection<GroupItem>();
+            InitializeFooterItemsSource();
+            InitializeCommands();
+
             OnPropertyChanged("MusicList");
             MediaHubImpl.GetInstance.MusicProviderInstance.SetContentUpdatedEventListener((s, e) =>
             {
@@ -84,9 +115,67 @@ namespace TVMediaHub.Tizen.ViewModels
             }
         }
 
-        public void TestRead()
+        /// <summary>
+        /// A method for initializing the SourceList, SortOptionList and OptionList
+        /// </summary>
+        private void InitializeFooterItemsSource()
         {
-            ReadMusicList(option);
+            var list = new List<string>
+            {
+                "SONG",
+                "ALBUM",
+                "ARTIST",
+                "GENRE",
+            };
+            SortOptions = list;
+            OnPropertyChanged("SortOptions");
+
+            list = new List<string>
+            {
+                "DETAIL INFO",
+                "DELETE"
+            };
+            OptionList = list;
+            OnPropertyChanged("OptionList");
+        }
+
+        /// <summary>
+        /// A method for initializing commands that are used in Image tab
+        /// </summary>
+        private void InitializeCommands()
+        {
+            ChangeSortOptionCommand = new Command<string>((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");
         }
     }
 }
index 731d840..8ae6b99 100755 (executable)
@@ -235,11 +235,6 @@ namespace TVMediaHub.Tizen.Views
             InitializeFooter();
             ItemsSource.CollectionChanged += ItemsSourceCollectionChanged;
             PropertyChanged += ImageTabPropertyChanged;
-
-            SynchronizationContext.Current.Post((o) =>
-            {
-                InitializePage();
-            }, "");
         }
 
         /// <summary>
index 174bf6e..9404527 100644 (file)
         <Label x:Name="SongTitle"
                Grid.Row="0"
                Grid.Column="1"
+               LineBreakMode="TailTruncation"
                Text="{Binding ContentName}"/>
         <Label x:Name="Artist"
                Grid.Row="1"
-               Grid.Column="1"/>
+               Grid.Column="1"
+               LineBreakMode="TailTruncation"/>
         <Label x:Name="AlbumTitle"
                Grid.Row="2"
-               Grid.Column="1"/>
+               Grid.Column="1"
+               LineBreakMode="TailTruncation"/>
     </Grid>
 </RelativeLayout>
\ No newline at end of file
index a35021e..840f471 100644 (file)
@@ -72,8 +72,11 @@ namespace TVMediaHub.Tizen.Views
             HeightRequest = SizeUtils.GetHeightSize(134);
             AlbumCover.WidthRequest = SizeUtils.GetWidthSize(134);
             AlbumCover.HeightRequest = SizeUtils.GetHeightSize(134);
+            SongTitle.WidthRequest = SizeUtils.GetWidthSize(266);
             SongTitle.FontSize = SizeUtils.GetFontSize(20);
+            Artist.WidthRequest = SizeUtils.GetWidthSize(266);
             Artist.FontSize = SizeUtils.GetFontSize(17);
+            AlbumTitle.WidthRequest = SizeUtils.GetWidthSize(266);
             AlbumTitle.FontSize = SizeUtils.GetFontSize(17);
         }
 
index 1af1646..78f5d61 100755 (executable)
@@ -6,6 +6,7 @@
                   xmlns:Views="clr-namespace:TVMediaHub.Tizen.Views"
                   Title="Music"
                   ChangeSortOptionCommand="{Binding ChangeSortOptionCommand}"
+                  GetInformationsCommand="{Binding GetInformationsCommand}"
                   ItemsSource="{Binding MusicList}">
     <!-- TODO : Fix to Guide  -->
 
                     RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}">
         <RelativeLayout RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"
                         RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}">
+            <Views:FooterDeleteStatus x:Name="FooterDelete" IsVisible="False"
+                                      RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"
+                                      RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
+                                      SelectedCount="{Binding SelectedCount}"/>
             <Views:FooterNormalStatus x:Name="FooterNormal"  IsVisible="True"
                                       IsFooterEnabled="True"
                                       RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"
@@ -22,7 +27,7 @@
                                       OptionList="{Binding OptionList}"/>
         </RelativeLayout>
         <ScrollView x:Name="MusicTabScrollView"
-                    RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"
+                    RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.855}"
                     RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
                     Orientation="Horizontal" IsVisible="False">
             <StackLayout x:Name="MusicContentView"
index 0aaa5cd..69ff533 100755 (executable)
@@ -17,6 +17,8 @@
 using System;
 using System.Collections.ObjectModel;
 using System.Collections.Specialized;
+using System.ComponentModel;
+using System.Threading;
 using System.Windows.Input;
 using TVMediaHub.Tizen.Controls;
 using TVMediaHub.Tizen.DataModels;
@@ -28,11 +30,16 @@ using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
 
 namespace TVMediaHub.Tizen.Views
 {
+
     /// <summary>
     /// A custom ContentPage for displaying Music tab
     /// </summary>
     public partial class MusicTab : ContentPageEx
     {
+        /// <summary>
+        /// The flag whether content is ready
+        /// </summary>
+        private bool IsContentReady = false;
 
         /// <summary>
         /// Identifies the ItemsSource bindable property
@@ -61,6 +68,21 @@ namespace TVMediaHub.Tizen.Views
             get { return (ICommand)GetValue(ChangeSortOptionCommandProperty); }
             set { SetValue(ChangeSortOptionCommandProperty, value); }
         }
+
+        /// <summary>
+        /// Identifies the GetInformationsCommand bindable property
+        /// </summary>
+        public static readonly BindableProperty GetInformationsCommandProperty = BindableProperty.Create("GetInformationsCommand", typeof(ICommand), typeof(MusicTab), default(ICommand));
+
+        /// <summary>
+        /// Gets or sets GetInformationsCommand
+        /// </summary>
+        public ICommand GetInformationsCommand
+        {
+            get { return (ICommand)GetValue(GetInformationsCommandProperty); }
+            set { SetValue(GetInformationsCommandProperty, value); }
+        }
+
         /// <summary>
         /// 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
         }
 
-
         /// <summary>
         /// A method for initializing the size of the items that are used in Music tab
         /// </summary>
@@ -119,6 +137,11 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         protected override void InitializePage()
         {
+            if (IsContentReady == false)
+            {
+                GetInformationsCommand?.Execute("");
+                IsContentReady = true;
+            }
         }
 
         /// <summary>
@@ -142,6 +165,7 @@ namespace TVMediaHub.Tizen.Views
         {
         }
 
+
         /// <summary>
         /// Occurs when an item is added, removed, changed, moved, or the entire list is refreshed.
         /// </summary>
@@ -149,7 +173,7 @@ namespace TVMediaHub.Tizen.Views
         /// <param name="e">Information about the event</param>
         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;
+                }
+            }
 
         }