(WIP) Implements ContentUpdated event handler
authorHyerim Kim <rimi.kim@samsung.com>
Thu, 25 May 2017 12:25:00 +0000 (21:25 +0900)
committerHyerim Kim <rimi.kim@samsung.com>
Fri, 26 May 2017 06:37:27 +0000 (15:37 +0900)
Implements SelectAll button actions

Change-Id: I56d0029aa23d6b1ec2ba48a1aefcae16e49a2a78
Signed-off-by: Hyerim Kim <rimi.kim@samsung.com>
13 files changed:
TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs
TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs
TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs
TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs
TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs
TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs
TVMediaHub/TVMediaHub.Tizen/Views/FooterDeleteStatus.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs

index 6563a37..a2fcaec 100755 (executable)
@@ -49,10 +49,7 @@ namespace TVMediaHub.Tizen.Models
         /// <returns>A condition string</returns>
         abstract protected string GetConditionStringForSelection();
 
-        /// <summary>
-        /// An event handler for update event
-        /// </summary>
-        private EventHandler UpdateListeners;
+        abstract public void SetContentUpdatedEventListener(EventHandler<ContentUpdatedEventArgs> listener);
 
         private string TAG = "MediaHub";
 
@@ -407,7 +404,6 @@ namespace TVMediaHub.Tizen.Models
             try
             {
                 ContentManager.Database.Update(media);
-                UpdateListeners?.Invoke(this, EventArgs.Empty);
             }
             catch (Exception exception)
             {
@@ -416,14 +412,5 @@ namespace TVMediaHub.Tizen.Models
 
             return true;
         }
-
-        /// <summary>
-        /// A method for adding update event handler
-        /// </summary>
-        /// <param name="listener">An event handler to be executed</param>
-        void SetUpdateListener(EventHandler listener)
-        {
-            UpdateListeners += listener;
-        }
     }
 }
index 5d5d473..1993402 100755 (executable)
  * limitations under the License.
  */
 
+using System;
+using Tizen.Content.MediaContent;
+using TVMediaHub.Tizen.Utils;
+
 namespace TVMediaHub.Tizen.Models
 {
     /// <summary>
@@ -36,5 +40,10 @@ namespace TVMediaHub.Tizen.Models
         {
             return "(MEDIA_TYPE=0) AND (MEDIA_MIME_TYPE LIKE 'image%') AND NOT (MEDIA_PATH LIKE '%.tn')";
         }
+
+        public override void SetContentUpdatedEventListener(EventHandler<ContentUpdatedEventArgs> listener)
+        {
+            ContentDatabase.ContentUpdated += listener;
+        }
     }
 }
index fc94ef6..370525a 100755 (executable)
@@ -14,6 +14,9 @@
  * limitations under the License.
  */
 
+using System;
+using Tizen.Content.MediaContent;
+
 namespace TVMediaHub.Tizen.Models
 {
     /// <summary>
@@ -36,5 +39,10 @@ namespace TVMediaHub.Tizen.Models
         {
             return "(MEDIA_TYPE=8)";
         }
+
+        public override void SetContentUpdatedEventListener(EventHandler<ContentUpdatedEventArgs> listener)
+        {
+            ContentDatabase.ContentUpdated += listener;
+        }
     }
 }
index ba7ea3b..6543a1f 100755 (executable)
@@ -86,5 +86,10 @@ namespace TVMediaHub.Tizen.Models
             DbgPort.D("PlayedAt : " + videoContent.PlayedAt.ToString());
             ContentManager.Database.Update(videoContent);
         }
+
+        public override void SetContentUpdatedEventListener(EventHandler<ContentUpdatedEventArgs> listener)
+        {
+            ContentDatabase.ContentUpdated += listener;
+        }
     }
 }
\ No newline at end of file
index 7c01d65..8981e87 100755 (executable)
@@ -47,6 +47,8 @@ namespace TVMediaHub.Tizen.ViewModels
         /// </summary>
         private int displayingImageIndex;
 
+        private SortOption option = SortOption.Title;
+
         /// <summary>
         /// Gets or sets the displayingImageIndex
         /// </summary>
@@ -262,6 +264,16 @@ namespace TVMediaHub.Tizen.ViewModels
             ImageList = new ObservableCollection<GroupItem>();
             SelectedList = new List<MediaInformation>();
             OnPropertyChanged("ImageList");
