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);
}
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++;
{
while (await Delay())
{
- foreach(var (ap,view) in apToViewMap.ToList())
+ foreach (var (ap, view) in apToViewMap.ToList())
{
try
{
catch (Exception ex)
{
Tizen.Log.Error("oobe", $"failed to refresh ap {ap.NetworkInformation.Essid} {ex.ToString()}");
-
+
Views.Remove(view);
apToViewMap.Remove(ap);
ap.Dispose();
{
await Task.Delay(10_000, updatingCancellation.Token);
}
- catch (Exception)
- {
+ catch (Exception)
+ {
}
return updatingCancellation.IsCancellationRequested == false;
}
{
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()
{
FontStyle = FontsStyles.Regular(),
};
this.Add(detail);
+
+ detector = new TapGestureDetector();
+ detector.Detected += (s, e) => Tapped?.Invoke();
+ detector.Attach(this);
}
else
{
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)
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)