Implements context popup in AppsSubPanel
authorHyerim Kim <rimi.kim@samsung.com>
Fri, 5 May 2017 02:38:48 +0000 (11:38 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:54 +0000 (18:34 +0900)
Prevents continuous click event on Move mode

Change-Id: I9671e0be790199fae926f198b48425de3e44c852
Signed-off-by: Hyerim Kim <rimi.kim@samsung.com>
12 files changed:
TVHome/TVHome/Controls/MainPanelButton.xaml.cs
TVHome/TVHome/Controls/PanelButton.cs
TVHome/TVHome/Controls/SubPanelAllAppsButton.xaml
TVHome/TVHome/Controls/SubPanelAllAppsButton.xaml.cs
TVHome/TVHome/Controls/SubPanelButton.xaml
TVHome/TVHome/Controls/SubPanelButton.xaml.cs
TVHome/TVHome/Controls/SubPanelSettingButton.xaml
TVHome/TVHome/Controls/SubPanelSettingButton.xaml.cs
TVHome/TVHome/Controls/SubPanelThumbnailButton.xaml.cs
TVHome/TVHome/Views/MainPage.xaml.cs
TVHome/TVHome/Views/Panel.cs
TVHome/TVHome/Views/SubPanel.xaml.cs

index 17eee40..4673323 100755 (executable)
@@ -146,17 +146,13 @@ namespace TVHome.Controls
         }
 
         /// <summary>
-        /// A method for changing the button's LayoutOptions according to parameter
+        /// A method for showing context popup
         /// </summary>
-        /// <param name="isMoveMode">A flag indicates whether the SubPanel is MoveMode or not</param>
-        public override void ChangeLayoutOptions(bool isMoveMode)
+        public override void ShowContextPopup()
         {
         }
 
-        /// <summary>
-        /// A method for showing context popup
-        /// </summary>
-        public override void ShowContextPopup()
+        public override void ChangeShowOptionsMode(bool showOptions)
         {
         }
     }
index 84fa5b6..b2591c0 100755 (executable)
@@ -28,6 +28,9 @@ namespace TVHome.Controls
     {
         public bool isMoveMode;
         public bool isFocused;
+        public bool isShowOptions;
+        public bool rightMoving;
+        public bool leftMoving;
         /// <summary>
         /// A Command will be executed the button is focused.
         /// </summary>
@@ -63,6 +66,8 @@ namespace TVHome.Controls
         /// </summary>
         public ICommand OnClearAllCommand { get; set; }
 
+        public ICommand OnDefaultModeCommand { get; set; }
+
         /// <summary>
         /// Handles Button Focused event
         /// </summary>
@@ -92,14 +97,10 @@ namespace TVHome.Controls
         public abstract void ChangeMoveMode(bool isMoveMode, bool isDefault);
 
         /// <summary>
-        /// A method for changing the button's LayoutOptions according to parameter
-        /// </summary>
-        /// <param name="isMoveMode">A flag indicates whether the SubPanel is MoveMode or not</param>
-        public abstract void ChangeLayoutOptions(bool isMoveMode);
-
-        /// <summary>
         /// A method for showing context popup
         /// </summary>
         public abstract void ShowContextPopup();
+
+        public abstract void ChangeShowOptionsMode(bool isShowOptions);
     }
 }
index f12a969..706b656 100755 (executable)
@@ -4,7 +4,8 @@
                       xmlns:Controls="clr-namespace:TVHome.Controls"
                       x:Class="TVHome.Controls.SubPanelAllAppsButton">
   <RelativeLayout x:Name="ButtonBox"
-                  HorizontalOptions="Center">
+                  HorizontalOptions="Center"
+                  VerticalOptions="End">
     <Image x:Name="ButtonImage"
            RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=0.120879}"
            RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.095652}"
index 94b1844..5beba18 100755 (executable)
@@ -105,27 +105,13 @@ namespace TVHome.Controls
         }
 
         /// <summary>
-        /// A method for changing the button's LayoutOptions according to parameter
+        /// A method for showing context popup
         /// </summary>
-        /// <param name="isMoveMode">A flag indicates whether the SubPanel is MoveMode or not</param>
-        public override void ChangeLayoutOptions(bool isMoveMode)
+        public override void ShowContextPopup()
         {
-            if (isMoveMode)
-            {
-                View.VerticalOptions = LayoutOptions.End;
-            }
-            else
-            {
-                View.VerticalOptions = LayoutOptions.Start;
-            }
-
-            View.TranslateTo(0, 0, 0);
         }
 
