Fix the issue that paired and searched views are scrolled separately 82/284882/1
authorWootak Jung <wootak.jung@samsung.com>
Wed, 30 Nov 2022 00:58:38 +0000 (09:58 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Wed, 30 Nov 2022 01:01:13 +0000 (10:01 +0900)
Combine paired and searched views into one
Manage paired and searched devices as each collection

Change-Id: Ie8da84681bba62df1dcc82944807ac8be5cabc27
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
SettingBluetooth/SettingBluetooth/Model/BtDevice.cs
SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs
SettingBluetooth/SettingBluetooth/View/BtMainView.cs
packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk

index d7e5dbfc56fb3c4a7a72183f6e39f3c332e5f809..7596cf360e8f349dcb6b2464d1386f597ce259a1 100644 (file)
@@ -129,10 +129,12 @@ namespace SettingBluetooth.Model
         }
 
         // for dummy instance (No devices found, Paired device)
-        internal BtDevice(string address)
+        internal BtDevice(string address, bool isPaired)
         {
             mAddress = address;
             mName = address;
+            mIsPaired = isPaired;
+            mDeviceState = isPaired ? BtDeviceState.Paired : BtDeviceState.Idle;
         }
 
         internal string Address
index 542d8c8759a45899be0c27935d62da190af2c03c..e88c629a400a392bce92647333fb53370e5dae60 100644 (file)
@@ -180,7 +180,7 @@ namespace SettingBluetooth
             }
         }
 
