From 2ffc87d09da2ec73ed3a1aade1124bb7a06579ee Mon Sep 17 00:00:00 2001 From: "jjie.choi" Date: Wed, 31 May 2017 16:30:33 +0900 Subject: [PATCH 01/16] Implements ImageTab context popup Change-Id: I4651b6181a202e96c0fc8472aed05c9d42ee1231 Signed-off-by: jjie.choi --- .../ViewModels/ImageTabViewModel.cs | 7 ++- .../TVMediaHub.Tizen/Views/ImageGroup.xaml.cs | 33 ++++++++++++++ .../TVMediaHub.Tizen/Views/ImageItem.xaml.cs | 37 ++++++++++++++- TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs | 53 ++++++++++++++++++++++ .../TVMediaHub.Tizen/Views/VideoItem.xaml.cs | 2 +- 5 files changed, 128 insertions(+), 4 deletions(-) diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs index 1b6c541..7e2cfb4 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs @@ -414,8 +414,13 @@ namespace TVMediaHub.Tizen.ViewModels }, ""); }); - DeleteContentCommand = new Command(() => + DeleteContentCommand = new Command((SelectedItem) => { + if (!SelectedItem.Equals("")) + { + SelectedList.Clear(); + SelectedList.Add(SelectedItem); + } foreach (var info in SelectedList) { try diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs index 94990c9..cce28cf 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows.Input; +using Tizen.Content.MediaContent; using TVMediaHub.Tizen.DataModels; using TVMediaHub.Tizen.Models; using TVMediaHub.Tizen.Utils; @@ -43,6 +44,10 @@ namespace TVMediaHub.Tizen.Views /// private ICommand ItemClickCommand; + public delegate void ItemDeleteHandler(MediaInformation info); + + public ItemDeleteHandler OnItemDeleteHandler; + /// /// Gets or set ItemSource to display item /// @@ -69,6 +74,8 @@ namespace TVMediaHub.Tizen.Views public EventHandler GroupItemFocused; + public ImageItem focusedItem; + /// /// A constructor /// @@ -188,11 +195,23 @@ namespace TVMediaHub.Tizen.Views { GroupItemFocused?.Invoke(view, new GroupItemFocusEventArgs(X + view.X)); GroupContentArea.RaiseChild(view); + focusedItem = view; + }; + view.OnUnfocusedEventHandler += (se, ev) => + { + if (focusedItem.Equals(view as ImageItem)) + { + focusedItem = null; + } }; view.OnItemClickedHandler += (info) => { ItemClickCommand?.Execute(info); }; + view.DeleteItemHandler += (info) => + { + OnItemDeleteHandler?.Invoke(info); + }; GroupContentArea.Children.Add(view, index / 3, index % 3); index++; } @@ -331,5 +350,19 @@ namespace TVMediaHub.Tizen.Views { ItemClickCommand = command; } + + /// + /// If there is focused image item, notify the menu key pressed event to focused video item for show context popup + /// + /// If group has a focused image item, true; otherwise, false + public bool NotifyMenuKeyPressedToFocusedItem() + { + if (focusedItem != null) + { + focusedItem.ShowContextPopup(); + return true; + } + return false; + } } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs index c98b888..0444d39 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs @@ -17,6 +17,7 @@ using System; using System.ComponentModel; using Tizen.Content.MediaContent; +using Tizen.Xamarin.Forms.Extension; using TVMediaHub.Tizen.Utils; using Xamarin.Forms; using Xamarin.Forms.Xaml; @@ -85,11 +86,13 @@ namespace TVMediaHub.Tizen.Views /// A delegate will be executed when the item is clicked /// /// A clicked item's MediaInformation - public delegate void ClickEventHandler(MediaInformation info); + public delegate void ItemEventHandler(MediaInformation info); /// /// A ClickEventHandler for click event of the item /// - public ClickEventHandler OnItemClickedHandler; + public ItemEventHandler OnItemClickedHandler; + + public ItemEventHandler DeleteItemHandler; /// /// Identifies the IsDeleteMode bindable property @@ -370,6 +373,7 @@ namespace TVMediaHub.Tizen.Views /// A Focus event's argument private void OnItemUnfocused(object sender, FocusEventArgs e) { + OnUnfocusedEventHandler?.Invoke(sender, e); Easing easing = new Easing(EasingFunction.EasyIn2); this.AbortAnimation("FocusAnimation"); ImgFocused.Opacity = 0.0; @@ -407,6 +411,35 @@ namespace TVMediaHub.Tizen.Views IsLoaded = true; } } + public void ShowContextPopup() + { + if (!FocusArea.IsFocused) + { + return; + } + + ContextPopup popup = new ContextPopup(); + popup.Items.Add(new ContextPopupItem("FILE INFO")); + popup.Items.Add(new ContextPopupItem("DELETE")); + popup.SelectedIndexChanged += selectedIndexChanged; + popup.Show(this, this.Width / 2, this.Height + SizeUtils.GetHeightSize(72)); + + } + + private void selectedIndexChanged(object sender, EventArgs e) + { + var ctxPopup = sender as ContextPopup; + switch (ctxPopup.SelectedIndex) + { + case 0: + DbgPort.D("File info selected"); + break; + case 1: + DeleteItemHandler?.Invoke(SelectedImage); + break; + } + ctxPopup.Dismiss(); + } } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs index 501869b..a2f9e0b 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Threading; using System.Windows.Input; +using Tizen.Content.MediaContent; using TVMediaHub.Tizen.Controls; using TVMediaHub.Tizen.DataModels; using TVMediaHub.Tizen.Models; @@ -325,6 +326,10 @@ namespace TVMediaHub.Tizen.Views galleryGroup.BindingContext = group; galleryGroup.SetClickCommand(OnClickCommand); + galleryGroup.OnItemDeleteHandler += (info) => + { + ShowDeletePopup(info); + }; GalleryContentView.Children.Add(galleryGroup); ImageGroupList.Add(galleryGroup); @@ -606,5 +611,53 @@ namespace TVMediaHub.Tizen.Views GalleryContentView.TranslateTo(0, h0, 667); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } + + protected override void OnAppearing() + { + base.OnAppearing(); + // add Listener + App.MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, false); + App.MainWindow.KeyUp += MenuKeyListener; + } + + protected override void OnDisappearing() + { + base.OnDisappearing(); + // remove listener + App.MainWindow.KeyUp -= MenuKeyListener; + App.MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName); + } + private void MenuKeyListener(object sender, ElmSharp.EvasKeyEventArgs e) + { + if (e.KeyName.Equals(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName)) + { + NotifyMenuKeyPressed(); + } + } + + private void NotifyMenuKeyPressed() + { + if (GalleryContentView.Children.Count > 0) + { + foreach (ImageGroup group in GalleryContentView.Children) + { + if (group.NotifyMenuKeyPressedToFocusedItem()) + { + break; + } + } + + } + } + + private async void ShowDeletePopup(MediaInformation item) + { + bool answer = await DisplayAlert("Delete", "Delete '" + item.Title + "'?", "Yes", "No"); + if (answer) + { + DeleteContentCommand?.Execute(item); + } + + } } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs index 3f3ccd7..9ed3c78 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs @@ -448,7 +448,7 @@ namespace TVMediaHub.Tizen.Views } ContextPopup popup = new ContextPopup(); - popup.Items.Add(new ContextPopupItem("FILE INFO")); + popup.Items.Add(new ContextPopupItem(" FILE INFO ")); popup.Items.Add(new ContextPopupItem("DELETE")); popup.SelectedIndexChanged += selectedIndexChanged; popup.Show(this, this.Width/2, this.Height + SizeUtils.GetHeightSize(72)); -- 2.7.4 From 8d581de3d7e2b40323792fbf3cb73d58a4e055ec Mon Sep 17 00:00:00 2001 From: "Geunsun, Lee" Date: Fri, 2 Jun 2017 08:47:57 +0900 Subject: [PATCH 02/16] Change the log API : Log -> Dbgport Change-Id: I1d3da2e9411a6605fe74bc01a164b98ea33252dd --- TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs index a2fcaec..7a1093f 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs @@ -16,7 +16,6 @@ using System; using System.Collections.Generic; -using System.Threading; using System.Threading.Tasks; using Tizen; using Tizen.Content.MediaContent; @@ -51,8 +50,6 @@ namespace TVMediaHub.Tizen.Models abstract public void SetContentUpdatedEventListener(EventHandler listener); - private string TAG = "MediaHub"; - /// /// A constructor /// Connect to the media database to search, insert, remove or modify media information. @@ -65,7 +62,7 @@ namespace TVMediaHub.Tizen.Models } catch (Exception e) { - Log.Debug(TAG, e.Message); + DbgPort.E(e.Message); } } @@ -257,7 +254,7 @@ namespace TVMediaHub.Tizen.Models } catch (Exception exception) { - Log.Debug(TAG, exception.Message); + DbgPort.E(exception.Message); } return mediaInformations; @@ -344,7 +341,7 @@ namespace TVMediaHub.Tizen.Models } catch (Exception exception) { - Log.Debug(TAG, exception.Message); + DbgPort.E(exception.Message); } return mediaInformations; @@ -388,7 +385,7 @@ namespace TVMediaHub.Tizen.Models } catch (Exception exception) { - Log.Error(TAG, exception.Message); + DbgPort.E(exception.Message); } return true; @@ -407,7 +404,7 @@ namespace TVMediaHub.Tizen.Models } catch (Exception exception) { - Log.Error(TAG, exception.Message); + DbgPort.E(exception.Message); } return true; -- 2.7.4 From 69b1ed2edbc1cc0c9ce4068c5eb3fdd21b4f41d3 Mon Sep 17 00:00:00 2001 From: Heonjae Jang Date: Fri, 2 Jun 2017 15:14:58 +0900 Subject: [PATCH 03/16] Change Next, Prev Button clicked handler Change-Id: Idebdd18db7f2d23e5c7706d2ea8a701d1bceb299 Signed-off-by: Heonjae Jang --- .../Controls/MediaHubButton.xaml.cs | 71 +++---- .../ViewModels/VideoTabViewModel.cs | 69 +++++++ TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml | 4 +- .../TVMediaHub.Tizen/Views/VideoPlayer.xaml.cs | 217 ++++++++++++++------- 4 files changed, 255 insertions(+), 106 deletions(-) diff --git a/TVMediaHub/TVMediaHub.Tizen/Controls/MediaHubButton.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Controls/MediaHubButton.xaml.cs index 5c3b221..165ccd8 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Controls/MediaHubButton.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Controls/MediaHubButton.xaml.cs @@ -35,11 +35,6 @@ namespace TVMediaHub.Tizen.Controls int effectDuration = 200; /// - /// A flag that whether the button is handling clicked event or not - /// - private static bool isButtonRunning = false; - - /// /// Gets or sets MediaHubButtonIcon's image source /// public string MediaHubButtonIcon @@ -101,37 +96,45 @@ namespace TVMediaHub.Tizen.Controls /// private void InitializeButton() { - Btn.Clicked += async (s, e) => + Btn.Clicked += (s, e) => { - if (isButtonRunning) - { - return; - } - - isButtonRunning = true; - Clicked?.Invoke(this, EventArgs.Empty); - - try - { - BtnIcon.Source = PressedImage; -#pragma warning disable CS4014 - BG.ScaleTo(0.1, Convert.ToUInt32(effectDuration), Easing.CubicInOut); -#pragma warning restore CS4014 - await BG.FadeTo(0, Convert.ToUInt32(effectDuration), Easing.CubicInOut); - - BtnIcon.Source = NormalImage; -#pragma warning disable CS4014 - BG.ScaleTo(1, Convert.ToUInt32(effectDuration), Easing.CubicInOut); -#pragma warning restore CS4014 - await BG.FadeTo(1, Convert.ToUInt32(effectDuration), Easing.CubicInOut); - } - catch (Exception err) - { - DbgPort.D("Error : " + err.Message); - } - - isButtonRunning = false; + var BGScale = BG.Scale; + var BGOpacity = BG.Opacity; + + this.AbortAnimation("ClickAnimation"); + BtnIcon.Source = PressedImage; + this.Animate("ClickAnimation", (v) => + { + BG.Scale = BGScale - (BGScale - 0.1) * v; + BG.Opacity = BGOpacity - (BGOpacity - 0) * v; + }, + length: Convert.ToUInt32(effectDuration), + easing: Easing.CubicInOut, + finished: (progress, isCanceled) => + { + BtnIcon.Source = NormalImage; + if (!isCanceled) + { + this.Animate("ClickAnimation", (v) => + { + BG.Scale = 0.1 + 0.9 * v; + BG.Opacity = v; + }, + length: Convert.ToUInt32(effectDuration), + easing: Easing.CubicInOut, + finished: (progress2, isCanceled2) => + { + BG.Scale = 1; + BGOpacity = 1; + }); + } + else + { + BG.Scale = 1; + BGOpacity = 1; + } + }); }; } diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs index 33b1e61..14821b5 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs @@ -100,6 +100,16 @@ namespace TVMediaHub.Tizen.ViewModels public ICommand SelectAllContentCommand { get; set; } /// + /// A command for changing current video to next + /// + public ICommand SetNextVideoCommand { get; set; } + + /// + /// A command for changing current video to previous + /// + public ICommand SetPrevVideoCommand { get; set; } + + /// /// A command to set current video information /// public ICommand SetCurrentVideoInfo @@ -116,6 +126,15 @@ namespace TVMediaHub.Tizen.ViewModels /// Gets or sets the MediaInformation of current video /// public MediaInformation CurrentVideo { get; set; } + public int CurrentVideoIndex { get; set; } + public List PlayList { get; set; } + + public bool IsLastVideo { + get + { + return (PlayList.Count - 1) == CurrentVideoIndex; + } + } /// /// Gets or sets the DeleteStatus @@ -163,6 +182,8 @@ namespace TVMediaHub.Tizen.ViewModels InitializeCommands(); VideoList = new ObservableCollection(); SelectedList = new List(); + PlayList = new List(); + OnPropertyChanged("VideoList"); MediaHubImpl.GetInstance.VideoProviderInstance.SetContentUpdatedEventListener((sender, arg) => { @@ -288,6 +309,19 @@ namespace TVMediaHub.Tizen.ViewModels OnPropertyChanged("SelectedCount"); }); + + SetNextVideoCommand = new Command(() => + { + SetNextVideo(); + }); + + SetPrevVideoCommand = new Command(() => + { + SetPrevVideo(); + }); + OnPropertyChanged("SetNextVideoCommand"); + OnPropertyChanged("SetPrevVideoCommand"); + OnPropertyChanged("ChangeTabStatusCommand"); OnPropertyChanged("ChangeSortOptionCommand"); } @@ -347,6 +381,14 @@ namespace TVMediaHub.Tizen.ViewModels //await Task.Delay(1); VideoList.Add(group); } + + foreach (var group in VideoList) + { + foreach (var item in group.Contents) + { + PlayList.Add(item.Information); + } + } } /// @@ -356,10 +398,37 @@ namespace TVMediaHub.Tizen.ViewModels private void SetCurrentVideo(MediaInformation videoContent) { CurrentVideo = videoContent; + CurrentVideoIndex = PlayList.IndexOf(CurrentVideo); OnPropertyChanged("CurrentVideo"); } /// + /// A method for setting the next video + /// + private void SetPrevVideo() + { + if (CurrentVideoIndex != 0) + { + CurrentVideoIndex--; + CurrentVideo = PlayList[CurrentVideoIndex]; + OnPropertyChanged("CurrentVideo"); + } + } + + /// + /// A method for setting the next video + /// + private void SetNextVideo() + { + if (CurrentVideoIndex != (PlayList.Count - 1)) + { + CurrentVideoIndex++; + CurrentVideo = PlayList[CurrentVideoIndex]; + OnPropertyChanged("CurrentVideo"); + } + } + + /// /// A method for setting latest played time of the media file. /// /// A played media file diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml b/TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml index 54a7975..94c1978 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml @@ -6,7 +6,9 @@ xmlns:Utils="clr-namespace:TVMediaHub.Tizen.Utils" xmlns:ViewModels="clr-namespace:TVMediaHub.Tizen.ViewModels" xmlns:Controls="clr-namespace:TVMediaHub.Tizen.Controls" - CurrentVideo="{Binding CurrentVideo}"> + CurrentVideo="{Binding CurrentVideo}" + SetNextVideoCommand="{Binding SetNextVideoCommand}" + SetPrevVideoCommand="{Binding SetPrevVideoCommand}"> /// The media duration in Milliseconds. /// @@ -91,30 +100,9 @@ namespace TVMediaHub.Tizen.Views private int timerDueTime = 5000; /// - /// Gets or sets whether play status is back forward or back rewind + /// Gets or sets current play status /// - private bool IsInPlayBackRewFwd - { - set - { - if (value == false) - { - PlayBackForwardIndex = 0; - PlayBackRewindIndex = 0; - } - } - - get - { - if (PlayBackForwardIndex == 0 && - PlayBackRewindIndex == 0) - { - return false; - } - - return true; - } - } + private PlayStatus CurrentPlayStatus { get; set; } /// /// The value for play back forward index @@ -178,6 +166,34 @@ namespace TVMediaHub.Tizen.Views } /// + /// Identifies the SetNextVideoCommand bindable property + /// + public static readonly BindableProperty SetNextVideoCommandProperty = BindableProperty.Create("SetNextVideoCommand", typeof(ICommand), typeof(VideoPlayer), null); + + /// + /// A Command for setting current video to next video + /// + public ICommand SetNextVideoCommand + { + get { return (ICommand)GetValue(SetNextVideoCommandProperty); } + set { SetValue(SetNextVideoCommandProperty, value); } + } + + /// + /// Identifies the SetPrevVideoCommand bindable property + /// + public static readonly BindableProperty SetPrevVideoCommandProperty = BindableProperty.Create("SetPrevVideoCommand", typeof(ICommand), typeof(VideoPlayer), null); + + /// + /// A Command for setting current video to previous video + /// + public ICommand SetPrevVideoCommand + { + get { return (ICommand)GetValue(SetPrevVideoCommandProperty); } + set { SetValue(SetPrevVideoCommandProperty, value); } + } + + /// /// A constructor /// public VideoPlayer() @@ -185,7 +201,7 @@ namespace TVMediaHub.Tizen.Views BindingContext = VideoTabViewModelLocator.ViewModel; InitializeComponent(); InitializeFontSize(); - + PropertyChanged += VideoPlayePropertyChanged; mediaView = new Extension.MediaView(); mediaView.NativeViewCreated += (s, e) => @@ -217,16 +233,45 @@ namespace TVMediaHub.Tizen.Views } #pragma warning disable CS4014 - GradientDim.FadeTo(0, 667, Easing.CubicInOut); + GradientDim.FadeTo(0, 667, Easing.CubicInOut); ControlArea.TranslateTo(0, 93, 667, Easing.CubicInOut); ControlArea.FadeTo(0, 667, Easing.CubicInOut); TitleLabel.TranslateTo(0, -50, 667, Easing.CubicInOut); await TitleLabel.FadeTo(0, 667, Easing.CubicInOut); App.AppMainPage.Navigation.PopAsync(); - //Program.TransitionToMain(0); #pragma warning restore CS4014 - }; + }; + } + + /// + /// This method is called when the properties is changed + /// + /// The source of the event + /// A propertyChanged event argument + private void VideoPlayePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName.Equals("CurrentVideo")) + { + if (playerInstance.State == PlayerState.Playing || playerInstance.State == PlayerState.Paused) + { + try + { + playerInstance.Stop(); + playerInstance.Unprepare(); + playerDisplayInstance = new Display((MediaView)mediaView.NativeView); + playerInstance.Display = playerDisplayInstance; + videoMediaSource = new MediaUriSource(CurrentVideo.FilePath); + playerInstance.SetSource(videoMediaSource); + } + catch (Exception ex) + { + DbgPort.D(ex.Message); + return; + } + PrepareAsync(); + } + } } /// @@ -335,15 +380,14 @@ namespace TVMediaHub.Tizen.Views int playPosition = playerInstance.GetPlayPosition(); SetPlayTime(playPosition); progress.Progress = (double)playPosition / sourceDuration; - DbgPort.D("Status : " + playerInstance.State + "/" + prevPlayerStatus + ", temp : " + playPosition + ", progress : " + progress.Progress.ToString()); + //DbgPort.D("Status : " + playerInstance.State + "/" + prevPlayerStatus + ", temp : " + playPosition + ", progress : " + progress.Progress.ToString()); if (prevPlayerStatus != playerInstance.State) { if (playerInstance.State == PlayerState.Paused || playerInstance.State == PlayerState.Ready) { - if (IsInPlayBackRewFwd) + if (CurrentPlayStatus == PlayStatus.Rewind || CurrentPlayStatus == PlayStatus.FastFoward) { - IsInPlayBackRewFwd = false; playerInstance.SetPlaybackRate((PlayBackRate[0])); } @@ -360,19 +404,6 @@ namespace TVMediaHub.Tizen.Views prevPlayerStatus = playerInstance.State; } - - // TODO : check later, hotfix for VD GBM player - if ((PlayBackRewindIndex != 0 && playPosition < 4000) - || PlayBackForwardIndex != 0 && playPosition > (sourceDuration - 6000)) - { - IsInPlayBackRewFwd = false; - playerInstance.SetPlaybackRate((PlayBackRate[0])); - - if (SpeedInfo.Opacity == 1) - { - SpeedInfo.FadeTo(0.0, 100); - } - } }); if (playerInstance.State != PlayerState.Playing && @@ -403,24 +434,40 @@ namespace TVMediaHub.Tizen.Views playerInstance.Display = playerDisplayInstance; playerInstance.PlaybackCompleted += (obj, eventArg) => { + PlayBackRewindIndex = 0; + PlayBackForwardIndex = 0; DbgPort.D("PlaybackCompleted"); - try + + if (CurrentPlayStatus == PlayStatus.Rewind) { - playerInstance.Stop(); - playerInstance.Unprepare(); + try + { + CurrentPlayStatus = PlayStatus.Play; + playerInstance?.SetPlaybackRate(1); + playerInstance?.Start(); + } + catch (Exception ex) + { + DbgPort.E("Start Failed : " + ex.Message); + return; + } } - catch (Exception ex) + else if (VideoTabViewModelLocator.ViewModel.IsLastVideo) { - DbgPort.E("Stop Failed : " + ex.Message); + App.AppMainPage.Navigation.PopAsync(); + } + else + { + try + { + CurrentPlayStatus = PlayStatus.Play; + SetNextVideoCommand?.Execute(""); + } + catch (Exception ex) + { + DbgPort.E("Stop Failed : " + ex.Message); + } } - - PausePlayBtn.NormalImage = PausePlayBtn.NormalImage.Replace("pause", "play"); - PausePlayBtn.PressedImage = PausePlayBtn.PressedImage.Replace("pause", "play"); - PausePlayBtn.MediaHubButtonIcon = PausePlayBtn.NormalImage; - - // If you don't want to back automatically whenever VideoPlayer's play is over, remove below line. - // TODO: Remove this later, only for TDC - Navigation.PopToRootAsync(); }; videoMediaSource = new MediaUriSource(CurrentVideo.FilePath); @@ -530,8 +577,6 @@ namespace TVMediaHub.Tizen.Views /// private void PlayVideo() { - DbgPort.D("ElmSharp.Window is activated"); - try { playerInstance.Start(); @@ -611,6 +656,11 @@ namespace TVMediaHub.Tizen.Views /// An event's argument private async void PreviousBtnClicked(object sender, EventArgs e) { + if (playerInstance.State == PlayerState.Idle || playerInstance.State == PlayerState.Preparing) + { + return; + } + if (ControlArea.Opacity == 0) { SetControlAreaState(ControlAreaState.AUTO); @@ -620,17 +670,25 @@ namespace TVMediaHub.Tizen.Views SetControlAreaState(ControlAreaState.AUTO); - try - { - await playerInstance.SetPlayPositionAsync(0, true); - } - catch (Exception ex) + if (playerInstance.GetPlayPosition() < 1000) { - DbgPort.E("SetPlayPositionAsync Failed : " + ex.Message); + SetPrevVideoCommand?.Execute(""); return; } + else + { + try + { + await playerInstance.SetPlayPositionAsync(0, true); + } + catch (Exception ex) + { + DbgPort.E("SetPlayPositionAsync Failed : " + ex.Message); + return; + } - progress.Progress = 0.0; + progress.Progress = 0.0; + } } /// @@ -673,6 +731,7 @@ namespace TVMediaHub.Tizen.Views */ try { + CurrentPlayStatus = PlayStatus.Rewind; PlayBackRewindIndex++; playerInstance.SetPlaybackRate((PlayBackRate[PlayBackRewindIndex]) * -1); // TODO : check later, added as hotfix for VD GBM player @@ -715,6 +774,7 @@ namespace TVMediaHub.Tizen.Views if (playerInstance.State == PlayerState.Paused || playerInstance.State == PlayerState.Ready) { SetControlAreaState(ControlAreaState.SHOW); + CurrentPlayStatus = PlayStatus.Play; PlayVideo(); } else if (playerInstance.State == PlayerState.Playing) @@ -723,6 +783,7 @@ namespace TVMediaHub.Tizen.Views try { + CurrentPlayStatus = PlayStatus.Pause; playerInstance.Pause(); } catch (Exception ex) @@ -751,6 +812,7 @@ namespace TVMediaHub.Tizen.Views try { + CurrentPlayStatus = PlayStatus.FastFoward; PlayBackForwardIndex++; playerInstance.SetPlaybackRate(PlayBackRate[PlayBackForwardIndex]); // TODO : check later, added as hotfix for VD GBM player @@ -776,6 +838,11 @@ namespace TVMediaHub.Tizen.Views /// An event's argument private async void NextBtnClicked(object sender, EventArgs e) { + if (playerInstance.State == PlayerState.Idle || playerInstance.State == PlayerState.Preparing) + { + return; + } + if (ControlArea.Opacity == 0) { SetControlAreaState(ControlAreaState.AUTO); @@ -784,14 +851,22 @@ namespace TVMediaHub.Tizen.Views SetControlAreaState(ControlAreaState.AUTO); - try + if (playerInstance.GetPlayPosition() > sourceDuration - 1000) { - await playerInstance.SetPlayPositionAsync(sourceDuration - 500, true); + SetNextVideoCommand?.Execute(""); } - catch (Exception err) + else { - DbgPort.E("SetPlayPositionAsync Failed : " + err.Message); - return; + try + { + await playerInstance.SetPlayPositionAsync(sourceDuration - 1000, true); + } + catch (Exception err) + { + DbgPort.E("SetPlayPositionAsync Failed : " + err.Message); + return; + } + } progress.Progress = 1.0; @@ -831,7 +906,7 @@ namespace TVMediaHub.Tizen.Views TitleLabel.TranslateTo(0, 0, 667, Easing.CubicInOut); TitleLabel.FadeTo(1, 667, Easing.CubicInOut); - if (IsInPlayBackRewFwd) + if (CurrentPlayStatus == PlayStatus.Rewind || CurrentPlayStatus == PlayStatus.FastFoward) { SpeedInfo.FadeTo(1.0, 100); } -- 2.7.4 From a106fff30a1c28a969a40e3d2acf8c5f7664e299 Mon Sep 17 00:00:00 2001 From: "jjie.choi" Date: Thu, 1 Jun 2017 17:18:36 +0900 Subject: [PATCH 04/16] Implements file info popup for focused image/video item. Change-Id: I7821ebbf6fb2ee69092cee8de16ce4ecf970bfcd Signed-off-by: jjie.choi --- .../TVMediaHub.Tizen/Views/ImageGroup.xaml.cs | 9 +++--- .../TVMediaHub.Tizen/Views/ImageItem.xaml.cs | 33 ++++++++++++--------- TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs | 28 ++++++++++++++---- .../TVMediaHub.Tizen/Views/VideoGroup.xaml.cs | 9 +++--- .../TVMediaHub.Tizen/Views/VideoItem.xaml.cs | 34 +++++++++++++--------- TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs | 29 +++++++++++++----- 6 files changed, 95 insertions(+), 47 deletions(-) diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs index cce28cf..8658a6c 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs @@ -25,6 +25,7 @@ using TVMediaHub.Tizen.Utils; using Xamarin.Forms; using Xamarin.Forms.PlatformConfiguration.TizenSpecific; using Xamarin.Forms.Xaml; +using static TVMediaHub.Tizen.Views.ImageItem; namespace TVMediaHub.Tizen.Views { @@ -44,9 +45,9 @@ namespace TVMediaHub.Tizen.Views /// private ICommand ItemClickCommand; - public delegate void ItemDeleteHandler(MediaInformation info); + public delegate void ContextPopupItemSelectedEventHandler(MediaInformation info, ImageContextPopupItem item); - public ItemDeleteHandler OnItemDeleteHandler; + public ContextPopupItemSelectedEventHandler ContextPopupItemSelectedHandler; /// /// Gets or set ItemSource to display item @@ -208,9 +209,9 @@ namespace TVMediaHub.Tizen.Views { ItemClickCommand?.Execute(info); }; - view.DeleteItemHandler += (info) => + view.ContextPopupItemSelectedHandler += (info, selItem) => { - OnItemDeleteHandler?.Invoke(info); + ContextPopupItemSelectedHandler?.Invoke(info, selItem); }; GroupContentArea.Children.Add(view, index / 3, index % 3); index++; diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs index 0444d39..4952ab6 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs @@ -35,9 +35,14 @@ namespace TVMediaHub.Tizen.Views /// public enum ItemStatus { - NORMAL = 0, - SELECTED, + Normal = 0, + Selected, }; + public enum ImageContextPopupItem + { + FileInfo = 0, + Delete, + } /// /// A flag that whether the item is loaded or not @@ -92,7 +97,9 @@ namespace TVMediaHub.Tizen.Views /// public ItemEventHandler OnItemClickedHandler; - public ItemEventHandler DeleteItemHandler; + public delegate void ContextPopupItemSelectedEventHandler(MediaInformation info, ImageContextPopupItem item); + + public ContextPopupItemSelectedEventHandler ContextPopupItemSelectedHandler; /// /// Identifies the IsDeleteMode bindable property @@ -242,13 +249,13 @@ namespace TVMediaHub.Tizen.Views OnItemClickedHandler?.Invoke(SelectedImage); if (IsDeleteMode) { - if (CurStatus == ItemStatus.NORMAL) + if (CurStatus == ItemStatus.Normal) { - CurStatus = ItemStatus.SELECTED; + CurStatus = ItemStatus.Selected; } else { - CurStatus = ItemStatus.NORMAL; + CurStatus = ItemStatus.Normal; } UpdateView(); @@ -265,13 +272,13 @@ namespace TVMediaHub.Tizen.Views { ImgCheckDimmed.FadeTo(0.0, 167); ImgCheck.FadeTo(0.0, 167); - CurStatus = ItemStatus.NORMAL; + CurStatus = ItemStatus.Normal; } else { ImgCheckDimmed.FadeTo(0.75, 167); ImgCheck.FadeTo(0.99, 167); - CurStatus = ItemStatus.SELECTED; + CurStatus = ItemStatus.Selected; } } @@ -282,11 +289,11 @@ namespace TVMediaHub.Tizen.Views { switch (CurStatus) { - case ItemStatus.NORMAL: + case ItemStatus.Normal: ImgCheckDimmed.FadeTo(0.0, 167); ImgCheck.FadeTo(0.0, 167); break; - case ItemStatus.SELECTED: + case ItemStatus.Selected: ImgCheckDimmed.FadeTo(0.75, 167); ImgCheck.FadeTo(0.99, 167); break; @@ -304,7 +311,7 @@ namespace TVMediaHub.Tizen.Views { if (!IsDeleteMode) { - CurStatus = ItemStatus.NORMAL; + CurStatus = ItemStatus.Normal; UpdateView(); } } @@ -432,10 +439,10 @@ namespace TVMediaHub.Tizen.Views switch (ctxPopup.SelectedIndex) { case 0: - DbgPort.D("File info selected"); + ContextPopupItemSelectedHandler?.Invoke(SelectedImage, ImageContextPopupItem.FileInfo); break; case 1: - DeleteItemHandler?.Invoke(SelectedImage); + ContextPopupItemSelectedHandler?.Invoke(SelectedImage, ImageContextPopupItem.Delete); break; } ctxPopup.Dismiss(); diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs index a2f9e0b..542e2fb 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs @@ -20,6 +20,7 @@ using System.Collections.ObjectModel; using System.Threading; using System.Windows.Input; using Tizen.Content.MediaContent; +using Tizen.Xamarin.Forms.Extension; using TVMediaHub.Tizen.Controls; using TVMediaHub.Tizen.DataModels; using TVMediaHub.Tizen.Models; @@ -27,6 +28,7 @@ using TVMediaHub.Tizen.Utils; using TVMediaHub.Tizen.ViewModels; using Xamarin.Forms; using Xamarin.Forms.PlatformConfiguration.TizenSpecific; +using static TVMediaHub.Tizen.Views.ImageItem; namespace TVMediaHub.Tizen.Views { @@ -326,9 +328,9 @@ namespace TVMediaHub.Tizen.Views galleryGroup.BindingContext = group; galleryGroup.SetClickCommand(OnClickCommand); - galleryGroup.OnItemDeleteHandler += (info) => + galleryGroup.ContextPopupItemSelectedHandler += (info, item) => { - ShowDeletePopup(info); + ShowPopup(info, item); }; GalleryContentView.Children.Add(galleryGroup); ImageGroupList.Add(galleryGroup); @@ -650,12 +652,26 @@ namespace TVMediaHub.Tizen.Views } } - private async void ShowDeletePopup(MediaInformation item) + private async void ShowPopup(MediaInformation info, ImageContextPopupItem item) { - bool answer = await DisplayAlert("Delete", "Delete '" + item.Title + "'?", "Yes", "No"); - if (answer) + switch (item) { - DeleteContentCommand?.Execute(item); + case ImageContextPopupItem.FileInfo: + string message = "File name : " + info.Title + "\n"; + message += "File size : " + info.Size + "\n"; + message += "File format : " + info.MimeType + "\n"; + message += "File size : " + info.Size + "\n"; + message += "File path : " + info.FilePath; + await DisplayAlert("File Information", message, "Close"); + Dialog dialog = new Dialog(); + break; + case ImageContextPopupItem.Delete: + bool answer = await DisplayAlert("Delete", "Delete '" + info.Title + "'?", "Yes", "No"); + if (answer) + { + DeleteContentCommand?.Execute(item); + } + break; } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs index b063e65..6660de7 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs @@ -23,6 +23,7 @@ using TVMediaHub.Tizen.Utils; using Xamarin.Forms; using Xamarin.Forms.PlatformConfiguration.TizenSpecific; using Tizen.Content.MediaContent; +using static TVMediaHub.Tizen.Views.VideoItem; namespace TVMediaHub.Tizen.Views { @@ -59,9 +60,9 @@ namespace TVMediaHub.Tizen.Views /// private ICommand ItemClickCommand; - public delegate void ItemDeleteHandler(MediaInformation info); + public delegate void ContextPopupItemSelelectedEventHandler(MediaInformation info, VideoContextPopupItem item); - public ItemDeleteHandler OnItemDeleteHandler; + public ContextPopupItemSelelectedEventHandler ContextPopupItemSelectedHandler; /// /// Gets or sets source of list items /// @@ -262,9 +263,9 @@ namespace TVMediaHub.Tizen.Views { ItemClickCommand?.Execute(info); }; - view.DeleteItemHandler += (info) => + view.ContextPopupItemSelectedHandler += (info, selItem) => { - OnItemDeleteHandler?.Invoke(info); + ContextPopupItemSelectedHandler?.Invoke(info, selItem); }; GroupContentArea.Children.Add(view, index / 3, index % 3); diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs index 9ed3c78..e5f644f 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs @@ -38,10 +38,16 @@ namespace TVMediaHub.Tizen.Views /// public enum ItemStatus { - NORMAL = 0, - SELECTED, + Normal = 0, + Selected, }; + public enum VideoContextPopupItem + { + FileInfo = 0, + Delete, + } + /// /// A value of current ItemStatus /// @@ -105,7 +111,9 @@ namespace TVMediaHub.Tizen.Views /// public ItemEventHandler OnItemClickedHandler; - public ItemEventHandler DeleteItemHandler; + public delegate void ContextPopupItemSelectedEventHandler(MediaInformation info, VideoContextPopupItem item); + + public ContextPopupItemSelectedEventHandler ContextPopupItemSelectedHandler; /// /// Identifies the IsDeleteMode bindable property @@ -362,14 +370,14 @@ namespace TVMediaHub.Tizen.Views OnItemClickedHandler?.Invoke(VideoInfo); if (IsDeleteMode) { - if (CurStatus == ItemStatus.NORMAL) + if (CurStatus == ItemStatus.Normal) { - CurStatus = ItemStatus.SELECTED; + CurStatus = ItemStatus.Selected; PlayImage.FadeTo(0, 167); } else { - CurStatus = ItemStatus.NORMAL; + CurStatus = ItemStatus.Normal; PlayImage.FadeTo(0.99, 167); } #pragma warning restore CS4014 @@ -387,13 +395,13 @@ namespace TVMediaHub.Tizen.Views { CheckDimImage.FadeTo(0.0, 167); CheckImage.FadeTo(0.0, 167); - CurStatus = ItemStatus.NORMAL; + CurStatus = ItemStatus.Normal; } else { CheckDimImage.FadeTo(0.75, 167); CheckImage.FadeTo(0.99, 167); - CurStatus = ItemStatus.SELECTED; + CurStatus = ItemStatus.Selected; } } @@ -404,11 +412,11 @@ namespace TVMediaHub.Tizen.Views { switch (CurStatus) { - case ItemStatus.NORMAL: + case ItemStatus.Normal: CheckDimImage.FadeTo(0.0, 167); CheckImage.FadeTo(0.0, 167); break; - case ItemStatus.SELECTED: + case ItemStatus.Selected: CheckDimImage.FadeTo(0.75, 167); CheckImage.FadeTo(0.99, 167); break; @@ -434,7 +442,7 @@ namespace TVMediaHub.Tizen.Views { if (!IsDeleteMode) { - CurStatus = ItemStatus.NORMAL; + CurStatus = ItemStatus.Normal; UpdateView(); } } @@ -461,10 +469,10 @@ namespace TVMediaHub.Tizen.Views switch (ctxPopup.SelectedIndex) { case 0: - DbgPort.D("File info selected"); + ContextPopupItemSelectedHandler.Invoke(VideoInfo, VideoContextPopupItem.FileInfo); break; case 1: - DeleteItemHandler?.Invoke(VideoInfo); + ContextPopupItemSelectedHandler?.Invoke(VideoInfo, VideoContextPopupItem.Delete); break; } ctxPopup.Dismiss(); diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs index 7b3f35d..5f22bd9 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs @@ -26,6 +26,8 @@ using TVMediaHub.Tizen.ViewModels; using Xamarin.Forms; using Xamarin.Forms.PlatformConfiguration.TizenSpecific; using Tizen.Content.MediaContent; +using static TVMediaHub.Tizen.Views.VideoItem; +using Tizen.Xamarin.Forms.Extension; namespace TVMediaHub.Tizen.Views { @@ -311,9 +313,9 @@ namespace TVMediaHub.Tizen.Views var GroupItem = e.NewItems[0]; groupView.BindingContext = GroupItem; groupView.SetClickCommand(OnClickCommand); - groupView.OnItemDeleteHandler += (info) => + groupView.ContextPopupItemSelectedHandler += (info, item) => { - ShowDeletePopup(info); + ShowPopup(info, item); }; VideoTabList.Children.Add(groupView); @@ -639,14 +641,27 @@ namespace TVMediaHub.Tizen.Views } - private async void ShowDeletePopup(MediaInformation item) + private async void ShowPopup(MediaInformation info, VideoContextPopupItem item) { - bool answer = await DisplayAlert("Delete", "Delete '" + item.Title + "'?", "Yes", "No"); - if (answer) + switch (item) { - DeleteContentCommand?.Execute(item); + case VideoContextPopupItem.FileInfo: + string message = "File name : " + info.Title + "\n"; + message += "File size : " + info.Size + "\n"; + message += "File format : " + info.MimeType + "\n"; + message += "File size : " + info.Size + "\n"; + message += "File path : " + info.FilePath; + + await DisplayAlert("File Information", message, "Close"); + break; + case VideoContextPopupItem.Delete: + bool answer = await DisplayAlert("Delete", "Delete '" + info.Title + "'?", "Yes", "No"); + if (answer) + { + DeleteContentCommand?.Execute(item); + } + break; } - } } } -- 2.7.4 From 8694d4a71cff0b8a891f9bcd3eb8d6a1b66f3161 Mon Sep 17 00:00:00 2001 From: "Geunsun, Lee" Date: Mon, 5 Jun 2017 13:02:48 +0900 Subject: [PATCH 05/16] Implement viewmodel for music tab Change-Id: Iba23c8e3308cc11a7184e90d45832ba17e12b6a1 --- .../TVMediaHub.Tizen/Models/MusicProvider.cs | 2 +- .../ViewModels/MusicTabViewModel.cs | 64 +++++++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs index 370525a..25b5a5b 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs @@ -37,7 +37,7 @@ namespace TVMediaHub.Tizen.Models /// A condition string protected override string GetConditionStringForSelection() { - return "(MEDIA_TYPE=8)"; + return "(MEDIA_TYPE=3)"; } public override void SetContentUpdatedEventListener(EventHandler listener) diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs index ba505da..2709d99 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs @@ -14,12 +14,74 @@ * limitations under the License. */ +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using TVMediaHub.Tizen.Models; +using TVMediaHub.Tizen.Utils; + namespace TVMediaHub.Tizen.ViewModels { /// /// A class for ViewModel of Music tab /// - class MusicTabViewModel + public class MusicTabViewModel : INotifyPropertyChanged { + /// + /// Gets or sets the list of music group item + /// + public ObservableCollection MusicList { get; set; } + + private SortOption option = SortOption.Title; + + /// + /// An event that is occurred when property of ViewModel is changed + /// + public event PropertyChangedEventHandler PropertyChanged; + + /// + /// A method for invoking PropertyChanged event + /// + /// The name of property + public void OnPropertyChanged(string name) + { + PropertyChangedEventHandler handler = PropertyChanged; + if (handler != null) + { + handler(this, new PropertyChangedEventArgs(name)); + } + } + + /// + /// A constructor + /// + public MusicTabViewModel() + { + MusicList = new ObservableCollection(); + OnPropertyChanged("MusicList"); + MediaHubImpl.GetInstance.MusicProviderInstance.SetContentUpdatedEventListener((s, e) => + { + DbgPort.D("Content updated"); + }); + } + + /// + /// A method for reading music contents through MusicProvider and updating MusicList + /// + /// A current sort option + private async void ReadMusicList(SortOption option) + { + MusicList.Clear(); + IEnumerable templist = await MediaHubImpl.GetInstance.MusicProviderInstance.ReadAsync(option); + foreach (var group in templist) + { + await MediaHubImpl.GetInstance.MusicProviderInstance.CheckThumbnail(group.Contents); + } + + foreach (var group in templist) + { + MusicList.Add(group); + } + } } } -- 2.7.4 From 6fbea2b9fd431e97ecb15ca9971552e0d1518a6a Mon Sep 17 00:00:00 2001 From: "kyuho.jo" Date: Mon, 5 Jun 2017 13:41:19 +0900 Subject: [PATCH 06/16] Add rountines for checking availability of media contents Change-Id: Id5e55a24f08d902589d413a2ff938f815265e27e Signed-off-by: kyuho.jo --- .../DataModels/MediaInformationEx.cs | 26 ++++++ .../TVMediaHub.Tizen/Models/ContentProvider.cs | 97 ++++++++++++++-------- .../TVMediaHub.Tizen/Models/ImageProvider.cs | 19 +++++ .../TVMediaHub.Tizen/Models/MediaShortcutInfo.cs | 17 ++-- .../TVMediaHub.Tizen/Models/MusicProvider.cs | 14 ++++ .../TVMediaHub.Tizen/Models/VideoProvider.cs | 35 +++++--- .../TVMediaHub.Tizen/TVMediaHub.Tizen.csproj | 1 + .../ViewModels/ImageTabViewModel.cs | 35 ++++---- .../ViewModels/VideoTabViewModel.cs | 25 +++--- .../TVMediaHub.Tizen/Views/ImageGroup.xaml.cs | 2 +- .../TVMediaHub.Tizen/Views/ImageItem.xaml.cs | 13 +-- TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs | 15 ++-- .../TVMediaHub.Tizen/Views/VideoGroup.xaml.cs | 2 +- .../TVMediaHub.Tizen/Views/VideoItem.xaml.cs | 11 +-- .../TVMediaHub.Tizen/Views/VideoPlayer.xaml.cs | 11 +-- TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs | 15 ++-- 16 files changed, 221 insertions(+), 117 deletions(-) create mode 100644 TVMediaHub/TVMediaHub.Tizen/DataModels/MediaInformationEx.cs diff --git a/TVMediaHub/TVMediaHub.Tizen/DataModels/MediaInformationEx.cs b/TVMediaHub/TVMediaHub.Tizen/DataModels/MediaInformationEx.cs new file mode 100644 index 0000000..223cd9c --- /dev/null +++ b/TVMediaHub/TVMediaHub.Tizen/DataModels/MediaInformationEx.cs @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Tizen.Content.MediaContent; + +namespace TVMediaHub.Tizen.DataModels +{ + public class MediaInformationEx + { + public MediaInformation MediaContentInformation; + public bool IsAvailable; + }; +} diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs index 7a1093f..57b2aa9 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs @@ -20,6 +20,7 @@ using System.Threading.Tasks; using Tizen; using Tizen.Content.MediaContent; using TVMediaHub.Tizen.Utils; +using TVMediaHub.Tizen.DataModels; namespace TVMediaHub.Tizen.Models { @@ -48,6 +49,11 @@ namespace TVMediaHub.Tizen.Models /// A condition string abstract protected string GetConditionStringForSelection(); + /// + /// An abstract method to determine the availability of the content. + /// + abstract protected void CheckUnavailableContent(MediaInformationEx mediaContent); + abstract public void SetContentUpdatedEventListener(EventHandler listener); /// @@ -91,9 +97,9 @@ namespace TVMediaHub.Tizen.Models /// /// A current sort option /// A latest group item of current group - /// A media information to be converted to group item + /// A media information to be converted to group item /// A group item to be added - private GroupItem GetGroupItem(SortOption sortOption, GroupItem lastGroupItem, MediaInformation mediaInformation) + private GroupItem GetGroupItem(SortOption sortOption, GroupItem lastGroupItem, MediaInformationEx mediaInformationEx) { GroupItem currentGroupItem = lastGroupItem; string newTitle = null; @@ -102,34 +108,34 @@ namespace TVMediaHub.Tizen.Models switch (sortOption) { case SortOption.Title: - if (lastGroupItem == null || lastGroupItem.Title != mediaInformation.DisplayName[0].ToString()) + if (lastGroupItem == null || lastGroupItem.Title != mediaInformationEx.MediaContentInformation.DisplayName[0].ToString()) { newGroupFlag = true; - newTitle = mediaInformation.DisplayName[0].ToString(); + newTitle = mediaInformationEx.MediaContentInformation.DisplayName[0].ToString(); } break; case SortOption.Date: - if (lastGroupItem == null || lastGroupItem.Title != GetDateString(mediaInformation.TimeLine)) + if (lastGroupItem == null || lastGroupItem.Title != GetDateString(mediaInformationEx.MediaContentInformation.TimeLine)) { newGroupFlag = true; - newTitle = GetDateString(mediaInformation.TimeLine); + newTitle = GetDateString(mediaInformationEx.MediaContentInformation.TimeLine); } break; case SortOption.Genre: - if (lastGroupItem == null || lastGroupItem.Title != mediaInformation.Category) + if (lastGroupItem == null || lastGroupItem.Title != mediaInformationEx.MediaContentInformation.Category) { newGroupFlag = true; - newTitle = mediaInformation.Category; + newTitle = mediaInformationEx.MediaContentInformation.Category; } break; case SortOption.Type: - if (lastGroupItem == null || lastGroupItem.Title != mediaInformation.MediaType.ToString()) + if (lastGroupItem == null || lastGroupItem.Title != mediaInformationEx.MediaContentInformation.MediaType.ToString()) { newGroupFlag = true; - newTitle = mediaInformation.MediaType.ToString(); + newTitle = mediaInformationEx.MediaContentInformation.MediaType.ToString(); } break; @@ -148,13 +154,13 @@ namespace TVMediaHub.Tizen.Models } /// - /// A method for making group to be displayed from MediaInformation list + /// A method for making group to be displayed from MediaInformationEx list /// - /// A list of MediaInformation + /// A list of MediaInformationEx /// The current sort option /// A list of group item #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - private async Task> MakeGroupAsync(IEnumerable mediaInformations, SortOption sortOption) + private async Task> MakeGroupAsync(IEnumerable mediaInformationExList, SortOption sortOption) #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { DbgPort.D("MG Async"); @@ -162,20 +168,20 @@ namespace TVMediaHub.Tizen.Models GroupItem lastGroupItem = null; GroupItem currentGroupItem = null; - if (mediaInformations == null) + if (mediaInformationExList == null) { - throw new System.ArgumentException("mediaInformations must not be null."); + throw new System.ArgumentException("mediaInformationExList must not be null."); } - foreach (MediaInformation mediaInformation in mediaInformations) + foreach (MediaInformationEx mediaInformationEx in mediaInformationExList) { - var currentInformation = mediaInformation; + var currentInformation = mediaInformationEx; var shortcutInfo = new MediaShortcutInfo(currentInformation); // TODO : The catch implementation should be checked once again. try { - currentGroupItem = GetGroupItem(sortOption, currentGroupItem, mediaInformation); + currentGroupItem = GetGroupItem(sortOption, currentGroupItem, mediaInformationEx); } catch (Exception e) { @@ -187,6 +193,7 @@ namespace TVMediaHub.Tizen.Models { result.Add(currentGroupItem); lastGroupItem = currentGroupItem; + DbgPort.D("new Group : " + currentGroupItem.Title); } if (currentGroupItem != null) @@ -206,7 +213,7 @@ namespace TVMediaHub.Tizen.Models /// The start position of the given filter Starting from zero /// The number of items to be searched with respect to the offset /// A list of media informations - public IEnumerable ReadWithoutGroup(SortOption sortOption, string storageId = null, int offset = -1, int count = -1) + public IEnumerable ReadWithoutGroup(SortOption sortOption, string storageId = null, int offset = -1, int count = -1) { // Makes Content Filter by arguments var contentFilter = new ContentFilter(); @@ -247,17 +254,26 @@ namespace TVMediaHub.Tizen.Models contentFilter.Condition = GetConditionStringForSelection(); // Executes the 'select' query - IEnumerable mediaInformations = new List(); + IEnumerable mediaInformationList; + List mediaInformationExList = new List(); try { - mediaInformations = ContentManager.Database.SelectAll(contentFilter); + mediaInformationList = ContentManager.Database.SelectAll(contentFilter); + foreach (MediaInformation mediaInformation in mediaInformationList) + { + var mediaInformationEx = new MediaInformationEx(); + + mediaInformationEx.MediaContentInformation = mediaInformation; + CheckUnavailableContent(mediaInformationEx); + mediaInformationExList.Add(mediaInformationEx); + } } catch (Exception exception) { DbgPort.E(exception.Message); } - return mediaInformations; + return mediaInformationExList; } /// @@ -269,11 +285,11 @@ namespace TVMediaHub.Tizen.Models { foreach (var info in list) { - if (info.Information.ThumbnailPath == null) + if (info.Information.MediaContentInformation.ThumbnailPath == null) { try { - string path = await info.Information.CreateThumbnailAsync(); + string path = await info.Information.MediaContentInformation.CreateThumbnailAsync(); } catch (Exception e) { @@ -292,7 +308,7 @@ namespace TVMediaHub.Tizen.Models /// The number of items to be searched with respect to the offset /// A list of media informations #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - public async Task> ReadWithoutGroupAsync(SortOption sortOption, string storageId = null, int offset = -1, int count = -1) + public async Task> ReadWithoutGroupAsync(SortOption sortOption, string storageId = null, int offset = -1, int count = -1) #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { // Makes Content Filter by arguments @@ -334,17 +350,26 @@ namespace TVMediaHub.Tizen.Models contentFilter.Condition = GetConditionStringForSelection(); // Executes the 'select' query - IEnumerable mediaInformations = new List(); + List mediaInformationExList = new List(); try { - mediaInformations = ContentManager.Database.SelectAll(contentFilter); + IEnumerable mediaInformationList = ContentManager.Database.SelectAll(contentFilter); + + foreach (MediaInformation mediaInformation in mediaInformationList) + { + var mediaInformationEx = new MediaInformationEx(); + + mediaInformationEx.MediaContentInformation = mediaInformation; + CheckUnavailableContent(mediaInformationEx); + mediaInformationExList.Add(mediaInformationEx); + } } catch (Exception exception) { DbgPort.E(exception.Message); } - return mediaInformations; + return mediaInformationExList; } /// @@ -357,7 +382,7 @@ namespace TVMediaHub.Tizen.Models /// A list of group item public async Task> ReadAsync(SortOption sortOption, string storageId = null, int offset = -1, int count = -1) { - IEnumerable list = await ReadWithoutGroupAsync(sortOption, storageId, offset, count); + IEnumerable list = await ReadWithoutGroupAsync(sortOption, storageId, offset, count); return await MakeGroupAsync(list, sortOption); } @@ -367,9 +392,11 @@ namespace TVMediaHub.Tizen.Models /// /// A media Id to be read /// A media content with specific media id - public MediaInformation Read(String mediaID) + public MediaInformationEx Read(String mediaID) { - return ContentManager.Database.Select(mediaID); + var mediaInformationEx = new MediaInformationEx(); + mediaInformationEx.MediaContentInformation = ContentManager.Database.Select(mediaID); + return mediaInformationEx; } /// @@ -377,11 +404,11 @@ namespace TVMediaHub.Tizen.Models /// /// A media content to be deleted /// Always returns true - public bool Delete(MediaInformation media) + public bool Delete(MediaInformationEx media) { try { - ContentManager.Database.Delete(media); + ContentManager.Database.Delete(media.MediaContentInformation); } catch (Exception exception) { @@ -396,11 +423,11 @@ namespace TVMediaHub.Tizen.Models /// /// A media content to be updated /// Always returns true - public bool Update(MediaInformation media) + public bool Update(MediaInformationEx media) { try { - ContentManager.Database.Update(media); + ContentManager.Database.Update(media.MediaContentInformation); } catch (Exception exception) { diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs index 1993402..e7d297d 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs @@ -15,8 +15,10 @@ */ using System; +using System.IO; using Tizen.Content.MediaContent; using TVMediaHub.Tizen.Utils; +using TVMediaHub.Tizen.DataModels; namespace TVMediaHub.Tizen.Models { @@ -41,6 +43,23 @@ namespace TVMediaHub.Tizen.Models return "(MEDIA_TYPE=0) AND (MEDIA_MIME_TYPE LIKE 'image%') AND NOT (MEDIA_PATH LIKE '%.tn')"; } + /// + /// A method to determine the availability of the content. + /// + protected override void CheckUnavailableContent(MediaInformationEx mediaContent) + { + if (mediaContent.MediaContentInformation.FilePath != null) + { + // Check 1 : The size of the image file must be less than 4MB. + var fileInfo = new FileInfo(mediaContent.MediaContentInformation.FilePath); + + if (fileInfo != null && fileInfo.Length > 4 * 1024 * 1024) + { + mediaContent.IsAvailable = false; + } + } + } + public override void SetContentUpdatedEventListener(EventHandler listener) { ContentDatabase.ContentUpdated += listener; diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/MediaShortcutInfo.cs b/TVMediaHub/TVMediaHub.Tizen/Models/MediaShortcutInfo.cs index ee3dafe..0ddca92 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/MediaShortcutInfo.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/MediaShortcutInfo.cs @@ -15,6 +15,7 @@ */ using System.ComponentModel; +using TVMediaHub.Tizen.DataModels; using Tizen.Content.MediaContent; namespace TVMediaHub.Tizen.Models @@ -68,9 +69,9 @@ namespace TVMediaHub.Tizen.Models } /// - /// Gets or sets the MediaInformation object + /// Gets or sets the MediaInformationEx object /// - public MediaInformation Information { protected set; get; } + public MediaInformationEx Information { protected set; get; } /// /// Gets or sets the content's thumbnail path @@ -79,13 +80,13 @@ namespace TVMediaHub.Tizen.Models { get { - if (Information.ThumbnailPath == null) + if (Information.MediaContentInformation.ThumbnailPath == null) { - return Information.FilePath + ".tn"; + return Information.MediaContentInformation.FilePath + ".tn"; } else { - return Information.ThumbnailPath; + return Information.MediaContentInformation.ThumbnailPath; } } } @@ -95,14 +96,14 @@ namespace TVMediaHub.Tizen.Models /// public string ContentName { - get { return Information.Title; } + get { return Information.MediaContentInformation.Title; } } /// /// A constructor /// - /// A MediaInformation to be MediaShortcutInfo's data - public MediaShortcutInfo(MediaInformation information) + /// A MediaInformationEx to be MediaShortcutInfo's data + public MediaShortcutInfo(MediaInformationEx information) { Information = information; IsDeleteStatus = false; diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs index 25b5a5b..9eeabac 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs @@ -16,6 +16,7 @@ using System; using Tizen.Content.MediaContent; +using TVMediaHub.Tizen.DataModels; namespace TVMediaHub.Tizen.Models { @@ -40,6 +41,19 @@ namespace TVMediaHub.Tizen.Models return "(MEDIA_TYPE=3)"; } + /// + /// A method to determine the availability of the content. + /// + protected override void CheckUnavailableContent(MediaInformationEx mediaContent) + { + // TODO : Add unsupported mime type here + if (mediaContent.MediaContentInformation.IsDrm || + mediaContent.MediaContentInformation.MimeType.Contains("ogg")) + { + mediaContent.IsAvailable = false; + } + } + 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 6543a1f..47f38d5 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs @@ -17,8 +17,8 @@ using System; using System.Collections.Generic; using Tizen.Content.MediaContent; - using TVMediaHub.Tizen.Utils; +using TVMediaHub.Tizen.DataModels; namespace TVMediaHub.Tizen.Models { @@ -45,21 +45,34 @@ namespace TVMediaHub.Tizen.Models } /// + /// A method to determine the availability of the content. + /// + protected override void CheckUnavailableContent(MediaInformationEx mediaContent) + { + // TODO : Add unsupported mime type here + if (mediaContent.MediaContentInformation.IsDrm || + mediaContent.MediaContentInformation.MimeType.Contains("ogg")) + { + mediaContent.IsAvailable = false; + } + } + + /// /// A method for getting recently played video information /// /// A recently played video information - public MediaInformation GetRecentlyPlayedVideo() + public MediaInformationEx GetRecentlyPlayedVideo() { var contentFilter = new ContentFilter(); contentFilter.OrderKey = "MEDIA_LAST_PLAYED_TIME"; contentFilter.Order = ContentOrder.Desc; contentFilter.Condition = GetConditionStringForSelection(); - MediaInformation recentlyPlayedVideo = null; - IEnumerable mediaInformations = null; + MediaInformationEx recentlyPlayedVideo = new MediaInformationEx(); + IEnumerable mediaInformationList = null; try { - mediaInformations = ContentManager.Database.SelectAll(contentFilter); + mediaInformationList = ContentManager.Database.SelectAll(contentFilter); } catch (Exception exception) { @@ -67,9 +80,9 @@ namespace TVMediaHub.Tizen.Models return recentlyPlayedVideo; } - foreach (var mediaInformation in mediaInformations) + foreach (var mediaInformation in mediaInformationList) { - recentlyPlayedVideo = mediaInformation; + recentlyPlayedVideo.MediaContentInformation = mediaInformation; break; } @@ -80,11 +93,11 @@ namespace TVMediaHub.Tizen.Models /// A method for setting latest played time of the media file. /// /// A played media file - public void SetPlayedAt(MediaInformation videoContent) + public void SetPlayedAt(MediaInformationEx videoContent) { - videoContent.PlayedAt = DateTime.UtcNow; - DbgPort.D("PlayedAt : " + videoContent.PlayedAt.ToString()); - ContentManager.Database.Update(videoContent); + videoContent.MediaContentInformation.PlayedAt = DateTime.UtcNow; + DbgPort.D("PlayedAt : " + videoContent.MediaContentInformation.PlayedAt.ToString()); + ContentManager.Database.Update(videoContent.MediaContentInformation); } public override void SetContentUpdatedEventListener(EventHandler listener) diff --git a/TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj b/TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj index ab21f16..b1cbfcd 100755 --- a/TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj +++ b/TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj @@ -58,6 +58,7 @@ + diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs index 7e2cfb4..0544c11 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs @@ -219,7 +219,7 @@ namespace TVMediaHub.Tizen.ViewModels /// /// Gets or sets the SelectedList /// - public List SelectedList { get; set; } + public List SelectedList { get; set; } /// /// Gets the SelectedList's count @@ -262,7 +262,7 @@ namespace TVMediaHub.Tizen.ViewModels CreateImageInfoList(); ImageList = new ObservableCollection(); - SelectedList = new List(); + SelectedList = new List(); OnPropertyChanged("ImageList"); MediaHubImpl.GetInstance.ImageProviderInstance.SetContentUpdatedEventListener((sender, arg) => { @@ -326,7 +326,7 @@ namespace TVMediaHub.Tizen.ViewModels OnPropertyChanged("Effect"); }); - SetCurrentImageInfo = new Command((info) => + SetCurrentImageInfo = new Command((info) => { if (IsDeleteStatus) { @@ -414,7 +414,7 @@ namespace TVMediaHub.Tizen.ViewModels }, ""); }); - DeleteContentCommand = new Command((SelectedItem) => + DeleteContentCommand = new Command((SelectedItem) => { if (!SelectedItem.Equals("")) { @@ -425,7 +425,7 @@ namespace TVMediaHub.Tizen.ViewModels { try { - File.Delete(info.FilePath); + File.Delete(info.MediaContentInformation.FilePath); } catch(Exception exception) { @@ -464,12 +464,12 @@ namespace TVMediaHub.Tizen.ViewModels /// /// Finds specific Image in list and sets the DisplayingImageIndex /// - /// A MediaInformation to be found - private void FindImageInfoInList(MediaInformation info) + /// A MediaInformationEx to be found + private void FindImageInfoInList(MediaInformationEx info) { for (int i = 0; i < imagePlayList.Count; i++) { - if (imagePlayList[i].FilePath.Equals(info.FilePath)) + if (imagePlayList[i].FilePath.Equals(info.MediaContentInformation.FilePath)) { DisplayingImageIndex = i; return; @@ -481,24 +481,24 @@ namespace TVMediaHub.Tizen.ViewModels /// A method for setting the current image /// /// An information of current image - private void SetCurrentImage(MediaInformation info) + private void SetCurrentImage(MediaInformationEx info) { FindImageInfoInList(info); } /// - /// A method for creating ImageViewrInformation with specific MediaInformation + /// A method for creating ImageViewrInformation with specific MediaInformationEx /// - /// A specific MediaInformation + /// A specific MediaInformationEx /// A created ImageViewerInformation - private ImageViewerInfomation CreateImageViewerInfomation(MediaInformation info) + private ImageViewerInfomation CreateImageViewerInfomation(MediaInformationEx info) { ImageViewerInfomation ivInfo = new ImageViewerInfomation(); - ivInfo.Title = info.Title; - ivInfo.Date = info.ModifiedAt.ToString("ddd. d MMMM"); - ivInfo.FilePath = info.FilePath; - ivInfo.ThumbnailPath = info.ThumbnailPath; + ivInfo.Title = info.MediaContentInformation.Title; + ivInfo.Date = info.MediaContentInformation.ModifiedAt.ToString("ddd. d MMMM"); + ivInfo.FilePath = info.MediaContentInformation.FilePath; + ivInfo.ThumbnailPath = info.MediaContentInformation.ThumbnailPath; ivInfo.SavedRotation = 0; return ivInfo; @@ -516,7 +516,6 @@ namespace TVMediaHub.Tizen.ViewModels { await MediaHubImpl.GetInstance.ImageProviderInstance.CheckThumbnail(group.Contents); } - foreach (var group in tempList) { // TODO : remove delay @@ -530,7 +529,7 @@ namespace TVMediaHub.Tizen.ViewModels /// private void CreateImageInfoList() { - IEnumerable MediaInfoList = MediaHubImpl.GetInstance.ImageProviderInstance.ReadWithoutGroup(option); + IEnumerable MediaInfoList = MediaHubImpl.GetInstance.ImageProviderInstance.ReadWithoutGroup(option); imagePlayList = new List(); foreach (var item in MediaInfoList) diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs index 14821b5..a9027f7 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs @@ -24,6 +24,7 @@ using System.Windows.Input; using Tizen.Content.MediaContent; using TVMediaHub.Tizen.Models; using TVMediaHub.Tizen.Utils; +using TVMediaHub.Tizen.DataModels; using Xamarin.Forms; namespace TVMediaHub.Tizen.ViewModels @@ -51,7 +52,7 @@ namespace TVMediaHub.Tizen.ViewModels } } - // TODO : Change to MediaInformation + // TODO : Change to MediaInformationEx public string RecentlyWatchedContent { get; private set; } /// @@ -123,11 +124,11 @@ namespace TVMediaHub.Tizen.ViewModels private SortOption option = SortOption.Title; /// - /// Gets or sets the MediaInformation of current video + /// Gets or sets the MediaInformationEx of current video /// - public MediaInformation CurrentVideo { get; set; } + public MediaInformationEx CurrentVideo { get; set; } public int CurrentVideoIndex { get; set; } - public List PlayList { get; set; } + public List PlayList { get; set; } public bool IsLastVideo { get @@ -159,7 +160,7 @@ namespace TVMediaHub.Tizen.ViewModels /// /// A list of video contents to be displayed /// - public List SelectedList { get; set; } + public List SelectedList { get; set; } /// /// A count of SelectedList @@ -181,8 +182,8 @@ namespace TVMediaHub.Tizen.ViewModels InitializeFooterItemsSource(); InitializeCommands(); VideoList = new ObservableCollection(); - SelectedList = new List(); - PlayList = new List(); + SelectedList = new List(); + PlayList = new List(); OnPropertyChanged("VideoList"); MediaHubImpl.GetInstance.VideoProviderInstance.SetContentUpdatedEventListener((sender, arg) => @@ -216,7 +217,7 @@ namespace TVMediaHub.Tizen.ViewModels } } }); - DeleteContentCommand = new Command((SelectedItem) => + DeleteContentCommand = new Command((SelectedItem) => { if (!SelectedItem.Equals("")) { @@ -227,7 +228,7 @@ namespace TVMediaHub.Tizen.ViewModels { try { - File.Delete(info.FilePath); + File.Delete(info.MediaContentInformation.FilePath); } catch(Exception exception) { @@ -266,7 +267,7 @@ namespace TVMediaHub.Tizen.ViewModels }, ""); }); - SetCurrentVideoInfo = new Command((info) => + SetCurrentVideoInfo = new Command((info) => { if (IsDeleteStatus) { @@ -395,7 +396,7 @@ namespace TVMediaHub.Tizen.ViewModels /// A method for setting the current video /// /// An information of current video - private void SetCurrentVideo(MediaInformation videoContent) + private void SetCurrentVideo(MediaInformationEx videoContent) { CurrentVideo = videoContent; CurrentVideoIndex = PlayList.IndexOf(CurrentVideo); @@ -432,7 +433,7 @@ namespace TVMediaHub.Tizen.ViewModels /// A method for setting latest played time of the media file. /// /// A played media file - public void SetPlayedAt(MediaInformation videoContent) + public void SetPlayedAt(MediaInformationEx videoContent) { MediaHubImpl.GetInstance.VideoProviderInstance.SetPlayedAt(videoContent); } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs index 8658a6c..3ecce46 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs @@ -45,7 +45,7 @@ namespace TVMediaHub.Tizen.Views /// private ICommand ItemClickCommand; - public delegate void ContextPopupItemSelectedEventHandler(MediaInformation info, ImageContextPopupItem item); + public delegate void ContextPopupItemSelectedEventHandler(MediaInformationEx info, ImageContextPopupItem item); public ContextPopupItemSelectedEventHandler ContextPopupItemSelectedHandler; diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs index 4952ab6..856e647 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs @@ -19,6 +19,7 @@ using System.ComponentModel; using Tizen.Content.MediaContent; using Tizen.Xamarin.Forms.Extension; using TVMediaHub.Tizen.Utils; +using TVMediaHub.Tizen.DataModels; using Xamarin.Forms; using Xamarin.Forms.Xaml; @@ -91,13 +92,13 @@ namespace TVMediaHub.Tizen.Views /// A delegate will be executed when the item is clicked /// /// A clicked item's MediaInformation - public delegate void ItemEventHandler(MediaInformation info); + public delegate void ItemEventHandler(MediaInformationEx info); /// /// A ClickEventHandler for click event of the item /// public ItemEventHandler OnItemClickedHandler; - public delegate void ContextPopupItemSelectedEventHandler(MediaInformation info, ImageContextPopupItem item); + public delegate void ContextPopupItemSelectedEventHandler(MediaInformationEx info, ImageContextPopupItem item); public ContextPopupItemSelectedEventHandler ContextPopupItemSelectedHandler; @@ -125,12 +126,12 @@ namespace TVMediaHub.Tizen.Views /// /// Identifies the SelectedImage bindable property /// - public static readonly BindableProperty ImageInfoProperty = BindableProperty.Create("SelectedImage", typeof(MediaInformation), typeof(ImageItem), null); + public static readonly BindableProperty ImageInfoProperty = BindableProperty.Create("SelectedImage", typeof(MediaInformationEx), typeof(ImageItem), null); /// - /// Gets or sets the MediaInformation of selected image + /// Gets or sets the MediaInformationEx of selected image /// - public MediaInformation SelectedImage + public MediaInformationEx SelectedImage { set { @@ -139,7 +140,7 @@ namespace TVMediaHub.Tizen.Views get { - return (MediaInformation)GetValue(ImageInfoProperty); + return (MediaInformationEx)GetValue(ImageInfoProperty); } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs index 542e2fb..07a61ac 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs @@ -652,21 +652,22 @@ namespace TVMediaHub.Tizen.Views } } - private async void ShowPopup(MediaInformation info, ImageContextPopupItem item) + private async void ShowPopup(MediaInformationEx info, ImageContextPopupItem item) { switch (item) { case ImageContextPopupItem.FileInfo: - string message = "File name : " + info.Title + "\n"; - message += "File size : " + info.Size + "\n"; - message += "File format : " + info.MimeType + "\n"; - message += "File size : " + info.Size + "\n"; - message += "File path : " + info.FilePath; + string message = "File name : " + info.MediaContentInformation.Title + "\n"; + message += "File size : " + info.MediaContentInformation.Size + "\n"; + message += "File format : " + info.MediaContentInformation.MimeType + "\n"; + message += "File size : " + info.MediaContentInformation.Size + "\n"; + message += "File path : " + info.MediaContentInformation.FilePath; + await DisplayAlert("File Information", message, "Close"); Dialog dialog = new Dialog(); break; case ImageContextPopupItem.Delete: - bool answer = await DisplayAlert("Delete", "Delete '" + info.Title + "'?", "Yes", "No"); + bool answer = await DisplayAlert("Delete", "Delete '" + info.MediaContentInformation.Title + "'?", "Yes", "No"); if (answer) { DeleteContentCommand?.Execute(item); diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs index 6660de7..b2b52aa 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs @@ -60,7 +60,7 @@ namespace TVMediaHub.Tizen.Views /// private ICommand ItemClickCommand; - public delegate void ContextPopupItemSelelectedEventHandler(MediaInformation info, VideoContextPopupItem item); + public delegate void ContextPopupItemSelelectedEventHandler(MediaInformationEx info, VideoContextPopupItem item); public ContextPopupItemSelelectedEventHandler ContextPopupItemSelectedHandler; /// diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs index e5f644f..88c1125 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs @@ -19,6 +19,7 @@ using System.ComponentModel; using Tizen.Content.MediaContent; using Tizen.Xamarin.Forms.Extension; using TVMediaHub.Tizen.Utils; +using TVMediaHub.Tizen.DataModels; using Xamarin.Forms; namespace TVMediaHub.Tizen.Views @@ -105,13 +106,13 @@ namespace TVMediaHub.Tizen.Views /// A delegate will be executed when the item is clicked /// /// A clicked item's MediaInformation - public delegate void ItemEventHandler(MediaInformation info); + public delegate void ItemEventHandler(MediaInformationEx info); /// /// A ClickEventHandler for click event of the item /// public ItemEventHandler OnItemClickedHandler; - public delegate void ContextPopupItemSelectedEventHandler(MediaInformation info, VideoContextPopupItem item); + public delegate void ContextPopupItemSelectedEventHandler(MediaInformationEx info, VideoContextPopupItem item); public ContextPopupItemSelectedEventHandler ContextPopupItemSelectedHandler; @@ -139,12 +140,12 @@ namespace TVMediaHub.Tizen.Views /// /// Identifies the VideoInfo bindable property /// - public static readonly BindableProperty VideoInfoProperty = BindableProperty.Create("VideoInfo", typeof(MediaInformation), typeof(VideoItem), null); + public static readonly BindableProperty VideoInfoProperty = BindableProperty.Create("VideoInfo", typeof(MediaInformationEx), typeof(VideoItem), null); /// /// Gets or sets the VideoInfo of current video /// - public MediaInformation VideoInfo + public MediaInformationEx VideoInfo { set { @@ -153,7 +154,7 @@ namespace TVMediaHub.Tizen.Views get { - return (MediaInformation)GetValue(VideoInfoProperty); + return (MediaInformationEx)GetValue(VideoInfoProperty); } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml.cs index a4846b9..5ad9244 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml.cs @@ -19,6 +19,7 @@ using Tizen.Content.MediaContent; using Tizen.Multimedia; using TVMediaHub.Tizen.Utils; using TVMediaHub.Tizen.ViewModels; +using TVMediaHub.Tizen.DataModels; using TVMediaHub.Tizen.Controls; using Xamarin.Forms; using Extension = Tizen.Xamarin.Forms.Extension; @@ -154,14 +155,14 @@ namespace TVMediaHub.Tizen.Views /// /// Identifies the CurrenVideo bindable property /// - public static readonly BindableProperty CurrentVideoProperty = BindableProperty.Create("CurrentVideo", typeof(MediaInformation), typeof(VideoPlayer), null); + public static readonly BindableProperty CurrentVideoProperty = BindableProperty.Create("CurrentVideo", typeof(MediaInformationEx), typeof(VideoPlayer), null); /// /// Gets or sets CurrentVideo /// - public MediaInformation CurrentVideo + public MediaInformationEx CurrentVideo { - get { return (MediaInformation)GetValue(CurrentVideoProperty); } + get { return (MediaInformationEx)GetValue(CurrentVideoProperty); } set { SetValue(CurrentVideoProperty, value); } } @@ -261,7 +262,7 @@ namespace TVMediaHub.Tizen.Views playerInstance.Unprepare(); playerDisplayInstance = new Display((MediaView)mediaView.NativeView); playerInstance.Display = playerDisplayInstance; - videoMediaSource = new MediaUriSource(CurrentVideo.FilePath); + videoMediaSource = new MediaUriSource(CurrentVideo.MediaContentInformation.FilePath); playerInstance.SetSource(videoMediaSource); } catch (Exception ex) @@ -470,7 +471,7 @@ namespace TVMediaHub.Tizen.Views } }; - videoMediaSource = new MediaUriSource(CurrentVideo.FilePath); + videoMediaSource = new MediaUriSource(CurrentVideo.MediaContentInformation.FilePath); playerInstance.SetSource(videoMediaSource); } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs index 5f22bd9..6cf97ce 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs @@ -640,22 +640,21 @@ namespace TVMediaHub.Tizen.Views } } - - private async void ShowPopup(MediaInformation info, VideoContextPopupItem item) + private async void ShowPopup(MediaInformationEx info, VideoContextPopupItem item) { switch (item) { case VideoContextPopupItem.FileInfo: - string message = "File name : " + info.Title + "\n"; - message += "File size : " + info.Size + "\n"; - message += "File format : " + info.MimeType + "\n"; - message += "File size : " + info.Size + "\n"; - message += "File path : " + info.FilePath; + string message = "File name : " + info.MediaContentInformation.Title + "\n"; + message += "File size : " + info.MediaContentInformation.Size + "\n"; + message += "File format : " + info.MediaContentInformation.MimeType + "\n"; + message += "File size : " + info.MediaContentInformation.Size + "\n"; + message += "File path : " + info.MediaContentInformation.FilePath; await DisplayAlert("File Information", message, "Close"); break; case VideoContextPopupItem.Delete: - bool answer = await DisplayAlert("Delete", "Delete '" + info.Title + "'?", "Yes", "No"); + bool answer = await DisplayAlert("Delete", "Delete '" + info.MediaContentInformation.Title + "'?", "Yes", "No"); if (answer) { DeleteContentCommand?.Execute(item); -- 2.7.4 From ffd2d535511725e6151ff9c227f9941fa36be494 Mon Sep 17 00:00:00 2001 From: Hyerim Kim Date: Mon, 5 Jun 2017 16:44:04 +0900 Subject: [PATCH 07/16] Implements the StorageProvider and gets the contents according to sources Change-Id: I6f13dbde0eb256dd7c3befb03cb77b70e1be0548 Signed-off-by: Hyerim Kim --- .../TVMediaHub.Tizen/Models/ContentProvider.cs | 26 ++++- .../TVMediaHub.Tizen/Models/ImageProvider.cs | 4 +- TVMediaHub/TVMediaHub.Tizen/Models/MediaHubImpl.cs | 15 +++ .../TVMediaHub.Tizen/Models/MusicProvider.cs | 4 +- .../TVMediaHub.Tizen/Models/StorageProvider.cs | 27 +++-- .../TVMediaHub.Tizen/Models/VideoProvider.cs | 4 +- .../ViewModels/ImageTabViewModel.cs | 117 +++++++++++++++------ .../ViewModels/VideoTabViewModel.cs | 111 +++++++++++++++---- .../TVMediaHub.Tizen/Views/ImageGroup.xaml.cs | 2 +- TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml | 2 + TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs | 57 +++++++++- .../TVMediaHub.Tizen/Views/VideoGroup.xaml.cs | 2 +- TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml | 4 +- TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs | 56 +++++++++- 14 files changed, 353 insertions(+), 78 deletions(-) diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs index 57b2aa9..c15c604 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs @@ -54,7 +54,16 @@ namespace TVMediaHub.Tizen.Models /// abstract protected void CheckUnavailableContent(MediaInformationEx mediaContent); - abstract public void SetContentUpdatedEventListener(EventHandler listener); + /// + /// A method for handling ContentUpdatedEvent + /// + /// A handling method + abstract public void SetContentUpdatedEventListener(EventHandler listener); + + /// + /// An EventHandler be sent to Image, Video and MusicProvider when ContentUpdated event is triggered + /// + public EventHandler ContentUpdateFinished; /// /// A constructor @@ -65,6 +74,7 @@ namespace TVMediaHub.Tizen.Models try { ContentDatabase.Connect(); + ContentDatabase.ContentUpdated += ContentDatabaseContentUpdated; } catch (Exception e) { @@ -74,6 +84,20 @@ namespace TVMediaHub.Tizen.Models } /// + /// Handles ContentUpdated event that is triggered when db is changed. + /// + /// The source of the event + /// A ContentUpdatedEvent arguments + private void ContentDatabaseContentUpdated(object sender, ContentUpdatedEventArgs e) + { + if (e.UpdateType == MediaContentDBUpdateType.Update) + { + MediaHubImpl.GetInstance.StorageProviderInstance.CheckStorage(); + ContentUpdateFinished?.Invoke(this, null); + } + } + + /// /// Converts the value of the DateTime object to its equivalent string representation. /// /// A DateTime information diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs index e7d297d..63f1f5f 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs @@ -60,9 +60,9 @@ namespace TVMediaHub.Tizen.Models } } - public override void SetContentUpdatedEventListener(EventHandler listener) + public override void SetContentUpdatedEventListener(EventHandler listener) { - ContentDatabase.ContentUpdated += listener; + base.ContentUpdateFinished += listener; } } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/MediaHubImpl.cs b/TVMediaHub/TVMediaHub.Tizen/Models/MediaHubImpl.cs index bb53dfa..4e89dcc 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/MediaHubImpl.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/MediaHubImpl.cs @@ -83,6 +83,21 @@ namespace TVMediaHub.Tizen.Models } /// + /// An instance of the StorageProvider + /// + private static readonly StorageProvider storageProviderInstance = new StorageProvider(); + /// + /// Gets an instance of the StorageProvider + /// + public StorageProvider StorageProviderInstance + { + get + { + return storageProviderInstance; + } + } + + /// /// A constructor /// public MediaHubImpl() diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs index 9eeabac..d874120 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs @@ -54,9 +54,9 @@ namespace TVMediaHub.Tizen.Models } } - public override void SetContentUpdatedEventListener(EventHandler listener) + public override void SetContentUpdatedEventListener(EventHandler listener) { - ContentDatabase.ContentUpdated += listener; + base.ContentUpdateFinished += listener; } } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/StorageProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/StorageProvider.cs index 0ed2e48..39a80d1 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/StorageProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/StorageProvider.cs @@ -25,22 +25,37 @@ namespace TVMediaHub.Tizen.Models public class StorageProvider { /// + /// A list of external storage + /// + private IEnumerable storageList = new List(); + + /// + /// A list of storage id + /// + public List StorageId { get; protected set; } + + /// /// A constructor /// public StorageProvider() { - /// Connect to the media database to search, insert, remove or modify media information. - ContentDatabase.Connect(); + StorageId = new List(); + CheckStorage(); } /// - /// Returns the ContentCollections with optional filter from the media database. + /// Returns the list of the storage id of the media storage. /// /// Task with the list of the ContentCollection - public IEnumerable Read() + public void CheckStorage() { - return ContentManager.Database.SelectAll(null); - } + StorageId.Clear(); + storageList = ContentManager.Database.SelectAll(null); + foreach (var item in storageList) + { + StorageId.Add(item.Id); + } + } } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs index 47f38d5..7417734 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs @@ -100,9 +100,9 @@ namespace TVMediaHub.Tizen.Models ContentManager.Database.Update(videoContent.MediaContentInformation); } - public override void SetContentUpdatedEventListener(EventHandler listener) + public override void SetContentUpdatedEventListener(EventHandler listener) { - ContentDatabase.ContentUpdated += listener; + base.ContentUpdateFinished += listener; } } } \ No newline at end of file diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs index 0544c11..b36e2e5 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs @@ -20,7 +20,6 @@ using System.Runtime.CompilerServices; using System.Windows.Input; using Xamarin.Forms; using System.Linq; -using Tizen.Content.MediaContent; using TVMediaHub.Tizen.Models; using TVMediaHub.Tizen.DataModels; using System.Threading.Tasks; @@ -43,10 +42,18 @@ namespace TVMediaHub.Tizen.ViewModels public ObservableCollection ImageList { get; set; } /// + /// A dictionary list of the source and storage id + /// + private Dictionary sourcePairList; + + /// /// An index of displaying image /// private int displayingImageIndex; + /// + /// A sort option + /// private SortOption option = SortOption.Date; /// @@ -130,6 +137,11 @@ namespace TVMediaHub.Tizen.ViewModels public ICommand ChangeSortOptionCommand { get; set; } /// + /// A command for changing Source + /// + public ICommand ChangeSourceCommand { get; set; } + + /// /// A command for deleting a image content /// public ICommand DeleteContentCommand { get; set; } @@ -139,7 +151,6 @@ namespace TVMediaHub.Tizen.ViewModels /// public ICommand SelectAllContentCommand { get; set; } - private int SortBy; /// /// A flag that whether the content is delete mode or not /// @@ -166,6 +177,31 @@ namespace TVMediaHub.Tizen.ViewModels } /// + /// A flag that whether the BottomButtonList of Tab is needed to delete or not + /// + private bool isNeededClearList; + + /// + /// Gets or sets the isNeededClearList + /// + public bool IsNeededClearList + { + get + { + return isNeededClearList; + } + + set + { + if (isNeededClearList != value) + { + isNeededClearList = value; + OnPropertyChanged("IsNeededClearList"); + } + } + } + + /// /// A command for executing when CurrentImageInfo is changed /// public ICommand SetCurrentImageInfo @@ -257,22 +293,16 @@ namespace TVMediaHub.Tizen.ViewModels /// public ImageTabViewModel() { + ImageList = new ObservableCollection(); + SelectedList = new List(); + sourcePairList = new Dictionary(); InitializeFooterItemsSource(); InitializeCommands(); CreateImageInfoList(); - - 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(""); - } - */ + AddSourceListItem(); }); } @@ -347,6 +377,21 @@ namespace TVMediaHub.Tizen.ViewModels } }); + ChangeSourceCommand = new Command((name) => + { + if (name == null) + { + DbgPort.D("name is null"); + return; + } + + string id = sourcePairList[name]; + SynchronizationContext.Current.Post((o) => + { + ReadImageList(option, id); + }, ""); + }); + SelectAllContentCommand = new Command((IsSelectedAll) => { if (IsSelectedAll) @@ -442,24 +487,32 @@ namespace TVMediaHub.Tizen.ViewModels OnPropertyChanged("ChangeSortOptionCommand"); } - private void GetImageData(int source, int sortby) + /// + /// A method for making the source list + /// + private void AddSourceListItem() { + int index = 1; + sourcePairList.Clear(); + List tempList = new List(); - } + sourcePairList.Add("ALL SOURCE", null); + sourcePairList.Add("DEVICE", "media"); - private void OnSourceChanged(int source) - { + tempList.Add("ALL SOURCE"); + tempList.Add("DEVICE"); - } - - void OnSortbyChanged(int sortby) - { - if (SortBy != sortby) + foreach (var item in MediaHubImpl.GetInstance.StorageProviderInstance.StorageId) { - SortBy = sortby; + sourcePairList.Add("USB " + index, item); + tempList.Add("USB " + index); + index++; } - } + SourceList = tempList; + + OnPropertyChanged("SourceList"); + } /// /// Finds specific Image in list and sets the DisplayingImageIndex @@ -508,20 +561,25 @@ namespace TVMediaHub.Tizen.ViewModels /// A method for reading image contents through ImageProvider and updating ImageList /// /// A current sort option - private async void ReadImageList(SortOption option) + private async void ReadImageList(SortOption option, string storageId = null) { ImageList.Clear(); - IEnumerable tempList = await MediaHubImpl.GetInstance.ImageProviderInstance.ReadAsync(option); + IEnumerable tempList = await MediaHubImpl.GetInstance.ImageProviderInstance.ReadAsync(option, storageId); foreach (var group in tempList) { await MediaHubImpl.GetInstance.ImageProviderInstance.CheckThumbnail(group.Contents); } + + IsNeededClearList = true; + foreach (var group in tempList) { // TODO : remove delay await Task.Delay(1); ImageList.Add(group); } + + IsNeededClearList = false; } /// @@ -545,14 +603,9 @@ namespace TVMediaHub.Tizen.ViewModels /// private void InitializeFooterItemsSource() { - var list = new List - { - "ALL SOURCE", - }; - SourceList = list; - OnPropertyChanged("SourceList"); + AddSourceListItem(); - list = new List + var list = new List { "EVENT", "FILE FORMAT", diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs index a9027f7..749edca 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs @@ -21,7 +21,6 @@ using System.ComponentModel; using System.IO; using System.Threading; using System.Windows.Input; -using Tizen.Content.MediaContent; using TVMediaHub.Tizen.Models; using TVMediaHub.Tizen.Utils; using TVMediaHub.Tizen.DataModels; @@ -39,6 +38,8 @@ namespace TVMediaHub.Tizen.ViewModels /// public event PropertyChangedEventHandler PropertyChanged; + private Dictionary sourcePairList; + /// /// A method for invoking PropertyChanged event /// @@ -86,6 +87,11 @@ namespace TVMediaHub.Tizen.ViewModels public ICommand ChangeSortOptionCommand { get; set; } /// + /// A command for changing Source + /// + public ICommand ChangeSourceCommand { get; set; } + + /// /// A command for getting the list of video contents /// public ICommand GetInformationsCommand { get; set; } @@ -119,8 +125,14 @@ namespace TVMediaHub.Tizen.ViewModels get; } + /// + /// A flag that whether the content is delete mode or not + /// private bool isDeleteStatus; + /// + /// A sort option + /// private SortOption option = SortOption.Title; /// @@ -158,6 +170,31 @@ namespace TVMediaHub.Tizen.ViewModels } /// + /// A flag that whether the BottomButtonList of Tab is needed to delete or not + /// + private bool isNeededClearList; + + /// + /// Gets or sets the isNeededClearList + /// + public bool IsNeededClearList + { + get + { + return isNeededClearList; + } + + set + { + if (isNeededClearList != value) + { + isNeededClearList = value; + OnPropertyChanged("IsNeededClearList"); + } + } + } + + /// /// A list of video contents to be displayed /// public List SelectedList { get; set; } @@ -179,22 +216,16 @@ namespace TVMediaHub.Tizen.ViewModels public VideoTabViewModel() { DbgPort.D("Binding Context cotr " + DateTime.Now); - InitializeFooterItemsSource(); - InitializeCommands(); VideoList = new ObservableCollection(); SelectedList = new List(); PlayList = new List(); - + sourcePairList = new Dictionary(); + InitializeFooterItemsSource(); + InitializeCommands(); OnPropertyChanged("VideoList"); MediaHubImpl.GetInstance.VideoProviderInstance.SetContentUpdatedEventListener((sender, arg) => { - DbgPort.D("Content updated"); - /* - if (arg.UpdateType.Equals(MediaContentDBUpdateType.Update)) - { - GetInformationsCommand?.Execute(""); - } - */ + AddSourceListItem(); }); } @@ -266,7 +297,20 @@ namespace TVMediaHub.Tizen.ViewModels ReadVideoList(option); }, ""); }); + ChangeSourceCommand = new Command((name) => + { + if (name == null) + { + DbgPort.D("name is null"); + return; + } + string id = sourcePairList[name]; + SynchronizationContext.Current.Post((o) => + { + ReadVideoList(option, id); + }, ""); + }); SetCurrentVideoInfo = new Command((info) => { if (IsDeleteStatus) @@ -332,14 +376,9 @@ namespace TVMediaHub.Tizen.ViewModels /// private void InitializeFooterItemsSource() { - var list = new List - { - "ALL SOURCE", - }; - SourceList = list; - OnPropertyChanged("SourceList"); + AddSourceListItem(); - list = new List + var list = new List { "NAME", "GENRE", @@ -357,6 +396,33 @@ namespace TVMediaHub.Tizen.ViewModels OnPropertyChanged("OptionList"); } + /// + /// A method for making the source list + /// + private void AddSourceListItem() + { + int index = 1; + sourcePairList.Clear(); + List tempList = new List(); + + sourcePairList.Add("ALL SOURCE", null); + sourcePairList.Add("DEVICE", "media"); + + tempList.Add("ALL SOURCE"); + tempList.Add("DEVICE"); + + foreach (var item in MediaHubImpl.GetInstance.StorageProviderInstance.StorageId) + { + sourcePairList.Add("USB " + index, item); + tempList.Add("USB " + index); + index++; + } + + SourceList = tempList; + + OnPropertyChanged("SourceList"); + } + private void ReadRecentlyWatchedContent() { // TODO : Read from VideoProvider @@ -368,21 +434,26 @@ namespace TVMediaHub.Tizen.ViewModels /// A method for reading video contents through VideoProvider and updating VideoList /// /// A current sort option - private async void ReadVideoList(SortOption option) + private async void ReadVideoList(SortOption option, string storageId = null) { VideoList.Clear(); - IEnumerable tempList = await MediaHubImpl.GetInstance.VideoProviderInstance.ReadAsync(option); + + IEnumerable tempList = await MediaHubImpl.GetInstance.VideoProviderInstance.ReadAsync(option, storageId); foreach (var group in tempList) { await MediaHubImpl.GetInstance.VideoProviderInstance.CheckThumbnail(group.Contents); } + IsNeededClearList = true; + foreach (var group in tempList) { //await Task.Delay(1); VideoList.Add(group); } + IsNeededClearList = false; + foreach (var group in VideoList) { foreach (var item in group.Contents) diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs index 3ecce46..4a5fe66 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs @@ -200,7 +200,7 @@ namespace TVMediaHub.Tizen.Views }; view.OnUnfocusedEventHandler += (se, ev) => { - if (focusedItem.Equals(view as ImageItem)) + if (focusedItem != null && focusedItem.Equals(view as ImageItem)) { focusedItem = null; } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml index 142ebd2..b87e6d7 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml @@ -9,11 +9,13 @@ IsDeleteStatus="{Binding IsDeleteStatus}" GetInformationsCommand="{Binding GetInformationsCommand}" ChangeSortOptionCommand="{Binding ChangeSortOptionCommand}" + ChangeSourceCommand="{Binding ChangeSourceCommand}" DeleteModeChangeCommand="{Binding DeleteModeChangeCommand}" OnClickCommand="{Binding SetCurrentImageInfo}" DeleteContentCommand="{Binding DeleteContentCommand}" SelectAllContentCommand="{Binding SelectAllContentCommand}" SelectedCount="{Binding SelectedCount}" + IsNeededClearList="{Binding IsNeededClearList}" Title="Gallery"> + /// Identifies the ChangeSourceCommand bindable property + /// + public static readonly BindableProperty ChangeSourceCommandProperty = BindableProperty.Create("ChangeSourceCommand", typeof(ICommand), typeof(ImageTab), default(ICommand)); + + /// + /// Gets or sets ChangeSourceCommand Command + /// + public ICommand ChangeSourceCommand + { + get { return (ICommand)GetValue(ChangeSourceCommandProperty); } + set { SetValue(ChangeSourceCommandProperty, value); } + } + + /// /// Identifies the DeleteModeChangeCommand bindable property /// public static readonly BindableProperty DeleteModeChangeCommandProperty = BindableProperty.Create("DeleteModeChangeCommand", typeof(ICommand), typeof(ImageTab), default(ICommand)); @@ -174,6 +187,20 @@ namespace TVMediaHub.Tizen.Views } /// + /// Identifies the IsNeededClearList bindable property + /// + public static readonly BindableProperty IsNeededClearListProperty = BindableProperty.Create("IsNeededClearList", typeof(bool), typeof(ImageTab), false); + + /// + /// Gets or sets IsNeededClearList + /// + public bool IsNeededClearList + { + get { return (bool)GetValue(IsNeededClearListProperty); } + set { SetValue(IsNeededClearListProperty, value); } + } + + /// /// A list of bottom buttons /// private List> BottomButtonList; @@ -207,7 +234,7 @@ namespace TVMediaHub.Tizen.Views InitializeFonts(); InitializeFooter(); ItemsSource.CollectionChanged += ItemsSourceCollectionChanged; - + PropertyChanged += ImageTabPropertyChanged; SynchronizationContext.Current.Post((o) => { @@ -216,6 +243,22 @@ namespace TVMediaHub.Tizen.Views } /// + /// This method is called when the properties is changed + /// + /// The source of the event + /// A propertyChanged event argument + private void ImageTabPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName.Equals("IsNeededClearList")) + { + if (IsNeededClearList) + { + BottomButtonList.Clear(); + } + } + } + + /// /// A method for initializing list /// private void InitializeData() @@ -252,11 +295,8 @@ namespace TVMediaHub.Tizen.Views /// private void InitializeFooter() { - FooterNormal.OnDropdownSourceItemSelected += OnSourceChanged; - FooterNormal.OnDropdownSortItemSelected += OnSortOptionChanged; - FooterNormal.OnSelectedOptionIndexChanged += OnOptionSelected; FooterDelete.SelecteAllButtonEvent += OnSelectAllClicked; @@ -546,6 +586,11 @@ namespace TVMediaHub.Tizen.Views /// A SelectedItemChanged event's argument private void OnSourceChanged(object sender, SelectedItemChangedEventArgs e) { + String storageName = e.SelectedItem as String; + + BottomButtonList.Clear(); + ChangeSourceCommand?.Execute(storageName); + SetFooterFocusChain(ImageTabScrollView.ScrollX); } /// @@ -555,7 +600,9 @@ namespace TVMediaHub.Tizen.Views /// A SelectedItemChanged event's argument private void OnSortOptionChanged(object sender, SelectedItemChangedEventArgs e) { + BottomButtonList.Clear(); ChangeSortOptionCommand?.Execute(e.SelectedItem); + SetFooterFocusChain(ImageTabScrollView.ScrollX); } /// diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs index b2b52aa..444ff48 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs @@ -254,7 +254,7 @@ namespace TVMediaHub.Tizen.Views }; view.OnUnfocusedEventHandler += (se, ev) => { - if(focusedItem.Equals(view as VideoItem)) + if (focusedItem != null && focusedItem.Equals(view as VideoItem)) { focusedItem = null; } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml index 45412d9..b408c9b 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml @@ -10,11 +10,13 @@ IsDeleteStatus="{Binding IsDeleteStatus}" ChangeTabStatusCommand="{Binding ChangeTabStatusCommand}" ChangeSortOptionCommand="{Binding ChangeSortOptionCommand}" + ChangeSourceCommand="{Binding ChangeSourceCommand}" GetInformationsCommand="{Binding GetInformationsCommand}" OnClickCommand="{Binding SetCurrentVideoInfo}" DeleteContentCommand="{Binding DeleteContentCommand}" SelectAllContentCommand="{Binding SelectAllContentCommand}" - SelectedCount="{Binding SelectedCount}"> + SelectedCount="{Binding SelectedCount}" + IsNeededClearList="{Binding IsNeededClearList}"> diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs index 6cf97ce..868e5e6 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs @@ -91,6 +91,20 @@ namespace TVMediaHub.Tizen.Views } /// + /// Identifies the IsNeededClearList bindable property + /// + public static readonly BindableProperty IsNeededClearListProperty = BindableProperty.Create("IsNeededClearList", typeof(bool), typeof(ImageTab), false); + + /// + /// Gets or sets IsNeededClearList + /// + public bool IsNeededClearList + { + get { return (bool)GetValue(IsNeededClearListProperty); } + set { SetValue(IsNeededClearListProperty, value); } + } + + /// /// Identifies the ChangeTabStatusCommand bindable property /// public static readonly BindableProperty ChangeTabStatusCommandProperty = BindableProperty.Create("ChangeTabStatusCommand", typeof(ICommand), typeof(VideoTab), default(ICommand)); @@ -110,7 +124,7 @@ namespace TVMediaHub.Tizen.Views public static readonly BindableProperty ChangeSortOptionCommandProperty = BindableProperty.Create("ChangeSortOptionCommand", typeof(ICommand), typeof(VideoTab), default(ICommand)); /// - /// Gets or sets ChangeTabStatus Command + /// Gets or sets ChangeSortOption Command /// public ICommand ChangeSortOptionCommand { @@ -119,6 +133,20 @@ namespace TVMediaHub.Tizen.Views } /// + /// Identifies the ChangeSourceCommand bindable property + /// + public static readonly BindableProperty ChangeSourceCommandProperty = BindableProperty.Create("ChangeSourceCommand", typeof(ICommand), typeof(VideoTab), default(ICommand)); + + /// + /// Gets or sets ChangeSourceCommand Command + /// + public ICommand ChangeSourceCommand + { + get { return (ICommand)GetValue(ChangeSourceCommandProperty); } + set { SetValue(ChangeSourceCommandProperty, value); } + } + + /// /// Identifies the DeleteContentCommand bindable property /// public static readonly BindableProperty DeleteContentCommandProperty = BindableProperty.Create("DeleteContentCommand", typeof(ICommand), typeof(VideoTab), default(ICommand)); @@ -198,6 +226,23 @@ namespace TVMediaHub.Tizen.Views InitializeFonts(); InitializeFooter(); ItemsSource.CollectionChanged += ItemsSourceCollectionChanged; + PropertyChanged += VideoTabPropertyChanged; + } + + /// + /// This method is called when the properties is changed + /// + /// The source of the event + /// A propertyChanged event argument + private void VideoTabPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName.Equals("IsNeededClearList")) + { + if (IsNeededClearList) + { + BottomButtonList.Clear(); + } + } } /// @@ -238,9 +283,7 @@ namespace TVMediaHub.Tizen.Views private void InitializeFooter() { FooterNormal.OnDropdownSourceItemSelected += OnSourceChanged; - FooterNormal.OnDropdownSortItemSelected += OnSortOptionChanged; - FooterNormal.OnSelectedOptionIndexChanged += OnOptionSelected; FooterDelete.SelecteAllButtonEvent += OnSelectAllClicked; @@ -355,7 +398,6 @@ namespace TVMediaHub.Tizen.Views } else if (e.Action.ToString().Equals("Reset")) { - BottomButtonList.Clear(); VideoTabList.Children.Clear(); VideoGroupList.Clear(); if (!VideoNoContents.IsVisible) @@ -537,7 +579,10 @@ namespace TVMediaHub.Tizen.Views /// A SelectedItemChanged event's argument private void OnSourceChanged(object sender, SelectedItemChangedEventArgs e) { - // TODO : Source Change + String storageName = e.SelectedItem as String; + + ChangeSourceCommand?.Execute(storageName); + SetFooterFocusChain(VideoTabScrollView.ScrollX); } /// @@ -548,6 +593,7 @@ namespace TVMediaHub.Tizen.Views private void OnSortOptionChanged(object sender, SelectedItemChangedEventArgs e) { ChangeSortOptionCommand?.Execute(e.SelectedItem); + SetFooterFocusChain(VideoTabScrollView.ScrollX); } /// -- 2.7.4 From 938aec6a3432aa3ad0ebca3266d24f464a235398 Mon Sep 17 00:00:00 2001 From: "jjie.choi" Date: Mon, 5 Jun 2017 16:14:21 +0900 Subject: [PATCH 08/16] Implement Music Tab Change-Id: I66341dcfd7bb70abc5caeb106e3a00f6ed8a6292 Signed-off-by: jjie.choi --- .../ViewModels/MusicTabViewModel.cs | 5 + .../ViewModels/MusicTabViewModelLocator.cs | 39 +++++++ .../TVMediaHub.Tizen/Views/MediaHubMainPage.xaml | 3 +- TVMediaHub/TVMediaHub.Tizen/Views/MusicGroup.xaml | 16 +++ .../TVMediaHub.Tizen/Views/MusicGroup.xaml.cs | 97 ++++++++++++++++ TVMediaHub/TVMediaHub.Tizen/Views/MusicItem.xaml | 35 ++++++ .../TVMediaHub.Tizen/Views/MusicItem.xaml.cs | 126 +++++++++++++++++++++ TVMediaHub/TVMediaHub.Tizen/Views/MusicTab.xaml | 37 +++--- TVMediaHub/TVMediaHub.Tizen/Views/MusicTab.xaml.cs | 108 ++++++++++++++++++ 9 files changed, 449 insertions(+), 17 deletions(-) create mode 100644 TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModelLocator.cs create mode 100644 TVMediaHub/TVMediaHub.Tizen/Views/MusicGroup.xaml create mode 100644 TVMediaHub/TVMediaHub.Tizen/Views/MusicGroup.xaml.cs create mode 100644 TVMediaHub/TVMediaHub.Tizen/Views/MusicItem.xaml create mode 100644 TVMediaHub/TVMediaHub.Tizen/Views/MusicItem.xaml.cs diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs index 2709d99..fafed95 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModel.cs @@ -83,5 +83,10 @@ namespace TVMediaHub.Tizen.ViewModels MusicList.Add(group); } } + + public void TestRead() + { + ReadMusicList(option); + } } } diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModelLocator.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModelLocator.cs new file mode 100644 index 0000000..319961b --- /dev/null +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicTabViewModelLocator.cs @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace TVMediaHub.Tizen.ViewModels +{ + /// + /// A class to have static instance of MusicTabViewModel + /// + public static class MusicTabViewModelLocator + { + /// + /// An instance of the MusicTabViewModel + /// + private static MusicTabViewModel _viewModel = new MusicTabViewModel(); + /// + /// Gets the instance of the MusicTabViewModel + /// + public static MusicTabViewModel ViewModel + { + get + { + return _viewModel; + } + } + } +} \ No newline at end of file diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/MediaHubMainPage.xaml b/TVMediaHub/TVMediaHub.Tizen/Views/MediaHubMainPage.xaml index 2e09079..aa5f343 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/MediaHubMainPage.xaml +++ b/TVMediaHub/TVMediaHub.Tizen/Views/MediaHubMainPage.xaml @@ -6,6 +6,5 @@ Title="MEDIA HUB"> - - + diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/MusicGroup.xaml b/TVMediaHub/TVMediaHub.Tizen/Views/MusicGroup.xaml new file mode 100644 index 0000000..41301b1 --- /dev/null +++ b/TVMediaHub/TVMediaHub.Tizen/Views/MusicGroup.xaml @@ -0,0 +1,16 @@ + + + public partial class MusicTab : ContentPageEx { + + /// + /// Identifies the ItemsSource bindable property + /// + public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create("ItemsSource", typeof(ObservableCollection), typeof(MusicTab), default(ObservableCollection)); + + /// + /// Gets or set ItemSource to display music tab + /// + public ObservableCollection ItemsSource + { + get { return (ObservableCollection)GetValue(ItemsSourceProperty); } + set { SetValue(ItemsSourceProperty, value); } + } + + /// + /// Identifies the ChangeSortOptionCommand bindable property + /// + public static readonly BindableProperty ChangeSortOptionCommandProperty = BindableProperty.Create("ChangeSortOptionCommand", typeof(ICommand), typeof(MusicTab), default(ICommand)); + + /// + /// Gets or sets ChangeTabStatus Command + /// + public ICommand ChangeSortOptionCommand + { + get { return (ICommand)GetValue(ChangeSortOptionCommandProperty); } + set { SetValue(ChangeSortOptionCommandProperty, value); } + } /// /// A constructor /// Initializes the size of the items that are used in Music tab /// public MusicTab() { + BindingContext = MusicTabViewModelLocator.ViewModel; InitializeComponent(); InitializeSize(); InitializeFonts(); + InitializeFooter(); + + ItemsSource.CollectionChanged += ItemsSourceCollectionChanged; + + MusicTabViewModelLocator.ViewModel.TestRead(); + // TODO : for the test } + /// /// A method for initializing the size of the items that are used in Music tab /// @@ -59,6 +102,19 @@ namespace TVMediaHub.Tizen.Views } /// + /// Initialize elements on footer area + /// + private void InitializeFooter() + { + FooterNormal.OnDropdownSourceItemSelected += OnSourceChanged; + + FooterNormal.OnDropdownSortItemSelected += OnSortOptionChanged; + + FooterNormal.OnSelectedOptionIndexChanged += OnOptionSelected; + + } + + /// /// A method for initializing page when the page is appeared /// protected override void InitializePage() @@ -85,5 +141,57 @@ namespace TVMediaHub.Tizen.Views public override void RunShowAnimation() { } + + /// + /// Occurs when an item is added, removed, changed, moved, or the entire list is refreshed. + /// + /// The object that raised the event + /// Information about the event + private void ItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + if (e.Action.ToString().Equals("Add")) + { + if (MusicNoContents.IsVisible) + { + MusicNoContents.IsVisible = false; + MusicTabScrollView.IsVisible = true; + } + MusicGroup groupView = new MusicGroup(); + + var groupItem = e.NewItems[0]; + groupView.BindingContext = groupItem; + MusicContentView.Children.Add(groupView); + } + + } + + /// + /// This method is called when Source option is changed + /// + /// The source of the event + /// A SelectedItemChanged event's argument + private void OnSourceChanged(object sender, SelectedItemChangedEventArgs e) + { + // TODO : Source Change + } + + /// + /// This method is called when Sort option is changed + /// + /// The source of the event + /// A SelectedItemChanged event's argument + private void OnSortOptionChanged(object sender, SelectedItemChangedEventArgs e) + { + ChangeSortOptionCommand?.Execute(e.SelectedItem); + } + + /// + /// This method is called when option menu is changed + /// + /// The source of the event + /// A SelectedItemChanged event's argument + private void OnOptionSelected(object sender, ContextPopupSelectedEventArgs e) + { + } } } -- 2.7.4 From 26c81a958899b5de8d150a650587e7af0765e113 Mon Sep 17 00:00:00 2001 From: Hyerim Kim Date: Mon, 5 Jun 2017 18:23:09 +0900 Subject: [PATCH 09/16] Fixed Coding rule check Change-Id: I814ab960b9b341f5a017132c5b9dd608b01f043c Signed-off-by: Hyerim Kim --- TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs | 3 ++- TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs | 1 + TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs | 1 + TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs | 1 + TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs | 3 ++- TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs | 7 +++++-- TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs | 1 + TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs | 5 +++-- TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs | 2 ++ TVMediaHub/TVMediaHub.Tizen/Views/ImageViewer.xaml.cs | 4 ++-- TVMediaHub/TVMediaHub.Tizen/Views/SimpleImageViewer.xaml.cs | 1 + TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs | 3 ++- TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs | 7 ++++--- TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml.cs | 4 +++- TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs | 8 ++++---- 15 files changed, 34 insertions(+), 17 deletions(-) mode change 100644 => 100755 TVMediaHub/TVMediaHub.Tizen/Views/SimpleImageViewer.xaml.cs diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs index c15c604..672cfd0 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs @@ -52,6 +52,7 @@ namespace TVMediaHub.Tizen.Models /// /// An abstract method to determine the availability of the content. /// + /// A media content to be checked the availability abstract protected void CheckUnavailableContent(MediaInformationEx mediaContent); /// @@ -304,7 +305,7 @@ namespace TVMediaHub.Tizen.Models /// A method for making thumbnail of Media contents. /// /// A list of media contents - /// + /// A path of thumbnail public async Task CheckThumbnail(IEnumerable list) { foreach (var info in list) diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs index 63f1f5f..7a0cd72 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/ImageProvider.cs @@ -46,6 +46,7 @@ namespace TVMediaHub.Tizen.Models /// /// A method to determine the availability of the content. /// + /// A media content to be checked the availability protected override void CheckUnavailableContent(MediaInformationEx mediaContent) { if (mediaContent.MediaContentInformation.FilePath != null) diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs index d874120..381a321 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs @@ -44,6 +44,7 @@ namespace TVMediaHub.Tizen.Models /// /// A method to determine the availability of the content. /// + /// A media content to be checked the availability protected override void CheckUnavailableContent(MediaInformationEx mediaContent) { // TODO : Add unsupported mime type here diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs index 7417734..ed9ca1b 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/VideoProvider.cs @@ -47,6 +47,7 @@ namespace TVMediaHub.Tizen.Models /// /// A method to determine the availability of the content. /// + /// A media content to be checked the availability protected override void CheckUnavailableContent(MediaInformationEx mediaContent) { // TODO : Add unsupported mime type here diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs index b36e2e5..90c384f 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs @@ -466,13 +466,14 @@ namespace TVMediaHub.Tizen.ViewModels SelectedList.Clear(); SelectedList.Add(SelectedItem); } + foreach (var info in SelectedList) { try { File.Delete(info.MediaContentInformation.FilePath); } - catch(Exception exception) + catch (Exception exception) { // TODO: Handling exceptions DbgPort.E("Exception - " + exception.Message); diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs index 749edca..372eb07 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs @@ -142,7 +142,8 @@ namespace TVMediaHub.Tizen.ViewModels public int CurrentVideoIndex { get; set; } public List PlayList { get; set; } - public bool IsLastVideo { + public bool IsLastVideo + { get { return (PlayList.Count - 1) == CurrentVideoIndex; @@ -255,13 +256,14 @@ namespace TVMediaHub.Tizen.ViewModels SelectedList.Clear(); SelectedList.Add(SelectedItem); } + foreach (var info in SelectedList) { try { File.Delete(info.MediaContentInformation.FilePath); } - catch(Exception exception) + catch (Exception exception) { // TODO: Handling exceptions DbgPort.E("Exception - " + exception.Message); @@ -434,6 +436,7 @@ namespace TVMediaHub.Tizen.ViewModels /// A method for reading video contents through VideoProvider and updating VideoList /// /// A current sort option + /// A storage id private async void ReadVideoList(SortOption option, string storageId = null) { VideoList.Clear(); diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs index 4a5fe66..f87f44f 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs @@ -363,6 +363,7 @@ namespace TVMediaHub.Tizen.Views focusedItem.ShowContextPopup(); return true; } + return false; } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs index 856e647..a3d7c88 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs @@ -419,6 +419,7 @@ namespace TVMediaHub.Tizen.Views IsLoaded = true; } } + public void ShowContextPopup() { if (!FocusArea.IsFocused) @@ -429,12 +430,12 @@ namespace TVMediaHub.Tizen.Views ContextPopup popup = new ContextPopup(); popup.Items.Add(new ContextPopupItem("FILE INFO")); popup.Items.Add(new ContextPopupItem("DELETE")); - popup.SelectedIndexChanged += selectedIndexChanged; + popup.SelectedIndexChanged += SelectedIndexChanged; popup.Show(this, this.Width / 2, this.Height + SizeUtils.GetHeightSize(72)); } - private void selectedIndexChanged(object sender, EventArgs e) + private void SelectedIndexChanged(object sender, EventArgs e) { var ctxPopup = sender as ContextPopup; switch (ctxPopup.SelectedIndex) diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs index 00c50de..731d840 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs @@ -676,6 +676,7 @@ namespace TVMediaHub.Tizen.Views App.MainWindow.KeyUp -= MenuKeyListener; App.MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName); } + private void MenuKeyListener(object sender, ElmSharp.EvasKeyEventArgs e) { if (e.KeyName.Equals(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName)) @@ -719,6 +720,7 @@ namespace TVMediaHub.Tizen.Views { DeleteContentCommand?.Execute(item); } + break; } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageViewer.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageViewer.xaml.cs index e0b854a..b858412 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageViewer.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageViewer.xaml.cs @@ -451,7 +451,7 @@ namespace TVMediaHub.Tizen.Views /// /// A method for getting visible image /// - /// + /// The image to be seen private Xamarin.Forms.Image GetVisibleImage() { Xamarin.Forms.Image visibleImage = null; @@ -477,7 +477,7 @@ namespace TVMediaHub.Tizen.Views /// /// A method for getting invisible image /// - /// + /// The image to be unseen private Xamarin.Forms.Image GetUnVisibleImage() { Xamarin.Forms.Image unVisibleImage = null; diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/SimpleImageViewer.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/SimpleImageViewer.xaml.cs old mode 100644 new mode 100755 index 27593f9..e404f83 --- a/TVMediaHub/TVMediaHub.Tizen/Views/SimpleImageViewer.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/SimpleImageViewer.xaml.cs @@ -711,6 +711,7 @@ namespace TVMediaHub.Tizen.Views /// e /// A method for hiding control area when timer is over /// + /// The status to be set private void HideControlAreaHandler(object state) { SetControlAreaState(ControlAreaState.HIDE); diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs index 444ff48..ebc6a72 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs @@ -395,11 +395,12 @@ namespace TVMediaHub.Tizen.Views /// If group has a focused video item, true; otherwise, false public bool NotifyMenuKeyPressedToFocusedItem() { - if(focusedItem != null) + if (focusedItem != null) { focusedItem.ShowContextPopup(); return true; } + return false; } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs index 88c1125..2318310 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs @@ -459,12 +459,12 @@ namespace TVMediaHub.Tizen.Views ContextPopup popup = new ContextPopup(); popup.Items.Add(new ContextPopupItem(" FILE INFO ")); popup.Items.Add(new ContextPopupItem("DELETE")); - popup.SelectedIndexChanged += selectedIndexChanged; - popup.Show(this, this.Width/2, this.Height + SizeUtils.GetHeightSize(72)); + popup.SelectedIndexChanged += SelectedIndexChanged; + popup.Show(this, this.Width / 2, this.Height + SizeUtils.GetHeightSize(72)); } - private void selectedIndexChanged(object sender, EventArgs e) + private void SelectedIndexChanged(object sender, EventArgs e) { var ctxPopup = sender as ContextPopup; switch (ctxPopup.SelectedIndex) @@ -476,6 +476,7 @@ namespace TVMediaHub.Tizen.Views ContextPopupItemSelectedHandler?.Invoke(VideoInfo, VideoContextPopupItem.Delete); break; } + ctxPopup.Dismiss(); } } diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml.cs index 5ad9244..8ef7fe9 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml.cs @@ -270,6 +270,7 @@ namespace TVMediaHub.Tizen.Views DbgPort.D(ex.Message); return; } + PrepareAsync(); } } @@ -499,7 +500,7 @@ namespace TVMediaHub.Tizen.Views /// /// Sets the play time on the control area /// - /// + /// A current playing time private void SetPlayTime(int time) { int second = (time / 1000) % 60; @@ -558,6 +559,7 @@ namespace TVMediaHub.Tizen.Views /// e /// A method for hiding control area when timer is over /// + /// The status to be set private void HideControlAreaHandler(object state) { SetControlAreaState(ControlAreaState.HIDE); diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs index 868e5e6..86b10dd 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs @@ -25,12 +25,10 @@ using TVMediaHub.Tizen.Utils; using TVMediaHub.Tizen.ViewModels; using Xamarin.Forms; using Xamarin.Forms.PlatformConfiguration.TizenSpecific; -using Tizen.Content.MediaContent; -using static TVMediaHub.Tizen.Views.VideoItem; -using Tizen.Xamarin.Forms.Extension; namespace TVMediaHub.Tizen.Views { + using static TVMediaHub.Tizen.Views.VideoItem; /// /// A custom ContentPage for displaying the video tab /// @@ -663,6 +661,7 @@ namespace TVMediaHub.Tizen.Views App.MainWindow.KeyUp -= MenuKeyListener; App.MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName); } + private void MenuKeyListener(object sender, ElmSharp.EvasKeyEventArgs e) { if (e.KeyName.Equals(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName)) @@ -675,7 +674,7 @@ namespace TVMediaHub.Tizen.Views { if (VideoTabList.Children.Count > 0) { - foreach(VideoGroup group in VideoTabList.Children) + foreach (VideoGroup group in VideoTabList.Children) { if (group.NotifyMenuKeyPressedToFocusedItem()) { @@ -705,6 +704,7 @@ namespace TVMediaHub.Tizen.Views { DeleteContentCommand?.Execute(item); } + break; } } -- 2.7.4 From 241ef878bba9350dacd7a1234dc1e17c44d1e693 Mon Sep 17 00:00:00 2001 From: "Geunsun, Lee" Date: Wed, 7 Jun 2017 10:13:54 +0900 Subject: [PATCH 10/16] Add files for Music tab Change-Id: I4a69251d327825fd904e913f0066f02471e49ec8 --- TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj b/TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj index b1cbfcd..ebf69fe 100755 --- a/TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj +++ b/TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj @@ -86,6 +86,7 @@ + @@ -105,6 +106,12 @@ ImageTab.xaml + + MusicGroup.xaml + + + MusicItem.xaml + SimpleImageViewer.xaml @@ -301,6 +308,18 @@ Designer + + + MSBuild:UpdateDesignTimeXaml + Designer + + + + + MSBuild:UpdateDesignTimeXaml + Designer + + @@ -13,6 +14,10 @@ RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"> + /// A custom ContentPage for displaying Music tab /// public partial class MusicTab : ContentPageEx { + /// + /// The flag whether content is ready + /// + private bool IsContentReady = false; /// /// Identifies the ItemsSource bindable property @@ -61,6 +68,21 @@ namespace TVMediaHub.Tizen.Views get { return (ICommand)GetValue(ChangeSortOptionCommandProperty); } set { SetValue(ChangeSortOptionCommandProperty, value); } } + + /// + /// Identifies the GetInformationsCommand bindable property + /// + public static readonly BindableProperty GetInformationsCommandProperty = BindableProperty.Create("GetInformationsCommand", typeof(ICommand), typeof(MusicTab), default(ICommand)); + + /// + /// Gets or sets GetInformationsCommand + /// + public ICommand GetInformationsCommand + { + get { return (ICommand)GetValue(GetInformationsCommandProperty); } + set { SetValue(GetInformationsCommandProperty, value); } + } + /// /// A constructor /// Initializes the size of the items that are used in Music tab @@ -74,12 +96,8 @@ namespace TVMediaHub.Tizen.Views InitializeFooter(); ItemsSource.CollectionChanged += ItemsSourceCollectionChanged; - - MusicTabViewModelLocator.ViewModel.TestRead(); - // TODO : for the test } - /// /// A method for initializing the size of the items that are used in Music tab /// @@ -119,6 +137,11 @@ namespace TVMediaHub.Tizen.Views /// protected override void InitializePage() { + if (IsContentReady == false) + { + GetInformationsCommand?.Execute(""); + IsContentReady = true; + } } /// @@ -142,6 +165,7 @@ namespace TVMediaHub.Tizen.Views { } + /// /// Occurs when an item is added, removed, changed, moved, or the entire list is refreshed. /// @@ -149,7 +173,7 @@ namespace TVMediaHub.Tizen.Views /// Information about the event private void ItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { - if (e.Action.ToString().Equals("Add")) + if (e.Action.ToString().Equals(NotifyCollectionChangedAction.Add.ToString())) { if (MusicNoContents.IsVisible) { @@ -162,6 +186,15 @@ namespace TVMediaHub.Tizen.Views groupView.BindingContext = groupItem; MusicContentView.Children.Add(groupView); } + else if (e.Action.ToString().Equals(NotifyCollectionChangedAction.Reset.ToString())) + { + MusicContentView.Children.Clear(); + if (!MusicNoContents.IsVisible) + { + MusicTabScrollView.IsVisible = false; + MusicNoContents.IsVisible = true; + } + } } -- 2.7.4 From 3f1e3ed495078979b6f09ec0a184d6950d0b2ae8 Mon Sep 17 00:00:00 2001 From: Hyerim Kim Date: Thu, 8 Jun 2017 16:10:41 +0900 Subject: [PATCH 14/16] Modifies DeleteContentCommand in MediaHub Change-Id: I7566087bd10f6b620654963a726c3c753b9b2887 Signed-off-by: Hyerim Kim --- TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs | 2 +- TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs | 2 +- TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs | 5 +++-- TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs index 90c384f..fff156c 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs @@ -461,7 +461,7 @@ namespace TVMediaHub.Tizen.ViewModels DeleteContentCommand = new Command((SelectedItem) => { - if (!SelectedItem.Equals("")) + if (SelectedItem != null) { SelectedList.Clear(); SelectedList.Add(SelectedItem); diff --git a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs index 372eb07..5b75e26 100755 --- a/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs +++ b/TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs @@ -251,7 +251,7 @@ namespace TVMediaHub.Tizen.ViewModels }); DeleteContentCommand = new Command((SelectedItem) => { - if (!SelectedItem.Equals("")) + if (SelectedItem != null) { SelectedList.Clear(); SelectedList.Add(SelectedItem); diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs index 8ae6b99..81b7d10 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs @@ -564,7 +564,7 @@ namespace TVMediaHub.Tizen.Views if (answer) { - DeleteContentCommand?.Execute(""); + DeleteContentCommand?.Execute(null); GetInformationsCommand?.Execute(""); } @@ -713,7 +713,8 @@ namespace TVMediaHub.Tizen.Views bool answer = await DisplayAlert("Delete", "Delete '" + info.MediaContentInformation.Title + "'?", "Yes", "No"); if (answer) { - DeleteContentCommand?.Execute(item); + DeleteContentCommand?.Execute(info); + GetInformationsCommand?.Execute(""); } break; diff --git a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs index 86b10dd..9f27157 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs @@ -560,7 +560,7 @@ namespace TVMediaHub.Tizen.Views if (answer) { - DeleteContentCommand?.Execute(""); + DeleteContentCommand?.Execute(null); GetInformationsCommand?.Execute(""); } @@ -702,7 +702,8 @@ namespace TVMediaHub.Tizen.Views bool answer = await DisplayAlert("Delete", "Delete '" + info.MediaContentInformation.Title + "'?", "Yes", "No"); if (answer) { - DeleteContentCommand?.Execute(item); + DeleteContentCommand?.Execute(info); + GetInformationsCommand?.Execute(""); } break; -- 2.7.4 From d0e482dd6aabc55b9fa77b161e28302de7b601ac Mon Sep 17 00:00:00 2001 From: "Geunsun, Lee" Date: Wed, 7 Jun 2017 19:26:16 +0900 Subject: [PATCH 15/16] Implement the music player for the music tab Change-Id: I89095aac77e014ae8ba0ad5a73c237468b7f18d3 --- .../TVMediaHub.Tizen/Models/ContentProvider.cs | 2 + TVMediaHub/TVMediaHub.Tizen/Models/MediaHubImpl.cs | 4 + .../TVMediaHub.Tizen/Models/MusicPlayerModel.cs | 260 +++++++++++++++++++++ .../TVMediaHub.Tizen/Models/MusicProvider.cs | 1 - .../TVMediaHub.Tizen/TVMediaHub.Tizen.csproj | 12 + .../TVMediaHub.Tizen/Utils/EasingFunction.cs | 21 ++ .../ViewModels/ImageTabViewModel.cs | 5 +- .../ViewModels/MusicPlayerViewModel.cs | 105 +++++++++ .../ViewModels/MusicPlayerViewModelLocator.cs | 40 ++++ .../ViewModels/MusicTabViewModel.cs | 26 ++- .../ViewModels/MusicTabViewModelLocator.cs | 1 + .../ViewModels/VideoTabViewModelLocator.cs | 1 + .../TVMediaHub.Tizen/Views/ImageItem.xaml.cs | 1 + .../TVMediaHub.Tizen/Views/ImageViewer.xaml.cs | 3 +- .../TVMediaHub.Tizen/Views/MusicGroup.xaml.cs | 4 +- TVMediaHub/TVMediaHub.Tizen/Views/MusicItem.xaml | 20 +- .../TVMediaHub.Tizen/Views/MusicItem.xaml.cs | 8 +- TVMediaHub/TVMediaHub.Tizen/Views/MusicPlayer.xaml | 18 ++ .../TVMediaHub.Tizen/Views/MusicPlayer.xaml.cs | 37 +++ TVMediaHub/TVMediaHub.Tizen/Views/MusicTab.xaml | 8 +- TVMediaHub/TVMediaHub.Tizen/Views/MusicTab.xaml.cs | 1 + 21 files changed, 558 insertions(+), 20 deletions(-) create mode 100644 TVMediaHub/TVMediaHub.Tizen/Models/MusicPlayerModel.cs create mode 100644 TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicPlayerViewModel.cs create mode 100644 TVMediaHub/TVMediaHub.Tizen/ViewModels/MusicPlayerViewModelLocator.cs create mode 100644 TVMediaHub/TVMediaHub.Tizen/Views/MusicPlayer.xaml create mode 100644 TVMediaHub/TVMediaHub.Tizen/Views/MusicPlayer.xaml.cs diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs index 3d21b0b..3ffb646 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/ContentProvider.cs @@ -162,6 +162,7 @@ namespace TVMediaHub.Tizen.Models newGroupFlag = true; newTitle = mediaInformationEx.MediaContentInformation.MediaType.ToString(); } + break; case SortOption.Album: if (lastGroupItem == null || lastGroupItem.Title != (mediaInformationEx.MediaContentInformation as AudioInformation).Album) @@ -169,6 +170,7 @@ namespace TVMediaHub.Tizen.Models newGroupFlag = true; newTitle = (mediaInformationEx.MediaContentInformation as AudioInformation).Album.ToString(); } + break; case SortOption.Artist: if (lastGroupItem == null || lastGroupItem.Title != (mediaInformationEx.MediaContentInformation as AudioInformation).Artist) diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/MediaHubImpl.cs b/TVMediaHub/TVMediaHub.Tizen/Models/MediaHubImpl.cs index 4e89dcc..4d4a51d 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/MediaHubImpl.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/MediaHubImpl.cs @@ -26,6 +26,7 @@ namespace TVMediaHub.Tizen.Models /// An instance of the MediaHubImpl /// private static readonly MediaHubImpl instance = new MediaHubImpl(); + /// /// Gets an instance of the MediaHubImpl /// @@ -56,6 +57,7 @@ namespace TVMediaHub.Tizen.Models /// An instance of the MusicProvider /// private static readonly MusicProvider musicProviderInstance = new MusicProvider(); + /// /// Gets an instance of the MusicProvider /// @@ -71,6 +73,7 @@ namespace TVMediaHub.Tizen.Models /// An instance of the MusicProvider /// private static readonly VideoProvider videoProviderInstance = new VideoProvider(); + /// /// Gets an instance of the MusicProvider /// @@ -86,6 +89,7 @@ namespace TVMediaHub.Tizen.Models /// An instance of the StorageProvider /// private static readonly StorageProvider storageProviderInstance = new StorageProvider(); + /// /// Gets an instance of the StorageProvider /// diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/MusicPlayerModel.cs b/TVMediaHub/TVMediaHub.Tizen/Models/MusicPlayerModel.cs new file mode 100644 index 0000000..74c1294 --- /dev/null +++ b/TVMediaHub/TVMediaHub.Tizen/Models/MusicPlayerModel.cs @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Threading; +using System.Threading.Tasks; +using Tizen.Content.MediaContent; +using Tizen.Multimedia; +using TVMediaHub.Tizen.DataModels; +using TVMediaHub.Tizen.Utils; + +namespace TVMediaHub.Tizen.Models +{ + /// + /// A custom EventArgs with string fields + /// + public class MusicPlayerInfoEventArgs : EventArgs + { + public string Title; + public string Artist; + public string AlbumCover; + } + + /// + /// A custom EventArgs with double field + /// + public class MusicPlayerProgressEventArgs : EventArgs + { + public double Progress; + } + + /// + /// An instance of the MusicPlayerModel + /// + public class MusicPlayerModel + { + /// + /// A main instance class of the music player model instance + /// + private static readonly MusicPlayerModel instance = new MusicPlayerModel(); + + /// + /// An instance of the player + /// + private Player playerInstance; + + /// + /// An timer for the progressbar + /// + private Timer progressbarTimer; + + /// + /// The period of the timer + /// + private int timerPeriod = 1000; + + /// + /// An event handler for handling the current music information + /// + private EventHandler MusicPlayerInfoListener; + + /// + /// An event handler for handling the percentage of the progressbar + /// + private EventHandler MusicPlayerProgressListener; + + /// + /// The information of the current music + /// + public MediaInformationEx currentMusic; + + /// + /// Gets or sets the current music + /// + public MediaInformationEx CurrentMusic + { + get + { + return currentMusic; + } + + set + { + if (currentMusic != value) + { + currentMusic = value; + + /// 1. Stop the player + if (playerInstance.State == PlayerState.Playing) + { + StopPlayer(); + } + + /// 2. Play the current music + StartPlayerAsync((currentMusic.MediaContentInformation as AudioInformation).FilePath); + + /// 3. Update the information of the current music + MusicPlayerInfoListener?.Invoke(this, new MusicPlayerInfoEventArgs() + { + Title = (currentMusic.MediaContentInformation as AudioInformation).Title, + Artist = (currentMusic.MediaContentInformation as AudioInformation).Artist, + AlbumCover = ((currentMusic.MediaContentInformation as AudioInformation).ThumbnailPath.Length != 0) ? (currentMusic.MediaContentInformation as AudioInformation).ThumbnailPath : "img_media_no_contents.png", + }); + + /// 4. Update the progressbar of the current music + MusicPlayerProgressListener?.Invoke(this, new MusicPlayerProgressEventArgs() + { + Progress = (playerInstance.State == PlayerState.Idle || playerInstance.State == PlayerState.Preparing) ? 0 : Convert.ToDouble(playerInstance.GetPlayPosition()) / (currentMusic.MediaContentInformation as AudioInformation).Duration, + }); + } + } + } + + /// + /// Gets an instance of the music player model + /// + public static MusicPlayerModel Instance + { + get + { + return instance; + } + } + + /// + /// A constructor + /// + public MusicPlayerModel() + { + InitializePlayer(); + InitializeProgressbarTimer(); + } + + /// + /// Initialize the player instance + /// Register event handler for the player + /// + private void InitializePlayer() + { + playerInstance = new Player(); + + playerInstance.PlaybackCompleted += ((s, e) => + { + StopPlayer(); + }); + + playerInstance.PlaybackInterrupted += ((s, e) => + { + DbgPort.E("Error : " + Enum.GetName(typeof(PlayerError), e.Reason)); + + StopPlayer(); + }); + + playerInstance.ErrorOccurred += ((s, e) => + { + DbgPort.E("Error : " + Enum.GetName(typeof(PlayerError), e.Error)); + + StopPlayer(); + }); + } + + /// + /// Initialize the timer for the progressbar + /// + private void InitializeProgressbarTimer() + { + progressbarTimer = new Timer((object o) => + { + MusicPlayerProgressListener?.Invoke(this, new MusicPlayerProgressEventArgs() + { + Progress = (playerInstance.State == PlayerState.Idle || playerInstance.State == PlayerState.Preparing) ? 0 : Convert.ToDouble(playerInstance.GetPlayPosition()) / (currentMusic.MediaContentInformation as AudioInformation).Duration, + }); + }, null, Timeout.Infinite, Timeout.Infinite); + } + + /// + /// Starts the timer for the progressbar + /// + private void StartProgressbarTimer() + { + progressbarTimer.Change(0, timerPeriod); + } + + /// + /// Stops the timer for the porgressbar + /// + private void StopProgressbarTimer() + { + progressbarTimer.Change(Timeout.Infinite, Timeout.Infinite); + } + + /// + /// Plays the current music + /// + /// The file path of the media source + public void StartPlayerAsync(string filePath) + { + MediaSource source = new MediaUriSource(filePath); + playerInstance.SetSource(source); + + Task.Run(async () => + { + await playerInstance.PrepareAsync(); + + playerInstance.Start(); + + StartProgressbarTimer(); + }); + } + + /// + /// Stops the current music + /// + public void StopPlayer() + { + StopProgressbarTimer(); + + try + { + playerInstance.Stop(); + playerInstance.Unprepare(); + } + catch (Exception e) + { + DbgPort.E("Error : " + e.Message); + } + } + + /// + /// A method adds EventHandler to SetCurrentMusicInfoListener + /// + /// The EventHandler for adding + public void SetCurrentMusicInfoListener(EventHandler listener) + { + MusicPlayerInfoListener += listener; + } + + /// + /// A method adds EventHandler to SetCurrentMusicProgressListener + /// + /// The EventHandler for adding + public void SetCurrentMusicProgressListener(EventHandler listener) + { + MusicPlayerProgressListener += listener; + } + } +} diff --git a/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs b/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs index 381a321..95a5540 100755 --- a/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs +++ b/TVMediaHub/TVMediaHub.Tizen/Models/MusicProvider.cs @@ -15,7 +15,6 @@ */ using System; -using Tizen.Content.MediaContent; using TVMediaHub.Tizen.DataModels; namespace TVMediaHub.Tizen.Models diff --git a/TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj b/TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj index 6b66f2b..0666f86 100755 --- a/TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj +++ b/TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj @@ -65,6 +65,7 @@ + @@ -85,7 +86,9 @@ + + @@ -136,6 +139,9 @@ VideoItem.xaml + + MusicPlayer.xaml + VideoPlayer.xaml @@ -323,6 +329,12 @@ Designer + + + MSBuild:UpdateDesignTimeXaml + Designer + +