Implements ImageTab context popup
authorjjie.choi <jjie.choi@samsung.com>
Wed, 31 May 2017 07:30:33 +0000 (16:30 +0900)
committerjjie.choi <jjie.choi@samsung.com>
Wed, 31 May 2017 07:49:59 +0000 (16:49 +0900)
Change-Id: I4651b6181a202e96c0fc8472aed05c9d42ee1231
Signed-off-by: jjie.choi <jjie.choi@samsung.com>
TVMediaHub/TVMediaHub.Tizen/ViewModels/ImageTabViewModel.cs
TVMediaHub/TVMediaHub.Tizen/Views/ImageGroup.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/ImageItem.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/VideoItem.xaml.cs

index 1b6c541..7e2cfb4 100755 (executable)
@@ -414,8 +414,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 94990c9..cce28cf 100755 (executable)
@@ -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
         /// </summary>
         private ICommand ItemClickCommand;
 
+        public delegate void ItemDeleteHandler(MediaInformation info);
+
+        public ItemDeleteHandler OnItemDeleteHandler;
+
         /// <summary>
         /// Gets or set ItemSource to display item
         /// </summary>
@@ -69,6 +74,8 @@ namespace TVMediaHub.Tizen.Views
 
         public EventHandler<GroupItemFocusEventArgs> GroupItemFocused;
 
+        public ImageItem focusedItem;
+
         /// <summary>
         /// A constructor
         /// </summary>
@@ -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;
         }
+
+        /// <summary>
+        /// If there is focused image item, notify the menu key pressed event to focused video item for show context popup
+        /// </summary>
+        /// <returns>If group has a focused image item, true; otherwise, false</returns>
+        public bool NotifyMenuKeyPressedToFocusedItem()
+        {
+            if (focusedItem != null)
+            {
+                focusedItem.ShowContextPopup();
+                return true;
+            }
+            return false;
+        }
     }
 }
index c98b888..0444d39 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;
 using Xamarin.Forms.Xaml;
@@ -85,11 +86,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
@@ -370,6 +373,7 @@ namespace TVMediaHub.Tizen.Views
         /// <param name="e">A Focus event's argument</param>
         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();
+        }
 
     }
 }
index 501869b..a2f9e0b 100755 (executable)
@@ -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);
+            }
+
+        }
     }
 }
index 3f3ccd7..9ed3c78 100755 (executable)
@@ -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));