Add device sorting logic with the rssi 50/282850/1
authorWootak Jung <wootak.jung@samsung.com>
Wed, 12 Oct 2022 08:11:19 +0000 (17:11 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Wed, 12 Oct 2022 08:11:19 +0000 (17:11 +0900)
Change-Id: I170b213797fbc602bfd1954616c17506fe5bfa7d
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
SettingBluetooth/SettingBluetooth/Model/BtDevice.cs
SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs
packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk

index 4ce0a43eafbb05ba2d774a2d2a3ca85bec30983f..d7e5dbfc56fb3c4a7a72183f6e39f3c332e5f809 100644 (file)
@@ -17,6 +17,7 @@ namespace SettingBluetooth.Model
         private string[] mServiceUuids = null;
         private BluetoothServiceClassType mServiceMask = 0;
         private BtDeviceIcon mDeviceIcon;
+        private int mRssi = 0;
 
         private bool mIsA2dpSupported = false;
         private BluetoothAudio mBluetoothAudio = null;
@@ -33,6 +34,7 @@ namespace SettingBluetooth.Model
             mIsPaired = device.IsPaired;
             mDeviceState = state;
             mBluetoothDevice = device;
+            mRssi = device.Rssi;
             if (device.ServiceCount > 0)
             {
                 mServiceUuids = new string[device.ServiceCount];
@@ -213,6 +215,14 @@ namespace SettingBluetooth.Model
             }
         }
 
+        internal int Rssi
+        {
+            get
+            {
+                return mRssi;
+            }
+        }
+
         private void BluetoothDeviceBondCreated(object obj, BondCreatedEventArgs ev)
         {
             Log.Info(Program.LogTag, "BluetoothDeviceBondCreated. Address: " + ev.Device.Address + ", IsPaired: " + ev.Device.IsPaired);
index 7e3d1d76db83b9bf37e9d444c4cb467796af9030..936e8db867023977d8e62cf28f336159fe5af80a 100644 (file)
@@ -22,6 +22,7 @@ namespace SettingBluetooth
         public event PropertyChangedEventHandler PropertyChanged;
         BtDevice mBtDevice;
         private string mState;
+        private int mRssi;
 
         private void OnPropertyChanged(string propertyName)
         {
@@ -144,6 +145,14 @@ namespace SettingBluetooth
                 OnPropertyChanged("ImageUrl");
             }
         }
+
+        public int Rssi
+        {
+            get
+            {
+                return mRssi;
+            }
+        }
     }
 
     public class DeviceCollection : ObservableCollection<Device>
@@ -170,7 +179,29 @@ namespace SettingBluetooth
 
         internal void AddDevice(BtDevice btDevice)
         {
-            this.Add(new Device(btDevice));
+            if (this.Count == 0)
+            {
+                this.Add(new Device(btDevice));
+            }
+            else
+            {
+                bool added = false;
+                foreach (var item in this)
+                {
+                    if (btDevice.Rssi > item.Rssi)
+                    {
+                        int idx = this.IndexOf(item);
+                        this.Insert(idx, new Device(btDevice));
+                        added = true;
+                        break;
+                    }
+                }
+                if (added == false)
+                {
+                    this.Add(new Device(btDevice));
+                }
+            }
+            //this.Add(new Device(btDevice));
             Log.Info(Program.LogTag, "device(" + btDevice.Address + ") added");
         }
 
index 786e18a146a0ccdb53e4e6e38f79e17c5e560e72..4aa70efcbe5c3ebc498ba0f16390a379ad9eb5c1 100644 (file)
Binary files a/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk and b/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk differ