-        internal void AddDevice(BtDevice btDevice)
+        internal void AddDevice(BtDevice btDevice) // TODO: need to create AddDeviceFront function to add the device in front of the list for paired and unpaired case
         {
             if (this.Count == 0)
             {
@@ -208,14 +208,14 @@ namespace SettingBluetooth
             Log.Info(Program.LogTag, "device(" + btDevice.Address + ") added");
         }
 
-        internal void RemoveDevice(string address)
+        internal void RemoveDevice(BtDevice btDevice)
         {
             foreach (Device device in this)
             {
-                if (device.Address == address)
+                if (device.Address == btDevice.Address)
                 {
                     this.Remove(device);
-                    Log.Info(Program.LogTag, "device(" + address + ") removed");
+                    Log.Info(Program.LogTag, "device(" + device.Address + ") removed");
                     break;
                 }
             }
@@ -224,48 +224,93 @@ namespace SettingBluetooth
 
     public class DeviceSource : ObservableCollection<DeviceCollection>
     {
-        private DeviceCollection collection;
+        private DeviceCollection mSearched;
+        private DeviceCollection mPaired;
 
         public DeviceSource()
         {
             Log.Info(Program.LogTag, "DeviceSource created");
-            collection = new DeviceCollection(Resources.IDS_BT_BODY_AVAILABLE_DEVICES);
-            this.Add(collection);
+            mSearched = new DeviceCollection(Resources.IDS_BT_BODY_SCANNING_FOR_DEVICES_ING);
+            mPaired = new DeviceCollection(Resources.IDS_BT_BODY_PAIRED_DEVICES);
+            this.Add(mSearched);
+        }
+
+        internal void UpdateSearchedTitle(string title)
+        {
+            mSearched.Title = title;
+        }
+
+        internal void AddToSearched(BtDevice btDevice)
+        {
+            mSearched.AddDevice(btDevice);
+            UpdateState(btDevice); // TODO: don't need to find device item. let's use return value from above function
+        }
+
+        internal void AddToPaired(BtDevice btDevice)
+        {
+            if (mPaired.Count == 0)
+            {
+                this.Insert(0, mPaired);
+            }
+            mPaired.AddDevice(btDevice); // TODO: need to Add to in front of the list not Insert if paired
+            UpdateState(btDevice); // TODO: don't need to find device item. let's use return value from above function
+        }
+
+        internal void RemoveFromSearched(BtDevice btDevice)
+        {
+            mSearched.RemoveDevice(btDevice);
         }
 
-        internal void UpdateTitle(string title)
+        internal void RemoveFromPaired(BtDevice btDevice)
         {
-            collection.Title = title;
+            mPaired.RemoveDevice(btDevice);
+            if (mPaired.Count == 0)
+            {
+                this.Remove(mPaired);
+            }
         }
 
-        internal void AddDevice(BtDevice btDevice)
+        internal void RemoveAllSearchedDevices()
         {
-            collection.AddDevice(btDevice);
-            UpdateState(btDevice);
+            mSearched.Clear();
         }
 
-        internal void RemoveDevice(string address)
+        internal Device FindInSearched(BtDevice btDevice)
         {
-            collection.RemoveDevice(address);
+            foreach (Device device in mSearched)
+            {
+                if (device.Address == btDevice.Address)
+                {
+                    //Log.Info(Program.LogTag, "Device(" + device.Address + ") found in searched");
+                    return device;
+                }
+            }
+
+            return null;
         }
 
-        internal Device FindDevice(BtDevice btDevice)
+        internal Device FindInPaired(BtDevice btDevice)
         {
-            foreach (Device device in collection)
+            foreach (Device device in mPaired)
             {
                 if (device.Address == btDevice.Address)
                 {
-                    //Log.Info(Program.LogTag, "Device(" + address + ") found");
+                    //Log.Info(Program.LogTag, "Device(" + device.Address + ") found in paired");
                     return device;
                 }
             }
-            //Log.Info(Program.LogTag, "Device(" + address + ") not found");
+
             return null;
         }
 
         internal void UpdateState(BtDevice btDevice)
         {
-            var device = FindDevice(btDevice);
+            var device = FindInSearched(btDevice);
+            if (device == null)
+            {
+                device = FindInPaired(btDevice);
+            }
+
             switch (btDevice.DeviceState)
             {
                 case BtDeviceState.Idle:
@@ -296,11 +341,9 @@ namespace SettingBluetooth
 
     internal static class BtDeviceView
     {
-        static CollectionView mPairedDeviceView = null;
-        static CollectionView mSearchedDeviceView = null;
+        static CollectionView mDeviceView = null;
         static Button mScanButton = null;
-        static DeviceSource mSearchedDevice = null;
-        static DeviceSource mPairedDevice = null;
+        static DeviceSource mDeviceSource = null;
 
         private static CollectionView CreateCollectionView(DeviceSource source, bool isPairedDeviceView = false)
         {
@@ -335,9 +378,9 @@ namespace SettingBluetooth
                     item.Clicked += DeviceController.DeviceItemClicked;
                     item.IsSelectable = false;
 
-                    if (isPairedDeviceView == true)
-                    {
-                        var detailButton = new Button // TODO: need to use other type instead of Button
+                    //if (isPairedDeviceView == true) // TODO: need to use DataTemplateExtension and DataTemplateSelector
+                    //{
+                    var detailButton = new Button // TODO: need to use other type instead of Button
                         {
                             Text = "i"
                         };
@@ -350,7 +393,7 @@ namespace SettingBluetooth
                             BtDetailView.CreateDetailView(device);
                         };
                         item.Extra = detailButton;
-                    }
+                    //}
 
                     return item;
                 }),
@@ -373,30 +416,22 @@ namespace SettingBluetooth
                 SelectionMode = ItemSelectionMode.Single,
             };
 
-            if (isPairedDeviceView == false)
-            {
-                view.HeightSpecification = LayoutParamPolicies.MatchParent;
-            }
+            view.HeightSpecification = LayoutParamPolicies.MatchParent;
             //view.SelectionChanged += DeviceController.DeviceViewSelectionChanged;
 
             return view;
         }
 
-        internal static void AddPairedDeviceView(View view)
+        internal static void AddDeviceView(View view)
         {
-            mPairedDevice = new DeviceSource();
-            mPairedDeviceView = CreateCollectionView(mPairedDevice, true);
-            mPairedDevice.AddDevice(new BtDevice("dummy paired device")); // temporary device
-            mPairedDevice.UpdateTitle(Resources.IDS_BT_BODY_PAIRED_DEVICES);
-            view.Add(mPairedDeviceView);
-        }
+            Log.Info(Program.LogTag, "Add device view");
 
-        internal static void AddSearchedDeviceView(View view)
-        {
-            mSearchedDevice = new DeviceSource();
-            mSearchedDeviceView = CreateCollectionView(mSearchedDevice);
-            mSearchedDevice.AddDevice(new BtDevice("dummy searched device")); // temporary device
-            view.Add(mSearchedDeviceView);
+            mDeviceSource = new DeviceSource();
+            mDeviceView = CreateCollectionView(mDeviceSource);
+            mDeviceSource.AddToPaired(new BtDevice("dummy paired device", true)); // dummy device
+            mDeviceSource.AddToSearched(new BtDevice("dummy paired device", false)); // dummy device
+            view.Add(mDeviceView);
+            BtModel.GetBondedDevices();
 
             mScanButton = new Button
             {
@@ -406,30 +441,14 @@ namespace SettingBluetooth
             view.Add(mScanButton);
         }
 
-        internal static void AddDeviceView(View view)
+        internal static void RemoveDeviceView(View view)
         {
-            Log.Info(Program.LogTag, "Add device view");
-            AddPairedDeviceView(view);
-            AddSearchedDeviceView(view);
-            BtModel.GetBondedDevices();
-            AdapterController.AutoStart();
-        }
-
-        internal static void RemovePairedDeviceView(View view)
-        {
-            if (mPairedDeviceView)
-            {
-                view.Remove(mPairedDeviceView);
-                mPairedDeviceView = null;
-            }
-        }
+            Log.Info(Program.LogTag, "Remove device view");
 
-        internal static void RemoveSearchedDeviceView(View view)
-        {
-            if (mSearchedDeviceView)
+            if (mDeviceView)
             {
-                view.Remove(mSearchedDeviceView);
-                mSearchedDeviceView = null;
+                view.Remove(mDeviceView);
+                mDeviceView = null;
             }
 
             if (mScanButton)
@@ -439,9 +458,15 @@ namespace SettingBluetooth
             }
         }
 
-        internal static void UpdateSearchedViewTitle(string title)
+        internal static void RemoveAllSearchedDevices()
+        {
+            Log.Info(Program.LogTag, "Remove all searched devices");
+            mDeviceSource.RemoveAllSearchedDevices();
+        }
+
+        internal static void UpdateSearchedTitle(string title)
         {
-            mSearchedDevice.UpdateTitle(title);
+            mDeviceSource.UpdateSearchedTitle(title);
         }
 
         internal static void UpdateScanButtonText(string text)
@@ -458,43 +483,43 @@ namespace SettingBluetooth
                     // available cases: added new one, bond/unbond/audio failed
                     if (ev.BtDevice.IsPaired)
                     {
-                        if (mPairedDevice.FindDevice(ev.BtDevice) == null)
+                        if (mDeviceSource.FindInPaired(ev.BtDevice) == null)
                         {
-                            mPairedDevice.AddDevice(ev.BtDevice);
+                            mDeviceSource.AddToPaired(ev.BtDevice);
                         }
                         else
                         {
-                            mPairedDevice.UpdateState(ev.BtDevice);
+                            mDeviceSource.UpdateState(ev.BtDevice);
                         }
                     }
                     else
                     {
-                        if (mSearchedDevice.FindDevice(ev.BtDevice) != null) // bond/unbond/audio failed case
+                        if (mDeviceSource.FindInSearched(ev.BtDevice) != null) // bond/unbond/audio failed case
                         {
-                            mSearchedDevice.UpdateState(ev.BtDevice); // TODO: need to remove SubLabel in this case
+                            mDeviceSource.UpdateState(ev.BtDevice); // TODO: need to remove SubLabel in this case
                         }
                         else
                         {
-                            mSearchedDevice.AddDevice(ev.BtDevice); // added new one
+                            mDeviceSource.AddToSearched(ev.BtDevice); // added new one
                         }
                     }
                     break;
                 case BtDeviceState.Pairing:
-                    if (mSearchedDevice.FindDevice(ev.BtDevice) != null)
+                    if (mDeviceSource.FindInSearched(ev.BtDevice) != null)
                     {
-                        mSearchedDevice.UpdateState(ev.BtDevice);
+                        mDeviceSource.UpdateState(ev.BtDevice);
                     }
                     break;
                 case BtDeviceState.Unpairing:
                     break;
                 case BtDeviceState.Paired:
-                    if (mSearchedDevice.FindDevice(ev.BtDevice) != null)
+                    if (mDeviceSource.FindInSearched(ev.BtDevice) != null)
                     {
-                        mSearchedDevice.RemoveDevice(ev.BtDevice.Address);
+                        mDeviceSource.RemoveFromSearched(ev.BtDevice);
                     }
-                    if (mPairedDevice.FindDevice(ev.BtDevice) == null)
+                    if (mDeviceSource.FindInPaired(ev.BtDevice) == null)
                     {
-                        mPairedDevice.AddDevice(ev.BtDevice);
+                        mDeviceSource.AddToPaired(ev.BtDevice);
                         if (ev.BtDevice.IsA2dpSupported)
                         {
                             DeviceController.ConnectA2dp(ev.BtDevice);
@@ -502,35 +527,35 @@ namespace SettingBluetooth
                     }
                     else // audio disconnected case
                     {
-                        mPairedDevice.UpdateState(ev.BtDevice);
+                        mDeviceSource.UpdateState(ev.BtDevice);
                     }
                     break;
                 case BtDeviceState.Unpaired:
-                    if (mSearchedDevice.FindDevice(ev.BtDevice) == null)
+                    if (mDeviceSource.FindInSearched(ev.BtDevice) == null)
                     {
-                        mSearchedDevice.AddDevice(ev.BtDevice);
+                        mDeviceSource.AddToSearched(ev.BtDevice); // TODO: need to add in front of the list
                     }
-                    if (mPairedDevice.FindDevice(ev.BtDevice) != null)
+                    if (mDeviceSource.FindInPaired(ev.BtDevice) != null)
                     {
-                        mPairedDevice.RemoveDevice(ev.BtDevice.Address);
+                        mDeviceSource.RemoveFromPaired(ev.BtDevice);
                     }
                     break;
                 case BtDeviceState.Connecting:
-                    if (mPairedDevice.FindDevice(ev.BtDevice) != null)
+                    if (mDeviceSource.FindInPaired(ev.BtDevice) != null)
                     {
-                        mPairedDevice.UpdateState(ev.BtDevice);
+                        mDeviceSource.UpdateState(ev.BtDevice);
                     }
                     break;
                 case BtDeviceState.Connected:
-                    if (mPairedDevice.FindDevice(ev.BtDevice) != null)
+                    if (mDeviceSource.FindInPaired(ev.BtDevice) != null)
                     {
-                        mPairedDevice.UpdateState(ev.BtDevice);
+                        mDeviceSource.UpdateState(ev.BtDevice);
                     }
                     break;
                 case BtDeviceState.Disconnecting:
-                    if (mPairedDevice.FindDevice(ev.BtDevice) != null)
+                    if (mDeviceSource.FindInPaired(ev.BtDevice) != null)
                     {
-                        mPairedDevice.UpdateState(ev.BtDevice);
+                        mDeviceSource.UpdateState(ev.BtDevice);
                     }
                     break;
                 case BtDeviceState.ServiceSearching:
index 6150b77a8bcacbaa8d8d3181ecfedc53fa3669c1..c06cc6bc28b522d4833dd47afcbf415d575a30ab 100644 (file)
@@ -27,24 +27,23 @@ namespace SettingBluetooth
             switch (ev.OperationState)
             {
                 case BtOperationState.Deactivated:
-                    BtDeviceView.RemoveSearchedDeviceView(mMainView);
-                    BtDeviceView.RemovePairedDeviceView(mMainView);
+                    BtDeviceView.RemoveDeviceView(mMainView);
                     break;
                 case BtOperationState.Deactivating:
                     break;
                 case BtOperationState.Activated:
                     BtDeviceView.AddDeviceView(mMainView);
+                    AdapterController.AutoStart();
                     break;
                 case BtOperationState.Activating:
                     break;
                 case BtOperationState.Searching:
-                    BtDeviceView.RemoveSearchedDeviceView(mMainView);
-                    BtDeviceView.AddSearchedDeviceView(mMainView);
-                    BtDeviceView.UpdateSearchedViewTitle(Resources.IDS_BT_BODY_SCANNING_FOR_DEVICES_ING);
+                    BtDeviceView.RemoveAllSearchedDevices();
+                    BtDeviceView.UpdateSearchedTitle(Resources.IDS_BT_BODY_SCANNING_FOR_DEVICES_ING);
                     BtDeviceView.UpdateScanButtonText(Resources.IDS_BT_SK_STOP);
                     break;
                 case BtOperationState.Searched:
-                    BtDeviceView.UpdateSearchedViewTitle(Resources.IDS_BT_BODY_AVAILABLE_DEVICES);
+                    BtDeviceView.UpdateSearchedTitle(Resources.IDS_BT_BODY_AVAILABLE_DEVICES);
                     BtDeviceView.UpdateScanButtonText(Resources.IDS_BT_SK_SCAN);
                     break;
                 case BtOperationState.Pairing:
@@ -110,6 +109,7 @@ namespace SettingBluetooth
             if (BtModel.IsEnabled)
             {
                 BtDeviceView.AddDeviceView(mMainView);
+                AdapterController.AutoStart();
             }
 
             mMainPage = new ContentPage()
index 0283692b70e9dda400ed33fbe63617ed60bc4ad5..ed1d5eef91ecdb694100050846f82a300978ba50 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