Commit a5035d3d authored by Sonny Sasaka's avatar Sonny Sasaka Committed by Commit Bot

[Bluetooth] Sort device list in settings page

To improve user experience, this sorts the Bluetooth device list in
settings page so that the connected devices are shown on top followed by
non-connected devices.

BUG=b:168257187

Change-Id: I60fcb820d6a6409460970273aefb1824c7354ebf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419379
Commit-Queue: Sonny Sasaka <sonnysasaka@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810820}
parent 8b0e4822
...@@ -530,6 +530,18 @@ Polymer({ ...@@ -530,6 +530,18 @@ Polymer({
} }
}, },
/**
* Return the sorted devices based on the connected statuses, connected
* devices are first followed by non-connected devices.
*
* @param {!Array<!chrome.bluetooth.Device>} devices
* @return {!Array<!chrome.bluetooth.Device>}
* @private
*/
sortDevices_(devices) {
return devices.sort((a, b) => a.connected ? -1 : (b.connected ? 1 : 0));
},
/** /**
* Requests bluetooth device list from Chrome. Update deviceList_ once the * Requests bluetooth device list from Chrome. Update deviceList_ once the
* results are returned from chrome. * results are returned from chrome.
...@@ -541,7 +553,7 @@ Polymer({ ...@@ -541,7 +553,7 @@ Polymer({
limit: MAX_NUMBER_DEVICE_SHOWN limit: MAX_NUMBER_DEVICE_SHOWN
}; };
this.bluetooth.getDevices(filter, devices => { this.bluetooth.getDevices(filter, devices => {
this.deviceList_ = devices; this.deviceList_ = this.sortDevices_(devices);
// Check if we have yet to focus a deep-linked element. // Check if we have yet to focus a deep-linked element.
if (!this.pendingSettingId_) { if (!this.pendingSettingId_) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment