Fix Issue : Focusing is not working according to the TC 10/148010/2
authorHeonjae.Jang <Heonjae.Jang@samsung.com>
Wed, 6 Sep 2017 09:05:39 +0000 (18:05 +0900)
committerHeonjae.Jang <Heonjae.Jang@samsung.com>
Thu, 7 Sep 2017 01:57:38 +0000 (10:57 +0900)
Change-Id: I5e411da70814ac7f2154541462eab0e217b0095a
Signed-off-by: Heonjae.Jang <Heonjae.Jang@samsung.com>
TVApps/TVApps/Controls/AppListView.xaml
TVApps/TVApps/Controls/AppListView.xaml.cs
TVApps/TVApps/Views/FooterNormalStatus.xaml.cs
TVApps/TVApps/Views/MainPage.xaml
TVApps/TVApps/Views/MainPage.xaml.cs
TVHome/TVHome/ViewModels/MainPageViewModel.cs

index ec0576c..a78fca8 100755 (executable)
@@ -10,7 +10,8 @@
     <RelativeLayout x:Name="AppListGrid"
                     RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"
                     RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0}"
-                    RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0}">
+                    RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0}"
+                     HorizontalOptions="Start">
 
         <StackLayout x:Name="AppUpperList"
                      IsVisible="False"
index 09bd061..544053d 100755 (executable)
@@ -46,20 +46,6 @@ namespace TVApps.Controls
         }
 
         /// <summary>
-        /// Identifies the ItemTemplate bindable property
-        /// </summary>
-        public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create("ItemTemplate", typeof(DataTemplate), typeof(AppListView), default(DataTemplate));
-
-        /// <summary>
-        /// Gets or sets template of list items
-        /// </summary>
-        public DataTemplate ItemTemplate
-        {
-            get { return (DataTemplate)GetValue(ItemTemplateProperty); }
-            set { SetValue(ItemTemplateProperty, value); }
-        }
-
-        /// <summary>
         /// A count of items in list
         /// </summary>
         private int AppCount;
@@ -106,6 +92,8 @@ namespace TVApps.Controls
         /// </summary>
         public ICommand OnChangeFocusChainingCommand { get; set; }
 
+        public EventHandler<ScrolledEventArgs> ScrollPositionChanged;
+
         /// <summary>
         /// A constructor
         /// Adds PropertyChanged event handler
@@ -170,11 +158,33 @@ namespace TVApps.Controls
             AppCount = 0;
             AppUpperList.Children.Clear();
             AppLowerList.Children.Clear();
-            if (ItemTemplate == null || ItemsSource == null)
+
+            foreach (var item in ItemsSource)
             {
-                return;
-            }
+                var viewCell = new AppItemCell();
+                viewCell.BindingContext = item;
+                viewCell.OnClickedCommand = new Command(() =>
+                {
+                    item.DoAction();
+                });
+                var index = AppCount / 2;
+                viewCell.OnFocusedCommand = new Command(() =>
+                {
+                    ScrollToIndex(index);
+                });
+
+                if (AppCount % 2 == 0)
+                {
+                    Device.BeginInvokeOnMainThread(() => AppUpperList.Children.Add(viewCell));
+                }
+                else
+                {
+                    Device.BeginInvokeOnMainThread(() => AppLowerList.Children.Add(viewCell));
+                }
 
+                AppCount = AppCount + 1;
+
+            }
             foreach (var item in ItemsSource)
             {
                 var viewCell = new AppItemCell();
@@ -191,14 +201,15 @@ namespace TVApps.Controls
 
                 if (AppCount % 2 == 0)
                 {
-                    AppUpperList.Children.Add(viewCell);
+                    Device.BeginInvokeOnMainThread(() => AppUpperList.Children.Add(viewCell));
                 }
                 else
                 {
-                    AppLowerList.Children.Add(viewCell);
+                    Device.BeginInvokeOnMainThread(() => AppLowerList.Children.Add(viewCell));
                 }
 
                 AppCount = AppCount + 1;
+
             }
 
             if (AppCount > 0)
@@ -240,16 +251,11 @@ namespace TVApps.Controls
                 var lowerDistance = Math.Abs(ScrollX - lowerScrollX);
                 var upperDistance = Math.Abs(ScrollX - upperScrollX);
 
