170 lines
5.5 KiB
Dart
Executable File
170 lines
5.5 KiB
Dart
Executable File
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
|
|
import '../../../../blue/blue_manage.dart';
|
|
import '../../../../blue/io_protocol/io_setSupportFunctionsWithParameters.dart';
|
|
import '../../../../blue/io_reply.dart';
|
|
import '../../../../blue/io_tool/io_tool.dart';
|
|
import '../../../../blue/io_tool/manager_event_bus.dart';
|
|
import '../../../../blue/sender_manage.dart';
|
|
import '../../../../network/api_repository.dart';
|
|
import '../../../../tools/eventBusEventManage.dart';
|
|
import '../../../../tools/storage.dart';
|
|
import 'lockSoundSet_state.dart';
|
|
|
|
class LockSoundSetLogic extends BaseGetXController {
|
|
LockSoundSetState state = LockSoundSetState();
|
|
|
|
// 配置锁的常开模式设置 -> 锁声音设置
|
|
Future<void> _setLockSetGeneralSetting() async{
|
|
final LoginEntity entity = await ApiRepository.to.setLockSound(
|
|
lockId: state.lockSetInfoData.value.lockId!,
|
|
lockSound:state.isOpenLockSound.value == true ? 1 : 0,
|
|
lockSoundVolume:state.lockSoundLevel.value
|
|
);
|
|
|
|
if(entity.errorCode!.codeIsSuccessful){
|
|
// eventBus.fire(RefreshLockListInfoDataEvent());
|
|
state.lockSetInfoData.value.lockSettingInfo!.lockSound = state.isOpenLockSound.value == true ? 1 :0;
|
|
state.lockSetInfoData.value.lockSettingInfo!.lockSoundVolume = state.lockSoundLevel.value;
|
|
ifCanNext();
|
|
showToast('操作成功'.tr, something: (){
|
|
eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
|
Get.back();
|
|
});
|
|
}
|
|
}
|
|
|
|
// 获取解析后的数据
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
void _initReplySubscription() {
|
|
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
|
// 设置支持功能解析(带参数)
|
|
if(reply is SetSupportFunctionsWithParametersReply) {
|
|
_replySetSupportFunctionsWithParameters(reply);
|
|
}
|
|
|
|
// 读取支持功能(带参数)
|
|
// if(reply is ReadSupportFunctionsWithParametersReply) {
|
|
// _readSupportFunctionsWithParametersReply(reply);
|
|
// }
|
|
});
|
|
}
|
|
|
|
// 读取支持功能带参数数据解析
|
|
// Future<void> _readSupportFunctionsWithParametersReply(Reply reply) async {
|
|
// int status = reply.data[2];
|
|
// switch(status){
|
|
// case 0x00:
|
|
// //成功
|
|
// // state.autoLockTime.value = reply.data[7].toString();
|
|
//
|
|
// break;
|
|
// case 0x06:
|
|
// //无权限
|
|
// break;
|
|
// default:
|
|
// //失败
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
// 设置支持功能解析
|
|
Future<void> _replySetSupportFunctionsWithParameters(Reply reply) async {
|
|
final int status = reply.data[2];
|
|
switch(status){
|
|
case 0x00:
|
|
//成功
|
|
state.sureBtnState.value = 0;
|
|
cancelBlueConnetctToastTimer();
|
|
dismissEasyLoading();
|
|
_setLockSetGeneralSetting();
|
|
break;
|
|
case 0x06:
|
|
//无权限
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 设置支持功能(带参数)
|
|
Future<void> sendLockSound() async {
|
|
if(state.sureBtnState.value == 1){
|
|
return;
|
|
}
|
|
state.sureBtnState.value = 1;
|
|
|
|
showEasyLoading();
|
|
showBlueConnetctToastTimer(action: (){
|
|
dismissEasyLoading();
|
|
state.sureBtnState.value = 0;
|
|
});
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
|
if (connectionState == BluetoothConnectionState.connected) {
|
|
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
|
final List<int> getTokenList = changeStringListToIntList(token!);
|
|
|
|
final List<String>? publicKey = await Storage.getStringList(saveBluePublicKey);
|
|
final List<int> getPublicKeyList = changeStringListToIntList(publicKey!);
|
|
|
|
int type;
|
|
if(state.isOpenLockSound.value == false){
|
|
// 音量关了的时候
|
|
type = 0;
|
|
}else{
|
|
// 音量开了的时候
|
|
type = state.lockSoundLevel.value;
|
|
}
|
|
IoSenderManage.setSupportFunctionsWithParametersCommand(
|
|
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
|
|
userID: await Storage.getUid(),
|
|
featureBit: 33,
|
|
featureParaLength: 1,
|
|
featureData: <int>[type],
|
|
token: getTokenList,
|
|
needAuthor: 1,
|
|
publicKey: getPublicKeyList,
|
|
privateKey: getPrivateKeyList);
|
|
} else if (connectionState == BluetoothConnectionState.disconnected) {
|
|
dismissEasyLoading();
|
|
cancelBlueConnetctToastTimer();
|
|
state.sureBtnState.value = 0;
|
|
if(state.ifCurrentScreen.value == true){
|
|
showBlueConnetctToast();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
void ifCanNext() {
|
|
if((state.lockSoundLevel.value != state.lockSetInfoData.value.lockSettingInfo!.lockSoundVolume!) || (state.isOpenLockSound.value != (state.lockSetInfoData.value.lockSettingInfo!.lockSound == 1 ? true : false))){
|
|
state.canNext.value = true;
|
|
}else{
|
|
state.canNext.value = false;
|
|
}
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
super.onReady();
|
|
|
|
_initReplySubscription();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
super.onClose();
|
|
_replySubscription.cancel();
|
|
}
|
|
|
|
}
|