Move device view related functions to BtDeviceView.cs 91/282891/1
authorWootak Jung <wootak.jung@samsung.com>
Thu, 13 Oct 2022 04:35:40 +0000 (13:35 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Thu, 13 Oct 2022 04:35:40 +0000 (13:35 +0900)
Change-Id: I9410e8a2bba05f26c94de03ff5d22fdc6462f3aa
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs
SettingBluetooth/SettingBluetooth/View/BtMainView.cs
packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk

index 936e8db867023977d8e62cf28f336159fe5af80a..2a69d75e7940cf15b1ce7bfd38bb8494670566ed 100644 (file)
@@ -8,6 +8,8 @@ using Tizen.NUI.Binding;
 using Tizen;
 using SettingBluetooth.res.locale;
 using SettingBluetooth.Model;
+using Tizen.NUI;
+using SettingBluetooth.Controller;
 
 namespace SettingBluetooth
 {
@@ -290,4 +292,240 @@ namespace SettingBluetooth
             //Log.Info(Program.LogTag, "Device(" + btDevice.Address + ") updated. state: " + device.State);
         }
     }
+
+    internal static class BtDeviceView
+    {
+        static CollectionView mPairedDeviceView = null;
+        static CollectionView mSearchedDeviceView = null;
+        static Button mScanButton = null;
+        static DeviceSource mSearchedDevice = null;
+        static DeviceSource mPairedDevice = null;
+
+        private static CollectionView CreateCollectionView(DeviceSource source, bool isPairedDeviceView = false)
+        {
+            var view = new CollectionView()
+            {
+                ItemsSource = source,
+                ItemsLayouter = new LinearLayouter(),
+                ItemTemplate = new DataTemplate(() =>
+                {
+                    DefaultLinearItem item = new DefaultLinearItem()
+                    {
+                        WidthSpecification = LayoutParamPolicies.MatchParent,
+                    };
+                    item.Label.SetBinding(TextLabel.TextProperty, "Name");
+                    item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
+                    item.SubLabel.SetBinding(TextLabel.TextProperty, "State");
+                    item.SubLabel.HorizontalAlignment = HorizontalAlignment.Begin;
+                    ImageViewStyle imageViewStyle = new ImageViewStyle()
+                    {
+                        Color = new Selector<Color>()
+                        {
+                            Normal = new Color("#17234D"),
+                            Focused = new Color("#17234D"),
+                            Pressed = new Color("#FF6200"),
+                            Disabled = new Color("#CACACA"),
+                        },
+                    };
+                    item.Icon = new ImageView(imageViewStyle);
+                    item.Icon.SetBinding(ImageView.ResourceUrlProperty, "ImageUrl");
+                    item.Icon.WidthSpecification = 40;
+                    item.Icon.HeightSpecification = 40;
+                    item.Clicked += DeviceController.DeviceItemClicked;
+                    item.IsSelectable = false;
+
+                    if (isPairedDeviceView == true)
+                    {
+                        var detailButton = new Button // TODO: need to use other type instead of Button
+                        {
+                            Text = "i"
+                        };
+                        detailButton.WidthSpecification = 40;
+                        detailButton.Clicked += (obj, ev) =>
+                        {
+                            Button button = (Button)obj;
+                            var device = button.BindingContext as Device;
+                            Log.Debug(Program.LogTag, "Button clicked. Name: " + device.Name);
+                            BtDetailView.CreateDetailView(device);
+                        };
+                        item.Extra = detailButton;
+                    }
+
+                    return item;
+                }),
+
+                GroupHeaderTemplate = new DataTemplate(() =>
+                {
+                    DefaultTitleItem group = new DefaultTitleItem()
+                    {
+                        WidthSpecification = LayoutParamPolicies.MatchParent,
+                    };
+                    group.Label.SetBinding(TextLabel.TextProperty, "Title");
+                    group.Label.HorizontalAlignment = HorizontalAlignment.Begin;
+
+                    return group;
+                }),
+
+                IsGrouped = true,
+                ScrollingDirection = ScrollableBase.Direction.Vertical,
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                SelectionMode = ItemSelectionMode.Single,
+            };
+
+            if (isPairedDeviceView == false)
+            {
+                view.HeightSpecification = LayoutParamPolicies.MatchParent;
+            }
+            //view.SelectionChanged += DeviceController.DeviceViewSelectionChanged;
+
+            return view;
+        }
+
+        internal static void AddPairedDeviceView(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);
+        }
+
+        internal static void AddSearchedDeviceView(View view)
+        {
+            mSearchedDevice = new DeviceSource();
+            mSearchedDeviceView = CreateCollectionView(mSearchedDevice);
+            mSearchedDevice.AddDevice(new BtDevice("dummy searched device")); // temporary device
+            view.Add(mSearchedDeviceView);
+
+            mScanButton = new Button
+            {
+                Text = Resources.IDS_BT_SK_SCAN,
+            };
+            mScanButton.Clicked += AdapterController.ScanButtonClicked;
+            view.Add(mScanButton);
+        }
+
+        internal static void RemovePairedDeviceView(View view)
+        {
+            if (mPairedDeviceView)
+            {
+                view.Remove(mPairedDeviceView);
+                mPairedDeviceView = null;
+            }
+        }
+
+        internal static void RemoveSearchedDeviceView(View view)
+        {
+            if (mSearchedDeviceView)
+            {
+                view.Remove(mSearchedDeviceView);
+                mSearchedDeviceView = null;
+            }
+
+            if (mScanButton)
+            {
+                view.Remove(mScanButton);
+                mScanButton = null;
+            }
+        }
+
+        internal static void UpdateSearchedViewTitle(string title)
+        {
+            mSearchedDevice.UpdateTitle(title);
+        }
+
+        internal static void UpdateScanButtonText(string text)
+        {
+            mScanButton.Text = text;
+        }
+
+        internal static void BtModelDeviceChanged(object obj, BtDeviceChangedEventArgs ev)
+        {
+            Log.Debug(Program.LogTag, "BtModelDeviceChanged. Address: " + ev.BtDevice.Address + ", State: " + ev.BtDevice.DeviceState);
+            switch (ev.BtDevice.DeviceState)
+            {
+                case BtDeviceState.Idle:
+                    // available cases: added new one, bond/unbond/audio failed
+                    if (ev.BtDevice.IsPaired)
+                    {
+                        if (mPairedDevice.FindDevice(ev.BtDevice) == null)
+                        {
+                            mPairedDevice.AddDevice(ev.BtDevice);
+                        }
+                        else
+                        {
+                            mPairedDevice.UpdateState(ev.BtDevice);
+                        }
+                    }
+                    else
+                    {
+                        if (mSearchedDevice.FindDevice(ev.BtDevice) != null) // bond/unbond/audio failed case
+                        {
+                            mSearchedDevice.UpdateState(ev.BtDevice); // TODO: need to remove SubLabel in this case
+                        }
+                        else
+                        {
+                            mSearchedDevice.AddDevice(ev.BtDevice); // added new one
+                        }
+                    }
+                    break;
+                case BtDeviceState.Pairing:
+                    if (mSearchedDevice.FindDevice(ev.BtDevice) != null)
+                    {
+                        mSearchedDevice.UpdateState(ev.BtDevice);
+                    }
+                    break;
+                case BtDeviceState.Unpairing:
+                    break;
+                case BtDeviceState.Paired:
+                    if (mSearchedDevice.FindDevice(ev.BtDevice) != null)
+                    {
+                        mSearchedDevice.RemoveDevice(ev.BtDevice.Address);
+                    }
+                    if (mPairedDevice.FindDevice(ev.BtDevice) == null)
+                    {
+                        mPairedDevice.AddDevice(ev.BtDevice);
+                        //if (ev.BtDevice.IsA2dpSupported)
+                        //{
+                        //    DeviceController.ConnectA2dp(ev.BtDevice);
+                        //}
+                    }
+                    else // audio disconnected case
+                    {
+                        mPairedDevice.UpdateState(ev.BtDevice);
+                    }
+                    break;
+                case BtDeviceState.Unpaired:
+                    if (mSearchedDevice.FindDevice(ev.BtDevice) == null)
+                    {
+                        mSearchedDevice.AddDevice(ev.BtDevice);
+                    }
+                    if (mPairedDevice.FindDevice(ev.BtDevice) != null)
+                    {
+                        mPairedDevice.RemoveDevice(ev.BtDevice.Address);
+                    }
+                    break;
+                case BtDeviceState.Connecting:
+                    if (mPairedDevice.FindDevice(ev.BtDevice) != null)
+                    {
+                        mPairedDevice.UpdateState(ev.BtDevice);
+                    }
+                    break;
+                case BtDeviceState.Connected:
+                    if (mPairedDevice.FindDevice(ev.BtDevice) != null)
+                    {
+                        mPairedDevice.UpdateState(ev.BtDevice);
+                    }
+                    break;
+                case BtDeviceState.Disconnecting:
+                    if (mPairedDevice.FindDevice(ev.BtDevice) != null)
+                    {
+                        mPairedDevice.UpdateState(ev.BtDevice);
+                    }
+                    break;
+                case BtDeviceState.ServiceSearching:
+                    break;
+            }
+        }
+    }
 }
