From 8aa9d8efeea97845973148297d14363397b3be34 Mon Sep 17 00:00:00 2001 From: Hyerim Kim Date: Wed, 24 May 2017 17:07:45 +0900 Subject: [PATCH] (WIP) Implements delete contents in TV MediaHub Change-Id: I67659d1ea759b197d065fc22fffebad84c8f0ab0 Signed-off-by: Hyerim Kim --- .../ViewModels/ImageTabViewModel.cs | 51 ++++++++++++++ .../ViewModels/VideoTabViewModel.cs | 39 +++++++++-- TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml | 3 + TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs | 77 ++++++++++++++++++++-- TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml | 4 +- TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs | 55 ++++++++++++++-- 6 files changed, 212 insertions(+), 17 deletions(-) diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs index 03d23c7..7c01d65 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs @@ -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 /// public ICommand ChangeSortOptionCommand { get; set; } + /// + /// A command for deleting a image content + /// + public ICommand DeleteContentCommand { get; set; } + + /// + /// A command for selecting all video contents + /// + public ICommand SelectAllContentCommand { get; set; } + private int SortBy; /// /// 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((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) diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs index 5e912de..cf1806d 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs @@ -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; } /// + /// A command for selecting all video contents + /// + public ICommand SelectAllContentCommand { get; set; } + + /// /// A command to set current video information /// 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((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"); } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml index 925d0f9..142ebd2 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml @@ -11,6 +11,9 @@ ChangeSortOptionCommand="{Binding ChangeSortOptionCommand}" DeleteModeChangeCommand="{Binding DeleteModeChangeCommand}" OnClickCommand="{Binding SetCurrentImageInfo}" + DeleteContentCommand="{Binding DeleteContentCommand}" + SelectAllContentCommand="{Binding SelectAllContentCommand}" + SelectedCount="{Binding SelectedCount}" Title="Gallery"> /// Identifies the OnClickCommand bindable property /// - 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)); /// /// Gets or sets OnClickCommand @@ -117,9 +117,44 @@ namespace TVMediaHub.Tizen.Views } /// + /// Identifies the DeleteContentCommand bindable property + /// + public static readonly BindableProperty DeleteContentCommandProperty = BindableProperty.Create("DeleteContentCommand", typeof(ICommand), typeof(ImageTab), default(ICommand)); + + /// + /// Gets or sets DeleteContentCommand + /// + public ICommand DeleteContentCommand + { + get + { + return (ICommand)GetValue(DeleteContentCommandProperty); + } + + set + { + SetValue(DeleteContentCommandProperty, value); + } + } + + /// + /// Identifies the DeleteContentCommand bindable property + /// + public static readonly BindableProperty SelectAllContentCommandProperty = BindableProperty.Create("SelectAllContentCommand", typeof(ICommand), typeof(ImageTab), default(ICommand)); + + /// + /// Gets or sets SelectAllContent Command + /// + public ICommand SelectAllContentCommand + { + get { return (ICommand)GetValue(SelectAllContentCommandProperty); } + set { SetValue(SelectAllContentCommandProperty, value); } + } + + /// /// Identifies the IsDeleteStatus bindable property /// - 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); /// /// Gets or sets IsDeleteStatus @@ -136,6 +171,20 @@ namespace TVMediaHub.Tizen.Views private List> BottomButtonList; /// + /// Identifies the SelectedCount bindable property + /// + public static readonly BindableProperty SelectedCountProperty = BindableProperty.Create("SelectedCount", typeof(int), typeof(ImageTab), 0); + + /// + /// Gets or sets count of selected item + /// + public int SelectedCount + { + get { return (int)GetValue(SelectedCountProperty); } + set { SetValue(SelectedCountProperty, value); } + } + + /// /// A constructor /// public ImageTab() @@ -424,7 +473,7 @@ namespace TVMediaHub.Tizen.Views /// An event's argument private void OnSelectAllClicked(object sender, EventArgs e) { - + SelectAllContentCommand?.Execute(""); } /// @@ -432,9 +481,27 @@ namespace TVMediaHub.Tizen.Views /// /// The source of the event /// An event's argument - 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); diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml index d3d576b..45412d9 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml @@ -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}"> diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs index 58336da..0001dba 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs @@ -123,9 +123,23 @@ namespace TVMediaHub.Tizen.Views } /// + /// Identifies the DeleteContentCommand bindable property + /// + public static readonly BindableProperty SelectAllContentCommandProperty = BindableProperty.Create("SelectAllContentCommand", typeof(ICommand), typeof(VideoTab), default(ICommand)); + + /// + /// Gets or sets SelectAllContent Command + /// + public ICommand SelectAllContentCommand + { + get { return (ICommand)GetValue(SelectAllContentCommandProperty); } + set { SetValue(SelectAllContentCommandProperty, value); } + } + + /// /// Identifies the OnClickCommand bindable property /// - 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)); /// /// Gets or sets OnClick Command @@ -144,6 +158,20 @@ namespace TVMediaHub.Tizen.Views } /// + /// Identifies the SelectedCount bindable property + /// + public static readonly BindableProperty SelectedCountProperty = BindableProperty.Create("SelectedCount", typeof(int), typeof(VideoTab), 0); + + /// + /// Gets or sets count of selected item + /// + public int SelectedCount + { + get { return (int)GetValue(SelectedCountProperty); } + set { SetValue(SelectedCountProperty, value); } + } + + /// /// A list of bottom buttons /// private List> BottomButtonList; @@ -435,6 +463,7 @@ namespace TVMediaHub.Tizen.Views /// An event's argument private void OnSelectAllClicked(object sender, EventArgs e) { + SelectAllContentCommand?.Execute(""); } /// @@ -442,11 +471,27 @@ namespace TVMediaHub.Tizen.Views /// /// The source of the event /// An event's argument - 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); -- 2.7.4