From: cheoleun moon Date: Tue, 11 Oct 2022 13:19:12 +0000 (+0900) Subject: Add WiFiAP to AP class X-Git-Tag: accepted/tizen/unified/20221216.024031~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f76a9d4663a540c5ad20753d8dc53393014d0ba2;p=profile%2Fiot%2Fapps%2Fdotnet%2Fsetting-wifi.git Add WiFiAP to AP class Change-Id: I3b327b5c60b37878c52786344c2d3c6a2c24ecf0 --- diff --git a/SettingWiFi/SettingWiFi/Logger.cs b/SettingWiFi/SettingWiFi/Logger.cs new file mode 100644 index 0000000..9b58722 --- /dev/null +++ b/SettingWiFi/SettingWiFi/Logger.cs @@ -0,0 +1,24 @@ +using Tizen; + +namespace SettingWiFi +{ + internal class Logger + { + internal static readonly string LogTag = "SettingWiFi.App"; + + internal static void Debug(string msg) + { + Log.Debug(LogTag, msg); + } + + internal static void Info(string msg) + { + Log.Info(LogTag, msg); + } + + internal static void Error(string msg) + { + Log.Error(LogTag, msg); + } + } +} \ No newline at end of file diff --git a/SettingWiFi/SettingWiFi/controller/WiFi.cs b/SettingWiFi/SettingWiFi/controller/WiFi.cs index 03f454e..d37f74a 100755 --- a/SettingWiFi/SettingWiFi/controller/WiFi.cs +++ b/SettingWiFi/SettingWiFi/controller/WiFi.cs @@ -61,24 +61,25 @@ namespace SettingWiFi return null; } - public async Task Connect(string essid, string password) + public async Task Connect(AP ap, string password) { Debug("WiFi.Connect"); - WiFiAP ap = FindAP(essid); + if (ap == null) { - Debug("Cannet find " + essid); + Debug("Cannot find AP"); return; } + WiFiAP apHandle = ap.ApHandle; if (password.Length > 0) { - ap.SecurityInformation.SetPassphrase(password); + apHandle.SecurityInformation.SetPassphrase(password); } try { - await ap.ConnectAsync(); + await apHandle.ConnectAsync(); } catch (Exception e) { @@ -159,7 +160,7 @@ namespace SettingWiFi if (item.NetworkInformation.ConnectionState.ToString().Equals(Resources.IDS_WIFI_SBODY_CONNECTED_M_STATUS)) { - apInfoList.Add(new AP(item.NetworkInformation.Essid, Resources.IDS_WIFI_SBODY_CONNECTED_M_STATUS, securityType, isWpsSupported)); + apInfoList.Add(new AP(item, item.NetworkInformation.Essid, Resources.IDS_WIFI_SBODY_CONNECTED_M_STATUS, securityType, isWpsSupported)); continue; } string text = ""; @@ -181,7 +182,7 @@ namespace SettingWiFi text = Resources.IDS_ST_BODY_SECURED_ABB_M_WIFI_AP_SUMMARY; } - apInfoList.Add(new AP(item.NetworkInformation.Essid, text, securityType, isWpsSupported)); + apInfoList.Add(new AP(item, item.NetworkInformation.Essid, text, securityType, isWpsSupported)); } return apInfoList; diff --git a/SettingWiFi/SettingWiFi/model/AP.cs b/SettingWiFi/SettingWiFi/model/AP.cs new file mode 100755 index 0000000..9a743d0 --- /dev/null +++ b/SettingWiFi/SettingWiFi/model/AP.cs @@ -0,0 +1,97 @@ +using System; +using System.ComponentModel; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Tizen; +using Tizen.NUI.BaseComponents; +using Tizen.NUI.Components; +using Tizen.NUI.Binding; +using Tizen.Network.WiFi; +using SettingWiFi.res.locale; +using static SettingWiFi.Logger; + + +namespace SettingWiFi +{ + public class AP : INotifyPropertyChanged + { + string iconDir = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "icon.png"; + private string essid; + private string state; + private string secType; + private bool isWps; + + public event PropertyChangedEventHandler PropertyChanged; + + private void OnPropertyChanged(string propertyName) + { + Debug("OnPropertyChanged"); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public AP(WiFiAP apHandle, string apEssid, string apState, string apSecType, bool apIsWps) + { + ApHandle = apHandle; + essid = apEssid; + state = apState; + secType = apSecType; + isWps = apIsWps; + } + + public WiFiAP ApHandle + { + get; + set; + } + + public string Essid + { + get + { + return essid; + } + set + { + essid = value; + OnPropertyChanged("Essid"); + } + } + + public string ImageUrl + { + get + { + return iconDir; + } + } + + public string State + { + get + { + return state; + } + set + { + state = value; + OnPropertyChanged("State"); + } + } + + public string SecType + { + get + { + return secType; + } + } + + public bool IsWps + { + get + { + return isWps; + } + } + }; +} \ No newline at end of file diff --git a/SettingWiFi/SettingWiFi/view/AP.cs b/SettingWiFi/SettingWiFi/view/AP.cs deleted file mode 100755 index d335009..0000000 --- a/SettingWiFi/SettingWiFi/view/AP.cs +++ /dev/null @@ -1,192 +0,0 @@ -using System; -using System.ComponentModel; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using Tizen; -using Tizen.NUI.BaseComponents; -using Tizen.NUI.Components; -using Tizen.NUI.Binding; -using Tizen.Network.WiFi; -using SettingWiFi.res.locale; -using static SettingWiFi.Logger; - - -namespace SettingWiFi -{ - public class AP : INotifyPropertyChanged - { - string iconDir = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "icon.png"; - private string essid; - private string state; - private string secType; - private bool isWps; - - public event PropertyChangedEventHandler PropertyChanged; - - private void OnPropertyChanged(string propertyName) - { - Debug("OnPropertyChanged"); - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - - public AP(string apEssid, string apState, string apSecType, bool apIsWps) - { - essid = apEssid; - state = apState; - secType = apSecType; - isWps = apIsWps; - } - - public string Essid - { - get - { - return essid; - } - set - { - essid = value; - OnPropertyChanged("Essid"); - } - } - - public string ImageUrl - { - get - { - return iconDir; - } - } - - public string State - { - get - { - return state; - } - set - { - state = value; - OnPropertyChanged("State"); - } - } - - public string SecType - { - get - { - return secType; - } - } - - public bool IsWps - { - get - { - return isWps; - } - } - }; - - public class DeviceCollection : ObservableCollection - { - private string title; - - public DeviceCollection(string groupTitle) - { - title = groupTitle; - this.UpdateScanList(null); - } - - public string Title - { - get - { - return title; - } - set - { - title = value; - OnPropertyChanged(new PropertyChangedEventArgs("Title")); - } - } - - public void UpdateScanList(List apList) - { - if (apList == null) - { - Debug("apList is null"); - this.Add(new AP("", "", "", false)); - return; - } - // Clear method have some issue about asynchronous actions, - // so call Remove for all item is recommanded. - while (this.Count > 0) - { - this.RemoveAt(this.Count - 1); - } - - foreach (var item in apList) - { - this.Add(new AP(item.Essid, item.State, item.SecType, item.IsWps)); - } - } - - public void RemoveScanList() - { - while (this.Count > 0) - { - this.RemoveAt(this.Count - 1); - } - } - - public void UpdateState(AP ap) - { - string text = ""; - - if (ap.SecType.Equals(Resources.IDS_ST_BODY_NONE)) - { - text = Resources.IDS_WIFI_POP_OPEN; - } - else if (ap.SecType.Equals(Resources.IDS_WIFI_BODY_EAP)) - { - text = Resources.IDS_ST_BODY_SECURED_ABB_M_WIFI_AP_SUMMARY + " (Eap)"; - } - else if (ap.IsWps) - { - text = Resources.IDS_ST_BODY_SECURED_ABB_M_WIFI_AP_SUMMARY + " (WPS available)"; - } - else - { - text = Resources.IDS_ST_BODY_SECURED_ABB_M_WIFI_AP_SUMMARY; - } - - ap.State = text; - } - } - - public class APSource : ObservableCollection - { - private DeviceCollection available; - public APSource() - { - available = new DeviceCollection("Available networks"); - this.Add(available); - } - - public void UpdateScanList(List apList) - { - available.UpdateScanList(apList); - } - - public void RemoveScanList() - { - available.RemoveScanList(); - } - - public void UpdateState(AP ap) - { - available.UpdateState(ap); - } - } -} \ No newline at end of file diff --git a/SettingWiFi/SettingWiFi/view/APSource.cs b/SettingWiFi/SettingWiFi/view/APSource.cs new file mode 100755 index 0000000..a4076f2 --- /dev/null +++ b/SettingWiFi/SettingWiFi/view/APSource.cs @@ -0,0 +1,117 @@ +using System; +using System.ComponentModel; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Tizen; +using Tizen.NUI.BaseComponents; +using Tizen.NUI.Components; +using Tizen.NUI.Binding; +using Tizen.Network.WiFi; +using SettingWiFi.res.locale; +using static SettingWiFi.Logger; + + +namespace SettingWiFi +{ + public class DeviceCollection : ObservableCollection + { + private string title; + + public DeviceCollection(string groupTitle) + { + title = groupTitle; + this.UpdateScanList(null); + } + + public string Title + { + get + { + return title; + } + set + { + title = value; + OnPropertyChanged(new PropertyChangedEventArgs("Title")); + } + } + + public void UpdateScanList(List apList) + { + if (apList == null) + { + Debug("apList is null"); + this.Add(new AP(null, "", "", "", false)); + return; + } + // Clear method have some issue about asynchronous actions, + // so call Remove for all item is recommanded. + while (this.Count > 0) + { + this.RemoveAt(this.Count - 1); + } + + foreach (var item in apList) + { + this.Add(new AP(item.ApHandle, item.Essid, item.State, item.SecType, item.IsWps)); + } + } + + public void RemoveScanList() + { + while (this.Count > 0) + { + this.RemoveAt(this.Count - 1); + } + } + + public void UpdateState(AP ap) + { + string text = ""; + + if (ap.SecType.Equals(Resources.IDS_ST_BODY_NONE)) + { + text = Resources.IDS_WIFI_POP_OPEN; + } + else if (ap.SecType.Equals(Resources.IDS_WIFI_BODY_EAP)) + { + text = Resources.IDS_ST_BODY_SECURED_ABB_M_WIFI_AP_SUMMARY + " (Eap)"; + } + else if (ap.IsWps) + { + text = Resources.IDS_ST_BODY_SECURED_ABB_M_WIFI_AP_SUMMARY + " (WPS available)"; + } + else + { + text = Resources.IDS_ST_BODY_SECURED_ABB_M_WIFI_AP_SUMMARY; + } + + ap.State = text; + } + } + + public class APSource : ObservableCollection + { + private DeviceCollection available; + public APSource() + { + available = new DeviceCollection("Available networks"); + this.Add(available); + } + + public void UpdateScanList(List apList) + { + available.UpdateScanList(apList); + } + + public void RemoveScanList() + { + available.RemoveScanList(); + } + + public void UpdateState(AP ap) + { + available.UpdateState(ap); + } + } +} \ No newline at end of file diff --git a/SettingWiFi/SettingWiFi/view/ConnectPage.cs b/SettingWiFi/SettingWiFi/view/ConnectPage.cs index 8093651..df277e4 100644 --- a/SettingWiFi/SettingWiFi/view/ConnectPage.cs +++ b/SettingWiFi/SettingWiFi/view/ConnectPage.cs @@ -82,15 +82,10 @@ namespace SettingWiFi Navigator.Pop(); } - private async void Connect() + private void Connect() { mAp.State = Resources.IDS_WIFI_BODY_CONNECTING_ING; - await mWifi.Connect(mAp.Essid, "datanetwork"); - - if(mWifi.GetConnectedAP().Equals(mAp.Essid)) - { - mAp.State = Resources.IDS_WIFI_SBODY_CONNECTED_M_STATUS; - } + mWifi.Connect(mAp, "datanetwork"); } } } \ No newline at end of file diff --git a/SettingWiFi/SettingWiFi/view/Logger.cs b/SettingWiFi/SettingWiFi/view/Logger.cs deleted file mode 100644 index 9b58722..0000000 --- a/SettingWiFi/SettingWiFi/view/Logger.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Tizen; - -namespace SettingWiFi -{ - internal class Logger - { - internal static readonly string LogTag = "SettingWiFi.App"; - - internal static void Debug(string msg) - { - Log.Debug(LogTag, msg); - } - - internal static void Info(string msg) - { - Log.Info(LogTag, msg); - } - - internal static void Error(string msg) - { - Log.Error(LogTag, msg); - } - } -} \ No newline at end of file