From: luozheng <1732036298@qq.com> Date: Mon, 1 Dec 2025 03:18:28 +0000 (+0800) Subject: 优化蓝牙耳机列表“我的设备”显示:先显示已连接的设备,再显示未连接的设备 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=a503851257a540f60ee6603e7ffa7fcfad1c045a;p=mirrors%2FFD230.git 优化蓝牙耳机列表“我的设备”显示:先显示已连接的设备,再显示未连接的设备 --- diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueListAdapter.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueListAdapter.h index 1a9487c8e..121f36e71 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueListAdapter.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueListAdapter.h @@ -85,8 +85,8 @@ public: uint16_t GetDeviceCount() const; // 限制常量 - // “我的设备”中显示已绑定的音频设备,最多显示2个 - static constexpr uint16_t MAX_CONNECTED_DEVICES = 2; + // “我的设备”中显示已绑定的音频设备,最多显示5个(优先显示已连接的设备) + static constexpr uint16_t MAX_CONNECTED_DEVICES = 5; static constexpr uint16_t MAX_NEARBY_DEVICES = 10; // “附近的设备”最多显示10个 private: diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueListAdapter.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueListAdapter.cpp index 034971474..f2d48a457 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueListAdapter.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueListAdapter.cpp @@ -197,24 +197,53 @@ void ThunderBirdBlueListAdapter::BuildDisplayList() uint16_t connectedCount = 0; uint16_t nearbyCount = 0; - // 1. “我的设备”分组:显示已绑定的音频设备列表(最多显示 MAX_CONNECTED_DEVICES 个) + // 1. “我的设备”分组:显示已绑定的音频设备列表(优先显示已连接的设备) if (!connedDevices.IsEmpty()) { DeviceListItem headerItem; headerItem.type = DeviceItemType::SECTION_HEADER_CONNECTED; headerItem.isSelected = false; displayList_.push_back(headerItem); - // 遍历已绑定设备列表,最多添加 MAX_CONNECTED_DEVICES 个 + // 第一步:先收集所有已连接和未连接的设备 + std::list connectedDevicesList; // 已连接的设备 + std::list unconnectedDevicesList; // 未连接的设备 + ListNode* node = connedDevices.Begin(); - while (node != connedDevices.End() && connectedCount < MAX_CONNECTED_DEVICES) { + while (node != connedDevices.End()) { + if (bt_is_acl_connected((const bd_addr_t*)&node->data_.addr)) { + connectedDevicesList.push_back(node->data_); + } else { + unconnectedDevicesList.push_back(node->data_); + } + node = node->next_; + } + + // 第二步:优先添加已连接的设备 + for (auto& device : connectedDevicesList) { + if (connectedCount >= MAX_CONNECTED_DEVICES) { + break; + } DeviceListItem item; item.type = DeviceItemType::DEVICE_CONNECTED; - item.deviceInfo = node->data_; + item.deviceInfo = device; item.isSelected = false; displayList_.push_back(item); connectedCount++; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Added my device: %s", item.deviceInfo.deviceName); - node = node->next_; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Added my device (connected): %s", device.deviceName); + } + + // 第三步:再添加未连接的设备(如果还有空间) + for (auto& device : unconnectedDevicesList) { + if (connectedCount >= MAX_CONNECTED_DEVICES) { + break; + } + DeviceListItem item; + item.type = DeviceItemType::DEVICE_CONNECTED; + item.deviceInfo = device; + item.isSelected = false; + displayList_.push_back(item); + connectedCount++; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Added my device (unconnected): %s", device.deviceName); } }