+            MediaHubImpl.GetInstance.ImageProviderInstance.SetContentUpdatedEventListener((sender, arg) =>
+            {
+                DbgPort.D("Content updated");
+                /*
+                if (arg.UpdateType.Equals(MediaContentDBUpdateType.Update))
+                {
+                    GetInformationsCommand?.Execute("");
+                }
+                */
+            });
         }
 
         /// <summary>
@@ -335,18 +347,25 @@ namespace TVMediaHub.Tizen.ViewModels
                 }
             });
 
-            SelectAllContentCommand = new Command(() =>
+            SelectAllContentCommand = new Command<bool>((IsSelectedAll) =>
             {
-                foreach (var group in ImageList)
+                if (IsSelectedAll)
                 {
-                    foreach (var info in group.Contents)
+                    foreach (var group in ImageList)
                     {
-                        if (!SelectedList.Contains(info.Information))
+                        foreach (var info in group.Contents)
                         {
-                            SelectedList.Add(info.Information);
+                            if (!SelectedList.Contains(info.Information))
+                            {
+                                SelectedList.Add(info.Information);
+                            }
                         }
                     }
                 }
+                else
+                {
+                    SelectedList.Clear();
+                }
 
                 OnPropertyChanged("SelectedCount");
             });
@@ -369,17 +388,20 @@ namespace TVMediaHub.Tizen.ViewModels
 
             ChangeSortOptionCommand = new Command<string>((opt) =>
             {
-                var option = opt.ToLower();
-                switch (option)
+                var optionString = opt.ToLower();
+                switch (optionString)
                 {
                     case "name":
                         ReadImageList(SortOption.Title);
+                        option = SortOption.Title;
                         break;
                     case "event":
                         ReadImageList(SortOption.Date);
+                        option = SortOption.Date;
                         break;
                     case "file format":
                         ReadImageList(SortOption.Type);
+                        option = SortOption.Type;
                         break;
                 }
             });
@@ -388,7 +410,7 @@ namespace TVMediaHub.Tizen.ViewModels
             {
                 SynchronizationContext.Current.Post((o) =>
                 {
-                    ReadImageList(SortOption.Title);
+                    ReadImageList(option);
                 }, "");
             });
 
index cf1806d..745ccd2 100755 (executable)
@@ -110,6 +110,8 @@ namespace TVMediaHub.Tizen.ViewModels
 
         private bool isDeleteStatus;
 
+        private SortOption option = SortOption.Title;
+
         /// <summary>
         /// Gets or sets the MediaInformation of current video
         /// </summary>
@@ -162,6 +164,16 @@ namespace TVMediaHub.Tizen.ViewModels
             VideoList = new ObservableCollection<GroupItem>();
             SelectedList = new List<MediaInformation>();
             OnPropertyChanged("VideoList");
+            MediaHubImpl.GetInstance.VideoProviderInstance.SetContentUpdatedEventListener((sender, arg) =>
+            {
+                DbgPort.D("Content updated");
+                /*
+                if (arg.UpdateType.Equals(MediaContentDBUpdateType.Update))
+                {
+                    GetInformationsCommand?.Execute("");
+                }
+                */
+            });
         }
 
         /// <summary>
@@ -203,17 +215,20 @@ namespace TVMediaHub.Tizen.ViewModels
             });
             ChangeSortOptionCommand = new Command<string>((opt) =>
             {
-                var option = opt.ToLower();
-                switch (option)
+                var optionString = opt.ToLower();
+                switch (optionString)
                 {
                     case "date":
                         ReadVideoList(SortOption.Date);
+                        option = SortOption.Date;
                         break;
                     case "genre":
                         ReadVideoList(SortOption.Genre);
+                        option = SortOption.Genre;
                         break;
                     case "name":
                         ReadVideoList(SortOption.Title);
+                        option = SortOption.Title;
                         break;
                 }
             });
@@ -221,7 +236,7 @@ namespace TVMediaHub.Tizen.ViewModels
             {
                 SynchronizationContext.Current.Post((o) =>
                 {
-                    ReadVideoList(SortOption.Title);
+                    ReadVideoList(option);
                 }, "");
             });
 
@@ -246,18 +261,25 @@ namespace TVMediaHub.Tizen.ViewModels
                 }
             });
 