-                if (lowerDistance > upperDistance)
-                {
-                    await Task.Delay(1);
-                    await ScrollToAsync(upperScrollX, 0, true);
-                }
-                else
-                {
-                    await Task.Delay(1);
-                    await ScrollToAsync(lowerScrollX, 0, true);
-                }
+                var scrollPositionX = lowerDistance > upperDistance ? upperScrollX : lowerScrollX;
+                ScrollPositionChanged?.Invoke(this, new ScrolledEventArgs(scrollPositionX, 0));
+
+                await Task.Delay(1);
+                await ScrollToAsync(scrollPositionX, 0, true);
             }
         }
 
index 766699a..07bc4fd 100755 (executable)
@@ -36,12 +36,12 @@ namespace TVApps.Views
         /// <summary>
         /// The drop down list of sort options
         /// </summary>
-        private DropdownList SortButton;
+        public DropdownList SortList { get; private set; }
 
         /// <summary>
         /// The Option button object
         /// </summary>
-        private Button OptionButton;
+        public Button OptionButton { get; private set; }
 
         /// <summary>
         /// Identifies the PinAppCommand bindable property
@@ -114,15 +114,6 @@ namespace TVApps.Views
         }
 
         /// <summary>
-        /// Gets Sort DropdownList
-        /// </summary>
-        /// <returns>Returns Sort DropdownList</returns>
-        public DropdownList GetSortDropdownList()
-        {
-            return SortButton;
-        }
-
-        /// <summary>
         /// Creates Option Button
         /// </summary>
         private void CreateOptionButton()
@@ -148,21 +139,21 @@ namespace TVApps.Views
         {
             List<string> SortList = new List<string> { "NEWEST", "A - Z", "Z - A" };
 
-            SortButton = new DropdownList();
-            SortButton.ItemsSource = SortList;
-            SortButton.SelectedItem = SortList[0];
+            this.SortList = new DropdownList();
+            this.SortList.ItemsSource = SortList;
+            this.SortList.SelectedItem = SortList[0];
 
-            SortButton.Expanded += (s, e) =>
+            this.SortList.Expanded += (s, e) =>
             {
-                ChangeBackKeyInfoCommand?.Execute(SortButton.IsExpanded);
+                ChangeBackKeyInfoCommand?.Execute(this.SortList.IsExpanded);
             };
 
-            SortButton.Collapsed += (s, e) =>
+            this.SortList.Collapsed += (s, e) =>
             {
-                ChangeBackKeyInfoCommand?.Execute(SortButton.IsExpanded);
+                ChangeBackKeyInfoCommand?.Execute(this.SortList.IsExpanded);
             };
 
-            SortButton.ItemSelected += (s, e) =>
+            this.SortList.ItemSelected += (s, e) =>
             {
                 if (SortList.Contains(e.SelectedItem.ToString()))
                 {
@@ -170,7 +161,7 @@ namespace TVApps.Views
                 }
             };
 
-            this.Children.Add(SortButton,
+            this.Children.Add(this.SortList,
                 heightConstraint: Constraint.Constant(SizeUtils.GetHeightSize(80)),
                 widthConstraint: Constraint.Constant(SizeUtils.GetWidthSize(300)),
                 yConstraint: Constraint.Constant(SizeUtils.GetHeightSize(662)),
index 1d3823a..b132946 100755 (executable)
       </StackLayout>
     </Grid>
 
-    <Controls:AppListView x:Name="AppList"
+        <Controls:AppListView x:Name="AppList"
                           Grid.Row="1"
                           Grid.RowSpan="4"
-                          ItemsSource="{Binding InstalledAppList}">
-      <Controls:AppListView.ItemTemplate>
-        <DataTemplate>
-          <Controls:AppItemCell/>
-        </DataTemplate>
-      </Controls:AppListView.ItemTemplate>
-    </Controls:AppListView>
+                          ItemsSource="{Binding InstalledAppList}"/>
 
-    <BoxView x:Name="PageDimBox"
+
+        <BoxView x:Name="PageDimBox"
              Color="Black"
              Grid.Row="0"
              Grid.RowSpan="7"
index 8046227..90f0721 100755 (executable)
@@ -29,6 +29,7 @@ using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
 
 namespace TVApps.Views
 {
+    using System;
     using Tizen = Xamarin.Forms.PlatformConfiguration.Tizen;
     /// <summary>
     /// A custom view for displaying main page of TV Apps
@@ -180,6 +181,8 @@ namespace TVApps.Views
                 AppList.InitializeFocus();
             });
 
+            AppList.ScrollPositionChanged += OnScrollPositionChanged;
+
             FooterNormal.ChangeBackKeyInfoCommand = new Command<bool>((isShowingPopup) =>
             {
                 if (isShowingPopup)
@@ -193,6 +196,11 @@ namespace TVApps.Views
             });
         }
 
+        private void OnScrollPositionChanged(object sender, ScrolledEventArgs e)
+        {
+            SetFocusChainingWithCurrentStatus(CurrentStatus, e.ScrollX);
+        }
+
         /// <summary>
         /// A method for customizing behavior immediately prior to the Page becoming visible
         /// Sets focus chain and Moves focus to first App icon
@@ -289,7 +297,7 @@ namespace TVApps.Views
                 }
             }
 
