Resolve HiddenConnectPage issue of searching and connectiong an AP. 48/284948/4
authorAkash <akash1.kumar@samsung.com>
Thu, 1 Dec 2022 10:30:09 +0000 (16:00 +0530)
committerAkash <akash1.kumar@samsung.com>
Tue, 6 Dec 2022 04:47:43 +0000 (10:17 +0530)
This patches resolves following issues
- Hidden AP connect not done.
- Scan AP, show loading, if there is no AP, back to previous input field.
- Hidden AP found is not located at the bottom of the scan list.

Change-Id: I2dd09feb0a452f25cffac134632bbb9a18f5c3f8
Signed-off-by: Akash <akash1.kumar@samsung.com>
SettingWiFi/SettingWiFi/view/HiddenConnectPage.cs
SettingWiFi/SettingWiFi/view/MainPage.cs
packaging/org.tizen.cssetting-wifi-1.0.0.tpk

index dcc22c9dc2145143c41535a665a5e71f86e58061..3f69eee7695e43accc1b97f9cb07081ad74f0980 100644 (file)
@@ -7,10 +7,13 @@ using static SettingWiFi.Logger;
 
 namespace SettingWiFi
 {
-    internal class HiddenConnectPage : ContentPage
+    internal class HiddenConnectPage : DialogPage
     {
         private WiFi mWifi;
         private APSource mApSource;
+        private TextField ssidField;
+        private AP mAp;
+        Window window = NUIApplication.GetDefaultWindow();
 
         internal HiddenConnectPage(WiFi wifi)
         {
@@ -20,98 +23,176 @@ namespace SettingWiFi
         internal void CreateComponents(APSource apSource)
         {
             mApSource = apSource;
+            Content = CreateNewPage();
+        }
 
-            var findView = new View()
-            {
-                Layout = new LinearLayout()
-                {
-                    LinearOrientation = LinearLayout.Orientation.Vertical,
-                },
-                WidthSpecification = 200,
-                HeightSpecification = 100,
-            };
+        private AlertDialog CreateNewPage()
+        {
+            var findView = CreateNewView(200, 100);
 
-            var ssidField = new TextField()
+            ssidField = new TextField()
             {
                 PlaceholderText = Resources.IDS_ST_BODY_NETWORK_SSID,
                 WidthSpecification = 400,
             };
 
-            // todo: add text input
-            var input = "dnet_sn";
-
             findView.Add(ssidField);
 
             var item = new DefaultLinearItem();
             findView.Add(item);
 
-            var cancelButton = new Button()
+            var cancelButton = CreateCancelButton();
+            var findButton = CreateButton(300, 80, Resources.IDS_COM_BODY_FIND);
+            findButton.Clicked += (object source, ClickedEventArgs args) =>
+            {
+                if (mWifi.IsActive())
+                {
+                    ConnectSpecificAP();
+                }
+            };
+
+            AlertDialog alt = new AlertDialog()
+            {
+                Title = Resources.IDS_WIFI_BUTTON_FIND_HIDDEN_NETWORK,
+                Content = findView,
+                Actions = new View[] { cancelButton, findButton, },
+            };
+            return alt;
+        }
+
+        private View CreateNewView(int width, int height)
+        {
+            var view = new View()
+            {
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Vertical,
+                },
+                WidthSpecification = width,
+                HeightSpecification = height,
+            };
+            return view;
+        }
+
+        private Button CreateButton(int width, int height, string name)
+        {
+            var button = new Button()
             {
-                Text = Resources.IDS_WIFI_SK_CANCEL,
-                WidthSpecification = 300,
-                HeightSpecification = 80,
+                Text = name,
+                WidthSpecification = width,
+                HeightSpecification = height,
             };
+            return button;
+        }
+
+        private Button CreateCancelButton()
+        {
+            var cancelButton = CreateButton(300, 80, Resources.IDS_WIFI_SK_CANCEL);
             cancelButton.Clicked += (object source, ClickedEventArgs args) =>
             {
                 Navigator.Pop();
             };
+            return cancelButton;
+        }
+
+        private AlertDialog CreateOpenAPPageView(AP ap)
+        {
+            var infoView = CreateNewView(680, 100);
 
-            var findButton = new Button()
+            var info = new DefaultLinearItem()
             {
-                Text = Resources.IDS_COM_BODY_FIND,
-                WidthSpecification = 300,
-                HeightSpecification = 80,
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                IsSelectable = false,
+                Text = Resources.IDS_WIFI_BODY_A_WI_FI_NETWORK_HAS_BEEN_DETECTED_YOU_WILL_BE_CONNECTED,
             };
-            findButton.Clicked += (object source, ClickedEventArgs args) =>
+
+            infoView.Add(info);
+            var cancelButton = CreateCancelButton();
+            var connectButton = CreateButton(300, 80, Resources.IDS_WIFI_BODY_CONNECT);
+
+            connectButton.Clicked += (object source, ClickedEventArgs args) =>
             {
                 if (mWifi.IsActive())
                 {
-                    ConnectSpecificAP(input);
+                    OnConnectClicked(ap, "");
                 }
             };
-
-            Content = new AlertDialog()
+            AlertDialog alt = new AlertDialog()
             {
-                Title = Resources.IDS_WIFI_BUTTON_FIND_HIDDEN_NETWORK,
-                Content = findView,
-                Actions = new View[] { cancelButton, findButton },
+                Title = ap.Essid,
+                Content = infoView,
+                Actions = new View[] { cancelButton, connectButton, },
             };
+            return alt;
+        }
+
+        private void ConnectOpenAP(AP ap)
+        {
+            Debug("Connect open AP");
+            Content = CreateOpenAPPageView(ap);
+        }
+
+        private async void OnConnectClicked(AP ap, string password)
+        {
+            Navigator.Pop();
+            await mWifi.Connect(ap, password);
+            if (mWifi.GetConnectedAP().Equals(ap.Essid))
+            {
+                ap.StateInfo = Resources.IDS_WIFI_SBODY_CONNECTED_M_STATUS;
+            }
         }
 
-        private async void ConnectSpecificAP(string essid)
+        private async void ConnectSpecificAP()
         {
+            mApSource.SetScanningState(true);
+            string essid = ssidField.Text;
+            Debug("Searhing Hidden AP named: " + essid);
             await mWifi.ScanSpecificAP(essid);
 
             List<AP> apList = mWifi.GetSpecificScanResult();
+            mApSource.SetScanningState(false);
+
             if (apList.Count == 0)
             {
-                Navigator.Pop();
+                Debug("No Hidden ap found with ssid " + essid);
+                Content = CreateNewPage();
                 return;
             }
-
-            // todo: locate on the bottom of the scan list
-            //if (apList.Count > 1)
-            //{
-            //    Navigator.Pop();
-            //    return;
-            //}
-
-            foreach (var item in apList)
+            else if (apList.Count == 1)
             {
-                if (item.SecType.Equals(Resources.IDS_WIFI_POP_OPEN))
+                mAp = apList[0];
+                Debug("A Hidden AP found with ssid " + essid);
+                if (!mAp.IsConnected())
                 {
-                    await mWifi.Connect(item, null);
+                    if (mAp.IsAPOpen())
+                    {
+                        ConnectOpenAP(mAp);
+                    }
+                    else
+                    {
+                        Navigator.Push(CreateConnectPage(mAp));
+                    }
                 }
                 else
                 {
-                    Navigator.Push(CreateConnectPage(item));
+                    Navigator.Pop();
                 }
-                break;
+                return;
+            }
+            else
+            {
+                //Debug("More than one ap found with ssid " + essid);
+
+                //foreach (var item in apList)
+                //{
+                //    Debug("More than one ap found with ssid " + essid);
+                //}
             }
         }
 
         private DialogPage CreateConnectPage(AP ap)
         {
+            window.GetDefaultNavigator().Pop();
             var page = new ConnectPage(mWifi);
             page.CreateComponents(ap);
             return page;
index c649755b35fe3ff9e1884aa9d045689682095fe5..bf8fb092cb9310923bae15f2ca5a65e1bada7262 100644 (file)
@@ -290,7 +290,7 @@ namespace SettingWiFi
             return page;
         }
 
-        private ContentPage CreateHiddenConnectPage()
+        private DialogPage CreateHiddenConnectPage()
         {
             var page = new HiddenConnectPage(mWifi);
             page.CreateComponents(mApSource);
index a9ba650764df7ae124decf3115999ccab4de626e..5e8012a624ed4a7f91706f9724b5ad5c45bde882 100644 (file)
Binary files a/packaging/org.tizen.cssetting-wifi-1.0.0.tpk and b/packaging/org.tizen.cssetting-wifi-1.0.0.tpk differ