优化蓝牙耳机列表“我的设备”显示:先显示已连接的设备,再显示未连接的设备
authorluozheng <1732036298@qq.com>
Mon, 1 Dec 2025 03:18:28 +0000 (11:18 +0800)
committerluozheng <1732036298@qq.com>
Mon, 1 Dec 2025 03:18:28 +0000 (11:18 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueListAdapter.h
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueListAdapter.cpp

index 1a9487c..121f36e 100644 (file)
@@ -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:
index 0349714..f2d48a4 100644 (file)
@@ -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<BluetoothCaseInfo> connectedDevicesList;  // 已连接的设备
+        std::list<BluetoothCaseInfo> unconnectedDevicesList; // 未连接的设备
+        
         ListNode<BluetoothCaseInfo>* 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);
         }
     }