-        /// <summary>
-        /// A method for showing context popup
-        /// </summary>
-        public override void ShowContextPopup()
+        public override void ChangeShowOptionsMode(bool showOptions)
         {
         }
     }
index b3aff64..4f5aeb2 100755 (executable)
@@ -4,7 +4,8 @@
                       xmlns:Controls="clr-namespace:TVHome.Controls"
                       x:Class="TVHome.Controls.SubPanelButton">
   <RelativeLayout x:Name="ButtonBox"
-                  HorizontalOptions="Center">
+                  HorizontalOptions="Center"
+                  VerticalOptions="End">
     <Image x:Name="ButtonImage"
            RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=0.120879}"
            RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.095652}"
index 38727b1..666c89f 100755 (executable)
@@ -28,11 +28,6 @@ namespace TVHome.Controls
     public partial class SubPanelButton : PanelButton
     {
         /// <summary>
-        /// A flag which enable showing a popup
-        /// </summary>
-        private bool isPopupShowing = false;
-
-        /// <summary>
         /// SubPanel icon's transition height value when it focused.
         /// </summary>
         private int selectTransitionHeight = SizeUtils.GetHeightSize(22);
@@ -58,7 +53,7 @@ namespace TVHome.Controls
             {
                 if (isMoveMode && IsEnabled)
                 {
-                    OnMoveCommand.Execute(e);
+                    OnMoveCommand?.Execute(e);
                 }
             });
 
@@ -85,7 +80,7 @@ namespace TVHome.Controls
         /// </summary>
         public override void ShowContextPopup()
         {
-            if (isPopupShowing)
+            if (isShowOptions)
             {
                 return;
             }
@@ -106,22 +101,29 @@ namespace TVHome.Controls
                 if (ctxPopup.SelectedIndex == 0)
                 {
                     OnMoveFinishedCommand.Execute("");
-                    ctxPopup.Dismiss();
                 }
                 else if (ctxPopup.SelectedIndex == 1)
                 {
                     OnUnpinCommand.Execute("");
-                    ctxPopup.Dismiss();
                 }
+
+                popup.Dismiss();
             };
 
             popup.Dismissed += (sender, args) =>
             {
-                isPopupShowing = false;
+                var ctxPopup = sender as ContextPopup;
+                isShowOptions = false;
+
+                if (ctxPopup.SelectedIndex == -1)
+                {
+                    OnDefaultModeCommand.Execute("");
+                }
             };
 
-            popup.Show(View);
-            isPopupShowing = true;
+            popup.Show(View, View.Width / 2, View.Height - (moveTransitionHeight + selectTransitionHeight));
+            ButtonTitle.FadeTo(0, 300);
+            isShowOptions = true;
         }
 
 
