Fixing review
authork.stepaniuk <k.stepaniuk@samsung.com>
Tue, 24 Mar 2020 08:10:30 +0000 (09:10 +0100)
committerLukasz Stanislawski/IoT & UI Sample (PLT) /SRPOL/Engineer/Samsung Electronics <l.stanislaws@samsung.com>
Wed, 25 Mar 2020 08:01:41 +0000 (09:01 +0100)
Signed-off-by: k.stepaniuk <k.stepaniuk@samsung.com>
Oobe/OobeWifi/Controls/Wifi/ApManager.cs
Oobe/OobeWifi/Controls/Wifi/ApView.cs
Oobe/OobeWifi/Controls/Wifi/WifiView.cs

index 07fe3e3..6858294 100644 (file)
@@ -28,7 +28,7 @@ namespace Oobe.Wifi.Controls.Wifi
 
         private void OnConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e)
         {
-            if(apToViewMap.TryGetValue(e.AP, out ApView view))
+            if (apToViewMap.TryGetValue(e.AP, out ApView view))
             {
                 view.Update(e.AP);
             }
@@ -49,15 +49,15 @@ namespace Oobe.Wifi.Controls.Wifi
             Views.Clear();
 
             int idx = 0;
-            foreach(var ap in aps)
+            foreach (var ap in aps)
             {
-                var view = new ApView();
-                if (apToViewMap.TryAdd(ap, view))
+                if (apToViewMap.ContainsKey(ap) == false)
                 {
+                    var view = new ApView();
                     view.Update(ap);
-                    view.Detector = new TapGestureDetector();
-                    view.Detector.Detected += (s, e) => onTapped(ap);
-                    view.Detector.Attach(view);
+                    view.Tapped += () => onTapped(ap);
+
+                    apToViewMap.Add(ap, view);
                     Views.Insert(idx, view);
 
                     idx++;
@@ -83,7 +83,7 @@ namespace Oobe.Wifi.Controls.Wifi
         {
             while (await Delay())
             {
-                foreach(var (ap,view) in apToViewMap.ToList())
+                foreach (var (ap, view) in apToViewMap.ToList())
                 {
                     try
                     {
@@ -93,7 +93,7 @@ namespace Oobe.Wifi.Controls.Wifi
                     catch (Exception ex)
                     {
                         Tizen.Log.Error("oobe", $"failed to refresh ap {ap.NetworkInformation.Essid} {ex.ToString()}");
-                        
+
                         Views.Remove(view);
                         apToViewMap.Remove(ap);
                         ap.Dispose();
@@ -108,8 +108,8 @@ namespace Oobe.Wifi.Controls.Wifi
             {
                 await Task.Delay(10_000, updatingCancellation.Token);
             }
-            catch (Exception) 
-            { 
+            catch (Exception)
+            {
             }
             return updatingCancellation.IsCancellationRequested == false;
         }
index 67f05dd..523461e 100644 (file)
@@ -8,11 +8,11 @@ namespace Oobe.Wifi.Controls.Wifi
 {
     public class ApView : View
     {
+        public event Action Tapped;
         private TextLabel detail = null;
         private View range = null;
-
         //detectors have to be kept separately because of GC, there is no link by ref between View and Detector
-        public TapGestureDetector Detector { get; set; }
+        private TapGestureDetector detector;
 
         public ApView()
         {
@@ -50,6 +50,10 @@ namespace Oobe.Wifi.Controls.Wifi
                     FontStyle = FontsStyles.Regular(),
                 };
                 this.Add(detail);
+
+                detector = new TapGestureDetector();
+                detector.Detected += (s, e) => Tapped?.Invoke();
+                detector.Attach(this);
             }
             else
             {
@@ -61,9 +65,18 @@ namespace Oobe.Wifi.Controls.Wifi
 
         private static string GetDetailInfo(WiFiAP wifiAp)
         {
-            return wifiAp.NetworkInformation.ConnectionState == WiFiConnectionState.Connected
-                ? "Connected"
-                : "Secured";
+            if (wifiAp.NetworkInformation.ConnectionState == WiFiConnectionState.Connected)
+            {
+                return "Connected";
+            }
+            else if (wifiAp.SecurityInformation.IsPassphraseRequired)
+            {
+                return "Secured";
+            }
+            else
+            {
+                return "Open";
+            }
         }
 
         private static string GetRangeImage(WiFiAP wifiAp)
index 4f9537c..7777e71 100644 (file)
@@ -72,9 +72,21 @@ namespace Oobe.Wifi.Controls.Wifi
 
         private static async void OnApTapped(Tizen.Network.WiFi.WiFiAP wifiAp)
         {
-            Tizen.Log.Debug("oobe", $"connect to wifi {wifiAp.NetworkInformation.Essid}");
-            wifiAp.SecurityInformation.SetPassphrase("");//type your passphrase
-            await wifiAp.ConnectAsync();
+            if (wifiAp.NetworkInformation.ConnectionState == Tizen.Network.WiFi.WiFiConnectionState.Connected)
+            {
+                Tizen.Log.Debug("oobe", $"Already connected to {wifiAp.NetworkInformation.Essid}");
+                return;
+            }
+            try
+            {
+                Tizen.Log.Debug("oobe", $"connecting to wifi {wifiAp.NetworkInformation.Essid}");
+                wifiAp.SecurityInformation.SetPassphrase("");//type your passphrase
+                await wifiAp.ConnectAsync();
+            }
+            catch (Exception ex)
+            {
+                Tizen.Log.Error("oobe", $"{ex.ToString()}");
+            }
         }
 
         private View CreateHeader(int width, int height)