-            SelectAllContentCommand = new Command(() =>
+            SelectAllContentCommand = new Command<bool>((IsSelectedAll) =>
             {
-                foreach (var group in VideoList)
+                if (IsSelectedAll)
                 {
-                    foreach (var info in group.Contents)
+                    foreach (var group in VideoList)
                     {
-                        if (!SelectedList.Contains(info.Information))
+                        foreach (var info in group.Contents)
                         {
-                            SelectedList.Add(info.Information);
+                            if (!SelectedList.Contains(info.Information))
+                            {
+                                SelectedList.Add(info.Information);
+                            }
                         }
                     }
                 }
+                else
+                {
+                    SelectedList.Clear();
+                }
 
                 OnPropertyChanged("SelectedCount");
             });
index 38f9369..1422f39 100755 (executable)
@@ -33,6 +33,11 @@ namespace TVMediaHub.Tizen.Views
         public EventHandler CancelButtonEvent;
 
         /// <summary>
+        /// The flag that whether all contents are selected or not
+        /// </summary>
+        public bool IsSelectedAll { get; set; }
+
+        /// <summary>
         /// Identifies the SelectedCount bindable property
         /// </summary>
         public static readonly BindableProperty SelectedCountProperty = BindableProperty.Create("SelectedCount", typeof(int), typeof(FooterDeleteStatus), 0);
@@ -93,8 +98,21 @@ namespace TVMediaHub.Tizen.Views
         public FooterDeleteStatus()
         {
             InitializeComponent();
+            IsSelectedAll = false;
+
             SelectAllButton.Clicked += (s, e) =>
             {
+                IsSelectedAll = !IsSelectedAll;
+
+                if (IsSelectedAll)
+                {
+                    SelectAllButton.Text = "Unselect All";
+                }
+                else
+                {
+                    SelectAllButton.Text = "Select All";
+                }
+
                 SelecteAllButtonEvent?.Invoke(s, e);
             };
             OkButton.Clicked += (s, e) =>
index 546273e..94990c9 100755 (executable)
@@ -65,6 +65,7 @@ namespace TVMediaHub.Tizen.Views
         public List<Button> LeftFocusList { get; protected set; }
         public List<Button> RightFocusList { get; protected set; }
         public List<KeyValuePair<double, Button>> BottomFocusList { get; protected set; }
+        public List<ImageItem> ImageItemList { get; set; }
 
         public EventHandler<GroupItemFocusEventArgs> GroupItemFocused;
 
@@ -93,6 +94,7 @@ namespace TVMediaHub.Tizen.Views
             LeftFocusList = new List<Button>();
             RightFocusList = new List<Button>();
             BottomFocusList = new List<KeyValuePair<double, Button>>();
+            ImageItemList = new List<ImageItem>();
 
             GroupTitle.TextColor = Color.FromRgba(255, 255, 255, 31);
 
@@ -175,11 +177,13 @@ namespace TVMediaHub.Tizen.Views
             {
                 var index = 0;
                 ChildrenFocusList.Clear();
+                ImageItemList.Clear();
                 foreach (var item in ItemsSource)
                 {
                     var view = new ImageItem();
                     ChildrenFocusList.Add(view.GetFocusArea());
                     view.BindingContext = item;
+                    ImageItemList.Add(view);
                     view.OnFocusedEventHandler += (se, ev) =>
                     {
                         GroupItemFocused?.Invoke(view, new GroupItemFocusEventArgs(X + view.X));
index 1ebfc27..c98b888 100755 (executable)
@@ -256,6 +256,22 @@ namespace TVMediaHub.Tizen.Views
             }
         }
 
+        public void UpdateViewSelectAll(bool isSelectedAll)
+        {
+            if (!isSelectedAll)
+            {
+                ImgCheckDimmed.FadeTo(0.0, 167);
+                ImgCheck.FadeTo(0.0, 167);
+                CurStatus = ItemStatus.NORMAL;
+            }
+            else
+            {
+                ImgCheckDimmed.FadeTo(0.75, 167);
+                ImgCheck.FadeTo(0.99, 167);
+                CurStatus = ItemStatus.SELECTED;
+            }
+        }
+
         /// <summary>
         /// A method for updating view according to current status
         /// </summary>
index 0d5f6ce..fcd5b10 100755 (executable)
@@ -40,6 +40,11 @@ namespace TVMediaHub.Tizen.Views
         private bool IsContentReady = false;
 
         /// <summary>
+        /// The flag that whether all contents are selected or not
+        /// </summary>
+        private bool IsSelectedAll { get; set; }
+
+        /// <summary>
         /// Identifies the ItemsSource bindable property
         /// </summary>
         public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create("ItemsSource", typeof(ObservableCollection<GroupItem>), typeof(ImageTab), default(ObservableCollection<GroupItem>));
@@ -170,6 +175,8 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         private List<KeyValuePair<double, Button>> BottomButtonList;
 
+        public List<ImageGroup> ImageGroupList { get; set; }
+
         /// <summary>
         /// Identifies the SelectedCount bindable property
         /// </summary>
@@ -211,6 +218,7 @@ namespace TVMediaHub.Tizen.Views
         private void InitializeData()
         {
             BottomButtonList = new List<KeyValuePair<double, Button>>();
+            ImageGroupList = new List<ImageGroup>();
         }
 
         /// <summary>
@@ -318,6 +326,7 @@ namespace TVMediaHub.Tizen.Views
                 galleryGroup.BindingContext = group;
                 galleryGroup.SetClickCommand(OnClickCommand);
                 GalleryContentView.Children.Add(galleryGroup);
+                ImageGroupList.Add(galleryGroup);
 
                 galleryGroup.GetTitleFocusArea().Focused += (se, ev) =>
                 {
@@ -350,6 +359,7 @@ namespace TVMediaHub.Tizen.Views
             else if (e.Action.ToString().Equals("Reset"))
             {
                 GalleryContentView.Children.Clear();
+                ImageGroupList.Clear();
                 if (!GalleryNoContents.IsVisible)
                 {
                     ImageTabScrollView.IsVisible = false;
@@ -473,7 +483,16 @@ namespace TVMediaHub.Tizen.Views
         /// <param name="e">An event's argument</param>
         private void OnSelectAllClicked(object sender, EventArgs e)
         {
-            SelectAllContentCommand?.Execute("");
+            IsSelectedAll = FooterDelete.IsSelectedAll;
+            SelectAllContentCommand?.Execute(IsSelectedAll);
+
+            foreach (var group in ImageGroupList)
+            {
+                foreach (var item in group.ImageItemList)
+                {
+                    item.UpdateViewSelectAll(IsSelectedAll);
+                }
+            }
         }
 
         /// <summary>
@@ -492,6 +511,11 @@ namespace TVMediaHub.Tizen.Views
             else if (SelectedCount > 1)
             {
                 title = "Delete Selected";
+
+                if (IsSelectedAll)
+                {
+                    title = "Delete All";
+                }
             }
 
             bool answer = await DisplayAlert(title, "Do you want to delete?", "YES", "NO");
@@ -502,6 +526,7 @@ namespace TVMediaHub.Tizen.Views
                 GetInformationsCommand?.Execute("");
             }
 
+            DeleteModeChangeCommand?.Execute("");
             FooterNormal.IsVisible = true;
             FooterDelete.IsVisible = false;
             SetFooterFocusChain(ImageTabScrollView.ScrollX);
@@ -539,6 +564,7 @@ namespace TVMediaHub.Tizen.Views
                 DeleteModeChangeCommand?.Execute("");
                 FooterNormal.IsVisible = false;
                 FooterDelete.IsVisible = true;
+                SetFooterFocusChain(ImageTabScrollView.ScrollX);
             }
         }
 
index 72032e7..4097ae3 100755 (executable)
@@ -85,6 +85,11 @@ namespace TVMediaHub.Tizen.Views
         public List<KeyValuePair<double, Button>> BottomFocusList { get; protected set; }
 
         /// <summary>
+        /// A list of video items
+        /// </summary>
+        public List<VideoItem> VideoItemList { get; set; }
+
+        /// <summary>
         /// A constructor
         /// Initializes several lists and properties that are used in this class
         /// Initializes several size of the items that are used in this class
@@ -106,6 +111,7 @@ namespace TVMediaHub.Tizen.Views
             LeftFocusList = new List<Button>();
             RightFocusList = new List<Button>();
             BottomFocusList = new List<KeyValuePair<double, Button>>();
+            VideoItemList = new List<VideoItem>();
 
             GroupTitle = new Xamarin.Forms.Label();
             GroupTitleFocusArea = new Button();
@@ -225,11 +231,13 @@ namespace TVMediaHub.Tizen.Views
             {
                 var index = 0;
                 ChildrenFocusList.Clear();
+                VideoItemList.Clear();
                 foreach (var item in ItemsSource)
                 {
                     var view = new VideoItem();
                     ChildrenFocusList.Add(view.GetFocusArea());
                     view.BindingContext = item;
+                    VideoItemList.Add(view);
                     view.OnFocusedEventHandler += (se, ev) =>
                     {
                         GroupItemFocused?.Invoke(view, new GroupItemFocusEventArgs(X + view.X));
index df2d721..b1a0352 100755 (executable)
@@ -377,6 +377,22 @@ namespace TVMediaHub.Tizen.Views
             }
         }
 
+        public void UpdateViewSelectAll(bool isSelectedAll)
+        {
+            if (!isSelectedAll)
+            {
+                CheckDimImage.FadeTo(0.0, 167);
+                CheckImage.FadeTo(0.0, 167);
+                CurStatus = ItemStatus.NORMAL;
+            }
+            else
+            {
+                CheckDimImage.FadeTo(0.75, 167);
+                CheckImage.FadeTo(0.99, 167);
+                CurStatus = ItemStatus.SELECTED;
+            }
+        }
+
         /// <summary>
         /// A method for updating view according to current status
         /// </summary>
index 0001dba..5460f56 100755 (executable)
@@ -39,6 +39,13 @@ namespace TVMediaHub.Tizen.Views
         private bool IsContentReady = false;
 
         /// <summary>
+        /// The flag that whether all contents are selected or not
+        /// </summary>
+        private bool IsSelectedAll { get; set; }
+
+        public List<VideoGroup> VideoGroupList { get; set; }
+
+        /// <summary>
         /// Identifies the ItemsSource bindable property
         /// </summary>
         public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create("ItemsSource", typeof(ObservableCollection<GroupItem>), typeof(VideoTab), default(ObservableCollection<GroupItem>));
@@ -196,6 +203,7 @@ namespace TVMediaHub.Tizen.Views
         private void InitializeData()
         {
             BottomButtonList = new List<KeyValuePair<double, Button>>();
+            VideoGroupList = new List<VideoGroup>();
         }
 
         /// <summary>
@@ -303,6 +311,7 @@ namespace TVMediaHub.Tizen.Views
                 groupView.BindingContext = GroupItem;
                 groupView.SetClickCommand(OnClickCommand);
                 VideoTabList.Children.Add(groupView);
+                VideoGroupList.Add(groupView);
 
                 groupView.GroupTitleFocusArea.Focused += (se, ev) =>
                 {
@@ -340,6 +349,7 @@ namespace TVMediaHub.Tizen.Views
             {
                 BottomButtonList.Clear();
                 VideoTabList.Children.Clear();
+                VideoGroupList.Clear();
                 if (!VideoNoContents.IsVisible)
                 {
                     VideoTabScrollView.IsVisible = false;
@@ -463,7 +473,16 @@ namespace TVMediaHub.Tizen.Views
         /// <param name="e">An event's argument</param>
         private void OnSelectAllClicked(object sender, EventArgs e)
         {
-            SelectAllContentCommand?.Execute("");
+            IsSelectedAll = FooterDelete.IsSelectedAll;
+            SelectAllContentCommand?.Execute(IsSelectedAll);
+
+            foreach (var group in VideoGroupList)
+            {
+                foreach (var item in group.VideoItemList)
+                {
+                    item.UpdateViewSelectAll(IsSelectedAll);
+                }
+            }
         }
 
         /// <summary>
@@ -482,6 +501,11 @@ namespace TVMediaHub.Tizen.Views
             else if (SelectedCount > 1)
             {
                 title = "Delete Selected";
+
+                if (IsSelectedAll)
+                {
+                    title = "Delete All";
+                }
             }
 
             bool answer = await DisplayAlert(title, "Do you want to delete?", "YES", "NO");
@@ -492,6 +516,7 @@ namespace TVMediaHub.Tizen.Views
                 GetInformationsCommand?.Execute("");
             }
 
+            ChangeTabStatusCommand?.Execute("");
             FooterNormal.IsVisible = true;
             FooterDelete.IsVisible = false;
             SetFooterFocusChain(VideoTabScrollView.ScrollX);