199 lines
7.2 KiB
Dart
Executable File
199 lines
7.2 KiB
Dart
Executable File
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/apm/apm_helper.dart';
|
|
import 'package:star_lock/appRouters.dart';
|
|
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
|
import 'package:star_lock/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_entity.dart';
|
|
import 'package:star_lock/mine/mineSet/lockUserManage/expireLockList/expireElectronicKey/expireLockList_entity.dart';
|
|
import 'package:star_lock/mine/mineSet/mineSet/mineSet_state.dart';
|
|
import 'package:star_lock/mine/mineSet/mineSet/userSettingInfoEntity.dart';
|
|
import 'package:star_lock/mine/mineSet/mineSet/weChatQRCodeEntity.dart';
|
|
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
|
|
import 'package:star_lock/tools/push/notification_service.dart';
|
|
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
|
import 'package:star_lock/tools/showCupertinoAlertView.dart';
|
|
import 'package:star_lock/tools/storage.dart';
|
|
import 'package:star_lock/versionUndate/versionUndate_entity.dart';
|
|
|
|
import '../../../../network/api_repository.dart';
|
|
import '../../../../tools/baseGetXController.dart';
|
|
import '../../../blue/blue_manage.dart';
|
|
import '../../../talk/udp/udp_help.dart';
|
|
import '../../../tools/dateTool.dart';
|
|
import '../../../tools/store_service.dart';
|
|
|
|
class MineSetLogic extends BaseGetXController {
|
|
final MineSetState state = MineSetState();
|
|
|
|
//用户信息
|
|
Future<void> userSettingsInfoRequest() async {
|
|
final UserSettingInfoEntity entity =
|
|
await ApiRepository.to.userSettingsInfo();
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
state.userInfoData.value = entity.data!;
|
|
state.userSetting.value = entity.data!.userSettings!;
|
|
state.lockScreen.value = entity.data!.userSettings!.lockScreen!;
|
|
state.hideExpiredAccessFlag.value =
|
|
entity.data!.userSettings!.hideExpiredAccessFlag!;
|
|
|
|
//提示音
|
|
if (entity.data!.alertMode == 1) {
|
|
state.isPrompTone.value = true;
|
|
} else {
|
|
state.isPrompTone.value = false;
|
|
}
|
|
//触摸开锁
|
|
if (entity.data!.userSettings!.touchUnlockFlag! == 1) {
|
|
state.isTouchUnlock.value = true;
|
|
} else {
|
|
state.isTouchUnlock.value = false;
|
|
}
|
|
//微信公众号推送
|
|
if (entity.data!.mpWechatPushSwitch! == 1) {
|
|
state.isWechatPublicAccountPush.value = true;
|
|
} else {
|
|
state.isWechatPublicAccountPush.value = false;
|
|
}
|
|
//是否打开Amazon Alexa
|
|
entity.data!.isAmazonAlexa! == 1
|
|
? state.isAmazonAlexa.value = true
|
|
: state.isAmazonAlexa.value = false;
|
|
|
|
//是否打开Google Home
|
|
entity.data!.isGoogleHome! == 1
|
|
? state.isGoogleHome.value = true
|
|
: state.isGoogleHome.value = false;
|
|
}
|
|
}
|
|
|
|
//用户信息
|
|
Future<void> getUserInfoRequest() async {
|
|
final MinePersonInfoEntity entity = await ApiRepository.to.getUserInfo();
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
Storage.setBool(saveIsVip, entity.data!.isVip! == 1);
|
|
state.amazonAlexaData.value = entity.data!.amazonAlexa ?? AmazonAlexa();
|
|
state.googleHomeData.value = entity.data!.googleHome ?? GoogleHome();
|
|
}
|
|
}
|
|
|
|
//更新提示音
|
|
Future<void> updatePrompToneRequest() async {
|
|
final ExpireLockListEntity entity = await ApiRepository.to
|
|
.setAlertMode('1', state.isPrompTone.value == true ? '1' : '2');
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast('设置成功'.tr);
|
|
userSettingsInfoRequest();
|
|
}
|
|
}
|
|
|
|
//设置微信公众号推送
|
|
Future<void> setMpWechatPushSwitchRequest(BuildContext widgetContext) async {
|
|
final VersionUndateEntity entity = await ApiRepository.to
|
|
.setMpWechatPushSwitch(
|
|
mpWechatPushSwitch:
|
|
state.isWechatPublicAccountPush.value == true ? 1 : 2);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast('设置成功'.tr);
|
|
userSettingsInfoRequest();
|
|
} else if (entity.errorCode! == 421) {
|
|
if (state.isWechatPublicAccountPush.value == true) {
|
|
//请先扫码绑定微信公众号
|
|
getMpWechatQrCodeRequest(widgetContext);
|
|
}
|
|
}
|
|
}
|
|
|
|
//获取微信公众号二维码
|
|
Future<void> getMpWechatQrCodeRequest(BuildContext widgetContext) async {
|
|
final GetWechatQrCodeEntity entity =
|
|
await ApiRepository.to.getMpWechatQrCode();
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
state.qrCodeUrl.value = entity.data!.qrCodeUrl!;
|
|
state.qrCodeText.value = entity.data!.mpName ?? '';
|
|
showQRImageAlert(state.qrCodeUrl.value, widgetContext);
|
|
}
|
|
}
|
|
|
|
void showQRImageAlert(String qrCodeUrl, BuildContext widgetContext) {
|
|
ShowCupertinoAlertView()
|
|
.showQRImageAlert(widgetContext, qrCodeUrl, state.qrCodeText.value);
|
|
}
|
|
|
|
//退出登录请求
|
|
Future<void> userLogoutRequest() async {
|
|
final String? deviceID = await Storage.getString(appDeviceID);
|
|
final LoginEntity entity =
|
|
await ApiRepository.to.userLogout(storageNonce: deviceID ?? '');
|
|
final String getMobile = (await Storage.getMobile())!;
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
ApmHelper.instance.logout();
|
|
ApmHelper.instance.trackEvent('logout', {
|
|
'lock_name': BlueManage().connectDeviceName,
|
|
'account':
|
|
getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!,
|
|
'date': DateTool().getNowDateWithType(1),
|
|
'logout_result': '成功',
|
|
});
|
|
|
|
// 取消所有本地通知
|
|
await NotificationService().cancelAllNotifications();
|
|
|
|
// UdpHelp().closeUDP();
|
|
logOut();
|
|
|
|
// StoreService.to.saveLanguageCode('');
|
|
// Get.updateLocale(Get.deviceLocale!);
|
|
|
|
BlueManage().disconnect();
|
|
StartChartManage().destruction();
|
|
StartChartManage().closeUdpSocket();
|
|
Get.offNamedUntil(Routers.starLockLoginPage, (Route route) => false);
|
|
} else {
|
|
ApmHelper.instance.logout();
|
|
ApmHelper.instance.trackEvent('logout', {
|
|
'lock_name': BlueManage().connectDeviceName,
|
|
'account':
|
|
getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!,
|
|
'date': DateTool().getNowDateWithType(1),
|
|
'logout_result': '${entity.errorCode}--${entity.errorMsg}',
|
|
});
|
|
}
|
|
}
|
|
|
|
///退出登录
|
|
void logOut() async {
|
|
final XSJPushProvider jpushProvider = XSJPushProvider();
|
|
await jpushProvider.resetJPushService();
|
|
Storage.clearAll();
|
|
}
|
|
|
|
//更新触摸开锁
|
|
Future<void> updateTouchUnlockRequest() async {
|
|
final ExpireLockListEntity entity = await ApiRepository.to
|
|
.setTouchUnlockFlag(state.isTouchUnlock.value == true ? '1' : '2');
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast('设置成功'.tr);
|
|
userSettingsInfoRequest();
|
|
}
|
|
}
|
|
|
|
// // 下级界面修改成功后传递数据
|
|
// StreamSubscription? _getNumberEvent;
|
|
// void _initLoadDataAction() {
|
|
// // 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
|
|
// _getNumberEvent = eventBus
|
|
// .on<ChangeLanguageBlockLastLanguageEvent>()
|
|
// .listen((ChangeLanguageBlockLastLanguageEvent event) {
|
|
// state.currentLanguage.value = CurrentLocaleTool.getCurrentLocaleString();
|
|
// });
|
|
// }
|
|
|
|
@override
|
|
Future<void> onReady() async {
|
|
super.onReady();
|
|
getUserInfoRequest();
|
|
}
|
|
}
|