[TPLAPP-4006] Implemented BackKey event handler for the DropDownSort. 63/152763/2
authorSung-jae Park <nicesj@nicesj.com>
Wed, 27 Sep 2017 04:57:53 +0000 (13:57 +0900)
committerSung-jae Park <nicesj@nicesj.com>
Wed, 27 Sep 2017 05:21:15 +0000 (14:21 +0900)
The "exit" popup has not to be displayed if the DropDownSort is expanded.

The BackKey event is handled from the MediaHubMainPage,
and the DropDownSort is implemented in the FooterNormalStatus.

I added a flag named "DisableBackKeyHandler" to the MediaHubMainPage to control the BackKey event handler.
and the "DisableBackKeyHandler" is toggled by the FooterNormalStatus instance.

The FooterNormalStatus instance was able to access the MediaHubMainPage via the AppMainPage object of the App instance,
so I added event handlers such as the collased and the expanded for the DropDownSort instance.

When DropDownSort is expanded, I set true to the "DisableBackKeyHandler" then the BackKey would blocked.

I also added KeyDown event handler in the FooterNormalStatus instance.
In the event handler, if the DropDownSort is expanded, I collased it.

The KeyDown event handler is added and removed from the Expanded and Collapsed event handler of the DropDownSort instance.

Change-Id: I106d53569471a66c6ff867d92c3d012d3b34f80b
Signed-off-by: Sung-jae Park <nicesj@nicesj.com>
TVMediaHub/TVMediaHub.Tizen/ViewModels/MediaHubMainPageViewModel.cs
TVMediaHub/TVMediaHub.Tizen/Views/FooterNormalStatus.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/MediaHubMainPage.xaml
TVMediaHub/TVMediaHub.Tizen/Views/MediaHubMainPage.xaml.cs

index 8ed51f2..309bc1c 100755 (executable)
@@ -31,6 +31,18 @@ namespace TVMediaHub.Tizen.ViewModels
         /// </summary>
         public string SourceName { get; set; }
 
+        private bool disableBackKeyHandler;
+
+        public bool DisableBackKeyHandler
+        {
+            set
+            {
+                disableBackKeyHandler = value;
+                OnPropertyChanged();
+            }
+            get => disableBackKeyHandler;
+        }
+
         /// <summary>
         /// An event that is occurred when property of MediaHubMainPageViewModel is changed
         /// </summary>
index 5a986cd..27fbd1d 100755 (executable)
@@ -149,6 +149,19 @@ namespace TVMediaHub.Tizen.Views
             }
         }
 
+        private void KeyDownHandler(object sender, EventArgs e)
+        {
+            ElmSharp.EcoreKeyEventArgs arg = e as ElmSharp.EcoreKeyEventArgs;
+
+            if (arg != null && arg.KeyName.Contains("Back"))
+            {
+                if (DropdownSort.IsExpanded == true)
+                {
+                    DropdownSort.Collapse();
+                }
+            }
+        }
+
         /// <summary>
         /// A method for initializing footer items
         /// </summary>
@@ -163,6 +176,26 @@ namespace TVMediaHub.Tizen.Views
             DropdownSource.ItemsSource = SourceList;
             DropdownSort.ItemsSource = SortOptions;
 
+            DropdownSort.Collapsed += (s, e) =>
+            {
+                if (App.AppMainPage != null && App.AppMainPage.RootPage != null)
+                {
+                    (App.AppMainPage.RootPage as MediaHubMainPage).DisableBackKeyHandler = false;
+
+                    App.KeyDownEvent.On -= KeyDownHandler;
+                }
+            };
+
+            DropdownSort.Expanded += (s, e) =>
+            {
+                if (App.AppMainPage != null && App.AppMainPage.RootPage != null)
+                {
+                    (App.AppMainPage.RootPage as MediaHubMainPage).DisableBackKeyHandler = true;
+
+                    App.KeyDownEvent.On += KeyDownHandler;
+                }
+            };
+
             DropdownSource.ItemSelected += (s, e) =>
             {
                 OnDropdownSourceItemSelected?.Invoke(s, e);
index 90bb86d..e3dfbfe 100755 (executable)
@@ -4,7 +4,8 @@
             x:Class="TVMediaHub.Tizen.Views.MediaHubMainPage"
             xmlns:Views="clr-namespace:TVMediaHub.Tizen.Views"
             Title="MEDIA HUB"
-            SourceName="{Binding SourceName}">
+            SourceName="{Binding SourceName}"
+            DisableBackKeyHandler="{Binding DisableBackKeyHandler}">
     <Views:VideoTab/>
     <Views:ImageTab/>
     <Views:MusicTab/>
index 9ba4c5d..d7d4e55 100755 (executable)
@@ -31,6 +31,13 @@ namespace TVMediaHub.Tizen.Views
     [XamlCompilation(XamlCompilationOptions.Compile)]
     public partial class MediaHubMainPage : TabbedPage
     {
+        public static readonly BindableProperty DisableBackKeyHandlerProperty = BindableProperty.Create("DisableBackKeyHandler", typeof(bool), typeof(MediaHubMainPage), false, BindingMode.OneWayToSource);
+        public bool DisableBackKeyHandler
+        {
+            get { return (bool)GetValue(DisableBackKeyHandlerProperty); }
+            set { SetValue(DisableBackKeyHandlerProperty, value); }
+        }
+
         /// <summary>
         /// Identifies the SourceName bindable property
         /// </summary>
@@ -115,6 +122,11 @@ namespace TVMediaHub.Tizen.Views
         /// <returns>Always returns true</returns>
         protected override bool OnBackButtonPressed()
         {
+            if (DisableBackKeyHandler == true)
+            {
+                return true;
+            }
+
             SynchronizationContext.Current.Post((o) =>
             {
 #pragma warning disable CS4014