Implements movie context popup
authorjjie.choi <jjie.choi@samsung.com>
Wed, 31 May 2017 02:33:15 +0000 (11:33 +0900)
committerjjie.choi <jjie.choi@samsung.com>
Wed, 31 May 2017 06:23:37 +0000 (15:23 +0900)
Change-Id: I68917fb3c11baaeda08b43733016aa01659fa47f
Signed-off-by: jjie.choi <jjie.choi@samsung.com>
TVMediaHub/TVMediaHub.Tizen/ViewModels/VideoTabViewModel.cs
TVMediaHub/TVMediaHub.Tizen/Views/VideoGroup.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs

index 745ccd2..33b1e61 100755 (executable)
@@ -195,8 +195,13 @@ namespace TVMediaHub.Tizen.ViewModels
                     }
                 }
             });
-            DeleteContentCommand = new Command(() =>
+            DeleteContentCommand = new Command<MediaInformation>((SelectedItem) =>
             {
+                if (!SelectedItem.Equals(""))
+                {
+                    SelectedList.Clear();
+                    SelectedList.Add(SelectedItem);
+                }
                 foreach (var info in SelectedList)
                 {
                     try
index 4097ae3..b063e65 100755 (executable)
@@ -22,6 +22,7 @@ using TVMediaHub.Tizen.Models;
 using TVMediaHub.Tizen.Utils;
 using Xamarin.Forms;
 using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
+using Tizen.Content.MediaContent;
 
 namespace TVMediaHub.Tizen.Views
 {
@@ -58,6 +59,9 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         private ICommand ItemClickCommand;
 
+        public delegate void ItemDeleteHandler(MediaInformation info);
+
+        public ItemDeleteHandler OnItemDeleteHandler;
         /// <summary>
         /// Gets or sets source of list items
         /// </summary>
@@ -84,6 +88,9 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         public List<KeyValuePair<double, Button>> BottomFocusList { get; protected set; }
 
+        private VideoItem focusedItem;
+
+
         /// <summary>
         /// A list of video items
         /// </summary>
@@ -242,11 +249,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 VideoItem))
+                        {
+                            focusedItem = null;
+                        }
                     };
                     view.OnItemClickedHandler += (info) =>
                     {
                         ItemClickCommand?.Execute(info);
                     };
+                    view.DeleteItemHandler += (info) =>
+                    {
+                        OnItemDeleteHandler?.Invoke(info);
+                    };
 
                     GroupContentArea.Children.Add(view, index / 3, index % 3);
                     index++;
@@ -368,5 +387,19 @@ namespace TVMediaHub.Tizen.Views
         {
             ItemClickCommand = command;
         }
+
+        /// <summary>
+        /// If there is focused video item, notify the menu key pressed event to focused video item for show context popup
+        /// </summary>
+        /// <returns>If group has a focused video item, true; otherwise, false</returns>
+        public bool NotifyMenuKeyPressedToFocusedItem()
+        {
+            if(focusedItem != null)
+            {
+                focusedItem.ShowContextPopup();
+                return true;
+            }
+            return false;
+        }
     }
 }
index b1a0352..3f3ccd7 100755 (executable)
@@ -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;
 
@@ -98,11 +99,13 @@ namespace TVMediaHub.Tizen.Views
         /// A delegate will be executed when the item is clicked
         /// </summary>
         /// <param name="info">A clicked item's MediaInformation</param>
-        public delegate void ClickEventHandler(MediaInformation info);
+        public delegate void ItemEventHandler(MediaInformation info);
         /// <summary>
         /// A ClickEventHandler for click event of the item
         /// </summary>
-        public ClickEventHandler OnItemClickedHandler;
+        public ItemEventHandler OnItemClickedHandler;
+
+        public ItemEventHandler DeleteItemHandler;
 
         /// <summary>
         /// Identifies the IsDeleteMode bindable property
@@ -256,6 +259,7 @@ namespace TVMediaHub.Tizen.Views
         /// <param name="e">A Focus event's argument</param>
         public void OnUnfocused(object sender, FocusEventArgs e)
         {
+            OnUnfocusedEventHandler?.Invoke(sender, e);
             Easing easing = new Easing(EasingFunction.EasyIn2);
             this.AbortAnimation("TextSliding");
             this.AbortAnimation("FocusAnimation");
@@ -435,5 +439,35 @@ namespace TVMediaHub.Tizen.Views
                 }
             }
         }
+
+        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(VideoInfo);
+                    break;
+            }
+            ctxPopup.Dismiss();
+        }
     }
 }
index b41c008..7b3f35d 100755 (executable)
@@ -25,6 +25,7 @@ using TVMediaHub.Tizen.Utils;
 using TVMediaHub.Tizen.ViewModels;
 using Xamarin.Forms;
 using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
+using Tizen.Content.MediaContent;
 
 namespace TVMediaHub.Tizen.Views
 {
@@ -310,6 +311,11 @@ namespace TVMediaHub.Tizen.Views
                 var GroupItem = e.NewItems[0];
                 groupView.BindingContext = GroupItem;
                 groupView.SetClickCommand(OnClickCommand);
+                groupView.OnItemDeleteHandler += (info) =>
+                {
+                    ShowDeletePopup(info);
+                };
+
                 VideoTabList.Children.Add(groupView);
                 VideoGroupList.Add(groupView);
 
@@ -593,5 +599,54 @@ namespace TVMediaHub.Tizen.Views
             VideoTabList.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 (VideoTabList.Children.Count > 0)
+            {
+                foreach(VideoGroup group in VideoTabList.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);
+            }
+
+        }
     }
 }