@@ -154,13 +156,12 @@ namespace TVHome.Controls
         /// <param name="isDefault">A flag indicates whether this method is called by ChangeToDefaultMode method</param>
         public override async void ChangeMoveMode(bool moveMode, bool isDefault)
         {
+            isMoveMode = moveMode;
+
 #pragma warning disable CS4014
             if (moveMode)
             {
                 ButtonTitle.FadeTo(0, 300);
-                View.TranslateTo(0, -moveTransitionHeight, 300);
-                ButtonImage.ScaleTo(1, 300);
-                isMoveMode = true;
 
                 for (int i = 0; i < 2; i++)
                 {
@@ -172,39 +173,32 @@ namespace TVHome.Controls
             }
             else
             {
-                isMoveMode = false;
                 if (!isDefault)
                 {
                     View.TranslateTo(SizeUtils.GetWidthSize((int)View.TranslationX), 0, 300);
                 }
                 else
                 {
+                    await View.TranslateTo(0, SizeUtils.GetHeightSize((int)View.TranslationY), 0);
                     View.TranslateTo(0, 0, 300);
                 }
 
                 OnFocused(null, null);
-                LeftBtnImg.FadeTo(0, 300);
-                await RightBtnImg.FadeTo(0, 300);
             }
 #pragma warning restore CS4014
         }
 
-        /// <summary>
-        /// A method for changing the button's LayoutOptions according to parameter
-        /// </summary>
-        /// <param name="isMoveMode">A flag indicates whether the SubPanel is MoveMode or not</param>
-        public override void ChangeLayoutOptions(bool isMoveMode)
+        public override async void ChangeShowOptionsMode(bool showOptions)
         {
-            if (isMoveMode)
+            if (showOptions)
             {
-                View.VerticalOptions = LayoutOptions.End;
+                View.TranslateTo(0, -moveTransitionHeight, 300);
+                ButtonImage.ScaleTo(1, 300);
             }
             else
             {
-                View.VerticalOptions = LayoutOptions.Start;
+                await View.TranslateTo(0, 0, 300);
             }
-
-            View.TranslateTo(0, 0, 0);
         }
 
         /// <summary>
@@ -227,7 +221,7 @@ namespace TVHome.Controls
 
 #pragma warning disable CS4014
             ButtonTitle.On<Xamarin.Forms.PlatformConfiguration.Tizen>().SetFontWeight(FontWeight.Medium);
-            ButtonTitle.FadeTo(0.99, 300);
+            ButtonTitle.FadeTo(0.8, 300);
             ButtonTitle.TranslateTo(0, selectTransitionHeight, 300);
 #pragma warning restore CS4014
             await ButtonImage.ScaleTo(1.3, 300);
@@ -242,11 +236,11 @@ namespace TVHome.Controls
         {
             isFocused = false;
 
-            if (!isMoveMode)
+            if (!isMoveMode && !isShowOptions)
             {
 #pragma warning disable CS4014
                 ButtonTitle.On<Xamarin.Forms.PlatformConfiguration.Tizen>().SetFontWeight(FontWeight.Normal);
-                ButtonTitle.FadeTo(0.5, 300);
+                ButtonTitle.FadeTo(0.6, 300);
                 ButtonTitle.TranslateTo(0, 0, 300);
 #pragma warning restore CS4014
                 await ButtonImage.ScaleTo(1, 300);
index 27f7c73..8d11d0c 100755 (executable)
@@ -4,7 +4,8 @@
                       xmlns:Controls="clr-namespace:TVHome.Controls"
                       x:Class="TVHome.Controls.SubPanelSettingButton">
   <RelativeLayout x:Name="ButtonBox"
-                  HorizontalOptions="Center" >
+                  HorizontalOptions="Center"
+                  VerticalOptions="End">
     <Image x:Name="ButtonImage"
            RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=0.120879}"
            RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Height, Factor=0.095652}"
index 3070a5a..0969367 100755 (executable)
@@ -105,17 +105,13 @@ namespace TVHome.Controls
         }
 
         /// <summary>
-        /// A method for changing the button's LayoutOptions according to parameter
+        /// A method for showing Context popup
         /// </summary>
-        /// <param name="isMoveMode">A flag indicates whether the SubPanel is MoveMode or not</param>
-        public override void ChangeLayoutOptions(bool isMoveMode)
+        public override void ShowContextPopup()
         {
         }
 
-        /// <summary>
-        /// A method for showing Context popup
-        /// </summary>
-        public override void ShowContextPopup()
+        public override void ChangeShowOptionsMode(bool showOptions)
         {
         }
     }
index b2a15ed..5488d3c 100755 (executable)
@@ -185,14 +185,6 @@ namespace TVHome.Controls
         }
 
         /// <summary>
-        /// A method for changing the button's LayoutOptions according to parameter
-        /// </summary>
-        /// <param name="isMoveMode">A flag indicates whether the SubPanel is MoveMode or not</param>
-        public override void ChangeLayoutOptions(bool isMoveMode)
-        {
-        }
-
-        /// <summary>
         /// A method for showing Context popup
         /// </summary>
         public override void ShowContextPopup()
@@ -235,5 +227,9 @@ namespace TVHome.Controls
             popup.Show(View);
             isPopupShowing = true;
         }
+
+        public override void ChangeShowOptionsMode(bool showOptions)
+        {
+        }
     }
 }
\ No newline at end of file
index 27d999a..682f44e 100755 (executable)
@@ -134,10 +134,10 @@ namespace TVHome.Views
                 ToggleIconified();
             });
 
