From 505d2ba0cf331caacee2cbf885e83b4a37610b61 Mon Sep 17 00:00:00 2001 From: Hyerim Kim Date: Thu, 25 May 2017 21:25:00 +0900 Subject: [PATCH] (WIP) Implements ContentUpdated event handler Implements SelectAll button actions Change-Id: I56d0029aa23d6b1ec2ba48a1aefcae16e49a2a78 Signed-off-by: Hyerim Kim --- .../TVMediaHub.Tizen/Models/ContentProvider.cs | 15 +-------- .../TVMediaHub.Tizen/Models/ImageProvider.cs | 9 +++++ .../TVMediaHub.Tizen/Models/MusicProvider.cs | 8 +++++ .../TVMediaHub.Tizen/Models/VideoProvider.cs | 5 +++ .../ViewModels/ImageTabViewModel.cs | 38 +++++++++++++++++----- .../ViewModels/VideoTabViewModel.cs | 38 +++++++++++++++++----- .../Views/FooterDeleteStatus.xaml.cs | 18 ++++++++++ .../TVMediaHub.Tizen/Views/ImageGroup.xaml.cs | 4 +++ .../TVMediaHub.Tizen/Views/ImageItem.xaml.cs | 16 +++++++++ TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs | 28 +++++++++++++++- .../TVMediaHub.Tizen/Views/VideoGroup.xaml.cs | 8 +++++ .../TVMediaHub.Tizen/Views/VideoItem.xaml.cs | 16 +++++++++ TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs | 27 ++++++++++++++- 13 files changed, 198 insertions(+), 32 deletions(-) diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs index 6563a37..a2fcaec 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs @@ -49,10 +49,7 @@ namespace TVMediaHub.Tizen.Models /// A condition string abstract protected string GetConditionStringForSelection(); - /// - /// An event handler for update event - /// - private EventHandler UpdateListeners; + abstract public void SetContentUpdatedEventListener(EventHandler 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; } - - /// - /// A method for adding update event handler - /// - /// An event handler to be executed - void SetUpdateListener(EventHandler listener) - { - UpdateListeners += listener; - } } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs index 5d5d473..1993402 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs @@ -14,6 +14,10 @@ * limitations under the License. */ +using System; +using Tizen.Content.MediaContent; +using TVMediaHub.Tizen.Utils; + namespace TVMediaHub.Tizen.Models { /// @@ -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 listener) + { + ContentDatabase.ContentUpdated += listener; + } } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs index fc94ef6..370525a 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs @@ -14,6 +14,9 @@ * limitations under the License. */ +using System; +using Tizen.Content.MediaContent; + namespace TVMediaHub.Tizen.Models { /// @@ -36,5 +39,10 @@ namespace TVMediaHub.Tizen.Models { return "(MEDIA_TYPE=8)"; } + + public override void SetContentUpdatedEventListener(EventHandler listener) + { + ContentDatabase.ContentUpdated += listener; + } } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs index ba7ea3b..6543a1f 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs @@ -86,5 +86,10 @@ namespace TVMediaHub.Tizen.Models DbgPort.D("PlayedAt : " + videoContent.PlayedAt.ToString()); ContentManager.Database.Update(videoContent); } + + public override void SetContentUpdatedEventListener(EventHandler listener) + { + ContentDatabase.ContentUpdated += listener; + } } } \ No newline at end of file diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs index 7c01d65..8981e87 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs @@ -47,6 +47,8 @@ namespace TVMediaHub.Tizen.ViewModels /// private int displayingImageIndex; + private SortOption option = SortOption.Title; + /// /// Gets or sets the displayingImageIndex /// @@ -262,6 +264,16 @@ namespace TVMediaHub.Tizen.ViewModels ImageList = new ObservableCollection(); SelectedList = new List(); OnPropertyChanged("ImageList"); + MediaHubImpl.GetInstance.ImageProviderInstance.SetContentUpdatedEventListener((sender, arg) => + { + DbgPort.D("Content updated"); + /* + if (arg.UpdateType.Equals(MediaContentDBUpdateType.Update)) + { + GetInformationsCommand?.Execute(""); + } + */ + }); } /// @@ -335,18 +347,25 @@ namespace TVMediaHub.Tizen.ViewModels } }); - SelectAllContentCommand = new Command(() => + SelectAllContentCommand = new Command((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((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); }, ""); }); diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs index cf1806d..745ccd2 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs @@ -110,6 +110,8 @@ namespace TVMediaHub.Tizen.ViewModels private bool isDeleteStatus; + private SortOption option = SortOption.Title; + /// /// Gets or sets the MediaInformation of current video /// @@ -162,6 +164,16 @@ namespace TVMediaHub.Tizen.ViewModels VideoList = new ObservableCollection(); SelectedList = new List(); OnPropertyChanged("VideoList"); + MediaHubImpl.GetInstance.VideoProviderInstance.SetContentUpdatedEventListener((sender, arg) => + { + DbgPort.D("Content updated"); + /* + if (arg.UpdateType.Equals(MediaContentDBUpdateType.Update)) + { + GetInformationsCommand?.Execute(""); + } + */ + }); } /// @@ -203,17 +215,20 @@ namespace TVMediaHub.Tizen.ViewModels }); ChangeSortOptionCommand = new Command((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((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"); }); diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/FooterDeleteStatus.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/FooterDeleteStatus.xaml.cs index 38f9369..1422f39 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/FooterDeleteStatus.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/FooterDeleteStatus.xaml.cs @@ -33,6 +33,11 @@ namespace TVMediaHub.Tizen.Views public EventHandler CancelButtonEvent; /// + /// The flag that whether all contents are selected or not + /// + public bool IsSelectedAll { get; set; } + + /// /// Identifies the SelectedCount bindable property /// 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) => diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs index 546273e..94990c9 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs @@ -65,6 +65,7 @@ namespace TVMediaHub.Tizen.Views public List private List> BottomButtonList; + public List ImageGroupList { get; set; } + /// /// Identifies the SelectedCount bindable property /// @@ -211,6 +218,7 @@ namespace TVMediaHub.Tizen.Views private void InitializeData() { BottomButtonList = new List>(); + ImageGroupList = new List(); } /// @@ -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 /// An event's argument 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); + } + } } /// @@ -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); } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs index 72032e7..4097ae3 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs @@ -85,6 +85,11 @@ namespace TVMediaHub.Tizen.Views public List> BottomFocusList { get; protected set; } /// + /// A list of video items + /// + public List VideoItemList { get; set; } + + /// /// 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