index a926a888bddd7d385e504d8aae04496f08e8309d..18554675efd50d30ebfa2b721e07bac5e71e0922 100644 (file)
@@ -1,14 +1,11 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using Tizen.Applications;
 using Tizen.NUI;
 using Tizen.NUI.BaseComponents;
 using Tizen.NUI.Components;
-using Tizen.Network.Bluetooth;
 using Tizen;
 using SettingBluetooth.res.locale;
-using Tizen.NUI.Binding;
 using SettingBluetooth.Model;
 using SettingBluetooth.Controller;
 
@@ -18,196 +15,38 @@ namespace SettingBluetooth
     {
         static ContentPage mMainPage;
         static View mMainView;
-        static CollectionView mPairedDeviceView = null;
-        static CollectionView mSearchedDeviceView = null;
-        static Button mScanButton = null;
-        static DeviceSource mSearchedDevice = null;
-        static DeviceSource mPairedDevice = null;
 
         public BtMainView() : base()
         {
         }
 
-        // TODO: Need to move device view related functions to BtDeviceView.cs.
-        private static CollectionView CreateCollectionView(DeviceSource source, bool isPairedDeviceView = false)
-        {
-            var view = new CollectionView()
-            {
-                ItemsSource = source,
-                ItemsLayouter = new LinearLayouter(),
-                ItemTemplate = new DataTemplate(() =>
-                {
-                    DefaultLinearItem item = new DefaultLinearItem()
-                    {
-                        WidthSpecification = LayoutParamPolicies.MatchParent,
-                    };
-                    item.Label.SetBinding(TextLabel.TextProperty, "Name");
-                    item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
-                    item.SubLabel.SetBinding(TextLabel.TextProperty, "State");
-                    item.SubLabel.HorizontalAlignment = HorizontalAlignment.Begin;
-                    ImageViewStyle imageViewStyle = new ImageViewStyle()
-                    {
-                        Color = new Selector<Color>()
-                        {
-                            Normal = new Color("#17234D"),
-                            Focused = new Color("#17234D"),
-                            Pressed = new Color("#FF6200"),
-                            Disabled = new Color("#CACACA"),
-                        },
-                    };
-                    item.Icon = new ImageView(imageViewStyle);
-                    item.Icon.SetBinding(ImageView.ResourceUrlProperty, "ImageUrl");
-                    item.Icon.WidthSpecification = 40;
-                    item.Icon.HeightSpecification = 40;
-                    item.Clicked += DeviceController.DeviceItemClicked;
-                    item.IsSelectable = false;
-
-                    if (isPairedDeviceView == true)
-                    {
-                        var detailButton = new Button // TODO: need to use other type instead of Button
-                        {
-                            Text = "i"
-                        };
-                        detailButton.WidthSpecification = 40;
-                        detailButton.Clicked += (obj, ev) =>
-                        {
-                            Button button = (Button)obj;
-                            var device = button.BindingContext as Device;
-                            Log.Debug(Program.LogTag, "Button clicked. Name: " + device.Name);
-                            BtDetailView.CreateDetailView(device);
-                        };
-                        item.Extra = detailButton;
-                    }
-
-                    return item;
-                }),
-
-                GroupHeaderTemplate = new DataTemplate(() =>
-                {
-                    DefaultTitleItem group = new DefaultTitleItem()
-                    {
-                        WidthSpecification = LayoutParamPolicies.MatchParent,
-                    };
-                    group.Label.SetBinding(TextLabel.TextProperty, "Title");
-                    group.Label.HorizontalAlignment = HorizontalAlignment.Begin;
-
-                    return group;
-                }),
-
-                IsGrouped = true,
-                ScrollingDirection = ScrollableBase.Direction.Vertical,
-                WidthSpecification = LayoutParamPolicies.MatchParent,
-                //HeightSpecification = LayoutParamPolicies.MatchParent,
-                SelectionMode = ItemSelectionMode.Single,
-            };
-
-            if (isPairedDeviceView == false)
-            {
-                view.HeightSpecification = LayoutParamPolicies.MatchParent;
-            }
-            //view.SelectionChanged += DeviceController.DeviceViewSelectionChanged;
-
-            return view;
-        }
-
-        private static void AddPairedDeviceView()
-        {
-            mPairedDevice = new DeviceSource();
-            mPairedDeviceView = CreateCollectionView(mPairedDevice, true);
-            mPairedDevice.AddDevice(new BtDevice("dummy paired device")); // temporary device
-            mPairedDevice.UpdateTitle(Resources.IDS_BT_BODY_PAIRED_DEVICES);
-            mMainView.Add(mPairedDeviceView);
-        }
-
-        private static void AddSearchedDeviceView()
-        {
-            mSearchedDevice = new DeviceSource();
-            mSearchedDeviceView = CreateCollectionView(mSearchedDevice);
-            mSearchedDevice.AddDevice(new BtDevice("dummy searched device")); // temporary device
-            mMainView.Add(mSearchedDeviceView);
-
-            mScanButton = new Button
-            {
-                Text = Resources.IDS_BT_SK_SCAN,
-            };
-            mScanButton.Clicked += AdapterController.ScanButtonClicked;
-            mMainView.Add(mScanButton);
-        }
-
-        //internal static void AddDeviceView()
-        //{
-        //    AddPairedDeviceView();
-        //    AddSearchedDeviceView();
-        //}
-
-        private static void UpdateSearchedViewTitle(string title)
-        {
-            mSearchedDevice.UpdateTitle(title);
-        }
-
-        private static void UpdateScanButtonText(string text)
-        {
-            mScanButton.Text = text;
-        }
-
-        private static void RemoveSearchedDeviceView()
-        {
-            if (mSearchedDeviceView)
-            {
-                mMainView.Remove(mSearchedDeviceView);
-                mSearchedDeviceView = null;
-            }
-
-            if (mScanButton)
-            {
-                mMainView.Remove(mScanButton);
-                mScanButton = null;
-            }
-        }
-
-        private static void RemovePairedDeviceView()
-        {
-            if (mPairedDeviceView)
-            {
-                mMainView.Remove(mPairedDeviceView);
-                mPairedDeviceView = null;
-            }
-        }
-
         private static void BtModelOperationStateChanged(object obj, BtOperationStateChangedEventArgs ev)
         {
             Log.Debug(Program.LogTag, "BtModelOperationStateChanged. OperationState: " + ev.OperationState);
             switch (ev.OperationState)
             {
                 case BtOperationState.Deactivated:
-                    RemoveSearchedDeviceView();
-                    RemovePairedDeviceView();
+                    BtDeviceView.RemoveSearchedDeviceView(mMainView);
+                    BtDeviceView.RemovePairedDeviceView(mMainView);
                     break;
                 case BtOperationState.Deactivating:
                     break;
                 case BtOperationState.Activated:
-                    if (mPairedDeviceView == null && mSearchedDeviceView == null)
-                    {
-                        Log.Info(Program.LogTag, "Add initial view");
-                        AddPairedDeviceView();
-                        AddSearchedDeviceView();
-                    }
-                    else
-                    {
-                        Log.Info(Program.LogTag, "Do nothing");
-                    }
+                    Log.Info(Program.LogTag, "Add initial view");
+                    BtDeviceView.AddPairedDeviceView(mMainView);
+                    BtDeviceView.AddSearchedDeviceView(mMainView);
                     break;
                 case BtOperationState.Activating:
                     break;
                 case BtOperationState.Searching:
-                    RemoveSearchedDeviceView();
-                    AddSearchedDeviceView();
-                    UpdateSearchedViewTitle(Resources.IDS_BT_BODY_SCANNING_FOR_DEVICES_ING);
-                    UpdateScanButtonText(Resources.IDS_BT_SK_STOP);
+                    BtDeviceView.RemoveSearchedDeviceView(mMainView);
+                    BtDeviceView.AddSearchedDeviceView(mMainView);
+                    BtDeviceView.UpdateSearchedViewTitle(Resources.IDS_BT_BODY_SCANNING_FOR_DEVICES_ING);
+                    BtDeviceView.UpdateScanButtonText(Resources.IDS_BT_SK_STOP);
                     break;
                 case BtOperationState.Searched:
-                    UpdateSearchedViewTitle(Resources.IDS_BT_BODY_AVAILABLE_DEVICES);
-                    UpdateScanButtonText(Resources.IDS_BT_SK_SCAN);
+                    BtDeviceView.UpdateSearchedViewTitle(Resources.IDS_BT_BODY_AVAILABLE_DEVICES);
+                    BtDeviceView.UpdateScanButtonText(Resources.IDS_BT_SK_SCAN);
                     break;
                 case BtOperationState.Pairing:
                     break;
@@ -216,107 +55,6 @@ namespace SettingBluetooth
             }
         }
 
-        private static void BtModelDeviceChanged(object obj, BtDeviceChangedEventArgs ev)
-        {
-            Log.Debug(Program.LogTag, "BtModelDeviceChanged. Address: " + ev.BtDevice.Address + ", State: " + ev.BtDevice.DeviceState);
-            switch (ev.BtDevice.DeviceState)
-            {
-                case BtDeviceState.Idle:
-                    // available cases: added new one, bond/unbond/audio failed/canceled
-
-                    //if (mSearchedDevice.FindDevice("dummy searched device") != null)
-                    //{
-                    //    mSearchedDevice.RemoveDevice("dummy searched device");
-                    //}
-
-                    if (ev.BtDevice.IsPaired)
-                    {
-                        if (mPairedDevice.FindDevice(ev.BtDevice) == null)
-                        {
-                            mPairedDevice.AddDevice(ev.BtDevice);
-                        }
-                        else
-                        {
-                            mPairedDevice.UpdateState(ev.BtDevice);
-                        }
-                    }
-                    else
-                    {
-                        if (mSearchedDevice.FindDevice(ev.BtDevice) != null) // bond/unbond/audio failed case
-                        {
-                            mSearchedDevice.UpdateState(ev.BtDevice); // TODO: need to remove SubLabel in this case
-                        }
-                        else
-                        {
-                            mSearchedDevice.AddDevice(ev.BtDevice); // added new one
-                        }
-                    }
-                    break;
-                case BtDeviceState.Pairing:
-                    if (mSearchedDevice.FindDevice(ev.BtDevice) != null)
-                    {
-                        mSearchedDevice.UpdateState(ev.BtDevice);
-                    }
-                    break;
-                case BtDeviceState.Unpairing:
-                    //mPairedDevice.RemoveDevice(ev.BtDevice.Address);
-                    break;
-                case BtDeviceState.Paired:
-                    //if (mPairedDevice.FindDevice("dummy paired device") != null)
-                    //{
-                    //    mPairedDevice.RemoveDevice("dummy paired device");
-                    //}
-
-                    if (mSearchedDevice.FindDevice(ev.BtDevice) != null)
-                    {
-                        mSearchedDevice.RemoveDevice(ev.BtDevice.Address);
-                    }
-                    if (mPairedDevice.FindDevice(ev.BtDevice) == null)
-                    {
-                        mPairedDevice.AddDevice(ev.BtDevice);
-                        //if (ev.BtDevice.IsA2dpSupported)
-                        //{
-                        //    DeviceController.ConnectA2dp(ev.BtDevice);
-                        //}
-                    }
-                    else // audio disconnected case
-                    {
-                        mPairedDevice.UpdateState(ev.BtDevice);
-                    }
-                    break;
-                case BtDeviceState.Unpaired:
-                    if (mSearchedDevice.FindDevice(ev.BtDevice) == null)
-                    {
-                        mSearchedDevice.AddDevice(ev.BtDevice);
-                    }
-                    if (mPairedDevice.FindDevice(ev.BtDevice) != null)
-                    {
-                        mPairedDevice.RemoveDevice(ev.BtDevice.Address);
-                    }
-                    break;
-                case BtDeviceState.Connecting:
-                    if (mPairedDevice.FindDevice(ev.BtDevice) != null)
-                    {
-                        mPairedDevice.UpdateState(ev.BtDevice);
-                    }
-                    break;
-                case BtDeviceState.Connected:
-                    if (mPairedDevice.FindDevice(ev.BtDevice) != null)
-                    {
-                        mPairedDevice.UpdateState(ev.BtDevice);
-                    }
-                    break;
-                case BtDeviceState.Disconnecting:
-                    if (mPairedDevice.FindDevice(ev.BtDevice) != null)
-                    {
-                        mPairedDevice.UpdateState(ev.BtDevice);
-                    }
-                    break;
-                case BtDeviceState.ServiceSearching:
-                    break;
-            }
-        }
-
         protected override void OnCreate(string contentInfo, Window window)
         {
             var appBar = new AppBar()
@@ -351,7 +89,7 @@ namespace SettingBluetooth
             mMainView.Add(onOffItem);
 
             BtModel.OperationStateChanged += BtModelOperationStateChanged;
-            BtModel.DeviceChanged += BtModelDeviceChanged;
+            BtModel.DeviceChanged += BtDeviceView.BtModelDeviceChanged;
 
             mMainPage = new ContentPage()
             {
index b1f79870f23be11197e9e197cfcae3cd95b74c39..2b53b8edb1a643fa964c4daf13d028d27bf2c37e 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