From: k.stepaniuk Date: Tue, 24 Mar 2020 08:10:30 +0000 (+0100) Subject: Fixing review X-Git-Tag: accepted/tizen/unified/20220322.015113~142 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6fd75089bfd3f4186b923b984a25ab97404c732e;p=profile%2Fiot%2Fapps%2Fdotnet%2Foobe-ui.git Fixing review Signed-off-by: k.stepaniuk --- diff --git a/Oobe/OobeWifi/Controls/Wifi/ApManager.cs b/Oobe/OobeWifi/Controls/Wifi/ApManager.cs index 07fe3e3..6858294 100644 --- a/Oobe/OobeWifi/Controls/Wifi/ApManager.cs +++ b/Oobe/OobeWifi/Controls/Wifi/ApManager.cs @@ -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; } diff --git a/Oobe/OobeWifi/Controls/Wifi/ApView.cs b/Oobe/OobeWifi/Controls/Wifi/ApView.cs index 67f05dd..523461e 100644 --- a/Oobe/OobeWifi/Controls/Wifi/ApView.cs +++ b/Oobe/OobeWifi/Controls/Wifi/ApView.cs @@ -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) diff --git a/Oobe/OobeWifi/Controls/Wifi/WifiView.cs b/Oobe/OobeWifi/Controls/Wifi/WifiView.cs index 4f9537c..7777e71 100644 --- a/Oobe/OobeWifi/Controls/Wifi/WifiView.cs +++ b/Oobe/OobeWifi/Controls/Wifi/WifiView.cs @@ -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)