diff --git a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart index f314088..d6cf274 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; +import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart'; import 'package:syncrow_app/features/scene/helper/scene_operations_data_helper.dart'; import 'package:syncrow_app/features/scene/model/create_scene_model.dart'; import 'package:syncrow_app/features/scene/model/scene_static_function.dart'; @@ -68,11 +69,30 @@ class CreateSceneBloc extends Bloc } if (!updated) { // Add new function if not found + OperationDialogType getOperationDialogType(String? code, [value]) { + if (code == null) { + return OperationDialogType.none; + } + if (code.contains('delay')) { + return OperationDialogType.delay; + } else if (code.contains('countdown')) { + return OperationDialogType.countdown; + } else if (code.contains('set_temp')) { + return OperationDialogType.temperature; + } else if (value.toString().toLowerCase().trim() == 'on' || + value.toString().toLowerCase().trim() == 'off') { + return OperationDialogType.onOff; + } + return OperationDialogType.listOfOptions; + } + var newElement = SceneStaticFunction( operationName: event.operation, deviceName: event.deviceName, icon: event.icon, code: event.deviceControlModel.code ?? '', + operationDialogType: getOperationDialogType( + event.deviceControlModel.code, event.deviceControlModel.value), deviceId: event.deviceId, functionValue: event.deviceControlModel.value, operationalValues: [ diff --git a/lib/features/scene/enum/operation_dialog_type.dart b/lib/features/scene/enum/operation_dialog_type.dart new file mode 100644 index 0000000..b1829b1 --- /dev/null +++ b/lib/features/scene/enum/operation_dialog_type.dart @@ -0,0 +1,9 @@ +enum OperationDialogType { + countdown, + delay, + temperature, + onOff, + integerSteps, + listOfOptions, + none, +} diff --git a/lib/features/scene/helper/scene_logic_helper.dart b/lib/features/scene/helper/scene_logic_helper.dart index 616e3fd..4372692 100644 --- a/lib/features/scene/helper/scene_logic_helper.dart +++ b/lib/features/scene/helper/scene_logic_helper.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart'; +import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart'; import 'package:syncrow_app/features/scene/model/create_scene_model.dart'; @@ -80,24 +81,26 @@ mixin SceneLogicHelper { Widget getTheCorrectDialogBody( SceneStaticFunction taskItem, + dynamic functionValue, ) { - if (taskItem.code.contains('temp_set')) { + if (taskItem.operationDialogType == OperationDialogType.temperature) { return AlertDialogTemperatureBody( taskItem: taskItem, - functionValue: taskItem.functionValue, + functionValue: functionValue ?? taskItem.functionValue, ); - } else if (taskItem.code.contains('countdown') || - taskItem.deviceId.contains('delay')) { + } else if ((taskItem.operationDialogType == + OperationDialogType.countdown) || + (taskItem.operationDialogType == OperationDialogType.delay)) { return AlertDialogCountdown( durationValue: taskItem.functionValue, - functionValue: taskItem.functionValue, + functionValue: functionValue ?? taskItem.functionValue, function: taskItem, ); } return AlertDialogFunctionsOperationsBody( taskItem: taskItem, - functionValue: taskItem.functionValue, + functionValue: functionValue ?? taskItem.functionValue, ); } } diff --git a/lib/features/scene/helper/scene_operations_data_helper.dart b/lib/features/scene/helper/scene_operations_data_helper.dart index 6ed5115..a93bcfd 100644 --- a/lib/features/scene/helper/scene_operations_data_helper.dart +++ b/lib/features/scene/helper/scene_operations_data_helper.dart @@ -1,5 +1,6 @@ import 'package:syncrow_app/features/devices/model/function_model.dart'; import 'package:syncrow_app/features/scene/enum/ac_values.dart'; +import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart'; import 'package:syncrow_app/features/scene/model/scene_details_model.dart'; import 'package:syncrow_app/features/scene/model/scene_static_function.dart'; import 'package:syncrow_app/generated/assets.dart'; @@ -128,6 +129,7 @@ mixin SceneOperationsDataHelper { operationName: 'Sensitivity', code: 'sensitivity', functionValue: functionValue, + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsSensitivityOperationIcon, @@ -205,17 +207,207 @@ mixin SceneOperationsDataHelper { SceneStaticFunction( deviceId: deviceId, deviceName: deviceName, - icon: Assets.assetsIconsDoorLock, - operationName: 'Set Door lock Normal Open', + icon: Assets.assetsFingerprintUnlock, + operationName: 'Fingerprint Unlock', functionValue: functionValue, - code: 'normal_open_switch', + code: 'unlock_fingerprint', + operationDialogType: OperationDialogType.integerSteps, operationalValues: [ SceneOperationalValue( - icon: Assets.assetsAcPower, description: "ON", value: true), + icon: '', + description: "", + value: 0, + ), + ], + ), + SceneStaticFunction( + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.assetsPasswordUnlock, + operationName: 'Password Unlock', + functionValue: functionValue, + code: 'unlock_password', + operationDialogType: OperationDialogType.integerSteps, + operationalValues: [ SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, - description: "OFF", - value: false), + icon: '', + description: "", + value: 0, + ), + ], + ), + SceneStaticFunction( + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.assetsCardUnlock, + operationName: 'Card Unlock', + functionValue: functionValue, + code: 'unlock_card', + operationDialogType: OperationDialogType.integerSteps, + operationalValues: [ + SceneOperationalValue( + icon: '', + description: "", + value: 0, + ), + ], + ), + SceneStaticFunction( + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.assetsLockAlarm, + operationName: 'Lock Alarm', + functionValue: functionValue, + code: 'alarm_lock', + operationDialogType: OperationDialogType.none, + operationalValues: [], + ), + SceneStaticFunction( + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.assetsRemoteUnlockReq, + operationName: 'Remote Unlock Request', + functionValue: functionValue, + code: 'unlock_request', + operationDialogType: OperationDialogType.integerSteps, + operationalValues: [ + SceneOperationalValue( + icon: '', + description: "", + value: 0, + ), + ], + ), + SceneStaticFunction( + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.assetsResidualElectricity, + operationName: 'Residual Electricity', + functionValue: functionValue, + code: 'residual_electricity', + operationDialogType: OperationDialogType.integerSteps, + operationalValues: [ + SceneOperationalValue( + icon: '', + description: "", + value: 0, + ), + ], + ), + SceneStaticFunction( + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.assetsDoubleLock, + operationName: 'Double Lock', + functionValue: functionValue, + operationDialogType: OperationDialogType.onOff, + code: 'reverse_lock', + operationalValues: [ + SceneOperationalValue( + icon: Assets.assetsAcPower, + description: "ON", + value: true, + ), + SceneOperationalValue( + icon: Assets.assetsAcPowerOFF, + description: "OFF", + value: false, + ), + ], + ), + SceneStaticFunction( + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.assetsRemoteUnlockViaApp, + operationName: 'Remote Unlock Via App', + functionValue: functionValue, + operationDialogType: OperationDialogType.integerSteps, + code: 'unlock_app', + operationalValues: [ + SceneOperationalValue( + icon: '', + description: "", + value: 0, + ), + ], + ), + SceneStaticFunction( + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.assetsHijackAlarm, + operationName: 'Hijack Alarm', + functionValue: functionValue, + operationDialogType: OperationDialogType.onOff, + code: 'hijack', + operationalValues: [ + SceneOperationalValue( + icon: Assets.assetsAcPower, + description: "ON", + value: true, + ), + SceneOperationalValue( + icon: Assets.assetsAcPowerOFF, + description: "OFF", + value: false, + ), + ], + ), + SceneStaticFunction( + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.assetsDoorlockNormalOpen, + operationName: 'Set Door Lock Normal Open', + functionValue: functionValue, + code: 'normal_open_switch', + operationDialogType: OperationDialogType.onOff, + operationalValues: [ + SceneOperationalValue( + icon: Assets.assetsAcPower, + description: "ON", + value: true, + ), + SceneOperationalValue( + icon: Assets.assetsAcPowerOFF, + description: "OFF", + value: false, + ), + ], + ), + SceneStaticFunction( + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.assetsDoorlockNormalOpen, + operationName: 'Doorbell', + functionValue: functionValue, + code: 'doorbell', + operationDialogType: OperationDialogType.onOff, + operationalValues: [ + SceneOperationalValue( + icon: Assets.assetsAcPower, + description: "ON", + value: true, + ), + SceneOperationalValue( + icon: Assets.assetsAcPowerOFF, + description: "OFF", + value: false, + ), + ], + ), + SceneStaticFunction( + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.assetsTempPasswordUnlock, + operationName: 'Temporary Password Unlock', + functionValue: functionValue, + operationDialogType: OperationDialogType.integerSteps, + code: 'unlock_temporary', + operationalValues: [ + SceneOperationalValue( + icon: '', + description: "", + value: 0, + ), ], ), ]; @@ -228,6 +420,7 @@ mixin SceneOperationsDataHelper { operationName: 'Set Door lock Normal Open', functionValue: functionValue, code: 'normal_open_switch', + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, description: "ON", value: true), @@ -253,6 +446,7 @@ mixin SceneOperationsDataHelper { operationName: 'Far Detection', code: 'far_detection', functionValue: functionValue, + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsFarDetectionFunction, @@ -311,6 +505,7 @@ mixin SceneOperationsDataHelper { operationName: 'Motion Detection Sensitivity', code: 'motion_sensitivity_value', functionValue: functionValue, + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsSensitivityOperationIcon, @@ -346,6 +541,7 @@ mixin SceneOperationsDataHelper { operationName: 'Motionless Detection Sensitivity', code: 'motionless_sensitivity', functionValue: functionValue, + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( iconValue: '1', @@ -386,6 +582,7 @@ mixin SceneOperationsDataHelper { operationName: 'Indicator', code: 'indicator', functionValue: functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, description: "ON", value: true), @@ -400,6 +597,7 @@ mixin SceneOperationsDataHelper { operationName: 'Nobody Time', code: 'presence_time', functionValue: functionValue, + operationDialogType: OperationDialogType.countdown, operationalValues: [ SceneOperationalValue(icon: '', value: 0), ], @@ -431,6 +629,7 @@ mixin SceneOperationsDataHelper { operationName: 'Switch Alarm Sound', code: 'switch_alarm_sound', functionValue: functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, description: "ON", value: true), @@ -445,6 +644,7 @@ mixin SceneOperationsDataHelper { operationName: 'Master State', code: 'master_state', functionValue: functionValue, + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, @@ -465,6 +665,7 @@ mixin SceneOperationsDataHelper { operationName: 'Factory Reset', code: 'factory_reset', functionValue: functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsSceneRefresh, description: "ON", value: true), @@ -490,6 +691,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 1 Switch', code: 'switch_1', functionValue: functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, description: "ON", value: true), @@ -504,6 +706,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 2 Switch', code: 'switch_2', functionValue: functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, description: "ON", value: true), @@ -518,6 +721,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 3 Switch', code: 'switch_3', functionValue: functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, description: "ON", value: true), @@ -532,6 +736,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 1 CountDown', code: 'countdown_1', functionValue: functionValue, + operationDialogType: OperationDialogType.countdown, operationalValues: [ SceneOperationalValue(icon: '', value: 0), ], @@ -543,6 +748,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 2 CountDown', code: 'countdown_2', functionValue: functionValue, + operationDialogType: OperationDialogType.countdown, operationalValues: [ SceneOperationalValue(icon: '', value: 0), ], @@ -554,6 +760,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 3 CountDown', code: 'countdown_3', functionValue: functionValue, + operationDialogType: OperationDialogType.countdown, operationalValues: [ SceneOperationalValue(icon: '', value: 0), ], @@ -577,6 +784,7 @@ mixin SceneOperationsDataHelper { operationName: 'Power', code: 'switch', functionValue: functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, @@ -597,6 +805,7 @@ mixin SceneOperationsDataHelper { operationName: 'Mode', code: 'mode', functionValue: functionValue, + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcCooling, @@ -622,6 +831,7 @@ mixin SceneOperationsDataHelper { operationName: 'Set Temperature', code: 'temp_set', functionValue: functionValue, + operationDialogType: OperationDialogType.temperature, operationalValues: [ SceneOperationalValue( icon: Assets.assetsCelsiusDegrees, @@ -637,6 +847,7 @@ mixin SceneOperationsDataHelper { operationName: 'Fan Speed', code: 'level', functionValue: functionValue, + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcFanLow, @@ -667,6 +878,7 @@ mixin SceneOperationsDataHelper { operationName: 'Child Lock', code: 'child_lock', functionValue: functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsSceneChildLock, @@ -700,6 +912,7 @@ mixin SceneOperationsDataHelper { deviceIcon: Assets.delay, icon: Assets.delay, operationName: 'delay', + operationDialogType: OperationDialogType.delay, functionValue: action.executorProperty.delaySeconds, code: '', operationalValues: [ @@ -725,6 +938,7 @@ mixin SceneOperationsDataHelper { operationName: 'Sensitivity', code: 'sensitivity', functionValue: executorProperty.functionValue, + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsSensitivityOperationIcon, @@ -790,6 +1004,7 @@ mixin SceneOperationsDataHelper { operationName: 'Set Door lock Normal Open', functionValue: executorProperty.functionValue, code: 'normal_open_switch', + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, description: "ON", value: true), @@ -812,6 +1027,7 @@ mixin SceneOperationsDataHelper { operationName: 'Far Detection', functionValue: executorProperty.functionValue, code: 'far_detection', + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsFarDetectionFunction, @@ -875,6 +1091,7 @@ mixin SceneOperationsDataHelper { operationName: 'Motion Detection Sensitivity', functionValue: executorProperty.functionValue, code: 'motion_sensitivity_value', + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsSensitivityOperationIcon, @@ -915,6 +1132,7 @@ mixin SceneOperationsDataHelper { operationName: 'Motionless Detection Sensitivity', functionValue: executorProperty.functionValue, code: 'motion_sensitivity_value', + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( iconValue: '1', @@ -960,9 +1178,13 @@ mixin SceneOperationsDataHelper { operationName: 'Indicator', functionValue: executorProperty.functionValue, code: 'indicator', + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( - icon: Assets.assetsAcPower, description: "ON", value: true), + icon: Assets.assetsAcPower, + description: "ON", + value: true, + ), SceneOperationalValue( icon: Assets.assetsAcPowerOFF, description: "OFF", @@ -982,6 +1204,7 @@ mixin SceneOperationsDataHelper { operationName: 'Nobody Time', functionValue: executorProperty.functionValue, code: 'presence_time', + operationDialogType: OperationDialogType.temperature, operationalValues: [ SceneOperationalValue(icon: '', value: 0), ], @@ -998,6 +1221,7 @@ mixin SceneOperationsDataHelper { operationName: 'Switch Alarm Sound', functionValue: executorProperty.functionValue, code: 'switch_alarm_sound', + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, @@ -1022,6 +1246,7 @@ mixin SceneOperationsDataHelper { operationName: 'Master State', functionValue: executorProperty.functionValue, code: 'master_state', + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, @@ -1047,6 +1272,7 @@ mixin SceneOperationsDataHelper { operationName: 'Reset Factory', functionValue: executorProperty.functionValue, code: 'factory_reset', + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsSceneRefresh, @@ -1070,6 +1296,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 1 Switch', code: 'switch_1', functionValue: executorProperty.functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, @@ -1080,11 +1307,11 @@ mixin SceneOperationsDataHelper { icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), - SceneOperationalValue( - icon: Assets.assetsSceneRefresh, - description: "Reverse Switch", - value: null, - ), + // SceneOperationalValue( + // icon: Assets.assetsSceneRefresh, + // description: "Reverse Switch", + // value: null, + // ), ], )); break; @@ -1097,6 +1324,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 2 Switch', code: 'switch_2', functionValue: executorProperty.functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, description: "ON", value: true), @@ -1104,11 +1332,11 @@ mixin SceneOperationsDataHelper { icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), - SceneOperationalValue( - icon: Assets.assetsSceneRefresh, - description: "Reverse Switch", - value: null, - ), + // SceneOperationalValue( + // icon: Assets.assetsSceneRefresh, + // description: "Reverse Switch", + // value: null, + // ), ], )); break; @@ -1121,6 +1349,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 3 Switch', code: 'switch_3', functionValue: executorProperty.functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, description: "ON", value: true), @@ -1128,11 +1357,11 @@ mixin SceneOperationsDataHelper { icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), - SceneOperationalValue( - icon: Assets.assetsSceneRefresh, - description: "Reverse Switch", - value: null, - ), + // SceneOperationalValue( + // icon: Assets.assetsSceneRefresh, + // description: "Reverse Switch", + // value: null, + // ), ], )); break; @@ -1145,6 +1374,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 1 CountDown', code: 'countdown_1', functionValue: executorProperty.functionValue, + operationDialogType: OperationDialogType.countdown, operationalValues: [ SceneOperationalValue(icon: '', value: 0), ], @@ -1159,6 +1389,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 2 CountDown', code: 'countdown_2', functionValue: executorProperty.functionValue, + operationDialogType: OperationDialogType.countdown, operationalValues: [ SceneOperationalValue(icon: '', value: 0), ], @@ -1173,6 +1404,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 3 CountDown', code: 'countdown_3', functionValue: executorProperty.functionValue, + operationDialogType: OperationDialogType.countdown, operationalValues: [ SceneOperationalValue(icon: '', value: 0), ], @@ -1187,6 +1419,7 @@ mixin SceneOperationsDataHelper { operationName: 'Power', code: 'switch', functionValue: executorProperty.functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, @@ -1210,6 +1443,7 @@ mixin SceneOperationsDataHelper { operationName: 'Set Temperature', code: 'temp_set', functionValue: executorProperty.functionValue, + operationDialogType: OperationDialogType.temperature, operationalValues: [ SceneOperationalValue( icon: Assets.assetsCelsiusDegrees, @@ -1228,6 +1462,7 @@ mixin SceneOperationsDataHelper { operationName: 'Mode', code: 'mode', functionValue: executorProperty.functionValue, + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcCooling, @@ -1256,6 +1491,7 @@ mixin SceneOperationsDataHelper { operationName: 'Fan Speed', code: 'level', functionValue: executorProperty.functionValue, + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcFanLow, @@ -1289,6 +1525,7 @@ mixin SceneOperationsDataHelper { operationName: 'Child Lock', code: 'child_lock', functionValue: executorProperty.functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsSceneChildLock, @@ -1330,6 +1567,7 @@ mixin SceneOperationsDataHelper { operationName: 'delay', functionValue: taskItem.functionValue, code: '', + operationDialogType: OperationDialogType.delay, operationalValues: [ SceneOperationalValue( icon: '', @@ -1352,6 +1590,7 @@ mixin SceneOperationsDataHelper { operationName: 'Sensitivity', code: 'sensitivity', functionValue: taskItem.functionValue, + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsSensitivityOperationIcon, @@ -1417,6 +1656,7 @@ mixin SceneOperationsDataHelper { operationName: 'Set Door lock Normal Open', functionValue: taskItem.functionValue, code: 'normal_open_switch', + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, description: "ON", value: true), @@ -1439,6 +1679,7 @@ mixin SceneOperationsDataHelper { operationName: 'Far Detection', functionValue: taskItem.functionValue, code: 'far_detection', + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsFarDetectionFunction, @@ -1502,6 +1743,7 @@ mixin SceneOperationsDataHelper { operationName: 'Motion Detection Sensitivity', functionValue: taskItem.functionValue, code: 'motion_sensitivity_value', + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsSensitivityOperationIcon, @@ -1542,6 +1784,7 @@ mixin SceneOperationsDataHelper { operationName: 'Motionless Detection Sensitivity', functionValue: taskItem.functionValue, code: 'motion_sensitivity_value', + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( iconValue: '1', @@ -1587,6 +1830,7 @@ mixin SceneOperationsDataHelper { operationName: 'Indicator', functionValue: taskItem.functionValue, code: 'indicator', + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, description: "ON", value: true), @@ -1609,6 +1853,7 @@ mixin SceneOperationsDataHelper { operationName: 'Nobody Time', functionValue: taskItem.functionValue, code: 'presence_time', + operationDialogType: OperationDialogType.temperature, operationalValues: [ SceneOperationalValue(icon: '', value: 0), ], @@ -1625,6 +1870,7 @@ mixin SceneOperationsDataHelper { operationName: 'Switch Alarm Sound', functionValue: taskItem.functionValue, code: 'switch_alarm_sound', + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, @@ -1649,6 +1895,7 @@ mixin SceneOperationsDataHelper { operationName: 'Master State', functionValue: taskItem.functionValue, code: 'master_state', + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, @@ -1674,6 +1921,7 @@ mixin SceneOperationsDataHelper { operationName: 'Reset Factory', functionValue: taskItem.functionValue, code: 'factory_reset', + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsSceneRefresh, @@ -1697,6 +1945,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 1 Switch', code: 'switch_1', functionValue: taskItem.functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, @@ -1719,6 +1968,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 2 Switch', code: 'switch_2', functionValue: taskItem.functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, description: "ON", value: true), @@ -1738,6 +1988,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 3 Switch', code: 'switch_3', functionValue: taskItem.functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, description: "ON", value: true), @@ -1757,6 +2008,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 1 CountDown', code: 'countdown_1', functionValue: taskItem.functionValue, + operationDialogType: OperationDialogType.countdown, operationalValues: [ SceneOperationalValue(icon: '', value: 0), ], @@ -1771,6 +2023,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 2 CountDown', code: 'countdown_2', functionValue: taskItem.functionValue, + operationDialogType: OperationDialogType.countdown, operationalValues: [ SceneOperationalValue(icon: '', value: 0), ], @@ -1785,6 +2038,7 @@ mixin SceneOperationsDataHelper { operationName: 'Light 3 CountDown', code: 'countdown_3', functionValue: taskItem.functionValue, + operationDialogType: OperationDialogType.countdown, operationalValues: [ SceneOperationalValue(icon: '', value: 0), ], @@ -1799,6 +2053,7 @@ mixin SceneOperationsDataHelper { operationName: 'Power', code: 'switch', functionValue: taskItem.functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcPower, @@ -1824,6 +2079,7 @@ mixin SceneOperationsDataHelper { functionValue: taskItem.functionValue != null ? ((taskItem.functionValue / 10) as double).toInt() : null, + operationDialogType: OperationDialogType.temperature, operationalValues: [ SceneOperationalValue( icon: Assets.assetsCelsiusDegrees, @@ -1842,6 +2098,7 @@ mixin SceneOperationsDataHelper { operationName: 'Mode', code: 'mode', functionValue: taskItem.functionValue, + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcCooling, @@ -1870,6 +2127,7 @@ mixin SceneOperationsDataHelper { operationName: 'Fan Speed', code: 'level', functionValue: taskItem.functionValue, + operationDialogType: OperationDialogType.listOfOptions, operationalValues: [ SceneOperationalValue( icon: Assets.assetsAcFanLow, @@ -1903,6 +2161,7 @@ mixin SceneOperationsDataHelper { operationName: 'Child Lock', code: 'child_lock', functionValue: taskItem.functionValue, + operationDialogType: OperationDialogType.onOff, operationalValues: [ SceneOperationalValue( icon: Assets.assetsSceneChildLock, diff --git a/lib/features/scene/model/scene_static_function.dart b/lib/features/scene/model/scene_static_function.dart index 43f7f09..7b364f3 100644 --- a/lib/features/scene/model/scene_static_function.dart +++ b/lib/features/scene/model/scene_static_function.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; +import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart'; import 'package:uuid/uuid.dart'; class SceneStaticFunction { @@ -13,6 +14,7 @@ class SceneStaticFunction { final String uniqueCustomId; final dynamic functionValue; final String? deviceIcon; + final OperationDialogType operationDialogType; SceneStaticFunction({ required this.icon, @@ -23,6 +25,7 @@ class SceneStaticFunction { required this.operationName, required this.functionValue, this.deviceIcon, + required this.operationDialogType, }) : uniqueCustomId = const Uuid().v4(); SceneStaticFunction copyWith({ @@ -35,6 +38,7 @@ class SceneStaticFunction { dynamic functionValue, String? deviceIcon, String? deviceName, + OperationDialogType? operationDialogType, }) { return SceneStaticFunction( icon: icon ?? this.icon, @@ -45,6 +49,7 @@ class SceneStaticFunction { operationName: operationName ?? this.operationName, functionValue: functionValue ?? this.functionValue, deviceIcon: deviceIcon ?? this.deviceIcon, + operationDialogType: operationDialogType ?? this.operationDialogType, ); } @@ -57,8 +62,8 @@ class SceneStaticFunction { 'deviceId': deviceId, 'operationName': operationName, 'functionValue': functionValue, - 'deviceIcon': deviceIcon - + 'deviceIcon': deviceIcon, + 'operationDialogType': operationDialogType.name }; } @@ -74,6 +79,9 @@ class SceneStaticFunction { operationName: map['operationName'] ?? '', functionValue: map['functionValue'] ?? '', deviceIcon: map['deviceIcon'] ?? '', + operationDialogType: map['operationDialogType'] != null + ? OperationDialogType.values.byName(map['operationDialogType']) + : OperationDialogType.none, ); } @@ -84,7 +92,7 @@ class SceneStaticFunction { @override String toString() { - return 'SceneStaticFunction(icon: $icon, name: $deviceName, code: $code, operationalValues: $operationalValues, deviceId: $deviceId, operationName: $operationName, functionValue: $functionValue, deviceIcon: $deviceIcon)'; + return 'SceneStaticFunction(icon: $icon, name: $deviceName, code: $code, operationalValues: $operationalValues, deviceId: $deviceId, operationName: $operationName, functionValue: $functionValue, deviceIcon: $deviceIcon, operationDialogType: $operationDialogType)'; } @override @@ -98,6 +106,7 @@ class SceneStaticFunction { other.operationName == operationName && other.functionValue == functionValue && other.deviceIcon == deviceIcon && + other.operationDialogType == operationDialogType && listEquals(other.operationalValues, operationalValues) && other.deviceId == deviceId; } @@ -111,6 +120,7 @@ class SceneStaticFunction { operationName.hashCode ^ functionValue.hashCode ^ deviceIcon.hashCode ^ + operationDialogType.hashCode ^ operationalValues.hashCode; } } diff --git a/lib/features/scene/view/device_functions_view.dart b/lib/features/scene/view/device_functions_view.dart index 74aeb7a..45daa3c 100644 --- a/lib/features/scene/view/device_functions_view.dart +++ b/lib/features/scene/view/device_functions_view.dart @@ -3,6 +3,8 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart'; +import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart'; +import 'package:syncrow_app/features/scene/helper/scene_logic_helper.dart'; import 'package:syncrow_app/features/scene/helper/scene_operations_data_helper.dart'; import 'package:syncrow_app/features/scene/model/scene_static_function.dart'; import 'package:syncrow_app/features/scene/widgets/alert_dialogs/alert_dialog_countdown.dart'; @@ -19,7 +21,7 @@ import 'package:syncrow_app/utils/context_extension.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; class DeviceFunctionsView extends StatelessWidget - with SceneOperationsDataHelper { + with SceneOperationsDataHelper, SceneLogicHelper { const DeviceFunctionsView({super.key}); @override @@ -88,136 +90,130 @@ class DeviceFunctionsView extends StatelessWidget ), leadingWidth: 80, padding: EdgeInsets.zero, - child: Padding( + child: ListView.builder( + shrinkWrap: true, + itemCount: functions.length, padding: const EdgeInsets.only(top: 24.0), - child: ListView.builder( - shrinkWrap: true, - itemCount: functions.length, - padding: EdgeInsets.zero, - physics: const NeverScrollableScrollPhysics(), - itemBuilder: (context, index) { - return DefaultContainer( - padding: index == 0 - ? const EdgeInsets.only(top: 8) - : index == functions.length - 1 - ? const EdgeInsets.only(bottom: 8) - : EdgeInsets.zero, - margin: EdgeInsets.zero, - borderRadius: index == 0 - ? const BorderRadius.only( - topLeft: Radius.circular(20), - topRight: Radius.circular(20)) - : index == functions.length - 1 - ? const BorderRadius.only( - bottomLeft: Radius.circular(20), - bottomRight: Radius.circular(20)) - : BorderRadius.zero, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - BlocBuilder( - builder: (context, state) { - return SceneListTile( - iconsSize: 22, - minLeadingWidth: 20, - assetPath: functions[index].icon, - titleString: functions[index].operationName, - trailingWidget: const Row( - mainAxisSize: MainAxisSize.min, - children: [ - /// selected value or the default value - // BodyMedium(text: ), - Icon( - Icons.arrow_forward_ios_rounded, - color: ColorsManager.greyColor, - size: 16, - ), - ], - ), - onPressed: () { - final functionValues = context - .read() - .selectedValues[functions[index].code]; + itemBuilder: (context, index) { + return DefaultContainer( + padding: index == 0 + ? const EdgeInsets.only(top: 8) + : index == functions.length - 1 + ? const EdgeInsets.only(bottom: 8) + : EdgeInsets.zero, + margin: EdgeInsets.zero, + borderRadius: index == 0 + ? const BorderRadius.only( + topLeft: Radius.circular(20), + topRight: Radius.circular(20)) + : index == functions.length - 1 + ? const BorderRadius.only( + bottomLeft: Radius.circular(20), + bottomRight: Radius.circular(20)) + : BorderRadius.zero, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + BlocBuilder( + builder: (context, state) { + return SceneListTile( + iconsSize: 22, + minLeadingWidth: 20, + assetPath: functions[index].icon, + titleString: functions[index].operationName, + trailingWidget: const Row( + mainAxisSize: MainAxisSize.min, + children: [ + /// selected value or the default value + // BodyMedium(text: ), + Icon( + Icons.arrow_forward_ios_rounded, + color: ColorsManager.greyColor, + size: 16, + ), + ], + ), + onPressed: () { + final functionValues = context + .read() + .selectedValues[functions[index].code]; - context.customAlertDialog( - alertBody: functions[index].code == 'temp_set' - ? AlertDialogTemperatureBody( - taskItem: functions[index], - functionValue: functionValues, - ) - : (functions[index] - .code - .contains('countdown') || - functions[index] - .code - .contains('presence_time')) - ? AlertDialogCountdown( - durationValue: functions[index] - .operationalValues - .first - .value, - function: functions[index], - functionValue: functionValues, - ) - : AlertDialogFunctionsOperationsBody( - taskItem: functions[index], - functionValue: functionValues, - ), - title: functions[index].operationName, - onConfirm: () { - final selectedValue = context - .read() - .selectedValues[functions[index].code]; - if (selectedValue == null) { - return; - } - context - .read() - .add(TempHoldSceneTasksEvent( - deviceControlModel: DeviceControlModel( - deviceId: device.uuid, - code: functions[index].code, - value: selectedValue, + context.customAlertDialog( + alertBody: functions[index].operationDialogType == + OperationDialogType.temperature + ? AlertDialogTemperatureBody( + taskItem: functions[index], + functionValue: functionValues, + ) + : ((functions[index].operationDialogType == + OperationDialogType.countdown) || + (functions[index].operationDialogType == + OperationDialogType.countdown)) + ? AlertDialogCountdown( + durationValue: functions[index] + .operationalValues + .first + .value, + function: functions[index], + functionValue: functionValues, + ) + : AlertDialogFunctionsOperationsBody( + taskItem: functions[index], + functionValue: functionValues, ), - deviceId: device.uuid ?? '', - operation: functions[index].operationName, - icon: device.icon ?? '', - deviceName: device.name ?? '', - uniqueId: functions[index].uniqueCustomId, - )); - Navigator.pop(context); - }, - onDismiss: () { - final tempTaskList = context - .read() - .tempTasksList; - for (var element in tempTaskList) { - if (element.code == functions[index].code) { - context.read().add( - RemoveTempTaskByIdEvent( - code: functions[index].code)); - context.read().add( - RemoveFromSelectedValueById( - code: functions[index].code)); - } + title: functions[index].operationName, + onConfirm: () { + final selectedValue = context + .read() + .selectedValues[functions[index].code]; + if (selectedValue == null) { + return; + } + context + .read() + .add(TempHoldSceneTasksEvent( + deviceControlModel: DeviceControlModel( + deviceId: device.uuid, + code: functions[index].code, + value: selectedValue, + ), + deviceId: device.uuid ?? '', + operation: functions[index].operationName, + icon: device.icon ?? '', + deviceName: device.name ?? '', + uniqueId: functions[index].uniqueCustomId, + )); + Navigator.pop(context); + }, + onDismiss: () { + final tempTaskList = + context.read().tempTasksList; + for (var element in tempTaskList) { + if (element.code == functions[index].code) { + context.read().add( + RemoveTempTaskByIdEvent( + code: functions[index].code)); + context.read().add( + RemoveFromSelectedValueById( + code: functions[index].code)); } - Navigator.pop(context); - }, - ); - }, - ); - }, - ), - index != functions.length - 1 - ? SizedBox( - width: context.width * 0.8, - child: const LightDivider()) - : const SizedBox(), - ], - ), - ); - }, - ), + } + Navigator.pop(context); + }, + ); + }, + ); + }, + ), + index != functions.length - 1 + ? SizedBox( + width: context.width * 0.8, + child: const LightDivider()) + : const SizedBox(), + ], + ), + ); + }, )); } } diff --git a/lib/features/scene/widgets/bottom_sheet_widget.dart b/lib/features/scene/widgets/bottom_sheet_widget.dart index 1bbd631..6967cae 100644 --- a/lib/features/scene/widgets/bottom_sheet_widget.dart +++ b/lib/features/scene/widgets/bottom_sheet_widget.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart'; +import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart'; import 'package:syncrow_app/features/scene/model/scene_static_function.dart'; import 'package:syncrow_app/features/scene/widgets/alert_dialogs/alert_dialog_countdown.dart'; import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart'; @@ -97,6 +98,7 @@ class CustomBottomSheetWidget extends StatelessWidget { operationName: 'Delay The Action', code: '', functionValue: 0, + operationDialogType: OperationDialogType.delay, operationalValues: [ SceneOperationalValue(icon: '', value: 0), ], diff --git a/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart b/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart index a50b2a6..07c2d82 100644 --- a/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart +++ b/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart @@ -62,7 +62,7 @@ class ThenAddedTasksContainer extends StatelessWidget /// show alert dialog based on type context.customAlertDialog( - alertBody: getTheCorrectDialogBody(functionOperation.first), + alertBody: getTheCorrectDialogBody(functionOperation.first, null), title: functionOperation.first.operationName, onConfirm: () { final savedCode = functionOperation.first.deviceId.contains('delay') diff --git a/pubspec.yaml b/pubspec.yaml index 3708e95..aaead8f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -74,7 +74,7 @@ flutter: - assets/icons/MenuIcons/SecurityAndPrivacyIcons/ - assets/icons/curtainsIcon/ - assets/icons/functions_icons/ - - assets/icons/functions_icons/automation_functions + - assets/icons/functions_icons/automation_functions/ fonts: - family: Aftika fonts: