From: Wootak Jung Date: Wed, 30 Nov 2022 00:58:38 +0000 (+0900) Subject: Fix the issue that paired and searched views are scrolled separately X-Git-Tag: accepted/tizen/unified/20230103.054909~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6a76889a85131fda523fee8d2e56d9526128b674;p=profile%2Fiot%2Fapps%2Fdotnet%2Fsetting-bluetooth.git Fix the issue that paired and searched views are scrolled separately Combine paired and searched views into one Manage paired and searched devices as each collection Change-Id: Ie8da84681bba62df1dcc82944807ac8be5cabc27 Signed-off-by: Wootak Jung --- diff --git a/SettingBluetooth/SettingBluetooth/Model/BtDevice.cs b/SettingBluetooth/SettingBluetooth/Model/BtDevice.cs index d7e5dbf..7596cf3 100644 --- a/SettingBluetooth/SettingBluetooth/Model/BtDevice.cs +++ b/SettingBluetooth/SettingBluetooth/Model/BtDevice.cs @@ -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 diff --git a/SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs b/SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs index 542d8c8..e88c629 100644 --- a/SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs +++ b/SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs @@ -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 { - 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: diff --git a/SettingBluetooth/SettingBluetooth/View/BtMainView.cs b/SettingBluetooth/SettingBluetooth/View/BtMainView.cs index 6150b77..c06cc6b 100644 --- a/SettingBluetooth/SettingBluetooth/View/BtMainView.cs +++ b/SettingBluetooth/SettingBluetooth/View/BtMainView.cs @@ -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() diff --git a/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk b/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk index 0283692..ed1d5ee 100644 Binary files a/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk and b/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk differ