Implement viewmodel for music tab
authorGeunsun, Lee <gs86.lee@samsung.com>
Mon, 5 Jun 2017 04:02:48 +0000 (13:02 +0900)
committerGeunsun, Lee <gs86.lee@samsung.com>
Mon, 5 Jun 2017 04:13:51 +0000 (13:13 +0900)
Change-Id: Iba23c8e3308cc11a7184e90d45832ba17e12b6a1

TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs
TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs

index 370525a..25b5a5b 100755 (executable)
@@ -37,7 +37,7 @@ namespace TVMediaHub.Tizen.Models
         /// <returns>A condition string</returns>
         protected override string GetConditionStringForSelection()
         {
-            return "(MEDIA_TYPE=8)";
+            return "(MEDIA_TYPE=3)";
         }
 
         public override void SetContentUpdatedEventListener(EventHandler<ContentUpdatedEventArgs> listener)
index ba505da..2709d99 100755 (executable)
  * limitations under the License.
  */
 
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using TVMediaHub.Tizen.Models;
+using TVMediaHub.Tizen.Utils;
+
 namespace TVMediaHub.Tizen.ViewModels
 {
     /// <summary>
     /// A class for ViewModel of Music tab
     /// </summary>
-    class MusicTabViewModel
+    public class MusicTabViewModel : INotifyPropertyChanged
     {
+        /// <summary>
+        /// Gets or sets the list of music group item
+        /// </summary>
+        public ObservableCollection<GroupItem> MusicList { get; set; }
+
+        private SortOption option = SortOption.Title;
+
+        /// <summary>
+        /// An event that is occurred when property of ViewModel is changed
+        /// </summary>
+        public event PropertyChangedEventHandler PropertyChanged;
+
+        /// <summary>
+        /// A method for invoking PropertyChanged event
+        /// </summary>
+        /// <param name="name">The name of property</param>
+        public void OnPropertyChanged(string name)
+        {
+            PropertyChangedEventHandler handler = PropertyChanged;
+            if (handler != null)
+            {
+                handler(this, new PropertyChangedEventArgs(name));
+            }
+        }
+
+        /// <summary>
+        /// A constructor
+        /// </summary>
+        public MusicTabViewModel()
+        {
+            MusicList = new ObservableCollection<GroupItem>();
+            OnPropertyChanged("MusicList");
+            MediaHubImpl.GetInstance.MusicProviderInstance.SetContentUpdatedEventListener((s, e) =>
+            {
+                DbgPort.D("Content updated");
+            });
+        }
+
+        /// <summary>
+        /// A method for reading music contents through MusicProvider and updating MusicList
+        /// </summary>
+        /// <param name="option">A current sort option</param>
+        private async void ReadMusicList(SortOption option)
+        {
+            MusicList.Clear();
+            IEnumerable<GroupItem> templist = await MediaHubImpl.GetInstance.MusicProviderInstance.ReadAsync(option);
+            foreach (var group in templist)
+            {
+                await MediaHubImpl.GetInstance.MusicProviderInstance.CheckThumbnail(group.Contents);
+            }
+
+            foreach (var group in templist)
+            {
+                MusicList.Add(group);
+            }
+        }
     }
 }