(WIP) Implements delete contents in TV MediaHub
authorHyerim Kim <rimi.kim@samsung.com>
Wed, 24 May 2017 08:07:45 +0000 (17:07 +0900)
committerHyerim Kim <rimi.kim@samsung.com>
Thu, 25 May 2017 04:53:01 +0000 (13:53 +0900)
Change-Id: I67659d1ea759b197d065fc22fffebad84c8f0ab0
Signed-off-by: Hyerim Kim <rimi.kim@samsung.com>
TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs
TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs
TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml
TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml
TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs

index 03d23c7..7c01d65 100755 (executable)
@@ -26,6 +26,9 @@ using TVMediaHub.Tizen.DataModels;
 using System.Threading.Tasks;
 using System.Collections.ObjectModel;
 using System.Threading;
+using TVMediaHub.Tizen.Utils;
+using System.IO;
+using System;
 
 namespace TVMediaHub.Tizen.ViewModels
 {
@@ -124,6 +127,16 @@ namespace TVMediaHub.Tizen.ViewModels
         /// </summary>
         public ICommand ChangeSortOptionCommand { get; set; }
 
+        /// <summary>
+        /// A command for deleting a image content
+        /// </summary>
+        public ICommand DeleteContentCommand { get; set; }
+
+        /// <summary>
+        /// A command for selecting all video contents
+        /// </summary>
+        public ICommand SelectAllContentCommand { get; set; }
+
         private int SortBy;
         /// <summary>
         /// A flag that whether the content is delete mode or not
@@ -322,6 +335,22 @@ namespace TVMediaHub.Tizen.ViewModels
                 }
             });
 
+            SelectAllContentCommand = new Command(() =>
+            {
+                foreach (var group in ImageList)
+                {
+                    foreach (var info in group.Contents)
+                    {
+                        if (!SelectedList.Contains(info.Information))
+                        {
+                            SelectedList.Add(info.Information);
+                        }
+                    }
+                }
+
+                OnPropertyChanged("SelectedCount");
+            });
+
             SavedRotationCommand = new Command<double>((rotation) =>
             {
                 if (rotation == -1D)
@@ -362,6 +391,28 @@ namespace TVMediaHub.Tizen.ViewModels
                     ReadImageList(SortOption.Title);
                 }, "");
             });
+
+            DeleteContentCommand = new Command(() =>
+            {
+                foreach (var info in SelectedList)
+                {
+                    try
+                    {
+                        File.Delete(info.FilePath);
+                    }
+                    catch(Exception exception)
+                    {
+                        // TODO: Handling exceptions
+                        DbgPort.E("Exception - " + exception.Message);
+                        return;
+                    }
+
+                    MediaHubImpl.GetInstance.ImageProviderInstance.Delete(info);
+                }
+            });
+
+            OnPropertyChanged("DeleteModeChangeCommand");
+            OnPropertyChanged("ChangeSortOptionCommand");
         }
 
         private void GetImageData(int source, int sortby)
index 5e912de..cf1806d 100755 (executable)
@@ -18,6 +18,7 @@ using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.ComponentModel;
+using System.IO;
 using System.Threading;
 using System.Windows.Input;
 using Tizen.Content.MediaContent;
@@ -94,6 +95,11 @@ namespace TVMediaHub.Tizen.ViewModels
         public ICommand DeleteContentCommand { get; set; }
 
         /// <summary>
+        /// A command for selecting all video contents
+        /// </summary>
+        public ICommand SelectAllContentCommand { get; set; }
+
+        /// <summary>
         /// A command to set current video information
         /// </summary>
         public ICommand SetCurrentVideoInfo
@@ -179,15 +185,20 @@ namespace TVMediaHub.Tizen.ViewModels
             });
             DeleteContentCommand = new Command(() =>
             {
-                IsDeleteStatus = !IsDeleteStatus;
-
-                foreach (var group in VideoList)
+                foreach (var info in SelectedList)
                 {
-                    foreach (var info in group.Contents)
+                    try
                     {
-                        info.IsDeleteStatus = IsDeleteStatus;
-                        MediaHubImpl.GetInstance.VideoProviderInstance.Delete(info.Information);
+                        File.Delete(info.FilePath);
                     }
+                    catch(Exception exception)
+                    {
+                        // TODO: Handling exceptions
+                        DbgPort.E("Exception - " + exception.Message);
+                        return;
+                    }
+
+                    MediaHubImpl.GetInstance.VideoProviderInstance.Delete(info);
                 }
             });
             ChangeSortOptionCommand = new Command<string>((opt) =>
@@ -234,6 +245,22 @@ namespace TVMediaHub.Tizen.ViewModels
                     SetCurrentVideo(info);
                 }
             });