-            SetFocusChainingWithCurrentStatus(CurrentStatus);
+            SetFocusChainingWithCurrentStatus(CurrentStatus, 0);
         }
 
         /// <summary>
@@ -306,22 +314,30 @@ namespace TVApps.Views
         /// <summary>
         /// A method for setting focus chain list with FooterNormalStatus
         /// </summary>
-        private void SetFocusChainingUpAndDownForDefaultMode()
+        private void SetFocusChainingUpAndDownForDefaultMode(double scrollX)
         {
-            List<View> lowerList = AppList.GetAppsLowerList().ToList();
-            DropdownList sortList = FooterNormal.GetSortDropdownList();
-
-            foreach (var item in lowerList)
+            var FocusableList = AppList.GetAppsLowerList().ToList().FindAll((item) =>
+            {
+                return scrollX <= item.X && (scrollX + 1920) >= item.X + item.Width;
+            });
+            DebuggingUtils.Dbg("FOCUSTEST" + FocusableList.Count + " // ");
+            foreach (var item in FocusableList)
             {
                 Button button = item.FindByName<Button>("ButtonFocusArea");
-                button?.On<Tizen>()?.SetNextFocusDownView(sortList);
+                button?.On<Tizen>()?.SetNextFocusDownView(FooterNormal.SortList);
+            }
+
+            if (FocusableList.Count == 7)
+            {
+                Button button = FocusableList.Last().FindByName<Button>("ButtonFocusArea");
+                button?.On<Tizen>()?.SetNextFocusDownView(FooterNormal.OptionButton);
             }
         }
 
         /// <summary>
         /// A method for setting focus chain list with FooterDeleteStatus
         /// </summary>
-        private void SetFocusChainingUpAndDownForDeleteMode()
+        private void SetFocusChainingUpAndDownForDeleteMode(double scrollX)
         {
             List<View> lowerList = AppList.GetAppsLowerList().ToList();
             Button cancelButton = FooterDelete.GetCancelButton();
@@ -343,7 +359,7 @@ namespace TVApps.Views
         /// <summary>
         /// A method for setting focus chain list with FooterPinStatus
         /// </summary>
-        private void SetFocusChainingUpAndDownForPinMode()
+        private void SetFocusChainingUpAndDownForPinMode(double scrollX)
         {
             List<View> lowerList = AppList.GetAppsLowerList().ToList();
             Button doneButton = FooterPin.GetDoneButton();
@@ -366,18 +382,18 @@ namespace TVApps.Views
         /// A method for changing focus chain list by Status
         /// </summary>
         /// <param name="status">The TVApps Application status</param>
-        private void SetFocusChainingWithCurrentStatus(AppsStatus status)
+        private void SetFocusChainingWithCurrentStatus(AppsStatus status, double scrollX)
         {
             switch (status)
             {
                 case AppsStatus.Pin:
-                    SetFocusChainingUpAndDownForPinMode();
+                    SetFocusChainingUpAndDownForPinMode(scrollX);
                     break;
                 case AppsStatus.Delete:
-                    SetFocusChainingUpAndDownForDeleteMode();
+                    SetFocusChainingUpAndDownForDeleteMode(scrollX);
                     break;
                 default:
-                    SetFocusChainingUpAndDownForDefaultMode();
+                    SetFocusChainingUpAndDownForDefaultMode(scrollX);
                     break;
             }
         }
@@ -472,7 +488,7 @@ namespace TVApps.Views
                 return true;
             }
 
-            DropdownList sortList = FooterNormal.GetSortDropdownList();
+            DropdownList sortList = FooterNormal.SortList;
 
             if (sortList.IsExpanded)
             {
index 11452ee..e371045 100755 (executable)
@@ -88,6 +88,7 @@ namespace TVHome.ViewModels
                     sub.OnStateChanged(currentState);
                 }
 
+                OnPropertyChanged("CurrentState");
             }
         }