-            AppsSubPanel.OnMoveCommand = new Command<bool>((isMoveMode) =>
+            AppsSubPanel.OnShowOptionsCommand = new Command<bool>((isShowOptions) =>
             {
                 var bounds = AppsSubPanel.Bounds;
-                if (isMoveMode)
+                if (isShowOptions)
                 {
                     PageMainPanel.FadeTo(0, 300);
                     PageMainPanel.IsVisible = false;
@@ -146,13 +146,13 @@ namespace TVHome.Views
                 }
                 else
                 {
-                    PageMainPanel.IsVisible = true;
                     PageMainPanel.FadeTo(1, 300);
                     bounds.Height -= 300;
                     bounds.Y += 300;
+                    PageMainPanel.IsVisible = true;
                 }
 
-                AppsSubPanel.LayoutTo(bounds, 300);
+                AppsSubPanel.LayoutTo(bounds, 0);
             });
 
             MessagingCenter.Subscribe<App, TVHomeStatus>(this, App.AppStatus, (sender, arg) =>
@@ -311,7 +311,7 @@ namespace TVHome.Views
         /// <returns>Always returns true</returns>
         protected override bool OnBackButtonPressed()
         {
-            if (AppsSubPanel.isMoveMode)
+            if (AppsSubPanel.isMoveMode || AppsSubPanel.isShowOptions)
             {
                 AppsSubPanel.ChangeToDefaultMode();
             }
index d232db2..4451799 100755 (executable)
@@ -137,6 +137,8 @@ namespace TVHome.Views
         /// </summary>
         public bool isMoveMode;
 
+        public bool isShowOptions;
+
         /// <summary>
         /// A method for handling panel focused event
         /// </summary>
index 36b891f..2504bde 100755 (executable)
@@ -42,9 +42,9 @@ namespace TVHome.Views
         private List<View> ButtonViewList;
 
         /// <summary>
-        /// A Command will be executed the button is moved.
+        /// A Command will be executed the option menus are showed.
         /// </summary>
-        public ICommand OnMoveCommand { get; set; }
+        public ICommand OnShowOptionsCommand { get; set; }
 
         /// <summary>
         /// SubPanel icon's transition height value when it focused.
@@ -64,6 +64,7 @@ namespace TVHome.Views
             InitializeComponent();
             isFocused = false;
             isMoveMode = false;
+            isShowOptions = false;
 
             ButtonList = new List<PanelButton>();
             ButtonViewList = new List<View>();
@@ -71,13 +72,21 @@ namespace TVHome.Views
 
             MessagingCenter.Subscribe<App>(this, "MenuKeyPressed", (sender) =>
             {
+                isShowOptions = true;
+
                 if (isFocused)
                 {
                     foreach (var item in ButtonList)
                     {
-                        if (item.isFocused)
+                        if (item is SubPanelButton)
                         {
-                            item.ShowContextPopup();
+                            if (item.isFocused)
+                            {
+                                OnShowOptionsCommand?.Execute(isShowOptions);
+                                item.ShowContextPopup();
+                                item.ChangeShowOptionsMode(isShowOptions);
+                                ChangeIsEnabledProperty(item.View, false);
+                            }
                         }
                     }
                 }
@@ -116,37 +125,38 @@ namespace TVHome.Views
                         button = new SubPanelButton();
                         button.OnMoveCommand = new Command<string>((direction) =>
                         {
+                            if (button.rightMoving || button.leftMoving)
+                            {
+                                return;
+                            }
+
                             int index = ButtonViewList.IndexOf(button.View);
                             if (direction.Equals("Right"))
                             {
-                                MoveItemToRight(index);
+                                button.rightMoving = true;
+                                MoveItemToRight(index, button);
                             }
                             else if (direction.Equals("Left"))
                             {
-                                MoveItemToLeft(index);
+                                button.leftMoving = true;
+                                MoveItemToLeft(index, button);
                             }
                         });
 
                         button.OnMoveFinishedCommand = new Command(() =>
                         {
-                            // TODO : This is triggered by LongTap event.
                             isMoveMode = !isMoveMode;
+                            isShowOptions = false;
 
-                            OnMoveCommand.Execute(isMoveMode);
-
-                            ChangeLayoutButtons(isMoveMode);
-                            ChangeIsEnabledProperty(button.View);
+                            ChangeIsEnabledProperty(button.View, false);
                             button.ChangeMoveMode(isMoveMode, false);
 
                             if (!isMoveMode)
                             {
-                                foreach (var viewItem in ButtonViewList)
-                                {
-                                    viewItem.TranslateTo(SizeUtils.GetWidthSize((int)viewItem.TranslationX), 0, 0);
-                                }
-
                                 OnMoveVMCommand.Execute(ButtonViewList);
                             }
+
+                            OnShowOptionsCommand.Execute(isMoveMode);
                         });
                     }
 
@@ -180,6 +190,10 @@ namespace TVHome.Views
                     AppShortcutInfo shortcut = (AppShortcutInfo)button.View.BindingContext;
                     OnUnpinVMCommand.Execute(shortcut.AppID);
                 });
+                button.OnDefaultModeCommand = new Command(() =>
+                {
+                    ChangeToDefaultMode();
+                });
 
                 PanelButtonStack.Children.Add(button.View);
                 ButtonViewList.Add(button.View);
@@ -216,30 +230,18 @@ namespace TVHome.Views
         /// A method is called when apps subpanel is changed to move mode and change item's IsEnabled property.
         /// </summary>
         /// <param name="selectedBtn">A selected button view to move</param>
-        private void ChangeIsEnabledProperty(View selectedBtn)
+        private void ChangeIsEnabledProperty(View selectedBtn, bool isEnabled)
         {
             foreach (var item in PanelButtonStack.Children)
             {
                 if (item != selectedBtn)
                 {
-                    item.IsEnabled = !isMoveMode;
+                    item.IsEnabled = isEnabled;
                 }
             }
         }
 
         /// <summary>
-        /// A method for changing button's LayoutOptions in SubPanel according to parameter
-        /// </summary>
-        /// <param name="isMoveMode">A flag indicates whether the SubPanel is MoveMode or not</param>
-        private void ChangeLayoutButtons(bool isMoveMode)
-        {
-            foreach (var item in ButtonList)
-            {
-                item.ChangeLayoutOptions(isMoveMode);
-            }
-        }
-
-        /// <summary>
         /// A method for hiding the panel
         /// </summary>
         public override async void HidePanel()
@@ -327,12 +329,13 @@ namespace TVHome.Views
             if (isMoveMode)
             {
                 isMoveMode = !isMoveMode;
+                isShowOptions = false;
 
                 foreach (var item in ButtonList)
                 {
                     if (item.isMoveMode)
                     {
-                        ChangeIsEnabledProperty(item.View);
+                        ChangeIsEnabledProperty(item.View, true);
                         item.ChangeMoveMode(isMoveMode, true);
                     }
                     else
@@ -341,14 +344,28 @@ namespace TVHome.Views
                     }
                 }
 
-                OnMoveCommand.Execute(isMoveMode);
-                ChangeLayoutButtons(isMoveMode);
-
                 ButtonViewList.Clear();
                 foreach (var stackItem in PanelButtonStack.Children)
                 {
                     ButtonViewList.Add(stackItem);
                 }
+
+                OnShowOptionsCommand.Execute(isMoveMode);
+            }
+            else if (isShowOptions)
+            {
+                isShowOptions = !isShowOptions;
+
+                foreach (var item in ButtonList)
+                {
+                    if (item.isFocused)
+                    {
+                        item.ChangeShowOptionsMode(isShowOptions);
+                        ChangeIsEnabledProperty(item.View, true);
+                    }
+                }
+
+                OnShowOptionsCommand?.Execute(isShowOptions);
             }
         }
 
