蓝牙模块优化

Signed-off-by: yansong <yansong14@huawei.com>
This commit is contained in:
yansong 2022-09-02 14:34:09 +08:00
parent 04e2fddec0
commit fb22877aa3
2 changed files with 13 additions and 4 deletions

View File

@ -101,7 +101,9 @@ export default class BluetoothDeviceController extends BaseSettingsController {
BluetoothModel.enableBluetooth();
} else {
BluetoothModel.disableBluetooth();
this.availableDevices = []
// remove all elements from availableDevices array
this.availableDevices.splice(0, this.availableDevices.length)
}
}

View File

@ -649,7 +649,7 @@ struct AvailableDeviceComponent {
* AvailableDevicesDataSource For Lazy Loading
*/
class AvailableDevicesDataSource extends BasicDataSource {
private availableDevicesArray: BluetoothDevice[] = [];
private availableDevicesArray: BluetoothDevice[] = null;
constructor(availableDevicesArray:BluetoothDevice[]){
super();
@ -657,10 +657,17 @@ class AvailableDevicesDataSource extends BasicDataSource {
}
public totalCount(): number {
return this.availableDevicesArray.length;
if(this.availableDevicesArray) {
return this.availableDevicesArray.length;
}
return 0;
}
public getData(index: number): any {
public getData(index: number): BluetoothDevice {
if(index < 0 || index >= this.totalCount()) {
LogUtil.log(ConfigData.TAG + 'index out of range.');
return null;
}
return this.availableDevicesArray[index];
}
}