Keeping "add new network" as last element
authork.stepaniuk <k.stepaniuk@samsung.com>
Wed, 25 Mar 2020 14:41:12 +0000 (15:41 +0100)
committerk.stepaniuk <k.stepaniuk@samsung.com>
Fri, 27 Mar 2020 10:23:51 +0000 (11:23 +0100)
Signed-off-by: k.stepaniuk <k.stepaniuk@samsung.com>
Oobe/OobeWifi/Controls/ListView.cs
Oobe/OobeWifi/Controls/SequenceLinearLayout.cs [new file with mode: 0644]
Oobe/OobeWifi/Controls/Wifi/WifiView.cs

index 46dc11d..f0b8b31 100644 (file)
@@ -1,5 +1,7 @@
+using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Linq;
+using System.Threading.Tasks;
 using Tizen.NUI;
 using Tizen.NUI.BaseComponents;
 using Tizen.NUI.Components;
@@ -10,6 +12,7 @@ namespace Oobe.Wifi.Controls
     {
         private ObservableCollection<View> items;
         private ScrollableBase scrollableBase = null;
+        private View footer = null;
         private int width;
         private int height;
 
@@ -19,6 +22,24 @@ namespace Oobe.Wifi.Controls
             this.height = height;
         }
 
+        public View Footer
+        {
+            get => footer;
+            set
+            {
+                if (footer != null)
+                {
+                    LayoutView.Remove(footer);
+                }
+                footer = value;
+                if (footer != null)
+                {
+                    LayoutView.Add(footer);
+                    (LayoutView.Layout as SequenceLinearLayout)?.KeepAsLast(footer.Layout);
+                }
+            }
+        }
+
         public ScrollableBase View
         {
             get
@@ -43,7 +64,7 @@ namespace Oobe.Wifi.Controls
                 {
                     View.Add(new View()
                     {
-                        Layout = new LinearLayout()
+                        Layout = new SequenceLinearLayout()
                         {
                             LinearOrientation = LinearLayout.Orientation.Vertical,
                             LinearAlignment = LinearLayout.Alignment.Center,
@@ -78,10 +99,7 @@ namespace Oobe.Wifi.Controls
             if (items != null)
             {
                 items.CollectionChanged -= OnCollectionChanged;
-                foreach (var child in LayoutView.Children.ToList())
-                {
-                    LayoutView.Remove(child);
-                }
+                RemoveItems();
                 LayoutView.HeightResizePolicy = ResizePolicyType.FitToChildren;
             }
         }
@@ -121,12 +139,17 @@ namespace Oobe.Wifi.Controls
             }
             else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset)
             {
-                foreach (var child in LayoutView.Children.ToList())
-                {
-                    LayoutView.Remove(child);
-                }
+                RemoveItems();
             }
             LayoutView.HeightResizePolicy = ResizePolicyType.FitToChildren;
         }
+
+        private void RemoveItems()
+        {
+            foreach (var child in LayoutView.Children.Where(x => x != Footer).ToList())
+            {
+                LayoutView.Remove(child);
+            }
+        }
     }
 }
diff --git a/Oobe/OobeWifi/Controls/SequenceLinearLayout.cs b/Oobe/OobeWifi/Controls/SequenceLinearLayout.cs
new file mode 100644 (file)
index 0000000..44ea308
--- /dev/null
@@ -0,0 +1,35 @@
+using System.Linq;
+using Tizen.NUI;
+
+namespace Oobe.Wifi.Controls
+{
+    public class SequenceLinearLayout : LinearLayout
+    {
+        private LayoutItem lastItem = null;
+
+        public void KeepAsLast(LayoutItem item)
+        {
+            lastItem = item;
+            if (item != null && item != LayoutChildren.Last())
+            {
+                if (LayoutChildren.Remove(item))
+                {
+                    LayoutChildren.Add(item);
+                    RequestLayout();
+                }
+            }
+        }
+
+        protected override void OnChildAdd(LayoutItem child)
+        {
+            base.OnChildAdd(child);
+            if (lastItem != null)
+            {
+                if (LayoutChildren.Remove(lastItem))//remove by position, or find from the end
+                {
+                    LayoutChildren.Add(lastItem);
+                }
+            }
+        }
+    }
+}
index ca9a86e..f79d609 100644 (file)
@@ -109,7 +109,6 @@ namespace Oobe.Wifi.Controls.Wifi
                 scan.IsEnabled = false;
                 ApManager.Views.Clear();
                 ApManager.UpdateTo(await State.Scan());
-                ApManager.Views.Add(CreateManualWifiView()); //should be built in listView
                 scan.IsEnabled = State.IsTurnedOn;
             };
             scan.IsEnabled = State.IsTurnedOn;
@@ -147,6 +146,7 @@ namespace Oobe.Wifi.Controls.Wifi
             var view = new View();
             var listView = new ListView(480, 328)//480, 335
             {
+                Footer = CreateManualWifiView(),
                 Items = ApManager.Views
             }.View;
             view.Add(listView);