develop_sky #3

Merged
liyi merged 43 commits from develop_sky into master_sky 2025-09-25 10:16:34 +08:00
2 changed files with 85 additions and 131 deletions
Showing only changes of commit cfde51c063 - Show all commits

View File

@ -45,8 +45,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
@override
void onInit() async {
super.onInit();
_replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
if (reply is VoicePackageConfigureReply) {
//
_handlerStartVoicePackageConfigure(reply);
@ -72,8 +71,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
final vendor = state.lockSetInfoData.value.lockBasicInfo?.vendor;
final model = state.lockSetInfoData.value.lockBasicInfo?.model;
final PassthroughListResponse entity =
await ApiRepository.to.getPassthroughList(data: {
final PassthroughListResponse entity = await ApiRepository.to.getPassthroughList(data: {
'vendor': vendor!,
'model': model!,
});
@ -110,18 +108,15 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
final passthroughItem = PassthroughItem(
lang: element.lang,
timbres: element.timbres,
langText:
ExtensionLanguageType.fromLocale(locales[indexOf]).lanTitle,
langText: ExtensionLanguageType.fromLocale(locales[indexOf]).lanTitle,
name: element.name,
);
state.languages.add(passthroughItem);
}
});
state.languages.refresh();
final lang = state
.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang;
final timbre = state
.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre;
final lang = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang;
final timbre = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre;
// for 访
for (int i = 0; i < state.languages.length; i++) {
final language = state.languages[i]; //
@ -156,8 +151,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
// APP层的语言
Locale? currentLocale = Get.locale; //
if (currentLocale != null) {
final indexWhere = state.languages
.indexWhere((element) => element.lang == currentLocale.toString());
final indexWhere = state.languages.indexWhere((element) => element.lang == currentLocale.toString());
state.selectPassthroughListIndex.value = indexWhere;
}
}
@ -192,15 +186,11 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
showBlueConnetctToastTimer(action: () {
dismissEasyLoading();
});
BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async {
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
final List<String>? privateKey =
await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
final List<String>? signKey =
await Storage.getStringList(saveBlueSignKey);
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
final String uid = await Storage.getUid() ?? '';
final String md5Str = md5.convert(data).toString().toUpperCase();
@ -219,8 +209,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
privateKey: getPrivateKeyList)
.packageData(),
);
} else if (deviceConnectionState ==
BluetoothConnectionState.disconnected) {
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
}
@ -233,16 +222,14 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
showBlueConnetctToastTimer(action: () {
dismissEasyLoading();
});
BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async {
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
BlueManage().writeCharacteristicWithResponse(
GetDeviceModelCommand(
lockID: BlueManage().connectDeviceName,
).packageData(),
);
} else if (deviceConnectionState ==
BluetoothConnectionState.disconnected) {
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
showBlueConnetctToast();
@ -251,8 +238,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
}
//
void _handlerStartVoicePackageConfigure(
VoicePackageConfigureReply reply) async {
void _handlerStartVoicePackageConfigure(VoicePackageConfigureReply reply) async {
final int status = reply.data[6];
switch (status) {
case 0x00:
@ -280,8 +266,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
if (state.data == null) return;
state.voiceSubcontractingIndex = 0;
state.voiceSubcontractingCount =
(state.data!.length + state.voiceSubcontractingSize - 1) ~/
state.voiceSubcontractingSize;
(state.data!.length + state.voiceSubcontractingSize - 1) ~/ state.voiceSubcontractingSize;
state.progress.value = 0.0; //
_sendNextPackage();
}
@ -332,8 +317,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
Uint8List packageData = state.data!.sublist(start, end);
//
state.progress.value =
(state.voiceSubcontractingIndex + 1) / state.voiceSubcontractingCount;
state.progress.value = (state.voiceSubcontractingIndex + 1) / state.voiceSubcontractingCount;
EasyLoading.showProgress(state.progress.value,
status: '正在发送数据 ${(state.progress.value * 100).toStringAsFixed(0)}%');
await _sendLanguageFileBleMessage(
@ -342,8 +326,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
);
}
_sendLanguageFileBleMessage(
{required int index, required Uint8List data}) async {
_sendLanguageFileBleMessage({required int index, required Uint8List data}) async {
await BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
@ -354,17 +337,15 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
data: data,
).packageData(),
);
} else if (deviceConnectionState ==
BluetoothConnectionState.disconnected) {
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
showBlueConnetctToast();
// showBlueConnetctToast();
}
});
}
void _handlerVoicePackageConfigureProcess(
VoicePackageConfigureProcessReply reply) {
void _handlerVoicePackageConfigureProcess(VoicePackageConfigureProcessReply reply) {
//
_sendTimeoutTimer?.cancel();
_isTimeout = false; //
@ -431,8 +412,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
});
}
Future<void> _executeLogic(
VoicePackageConfigureConfirmationReply reply) async {
Future<void> _executeLogic(VoicePackageConfigureConfirmationReply reply) async {
await _handlerVoicePackageConfigureConfirmation(reply);
}
@ -440,9 +420,12 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
VoicePackageConfigureConfirmationReply reply,
) async {
showEasyLoading();
showBlueConnetctToastTimer(action: () {
dismissEasyLoading();
});
showBlueConnetctToastTimer(
action: () {
dismissEasyLoading();
},
isShowBlueConnetctToast: false,
);
final LoginEntity entity = await ApiRepository.to.settingCurrentVoiceTimbre(
data: {
'lang': state.tempLangStr.value,
@ -452,10 +435,8 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
);
if (entity.errorCode!.codeIsSuccessful) {
showSuccess('设置成功'.tr, something: () async {
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang =
state.tempLangStr.value;
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
?.timbre = state.tempTimbreStr.value;
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang = state.tempLangStr.value;
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre = state.tempTimbreStr.value;
await BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async {
@ -466,11 +447,10 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
languageCode: state.tempLangStr.value,
).packageData(),
);
} else if (deviceConnectionState ==
BluetoothConnectionState.disconnected) {
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
showBlueConnetctToast();
// showBlueConnetctToast();
}
});
await Future.delayed(Duration(seconds: 1));
@ -491,8 +471,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
}
}
void handleLockCurrentVoicePacketResult(
ReadLockCurrentVoicePacketReply reply) {
void handleLockCurrentVoicePacketResult(ReadLockCurrentVoicePacketReply reply) {
final int status = reply.data[2];
switch (status) {
case 0x00:
@ -501,25 +480,21 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
const int languageCodeStartIndex = 3;
const int languageCodeLength = 20;
const int languageCodeEndIndex =
languageCodeStartIndex + languageCodeLength; // 23
const int languageCodeEndIndex = languageCodeStartIndex + languageCodeLength; // 23
if (reply.data.length < languageCodeEndIndex) {
throw Exception(
'Reply data is too short to contain LanguageCode. Expected at least $languageCodeEndIndex bytes, got ${reply.data.length}');
}
List<int> languageCodeBytes =
reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex);
List<int> languageCodeBytes = reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex);
String languageCode = String.fromCharCodes(languageCodeBytes);
languageCode = languageCode.trim(); //
languageCode =
languageCode.replaceAll('\u0000', ''); // (null bytes)
languageCode = languageCode.replaceAll('\u0000', ''); // (null bytes)
if (languageCode != null && languageCode != '') {
final indexWhere = state.languages
.indexWhere((element) => element.lang == languageCode);
final indexWhere = state.languages.indexWhere((element) => element.lang == languageCode);
if (indexWhere != -1) {
print('锁板上的语言是:$languageCode,下标是:$indexWhere');
state.selectPassthroughListIndex.value = indexWhere;
@ -541,9 +516,11 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
void readLockLanguage() async {
showEasyLoading();
showBlueConnetctToastTimer(action: () {
dismissEasyLoading();
});
showBlueConnetctToastTimer(
isShowBlueConnetctToast: false,
action: () {
dismissEasyLoading();
});
await BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
@ -552,11 +529,10 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
lockID: BlueManage().connectDeviceName,
).packageData(),
);
} else if (deviceConnectionState ==
BluetoothConnectionState.disconnected) {
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
showBlueConnetctToast();
// showBlueConnetctToast();
}
});
}