@@ -356,8 +373,9 @@ namespace TVHome.Views
         /// A method for moving the selected item to right
         /// </summary>
         /// <param name="index">A index of item to be moved</param>
-        private void MoveItemToRight(int index)
+        private void MoveItemToRight(int index, PanelButton button)
         {
+            var btn = button as SubPanelButton;
             View originItemView = ButtonViewList[index];
             int nextIndex = index + 1;
             if (nextIndex >= PanelButtonStack.Children.Count - 1)
@@ -386,7 +404,7 @@ namespace TVHome.Views
             animation.Add(0.5, 1, nextScaleUp);
             animation.Add(0, 1, nextTranslate);
 
-            animation.Commit(this, "MoveRightAnimation", 334);
+            animation.Commit(this, "MoveRightAnimation", 16, 334, null, (v, c)=> btn.rightMoving = false);
 
             if (SizeUtils.GetWidthSize((int)(originItemView.X + translateX + 216)) - SizeUtils.GetWidthSize((int)PanelScrollView.ScrollX) > SizeUtils.GetWidthSize(1920))
             {
@@ -401,8 +419,9 @@ namespace TVHome.Views
         /// A method for moving the selected item to left
         /// </summary>
         /// <param name="index">A index of item to be moved</param>
-        private void MoveItemToLeft(int index)
+        private void MoveItemToLeft(int index, PanelButton button)
         {
+            var btn = button as SubPanelButton;
             View originItemView = ButtonViewList[index];
             int prevIndex = index - 1;
 
@@ -432,7 +451,7 @@ namespace TVHome.Views
             animation.Add(0.5, 1, prevScaleUp);
             animation.Add(0, 1, prevTranslate);
 
-            animation.Commit(this, "MoveLeftAnimation", 334);
+            animation.Commit(this, "MoveLeftAnimation", 16, 334, null, (v,c)=> btn.leftMoving = false);
 
             if (SizeUtils.GetWidthSize((int)(originItemView.X + translateX)) - SizeUtils.GetWidthSize((int)PanelScrollView.ScrollX) < 0)
             {