(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 6563a37ecdf8ca221fdb89248933c128cfdf7b60..a2fcaecd463a58b1f0507ba33403489d71c46973 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 5d5d473a8ca68470fcd712b56ae06f409db0e04d..1993402aa01645f12449eb886d6e0007696f4070 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 fc94ef61c61888c9655817d6fc3e5bc748d8ce8b..370525ae5c23eca15e1e7c5b31eee2c2cfeea6f5 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 ba7ea3b1fd62f2962450f989599cc459e90043a8..6543a1fe44db892317e7dab301569d66d26024c9 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 7c01d6598d3e0614f29dc3f7c1e1c500a023856d..8981e87fba970db92021148290326c51431a551e 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 cf1806d33c2d809f9ea705cac42b55f793354741..745ccd210ee19da8e4879536333e8de69562bcb4 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 38f93693a2283c525e429e4d383fdde3f2857aab..1422f390f44851aea57ea266a13f5366dbb58d4c 100755 (executable)
@@ -32,6 +32,11 @@ namespace TVMediaHub.Tizen.Views
         public EventHandler OKButtonEvent;
         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>
@@ -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 546273e554afcaa69a978ad66b4c3ac9954c5f6c..94990c9e682d6473a4d099a29339b1d1b23b18ce 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 1ebfc271d10bcc66c740cf391df084c06d5220e5..c98b8883b5fb30c5a890a226a48c6887a954250a 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 0d5f6ce036ea08bb03c6cad4d3ca0e2e6ad529ba..fcd5b103f67a0aea4fc64c03a250b18d36c35488 100755 (executable)
@@ -39,6 +39,11 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         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>
@@ -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 72032e7a80cf7744fcd75b2f4260e0667f87f46e..4097ae3bf1621fd9424f363bb0e581c73d59307e 100755 (executable)
@@ -84,6 +84,11 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         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
@@ -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 df2d7211012da4725e831f4dc22d955097f14660..b1a0352d11fc3e363efa4fecfa4d89bec89cf45b 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 0001dba866f53dedf069a4901bc95da0b9be9579..5460f56b3ad49f7cd253674509938745bb11d42d 100755 (executable)
@@ -38,6 +38,13 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         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>
@@ -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);