View File

@ -43,8 +43,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
@override
void onInit() async {
super.onInit();
_replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
if (reply is VoicePackageConfigureReply) {
//
_handlerStartVoicePackageConfigure(reply);
@ -78,12 +77,14 @@ class LockVoiceSettingLogic extends BaseGetXController {
});
}
Future<void> _executeLogic(
VoicePackageConfigureConfirmationReply reply) async {
Future<void> _executeLogic(VoicePackageConfigureConfirmationReply reply) async {
showEasyLoading();
showBlueConnetctToastTimer(action: () {
dismissEasyLoading();
});
showBlueConnetctToastTimer(
action: () {
dismissEasyLoading();
},
isShowBlueConnetctToast: false,
);
final LoginEntity entity = await ApiRepository.to.settingCurrentVoiceTimbre(
data: {
'lang': state.tempLangStr.value,
@ -93,10 +94,8 @@ class LockVoiceSettingLogic extends BaseGetXController {
);
if (entity.errorCode!.codeIsSuccessful) {
showSuccess('设置成功'.tr, something: () async {
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang =
state.tempLangStr.value;
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
?.timbre = state.tempTimbreStr.value;
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang = state.tempLangStr.value;
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre = state.tempTimbreStr.value;
await BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async {
@ -107,16 +106,14 @@ class LockVoiceSettingLogic extends BaseGetXController {
languageCode: state.tempLangStr.value,
).packageData(),
);
} else if (deviceConnectionState ==
BluetoothConnectionState.disconnected) {
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
showBlueConnetctToast();
// showBlueConnetctToast();
}
});
await Future.delayed(Duration(seconds: 1));
eventBus
.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
Get.offAllNamed(Routers.starLockMain);
});
}
@ -145,8 +142,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
// APP层的语言
Locale? currentLocale = Get.locale; //
if (currentLocale != null) {
final indexWhere = state.languages
.indexWhere((element) => element.lang == currentLocale.toString());
final indexWhere = state.languages.indexWhere((element) => element.lang == currentLocale.toString());
state.selectPassthroughListIndex.value = indexWhere;
}
}
@ -176,15 +172,11 @@ class LockVoiceSettingLogic extends BaseGetXController {
showBlueConnetctToastTimer(action: () {
dismissEasyLoading();
});
BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async {
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
final List<String>? privateKey =
await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList =
changeStringListToIntList(privateKey!);
final List<String>? signKey =
await Storage.getStringList(saveBlueSignKey);
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
final String uid = await Storage.getUid() ?? '';
final String md5Str = md5.convert(data).toString().toUpperCase();
@ -203,8 +195,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
privateKey: getPrivateKeyList)
.packageData(),
);
} else if (deviceConnectionState ==
BluetoothConnectionState.disconnected) {
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
@ -216,8 +207,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
});
}
void _handlerVoicePackageConfigureProcess(
VoicePackageConfigureProcessReply reply) {
void _handlerVoicePackageConfigureProcess(VoicePackageConfigureProcessReply reply) {
//
_sendTimeoutTimer?.cancel();
_isTimeout = false; //
@ -235,8 +225,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
}
//
void _handlerStartVoicePackageConfigure(
VoicePackageConfigureReply reply) async {
void _handlerStartVoicePackageConfigure(VoicePackageConfigureReply reply) async {
final int status = reply.data[6];
switch (status) {
case 0x00:
@ -265,8 +254,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
final vendor = state.lockSetInfoData.value.lockBasicInfo?.vendor;
final model = state.lockSetInfoData.value.lockBasicInfo?.model;
final PassthroughListResponse entity =
await ApiRepository.to.getPassthroughList(data: {
final PassthroughListResponse entity = await ApiRepository.to.getPassthroughList(data: {
'vendor': vendor!,
'model': model!,
});
@ -302,8 +290,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
final passthroughItem = PassthroughItem(
lang: element.lang,
timbres: element.timbres,
langText:
ExtensionLanguageType.fromLocale(locales[indexOf]).lanTitle,
langText: ExtensionLanguageType.fromLocale(locales[indexOf]).lanTitle,
name: element.name,
);
@ -311,10 +298,8 @@ class LockVoiceSettingLogic extends BaseGetXController {
}
});
state.languages.refresh();
final lang = state
.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang;
final timbre = state
.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre;
final lang = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang;
final timbre = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre;
state.languages.value.forEach((element) {
final timbres = element.timbres;
timbres.forEach((item) {
@ -335,8 +320,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
if (state.data == null) return;
state.voiceSubcontractingIndex = 0;
state.voiceSubcontractingCount =
(state.data!.length + state.voiceSubcontractingSize - 1) ~/
state.voiceSubcontractingSize;
(state.data!.length + state.voiceSubcontractingSize - 1) ~/ state.voiceSubcontractingSize;
state.progress.value = 0.0; //
_sendNextPackage();
}
@ -380,8 +364,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
Uint8List packageData = state.data!.sublist(start, end);
//
state.progress.value =
(state.voiceSubcontractingIndex + 1) / state.voiceSubcontractingCount;
state.progress.value = (state.voiceSubcontractingIndex + 1) / state.voiceSubcontractingCount;
EasyLoading.showProgress(state.progress.value,
status: '正在发送数据 ${(state.progress.value * 100).toStringAsFixed(0)}%');
_sendLanguageFileBleMessage(
@ -391,8 +374,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
}
_sendLanguageFileBleMessage({required int index, required Uint8List data}) {
BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async {
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
BlueManage().writeCharacteristicWithResponse(
VoicePackageConfigureProcess(
@ -401,8 +383,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
data: data,
).packageData(),
);
} else if (deviceConnectionState ==
BluetoothConnectionState.disconnected) {
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
// showBlueConnetctToast();
@ -445,9 +426,12 @@ class LockVoiceSettingLogic extends BaseGetXController {
void readLockLanguage() async {
showEasyLoading();
showBlueConnetctToastTimer(action: () {
dismissEasyLoading();
});
showBlueConnetctToastTimer(
action: () {
dismissEasyLoading();
},
isShowBlueConnetctToast: false,
);
await BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
@ -456,17 +440,15 @@ class LockVoiceSettingLogic extends BaseGetXController {
lockID: BlueManage().connectDeviceName,
).packageData(),
);
} else if (deviceConnectionState ==
BluetoothConnectionState.disconnected) {
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
showBlueConnetctToast();
// showBlueConnetctToast();
}
});
}
void handleLockCurrentVoicePacketResult(
ReadLockCurrentVoicePacketReply reply) {
void handleLockCurrentVoicePacketResult(ReadLockCurrentVoicePacketReply reply) {
final int status = reply.data[2];
switch (status) {
case 0x00:
@ -475,28 +457,24 @@ class LockVoiceSettingLogic extends BaseGetXController {
const int languageCodeStartIndex = 3;
const int languageCodeLength = 20;
const int languageCodeEndIndex =
languageCodeStartIndex + languageCodeLength; // 23
const int languageCodeEndIndex = languageCodeStartIndex + languageCodeLength; // 23
if (reply.data.length < languageCodeEndIndex) {
throw Exception(
'Reply data is too short to contain LanguageCode. Expected at least $languageCodeEndIndex bytes, got ${reply.data.length}');
}
List<int> languageCodeBytes =
reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex);
List<int> languageCodeBytes = reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex);
String languageCode = String.fromCharCodes(languageCodeBytes);
languageCode = languageCode.trim(); //
languageCode =
languageCode.replaceAll('\u0000', ''); // (null bytes)
languageCode = languageCode.replaceAll('\u0000', ''); // (null bytes)
print('LanguageCode: $languageCode'); // : zh_CN, en_US
if (languageCode != null && languageCode != '') {
final indexWhere = state.languages
.indexWhere((element) => element.lang == languageCode);
final indexWhere = state.languages.indexWhere((element) => element.lang == languageCode);
if (indexWhere != -1) {
print('锁板上的语言是:$languageCode,下标是:$indexWhere');
state.selectPassthroughListIndex.value = indexWhere;