Merge branch 'develop_sky_liyi' into 'develop_sky'

fix:兼容没有新增读取、设置语音包协议的锁板

See merge request StarlockTeam/app-starlock!270
This commit is contained in:
李仪 2025-09-03 09:08:19 +00:00
commit fe13b0c2e0
4 changed files with 62 additions and 76 deletions

View File

@ -439,9 +439,24 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
_handlerVoicePackageConfigureConfirmation( _handlerVoicePackageConfigureConfirmation(
VoicePackageConfigureConfirmationReply reply, VoicePackageConfigureConfirmationReply reply,
) async { ) async {
final int status = reply.data[2]; showEasyLoading();
switch (status) { showBlueConnetctToastTimer(action: () {
case 0x00: dismissEasyLoading();
});
final LoginEntity entity = await ApiRepository.to.settingCurrentVoiceTimbre(
data: {
'lang': state.tempLangStr.value,
'timbre': state.tempTimbreStr.value,
},
lockId: state.lockSetInfoData.value.lockId!,
);
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;
await BlueManage().blueSendData(BlueManage().connectDeviceName, await BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async { (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) { if (deviceConnectionState == BluetoothConnectionState.connected) {
@ -458,10 +473,8 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
showBlueConnetctToast(); showBlueConnetctToast();
} }
}); });
break; await Future.delayed(Duration(seconds: 1));
default: });
showToast('设置'.tr + '失败'.tr);
break;
} }
} }
@ -470,24 +483,6 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
switch (status) { switch (status) {
case 0x00: case 0x00:
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
final LoginEntity entity =
await ApiRepository.to.settingCurrentVoiceTimbre(
data: {
'lang': state.tempLangStr.value,
'timbre': state.tempTimbreStr.value,
},
lockId: state.lockSetInfoData.value.lockId!,
);
if (entity.errorCode!.codeIsSuccessful) {
showSuccess('设置成功'.tr, something: () {
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
?.lang = state.tempLangStr.value;
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
?.timbre = state.tempTimbreStr.value;
eventBus.fire(
PassCurrentLockInformationEvent(state.lockSetInfoData.value));
});
}
dismissEasyLoading(); dismissEasyLoading();
break; break;
default: default:
@ -522,7 +517,6 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
languageCode = languageCode =
languageCode.replaceAll('\u0000', ''); // (null bytes) languageCode.replaceAll('\u0000', ''); // (null bytes)
if (languageCode != null && languageCode != '') { if (languageCode != null && languageCode != '') {
final indexWhere = state.languages final indexWhere = state.languages
.indexWhere((element) => element.lang == languageCode); .indexWhere((element) => element.lang == languageCode);

View File

@ -64,7 +64,7 @@ class _SpeechLanguageSettingsPageState
return CommonItem( return CommonItem(
leftTitel: soundType, leftTitel: soundType,
leftTitleStyle: TextStyle( leftTitleStyle: TextStyle(
fontSize: 22.sp, fontSize: 20.sp,
fontWeight: state.selectSoundTypeIndex.value == index fontWeight: state.selectSoundTypeIndex.value == index
? FontWeight.bold ? FontWeight.bold
: null, : null,
@ -111,7 +111,7 @@ class _SpeechLanguageSettingsPageState
return CommonItem( return CommonItem(
leftTitel: item.langText, leftTitel: item.langText,
leftTitleStyle: TextStyle( leftTitleStyle: TextStyle(
fontSize: 22.sp, fontSize: 20.sp,
fontWeight: state.selectPassthroughListIndex.value == index fontWeight: state.selectPassthroughListIndex.value == index
? FontWeight.bold ? FontWeight.bold
: null, : null,

View File

@ -84,22 +84,42 @@ class LockVoiceSettingLogic extends BaseGetXController {
showBlueConnetctToastTimer(action: () { showBlueConnetctToastTimer(action: () {
dismissEasyLoading(); dismissEasyLoading();
}); });
await BlueManage().blueSendData(BlueManage().connectDeviceName, final LoginEntity entity = await ApiRepository.to.settingCurrentVoiceTimbre(
(BluetoothConnectionState deviceConnectionState) async { data: {
if (deviceConnectionState == BluetoothConnectionState.connected) { 'lang': state.tempLangStr.value,
await BlueManage().writeCharacteristicWithResponse( 'timbre': state.tempTimbreStr.value,
SetVoicePackageFinalResult( },
lockID: BlueManage().connectDeviceName, lockId: state.lockSetInfoData.value.lockId!,
languageCode: state.tempLangStr.value, );
).packageData(), if (entity.errorCode!.codeIsSuccessful) {
); showSuccess('设置成功'.tr, something: () async {
} else if (deviceConnectionState == state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang =
BluetoothConnectionState.disconnected) { state.tempLangStr.value;
dismissEasyLoading(); state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
cancelBlueConnetctToastTimer(); ?.timbre = state.tempTimbreStr.value;
showBlueConnetctToast();
} await BlueManage().blueSendData(BlueManage().connectDeviceName,
}); (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
await BlueManage().writeCharacteristicWithResponse(
SetVoicePackageFinalResult(
lockID: BlueManage().connectDeviceName,
languageCode: state.tempLangStr.value,
).packageData(),
);
} else if (deviceConnectionState ==
BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
showBlueConnetctToast();
}
});
await Future.delayed(Duration(seconds: 1));
eventBus
.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
Get.offAllNamed(Routers.starLockMain);
});
}
} }
void handleSetResult(SetVoicePackageFinalResultReply reply) async { void handleSetResult(SetVoicePackageFinalResultReply reply) async {
@ -107,26 +127,6 @@ class LockVoiceSettingLogic extends BaseGetXController {
switch (status) { switch (status) {
case 0x00: case 0x00:
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
final LoginEntity entity =
await ApiRepository.to.settingCurrentVoiceTimbre(
data: {
'lang': state.tempLangStr.value,
'timbre': state.tempTimbreStr.value,
},
lockId: state.lockSetInfoData.value.lockId!,
);
if (entity.errorCode!.codeIsSuccessful) {
showSuccess('设置成功'.tr, something: () {
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
?.lang = state.tempLangStr.value;
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
?.timbre = state.tempTimbreStr.value;
eventBus.fire(
PassCurrentLockInformationEvent(state.lockSetInfoData.value));
Get.offAllNamed(Routers.starLockMain);
});
}
dismissEasyLoading(); dismissEasyLoading();
break; break;
default: default:
@ -473,33 +473,25 @@ class LockVoiceSettingLogic extends BaseGetXController {
// //
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
// 1. LanguageCode
// CmdID (2 bytes) + Status (1 byte) = 3 bytes -> LanguageCode 3
const int languageCodeStartIndex = 3; const int languageCodeStartIndex = 3;
const int languageCodeLength = 20; const int languageCodeLength = 20;
const int languageCodeEndIndex = const int languageCodeEndIndex =
languageCodeStartIndex + languageCodeLength; // 23 languageCodeStartIndex + languageCodeLength; // 23
// 2.
if (reply.data.length < languageCodeEndIndex) { if (reply.data.length < languageCodeEndIndex) {
throw Exception( throw Exception(
'Reply data is too short to contain LanguageCode. Expected at least $languageCodeEndIndex bytes, got ${reply.data.length}'); 'Reply data is too short to contain LanguageCode. Expected at least $languageCodeEndIndex bytes, got ${reply.data.length}');
} }
// 3. LanguageCode
List<int> languageCodeBytes = List<int> languageCodeBytes =
reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex); reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex);
// 4.
// UTF-8 ASCII
String languageCode = String.fromCharCodes(languageCodeBytes); String languageCode = String.fromCharCodes(languageCodeBytes);
// 5. () '\0'
// 20 '\0'
languageCode = languageCode.trim(); // languageCode = languageCode.trim(); //
languageCode = languageCode =
languageCode.replaceAll('\u0000', ''); // (null bytes) languageCode.replaceAll('\u0000', ''); // (null bytes)
// 6. 使 languageCode
print('LanguageCode: $languageCode'); // : zh_CN, en_US print('LanguageCode: $languageCode'); // : zh_CN, en_US
if (languageCode != null && languageCode != '') { if (languageCode != null && languageCode != '') {

View File

@ -96,7 +96,7 @@ class _LockVoiceSettingState extends State<LockVoiceSetting> {
return CommonItem( return CommonItem(
leftTitel: soundType, leftTitel: soundType,
leftTitleStyle: TextStyle( leftTitleStyle: TextStyle(
fontSize: 22.sp, fontSize: 20.sp,
fontWeight: state.selectSoundTypeIndex.value == index fontWeight: state.selectSoundTypeIndex.value == index
? FontWeight.bold ? FontWeight.bold
: null, : null,
@ -142,7 +142,7 @@ class _LockVoiceSettingState extends State<LockVoiceSetting> {
return CommonItem( return CommonItem(
leftTitel: item.langText, leftTitel: item.langText,
leftTitleStyle: TextStyle( leftTitleStyle: TextStyle(
fontSize: 22.sp, fontSize: 20.sp,
fontWeight: fontWeight:
state.selectPassthroughListIndex.value == index state.selectPassthroughListIndex.value == index
? FontWeight.bold ? FontWeight.bold
@ -152,7 +152,7 @@ class _LockVoiceSettingState extends State<LockVoiceSetting> {
isHaveLine: true, isHaveLine: true,
isHaveDirection: false, isHaveDirection: false,
isHaveRightWidget: true, isHaveRightWidget: true,
leftTitleMaxWidth: 0.9.sw, leftTitleMaxWidth: 0.85.sw,
rightWidget: rightWidget:
state.selectPassthroughListIndex.value == index state.selectPassthroughListIndex.value == index
? Image( ? Image(