Skip to content

Commit

Permalink
[Bluetooth] Sort device list in settings page
Browse files Browse the repository at this point in the history
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: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810820}
  • Loading branch information
Sonny Sasaka authored and Commit Bot committed Sep 25, 2020
1 parent 8b0e482 commit a5035d3
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
* results are returned from chrome.
Expand All @@ -541,7 +553,7 @@ Polymer({
limit: MAX_NUMBER_DEVICE_SHOWN
};
this.bluetooth.getDevices(filter, devices => {
this.deviceList_ = devices;
this.deviceList_ = this.sortDevices_(devices);

// Check if we have yet to focus a deep-linked element.
if (!this.pendingSettingId_) {
Expand Down

0 comments on commit a5035d3

Please sign in to comment.