+
+            SelectAllContentCommand = new Command(() =>
+            {
+                foreach (var group in VideoList)
+                {
+                    foreach (var info in group.Contents)
+                    {
+                        if (!SelectedList.Contains(info.Information))
+                        {
+                            SelectedList.Add(info.Information);
+                        }
+                    }
+                }
+
+                OnPropertyChanged("SelectedCount");
+            });
             OnPropertyChanged("ChangeTabStatusCommand");
             OnPropertyChanged("ChangeSortOptionCommand");
         }
index 925d0f9..142ebd2 100755 (executable)
@@ -11,6 +11,9 @@
              ChangeSortOptionCommand="{Binding ChangeSortOptionCommand}"
              DeleteModeChangeCommand="{Binding DeleteModeChangeCommand}"
              OnClickCommand="{Binding SetCurrentImageInfo}"
+             DeleteContentCommand="{Binding DeleteContentCommand}"
+             SelectAllContentCommand="{Binding SelectAllContentCommand}"
+             SelectedCount="{Binding SelectedCount}"
              Title="Gallery">
     <RelativeLayout
         RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"
index c2f9d87..0d5f6ce 100755 (executable)
@@ -98,7 +98,7 @@ namespace TVMediaHub.Tizen.Views
         /// <summary>
         /// Identifies the OnClickCommand bindable property
         /// </summary>
-        public static readonly BindableProperty OnClickCommandProperty = BindableProperty.Create("OnClickCommand", typeof(ICommand), typeof(ImageItem), default(ICommand));
+        public static readonly BindableProperty OnClickCommandProperty = BindableProperty.Create("OnClickCommand", typeof(ICommand), typeof(ImageTab), default(ICommand));
 
         /// <summary>
         /// Gets or sets OnClickCommand
@@ -117,9 +117,44 @@ namespace TVMediaHub.Tizen.Views
         }
 
         /// <summary>
+        /// Identifies the DeleteContentCommand bindable property
+        /// </summary>
+        public static readonly BindableProperty DeleteContentCommandProperty = BindableProperty.Create("DeleteContentCommand", typeof(ICommand), typeof(ImageTab), default(ICommand));
+
+        /// <summary>
+        /// Gets or sets DeleteContentCommand
+        /// </summary>
+        public ICommand DeleteContentCommand
+        {
+            get
+            {
+                return (ICommand)GetValue(DeleteContentCommandProperty);
+            }
+
+            set
+            {
+                SetValue(DeleteContentCommandProperty, value);
+            }
+        }
+
+        /// <summary>
+        /// Identifies the DeleteContentCommand bindable property
+        /// </summary>
+        public static readonly BindableProperty SelectAllContentCommandProperty = BindableProperty.Create("SelectAllContentCommand", typeof(ICommand), typeof(ImageTab), default(ICommand));
+
+        /// <summary>
+        /// Gets or sets SelectAllContent Command
+        /// </summary>
+        public ICommand SelectAllContentCommand
+        {
+            get { return (ICommand)GetValue(SelectAllContentCommandProperty); }
+            set { SetValue(SelectAllContentCommandProperty, value); }
+        }
+
+        /// <summary>
         /// Identifies the IsDeleteStatus bindable property
         /// </summary>
-        public static readonly BindableProperty IsDeleteStatusProperty = BindableProperty.Create("IsDeleteStatus", typeof(bool), typeof(VideoTab), false);
+        public static readonly BindableProperty IsDeleteStatusProperty = BindableProperty.Create("IsDeleteStatus", typeof(bool), typeof(ImageTab), false);
 
         /// <summary>
         /// Gets or sets IsDeleteStatus
@@ -136,6 +171,20 @@ namespace TVMediaHub.Tizen.Views
         private List<KeyValuePair<double, Button>> BottomButtonList;
 
         /// <summary>
+        /// Identifies the SelectedCount bindable property
+        /// </summary>
+        public static readonly BindableProperty SelectedCountProperty = BindableProperty.Create("SelectedCount", typeof(int), typeof(ImageTab), 0);
+
+        /// <summary>
+        /// Gets or sets count of selected item
+        /// </summary>
+        public int SelectedCount
+        {
+            get { return (int)GetValue(SelectedCountProperty); }
+            set { SetValue(SelectedCountProperty, value); }
+        }
+
+        /// <summary>
         /// A constructor
         /// </summary>
         public ImageTab()
@@ -424,7 +473,7 @@ namespace TVMediaHub.Tizen.Views
         /// <param name="e">An event's argument</param>
         private void OnSelectAllClicked(object sender, EventArgs e)
         {
-
+            SelectAllContentCommand?.Execute("");
         }
 
         /// <summary>
@@ -432,9 +481,27 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         /// <param name="sender">The source of the event</param>
         /// <param name="e">An event's argument</param>
-        private void OnOKClicked(object sender, EventArgs e)
+        private async void OnOKClicked(object sender, EventArgs e)
         {
-            DeleteModeChangeCommand?.Execute("");
+            string title = "Delete";
+
+            if (SelectedCount < 1)
+            {
+                return;
+            }
+            else if (SelectedCount > 1)
+            {
+                title = "Delete Selected";
+            }
+
+            bool answer = await DisplayAlert(title, "Do you want to delete?", "YES", "NO");
+
+            if (answer)
+            {
+                DeleteContentCommand?.Execute("");
+                GetInformationsCommand?.Execute("");
+            }
+
             FooterNormal.IsVisible = true;
             FooterDelete.IsVisible = false;
             SetFooterFocusChain(ImageTabScrollView.ScrollX);
index d3d576b..45412d9 100755 (executable)
@@ -12,7 +12,9 @@
              ChangeSortOptionCommand="{Binding ChangeSortOptionCommand}"
              GetInformationsCommand="{Binding GetInformationsCommand}"
              OnClickCommand="{Binding SetCurrentVideoInfo}"
-             DeleteContentCommand="{Binding DeleteContentCommand}">
+             DeleteContentCommand="{Binding DeleteContentCommand}"
+             SelectAllContentCommand="{Binding SelectAllContentCommand}"
+             SelectedCount="{Binding SelectedCount}">
     <RelativeLayout
         RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"
         RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}">
index 58336da..0001dba 100755 (executable)
@@ -123,9 +123,23 @@ namespace TVMediaHub.Tizen.Views
         }
 
         /// <summary>
+        /// Identifies the DeleteContentCommand bindable property
+        /// </summary>
+        public static readonly BindableProperty SelectAllContentCommandProperty = BindableProperty.Create("SelectAllContentCommand", typeof(ICommand), typeof(VideoTab), default(ICommand));
+
+        /// <summary>
+        /// Gets or sets SelectAllContent Command
+        /// </summary>
+        public ICommand SelectAllContentCommand
+        {
+            get { return (ICommand)GetValue(SelectAllContentCommandProperty); }
+            set { SetValue(SelectAllContentCommandProperty, value); }
+        }
+
+        /// <summary>
         /// Identifies the OnClickCommand bindable property
         /// </summary>
-        public static readonly BindableProperty OnClickCommandProperty = BindableProperty.Create("OnClickCommand", typeof(ICommand), typeof(VideoItem), default(ICommand));
+        public static readonly BindableProperty OnClickCommandProperty = BindableProperty.Create("OnClickCommand", typeof(ICommand), typeof(VideoTab), default(ICommand));
 
         /// <summary>
         /// Gets or sets OnClick Command
@@ -144,6 +158,20 @@ namespace TVMediaHub.Tizen.Views
         }
 
         /// <summary>
+        /// Identifies the SelectedCount bindable property
+        /// </summary>
+        public static readonly BindableProperty SelectedCountProperty = BindableProperty.Create("SelectedCount", typeof(int), typeof(VideoTab), 0);
+
+        /// <summary>
+        /// Gets or sets count of selected item
+        /// </summary>
+        public int SelectedCount
+        {
+            get { return (int)GetValue(SelectedCountProperty); }
+            set { SetValue(SelectedCountProperty, value); }
+        }
+
+        /// <summary>
         /// A list of bottom buttons
         /// </summary>
         private List<KeyValuePair<double, Button>> BottomButtonList;
@@ -435,6 +463,7 @@ namespace TVMediaHub.Tizen.Views
         /// <param name="e">An event's argument</param>
         private void OnSelectAllClicked(object sender, EventArgs e)
         {
+            SelectAllContentCommand?.Execute("");
         }
 
         /// <summary>
@@ -442,11 +471,27 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         /// <param name="sender">The source of the event</param>
         /// <param name="e">An event's argument</param>
-        private void OnOKClicked(object sender, EventArgs e)
+        private async void OnOKClicked(object sender, EventArgs e)
         {
-            // TODO : Change to delete Content command
-            ChangeTabStatusCommand?.Execute("");
-            DeleteContentCommand?.Execute("");
+            string title = "Delete";
+
+            if (SelectedCount < 1)
+            {
+                return;
+            }
+            else if (SelectedCount > 1)
+            {
+                title = "Delete Selected";
+            }
+
+            bool answer = await DisplayAlert(title, "Do you want to delete?", "YES", "NO");
+
+            if (answer)
+            {
+                DeleteContentCommand?.Execute("");
+                GetInformationsCommand?.Execute("");
+            }
+
             FooterNormal.IsVisible = true;
             FooterDelete.IsVisible = false;
             SetFooterFocusChain(VideoTabScrollView.ScrollX);