push fixes

This commit is contained in:
ashrafzarkanisala
2024-08-01 03:11:03 +03:00
parent a242876e16
commit b66fbc32e7
21 changed files with 647 additions and 331 deletions

View File

@ -18,8 +18,11 @@ import 'package:syncrow_app/features/devices/view/widgets/curtains/curtain_view.
import 'package:syncrow_app/features/devices/view/widgets/devices_view_body.dart'; import 'package:syncrow_app/features/devices/view/widgets/devices_view_body.dart';
import 'package:syncrow_app/features/menu/view/menu_view.dart'; import 'package:syncrow_app/features/menu/view/menu_view.dart';
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart'; import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_event.dart';
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart'; import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart'; import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
import 'package:syncrow_app/features/scene/model/create_automation_model.dart';
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart'; import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
import 'package:syncrow_app/features/scene/view/create_scene_view.dart'; import 'package:syncrow_app/features/scene/view/create_scene_view.dart';
import 'package:syncrow_app/features/scene/view/scene_tasks_view.dart'; import 'package:syncrow_app/features/scene/view/scene_tasks_view.dart';
@ -385,6 +388,9 @@ class HomeCubit extends Cubit<HomeState> {
NavigationService.navigatorKey.currentContext! NavigationService.navigatorKey.currentContext!
.read<SmartSceneSelectBloc>() .read<SmartSceneSelectBloc>()
.add(const SmartSceneClearEvent()); .add(const SmartSceneClearEvent());
BlocProvider.of<EffectPeriodBloc>(
NavigationService.navigatorKey.currentState!.context)
.add(ResetEffectivePeriod());
}, },
), ),
IconButton( IconButton(

View File

@ -1,6 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart'; import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_event.dart';
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart'; import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart'; import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
import 'package:syncrow_app/features/scene/model/scenes_model.dart'; import 'package:syncrow_app/features/scene/model/scenes_model.dart';

View File

@ -92,30 +92,59 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
TempHoldSceneTasksEvent event, Emitter<CreateSceneState> emit) { TempHoldSceneTasksEvent event, Emitter<CreateSceneState> emit) {
emit(CreateSceneLoading()); emit(CreateSceneLoading());
bool updated = false; bool updated = false;
// Check and update if the task exists in tempTasksList
for (var element in tempTasksList) { for (var element in tempTasksList) {
if (element.code == event.deviceControlModel.code) { var updatedElement = element.copyWith(
// Update the existing function with new values operationName: event.operation,
var updatedElement = element.copyWith( deviceName: event.deviceName,
operationName: event.operation, icon: event.icon,
deviceName: event.deviceName, code: event.deviceControlModel.code ?? '',
icon: event.icon, deviceId: event.deviceId,
code: event.deviceControlModel.code ?? '', functionValue: event.deviceControlModel.value,
deviceId: event.deviceId, operationDialogType: event.operationType,
functionValue: event.deviceControlModel.value, operationalValues: [
operationDialogType: event.operationType, SceneOperationalValue(
operationalValues: [ value: event.deviceControlModel.value,
SceneOperationalValue( icon: '',
value: event.deviceControlModel.value, ),
icon: '', ],
), );
], tempTasksList[tempTasksList.indexOf(element)] = updatedElement;
); selectedValues[updatedElement.code] = event.deviceControlModel.value;
tempTasksList[tempTasksList.indexOf(element)] = updatedElement; updated = true;
selectedValues[updatedElement.code] = event.deviceControlModel.value; break;
updated = true; }
break;
if (!updated) {
/// for smart scene add to view
for (var element in tasksList) {
if (element.deviceId == event.deviceControlModel.deviceId &&
element.code == event.deviceControlModel.code) {
var updatedElement = element.copyWith(
operationName: event.operation,
deviceName: event.deviceName,
icon: event.icon,
code: event.deviceControlModel.code ?? '',
deviceId: event.deviceId,
functionValue: event.deviceControlModel.value,
operationDialogType: event.operationType,
operationalValues: [
SceneOperationalValue(
value: event.deviceControlModel.value,
icon: '',
),
],
);
tasksList[tasksList.indexOf(element)] = updatedElement;
selectedValues[updatedElement.code] = event.deviceControlModel.value;
updated = true;
break;
}
} }
} }
// Add new element if it doesn't exist in either list
if (!updated) { if (!updated) {
var newElement = SceneStaticFunction( var newElement = SceneStaticFunction(
operationName: event.operation, operationName: event.operation,
@ -319,7 +348,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
automationTempTasksList.clear(); automationTempTasksList.clear();
automationSelectedValues.clear(); automationSelectedValues.clear();
automationComparatorValues.clear(); automationComparatorValues.clear();
effectiveTime = null; effectiveTime =
EffectiveTime(start: '00:00', end: '23:59', loops: '1111111');
sceneType = CreateSceneEnum.none; sceneType = CreateSceneEnum.none;
conditionRule = 'or'; conditionRule = 'or';
emit(const CreateSceneWithTasks(success: true)); emit(const CreateSceneWithTasks(success: true));
@ -369,14 +399,31 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
conditionRule = response.decisionExpr ?? conditionRule; conditionRule = response.decisionExpr ?? conditionRule;
if (response.effectiveTime != null) { effectiveTime = response.effectiveTime != null
BlocProvider.of<EffectPeriodBloc>( ? EffectiveTime(
NavigationService.navigatorKey.currentState!.context) start: response.effectiveTime!.start,
.add(SetCustomTime(response.effectiveTime!.start, end: response.effectiveTime!.end,
response.effectiveTime!.end)); loops: response.effectiveTime!.loops,
BlocProvider.of<EffectPeriodBloc>( )
NavigationService.navigatorKey.currentState!.context) : EffectiveTime(start: '00:00', end: '23:59', loops: '1111111');
.add(ToggleDay(response.effectiveTime!.loops));
// Set Custom Time and reset days first
BlocProvider.of<EffectPeriodBloc>(
NavigationService.navigatorKey.currentContext!)
.add(SetCustomTime(effectiveTime!.start, effectiveTime!.end));
// Reset all days to not selected before toggling
BlocProvider.of<EffectPeriodBloc>(
NavigationService.navigatorKey.currentContext!)
.add(ResetDays());
// Iterate over the loops and toggle each day
for (int i = 0; i < effectiveTime!.loops.length; i++) {
if (effectiveTime!.loops[i] == '1') {
BlocProvider.of<EffectPeriodBloc>(
NavigationService.navigatorKey.currentContext!)
.add(ToggleDay(_getDayFromIndex(i)));
}
} }
emit(AddSceneTask( emit(AddSceneTask(
@ -401,6 +448,11 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
} }
} }
String _getDayFromIndex(int index) {
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
return days[index];
}
FutureOr<void> _clearTempTaskList( FutureOr<void> _clearTempTaskList(
ClearTempTaskListEvent event, Emitter<CreateSceneState> emit) { ClearTempTaskListEvent event, Emitter<CreateSceneState> emit) {
emit(CreateSceneLoading()); emit(CreateSceneLoading());
@ -408,20 +460,15 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
automationTempTasksList.clear(); automationTempTasksList.clear();
automationSelectedValues.clear(); automationSelectedValues.clear();
automationComparatorValues.clear(); automationComparatorValues.clear();
emit(AddSceneTask(
tasksList: tasksList,
automationTasksList: automationTasksList,
condition: conditionRule,
));
} else { } else {
tempTasksList.clear(); tempTasksList.clear();
selectedValues.clear(); selectedValues.clear();
emit(AddSceneTask(
tasksList: tasksList,
automationTasksList: automationTasksList,
condition: conditionRule,
));
} }
emit(AddSceneTask(
tasksList: tasksList,
automationTasksList: automationTasksList,
condition: conditionRule,
));
} }
FutureOr<void> _removeFromSelectedValueById( FutureOr<void> _removeFromSelectedValueById(

View File

@ -12,6 +12,8 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
on<SetPeriod>(_onSetPeriod); on<SetPeriod>(_onSetPeriod);
on<ToggleDay>(_onToggleDay); on<ToggleDay>(_onToggleDay);
on<SetCustomTime>(_onSetCustomTime); on<SetCustomTime>(_onSetCustomTime);
on<ResetEffectivePeriod>(_onResetEffectivePeriod);
on<ResetDays>(_onResetDays);
} }
void _onSetPeriod(SetPeriod event, Emitter<EffectPeriodState> emit) { void _onSetPeriod(SetPeriod event, Emitter<EffectPeriodState> emit) {
@ -39,13 +41,15 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
break; break;
} }
// Update CreateSceneBloc
BlocProvider.of<CreateSceneBloc>( BlocProvider.of<CreateSceneBloc>(
NavigationService.navigatorKey.currentState!.context) NavigationService.navigatorKey.currentContext!)
.add(EffectiveTimePeriodEvent(EffectiveTime( .add(EffectiveTimePeriodEvent(EffectiveTime(
start: startTime, end: endTime, loops: state.selectedDaysBinary))); start: startTime, end: endTime, loops: state.selectedDaysBinary)));
emit(state.copyWith(selectedPeriod: event.period)); emit(state.copyWith(
selectedPeriod: event.period,
customStartTime: startTime,
customEndTime: endTime));
} }
void _onToggleDay(ToggleDay event, Emitter<EffectPeriodState> emit) { void _onToggleDay(ToggleDay event, Emitter<EffectPeriodState> emit) {
@ -60,7 +64,7 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
emit(state.copyWith(selectedDaysBinary: newDaysBinary)); emit(state.copyWith(selectedDaysBinary: newDaysBinary));
BlocProvider.of<CreateSceneBloc>( BlocProvider.of<CreateSceneBloc>(
NavigationService.navigatorKey.currentState!.context) NavigationService.navigatorKey.currentContext!)
.add(EffectiveTimePeriodEvent(EffectiveTime( .add(EffectiveTimePeriodEvent(EffectiveTime(
start: state.customStartTime ?? '00:00', start: state.customStartTime ?? '00:00',
end: state.customEndTime ?? '23:59', end: state.customEndTime ?? '23:59',
@ -68,15 +72,48 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
} }
void _onSetCustomTime(SetCustomTime event, Emitter<EffectPeriodState> emit) { void _onSetCustomTime(SetCustomTime event, Emitter<EffectPeriodState> emit) {
String startTime = event.startTime;
String endTime = event.endTime;
EnumEffectivePeriodOptions period;
// Determine the period based on start and end times
if (startTime == '00:00' && endTime == '23:59') {
period = EnumEffectivePeriodOptions.allDay;
} else if (startTime == '06:00' && endTime == '18:00') {
period = EnumEffectivePeriodOptions.daytime;
} else if (startTime == '18:00' && endTime == '06:00') {
period = EnumEffectivePeriodOptions.night;
} else {
period = EnumEffectivePeriodOptions.custom;
}
emit(state.copyWith( emit(state.copyWith(
customStartTime: event.startTime, customEndTime: event.endTime)); customStartTime: startTime,
customEndTime: endTime,
selectedPeriod: period));
BlocProvider.of<CreateSceneBloc>( BlocProvider.of<CreateSceneBloc>(
NavigationService.navigatorKey.currentState!.context) NavigationService.navigatorKey.currentContext!)
.add(EffectiveTimePeriodEvent(EffectiveTime( .add(EffectiveTimePeriodEvent(EffectiveTime(
start: event.startTime, start: startTime, end: endTime, loops: state.selectedDaysBinary)));
end: event.endTime, }
loops: state.selectedDaysBinary)));
void _onResetEffectivePeriod(
ResetEffectivePeriod event, Emitter<EffectPeriodState> emit) {
emit(state.copyWith(
selectedPeriod: EnumEffectivePeriodOptions.allDay,
customStartTime: '00:00',
customEndTime: '23:59',
selectedDaysBinary: '1111111'));
BlocProvider.of<CreateSceneBloc>(
NavigationService.navigatorKey.currentContext!)
.add(EffectiveTimePeriodEvent(
EffectiveTime(start: '00:00', end: '23:59', loops: '1111111')));
}
void _onResetDays(ResetDays event, Emitter<EffectPeriodState> emit) {
emit(state.copyWith(selectedDaysBinary: '1111111'));
} }
int _getDayIndex(String day) { int _getDayIndex(String day) {

View File

@ -35,3 +35,10 @@ class SetCustomTime extends EffectPeriodEvent {
@override @override
List<Object> get props => [startTime, endTime]; List<Object> get props => [startTime, endTime];
} }
class ResetEffectivePeriod extends EffectPeriodEvent {}
class ResetDays extends EffectPeriodEvent {
@override
List<Object> get props => [];
}

View File

@ -37,6 +37,18 @@ class EffectPeriodState extends Equatable {
); );
} }
EnumEffectivePeriodOptions getEffectivePeriod() {
if (customStartTime == '00:00' && customEndTime == '23:59') {
return EnumEffectivePeriodOptions.allDay;
} else if (customStartTime == '06:00' && customEndTime == '18:00') {
return EnumEffectivePeriodOptions.daytime;
} else if (customStartTime == '18:00' && customEndTime == '06:00') {
return EnumEffectivePeriodOptions.night;
} else {
return EnumEffectivePeriodOptions.custom;
}
}
@override @override
List<Object?> get props => List<Object?> get props =>
[selectedPeriod, selectedDaysBinary, customStartTime, customEndTime]; [selectedPeriod, selectedDaysBinary, customStartTime, customEndTime];

View File

@ -18,6 +18,7 @@ class SmartSceneSelectBloc
SmartSceneSelectBloc() : super(SmartSceneSelectInitial()) { SmartSceneSelectBloc() : super(SmartSceneSelectInitial()) {
on<SmartSceneEnableEvent>(_onSmartSceneEnable); on<SmartSceneEnableEvent>(_onSmartSceneEnable);
on<SmartSceneClearEvent>(_smartSceneClear); on<SmartSceneClearEvent>(_smartSceneClear);
on<SmartSceneConfirmSelectionEvent>(_smartSceneConfirmSelection);
} }
SmartSceneEnable? smartSceneEnable; SmartSceneEnable? smartSceneEnable;
@ -25,29 +26,6 @@ class SmartSceneSelectBloc
FutureOr<void> _onSmartSceneEnable( FutureOr<void> _onSmartSceneEnable(
SmartSceneEnableEvent event, Emitter<SmartSceneSelectState> emit) { SmartSceneEnableEvent event, Emitter<SmartSceneSelectState> emit) {
smartSceneEnable = event.smartSceneEnable; smartSceneEnable = event.smartSceneEnable;
NavigationService.navigatorKey.currentState!.context
.read<CreateSceneBloc>()
.add(TempHoldSceneTasksEvent(
deviceControlModel: DeviceControlModel(
deviceId: smartSceneEnable?.entityId ?? '',
code: CreateSceneEnum.smartSceneSelect.name,
value: '',
),
deviceId: smartSceneEnable?.sceneORAutomationName ?? '',
operation: smartSceneEnable?.actionExecutor ?? '',
icon: smartSceneEnable?.isAutomation == true
? Assets.player
: Assets.handClickIcon,
deviceName: smartSceneEnable?.sceneORAutomationName ?? '',
uniqueId: '',
operationType: OperationDialogType.none,
isAutomation: false,
));
emit(SmartSceneSelected(smartSceneEnable: smartSceneEnable!));
NavigationService.navigatorKey.currentState!.context
.read<CreateSceneBloc>()
.add(const AddTaskEvent(isAutomation: false));
} }
FutureOr<void> _smartSceneClear( FutureOr<void> _smartSceneClear(
@ -55,4 +33,33 @@ class SmartSceneSelectBloc
smartSceneEnable = null; smartSceneEnable = null;
emit(SmartSceneSelectInitial()); emit(SmartSceneSelectInitial());
} }
FutureOr<void> _smartSceneConfirmSelection(
SmartSceneConfirmSelectionEvent event,
Emitter<SmartSceneSelectState> emit) {
final createSceneBloc = NavigationService.navigatorKey.currentState!.context
.read<CreateSceneBloc>();
createSceneBloc.add(TempHoldSceneTasksEvent(
deviceControlModel: DeviceControlModel(
deviceId: smartSceneEnable?.entityId ?? '',
code: CreateSceneEnum.smartSceneSelect.name,
value: smartSceneEnable?.actionExecutor ?? '',
),
deviceId: smartSceneEnable?.entityId ?? '',
operation: smartSceneEnable?.type ?? '',
icon: smartSceneEnable?.isAutomation == true
? Assets.player
: Assets.handClickIcon,
deviceName: smartSceneEnable?.sceneORAutomationName ?? '',
uniqueId: smartSceneEnable?.entityId ?? '',
operationType: OperationDialogType.none,
isAutomation: false,
));
emit(SmartSceneSelected(smartSceneEnable: smartSceneEnable!));
NavigationService.navigatorKey.currentState!.context
.read<CreateSceneBloc>()
.add(const AddTaskEvent(isAutomation: false));
}
} }

View File

@ -19,3 +19,7 @@ class SmartSceneEnableEvent extends SmartSceneSelectEvent {
class SmartSceneClearEvent extends SmartSceneSelectEvent { class SmartSceneClearEvent extends SmartSceneSelectEvent {
const SmartSceneClearEvent(); const SmartSceneClearEvent();
} }
class SmartSceneConfirmSelectionEvent extends SmartSceneSelectEvent {
const SmartSceneConfirmSelectionEvent();
}

View File

@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.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/bloc/create_scene/create_scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart'; import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart'; import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart';
import 'package:syncrow_app/features/scene/model/create_automation_model.dart'; import 'package:syncrow_app/features/scene/model/create_automation_model.dart';
@ -31,7 +30,6 @@ mixin SceneLogicHelper {
required List<SceneStaticFunction> conditions, required List<SceneStaticFunction> conditions,
}) { }) {
final sceneBloc = context.read<CreateSceneBloc>(); final sceneBloc = context.read<CreateSceneBloc>();
final smartSceneBloc = context.read<SmartSceneSelectBloc>();
if (isOnlyDelayOrDelayLast(actions)) { if (isOnlyDelayOrDelayLast(actions)) {
context.showCustomSnackbar( context.showCustomSnackbar(
@ -85,9 +83,8 @@ mixin SceneLogicHelper {
} }
if (task.code == CreateSceneEnum.smartSceneSelect.name) { if (task.code == CreateSceneEnum.smartSceneSelect.name) {
return CreateSceneAction( return CreateSceneAction(
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '', entityId: actions[index].deviceId,
actionExecutor: actionExecutor: actions[index].functionValue,
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
executorProperty: null); executorProperty: null);
} }
return CreateSceneAction( return CreateSceneAction(
@ -132,9 +129,8 @@ mixin SceneLogicHelper {
} }
if (task.code == CreateSceneEnum.smartSceneSelect.name) { if (task.code == CreateSceneEnum.smartSceneSelect.name) {
return CreateSceneAction( return CreateSceneAction(
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '', entityId: actions[index].deviceId,
actionExecutor: actionExecutor: actions[index].functionValue,
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
executorProperty: null); executorProperty: null);
} }
return CreateSceneAction( return CreateSceneAction(
@ -190,4 +186,16 @@ mixin SceneLogicHelper {
isAutomation: isAutomation, isAutomation: isAutomation,
); );
} }
String getTaskDescription(SceneStaticFunction taskItem) {
if (taskItem.code == CreateSceneEnum.smartSceneSelect.name) {
if (taskItem.operationName == 'automation') {
return 'Automation: ';
} else {
return 'Tab-To-Run: ';
}
} else {
return "${taskItem.operationName}: ";
}
}
} }

View File

@ -1,5 +1,6 @@
import 'package:syncrow_app/features/devices/model/function_model.dart'; 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/ac_values.dart';
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart'; import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart';
import 'package:syncrow_app/features/scene/helper/functions_per_device/ac_functions.dart'; import 'package:syncrow_app/features/scene/helper/functions_per_device/ac_functions.dart';
import 'package:syncrow_app/features/scene/helper/functions_per_device/door_lock_functions.dart'; import 'package:syncrow_app/features/scene/helper/functions_per_device/door_lock_functions.dart';
@ -171,13 +172,43 @@ mixin SceneOperationsDataHelper {
icon: Assets.delay, icon: Assets.delay,
operationName: 'delay', operationName: 'delay',
operationDialogType: OperationDialogType.delay, operationDialogType: OperationDialogType.delay,
functionValue: action.executorProperty.delaySeconds, functionValue: action.executorProperty?.delaySeconds,
code: '', code: '',
operationalValues: [ operationalValues: [
SceneOperationalValue( SceneOperationalValue(
icon: '', icon: '',
description: "", description: "",
value: action.executorProperty.delaySeconds, value: action.executorProperty?.delaySeconds,
),
],
),
);
} else if (action.name != null && action.type != null) {
// Handle smart scenes
functions.add(
SceneStaticFunction(
deviceId: action.entityId,
deviceName: action.name.toString(),
deviceIcon: action.type == 'automation'
? Assets.player
: Assets.handClickIcon,
icon: action.type == 'automation'
? Assets.player
: Assets.handClickIcon,
operationName: action.type.toString(),
operationDialogType: OperationDialogType.onOff,
functionValue: action.actionExecutor,
code: CreateSceneEnum.smartSceneSelect.name,
operationalValues: [
SceneOperationalValue(
icon: Assets.assetsAcPower,
description: "Enable",
value: 'rule_enable',
),
SceneOperationalValue(
icon: Assets.assetsAcPowerOFF,
description: "Disable",
value: 'rule_disable',
), ),
], ],
), ),
@ -260,7 +291,7 @@ mixin SceneOperationsDataHelper {
'factory_reset': _createFactoryResetFunction, 'factory_reset': _createFactoryResetFunction,
}; };
final functionCode = executorProperty.functionCode ?? ''; final functionCode = executorProperty?.functionCode ?? '';
final createFunction = functionMap[functionCode]; final createFunction = functionMap[functionCode];
if (createFunction != null) { if (createFunction != null) {
return createFunction(action, isAutomation, comparator); return createFunction(action, isAutomation, comparator);
@ -279,7 +310,7 @@ mixin SceneOperationsDataHelper {
bool isAutomation, [ bool isAutomation, [
String? comparator, String? comparator,
]) { ]) {
final functionValue = action.executorProperty.functionValue; final functionValue = action.executorProperty?.functionValue;
return SceneStaticFunction( return SceneStaticFunction(
deviceId: action.entityId, deviceId: action.entityId,
deviceName: deviceName, deviceName: deviceName,
@ -287,7 +318,7 @@ mixin SceneOperationsDataHelper {
icon: icon, icon: icon,
operationName: operationName, operationName: operationName,
functionValue: functionValue, functionValue: functionValue,
code: action.executorProperty.functionCode ?? '', code: action.executorProperty?.functionCode ?? '',
operationDialogType: operationDialogType, operationDialogType: operationDialogType,
operationalValues: operationalValues, operationalValues: operationalValues,
comparator: comparator ?? '==', comparator: comparator ?? '==',
@ -1168,7 +1199,36 @@ mixin SceneOperationsDataHelper {
), ),
]; ];
} }
if (taskItem.code == CreateSceneEnum.smartSceneSelect.name) {
return [
SceneStaticFunction(
deviceId: taskItem.deviceId,
deviceName: taskItem.deviceName.toString(),
deviceIcon: taskItem.operationName == 'automation'
? Assets.player
: Assets.handClickIcon,
icon: taskItem.operationName == 'automation'
? Assets.player
: Assets.handClickIcon,
operationName: taskItem.operationName,
operationDialogType: OperationDialogType.onOff,
functionValue: taskItem.functionValue == 'rule_enable' ? true : false,
code: CreateSceneEnum.smartSceneSelect.name,
operationalValues: [
SceneOperationalValue(
icon: Assets.assetsAcPower,
description: "Enable",
value: 'rule_enable',
),
SceneOperationalValue(
icon: Assets.assetsAcPowerOFF,
description: "Disable",
value: 'rule_disable',
),
],
),
];
}
return [ return [
_mapExecutorPropertyToSceneFunction( _mapExecutorPropertyToSceneFunction(
Action( Action(

View File

@ -65,19 +65,31 @@ class SceneDetailsModel {
class Action { class Action {
final String actionExecutor; final String actionExecutor;
final String entityId; final String entityId;
final ExecutorProperty executorProperty; ExecutorProperty? executorProperty;
String? name;
String? type;
Action({ Action({
required this.actionExecutor, required this.actionExecutor,
required this.entityId, required this.entityId,
required this.executorProperty, this.executorProperty,
this.name,
this.type,
}); });
String toRawJson() => json.encode(toJson()); String toRawJson() => json.encode(toJson());
static Action? fromJson(Map<String, dynamic> json) { static Action? fromJson(Map<String, dynamic> json) {
if (json['name'] != null && json['type'] != null) {
return Action(
actionExecutor: json["actionExecutor"],
entityId: json["entityId"],
name: json['name'],
type: json['type'],
);
}
if (json["executorProperty"] == null) { if (json["executorProperty"] == null) {
return null; // Return null if executorProperty is not present return null;
} }
return Action( return Action(
@ -90,7 +102,7 @@ class Action {
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
"actionExecutor": actionExecutor, "actionExecutor": actionExecutor,
"entityId": entityId, "entityId": entityId,
"executorProperty": executorProperty.toJson(), "executorProperty": executorProperty?.toJson(),
}; };
} }

View File

@ -3,12 +3,14 @@ class SmartSceneEnable {
final String actionExecutor; final String actionExecutor;
final String sceneORAutomationName; final String sceneORAutomationName;
final bool isAutomation; final bool isAutomation;
final String type;
SmartSceneEnable({ SmartSceneEnable({
required this.entityId, required this.entityId,
required this.actionExecutor, required this.actionExecutor,
required this.sceneORAutomationName, required this.sceneORAutomationName,
required this.isAutomation, required this.isAutomation,
required this.type,
}); });
factory SmartSceneEnable.fromJson(Map<String, dynamic> json) { factory SmartSceneEnable.fromJson(Map<String, dynamic> json) {
@ -17,6 +19,7 @@ class SmartSceneEnable {
actionExecutor: json['actionExecutor'], actionExecutor: json['actionExecutor'],
sceneORAutomationName: json['sceneORAutomationName'], sceneORAutomationName: json['sceneORAutomationName'],
isAutomation: json['isAutomation'], isAutomation: json['isAutomation'],
type: json['type'],
); );
} }
@ -26,6 +29,7 @@ class SmartSceneEnable {
'actionExecutor': actionExecutor, 'actionExecutor': actionExecutor,
'sceneORAutomationName': sceneORAutomationName, 'sceneORAutomationName': sceneORAutomationName,
'isAutomation': isAutomation, 'isAutomation': isAutomation,
'type': type,
}; };
} }
} }

View File

@ -24,17 +24,12 @@ class DeviceFunctionsView extends StatelessWidget
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
/// this whole widget needs a refactor later
///
/// static functions based on type
final device = (ModalRoute.of(context)?.settings.arguments as Map)['device'] final device = (ModalRoute.of(context)?.settings.arguments as Map)['device']
as DeviceModel; as DeviceModel;
final isAutomation = (ModalRoute.of(context)?.settings.arguments final isAutomation = (ModalRoute.of(context)?.settings.arguments
as Map)['isAutomationDeviceStatus'] as bool; as Map)['isAutomationDeviceStatus'] as bool;
/// static custom functions based on type
/// used for now until later backend fixes
List<SceneStaticFunction> functions = []; List<SceneStaticFunction> functions = [];
if (device.functions.isNotEmpty) { if (device.functions.isNotEmpty) {
functions = getFunctionsWithIcons( functions = getFunctionsWithIcons(
@ -47,128 +42,133 @@ class DeviceFunctionsView extends StatelessWidget
} }
return DefaultScaffold( return DefaultScaffold(
title: getTitle(type: device.productType), title: getTitle(type: device.productType),
actions: [ actions: [
TextButton( TextButton(
onPressed: () {
context
.read<CreateSceneBloc>()
.add(AddTaskEvent(isAutomation: isAutomation));
navigateToRoute(context, Routes.sceneTasksRoute);
},
child: BodyMedium(
text: 'Save',
fontWeight: FontWeight.normal,
fontColor: ColorsManager.secondaryColor.withOpacity(0.6),
),
),
],
leading: TextButton(
onPressed: () { onPressed: () {
final automationSelectedValue = context
context.read<CreateSceneBloc>().automationSelectedValues; .read<CreateSceneBloc>()
for (var element in device.functions) { .add(AddTaskEvent(isAutomation: isAutomation));
if (automationSelectedValue.containsKey(element.code)) { navigateToRoute(context, Routes.sceneTasksRoute);
context.read<CreateSceneBloc>().add(RemoveTempTaskByIdEvent(
code: element.code!, isAutomation: true));
context.read<CreateSceneBloc>().add(RemoveFromSelectedValueById(
code: element.code!, isAutomation: true));
}
}
final selectedValue =
context.read<CreateSceneBloc>().selectedValues;
for (var element in device.functions) {
if (selectedValue.containsKey(element.code)) {
context
.read<CreateSceneBloc>()
.add(RemoveTempTaskByIdEvent(code: element.code!));
context
.read<CreateSceneBloc>()
.add(RemoveFromSelectedValueById(code: element.code!));
}
}
Navigator.pop(context);
}, },
child: BodyMedium( child: BodyMedium(
text: 'Cancel', text: 'Save',
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
fontColor: ColorsManager.textPrimaryColor.withOpacity(0.6), fontColor: ColorsManager.secondaryColor.withOpacity(0.6),
), ),
), ),
leadingWidth: 80, ],
padding: EdgeInsets.zero, leading: TextButton(
child: ListView.builder( onPressed: () {
shrinkWrap: true, _cancelOperation(context, device, isAutomation);
itemCount: functions.length, },
padding: const EdgeInsets.only(top: 24.0), child: BodyMedium(
itemBuilder: (context, index) { text: 'Cancel',
return DefaultContainer( fontWeight: FontWeight.normal,
padding: index == 0 fontColor: ColorsManager.textPrimaryColor.withOpacity(0.6),
? const EdgeInsets.only(top: 8) ),
: index == functions.length - 1 ),
? const EdgeInsets.only(bottom: 8) leadingWidth: 80,
: EdgeInsets.zero, padding: EdgeInsets.zero,
margin: EdgeInsets.zero, child: ListView.builder(
borderRadius: index == 0 shrinkWrap: true,
? const BorderRadius.only( itemCount: functions.length,
topLeft: Radius.circular(20), padding: const EdgeInsets.only(top: 24.0),
topRight: Radius.circular(20)) itemBuilder: (context, index) {
: index == functions.length - 1 return DefaultContainer(
? const BorderRadius.only( padding: index == 0
bottomLeft: Radius.circular(20), ? const EdgeInsets.only(top: 8)
bottomRight: Radius.circular(20)) : index == functions.length - 1
: BorderRadius.zero, ? const EdgeInsets.only(bottom: 8)
child: Column( : EdgeInsets.zero,
mainAxisSize: MainAxisSize.min, margin: EdgeInsets.zero,
children: [ borderRadius: index == 0
BlocBuilder<CreateSceneBloc, CreateSceneState>( ? const BorderRadius.only(
builder: (context, state) { topLeft: Radius.circular(20), topRight: Radius.circular(20))
return SceneListTile( : index == functions.length - 1
iconsSize: 22, ? const BorderRadius.only(
minLeadingWidth: 20, bottomLeft: Radius.circular(20),
assetPath: functions[index].icon, bottomRight: Radius.circular(20))
titleString: functions[index].operationName, : BorderRadius.zero,
trailingWidget: const Row( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
/// selected value or the default value BlocBuilder<CreateSceneBloc, CreateSceneState>(
// BodyMedium(text: ), builder: (context, state) {
Icon( return SceneListTile(
Icons.arrow_forward_ios_rounded, iconsSize: 22,
color: ColorsManager.greyColor, minLeadingWidth: 20,
size: 16, assetPath: functions[index].icon,
), titleString: functions[index].operationName,
], trailingWidget: const Row(
), mainAxisSize: MainAxisSize.min,
onPressed: () { children: [
if (isAutomation) { Icon(
_showAutomationDialog( Icons.arrow_forward_ios_rounded,
context, color: ColorsManager.greyColor,
functions[index], size: 16,
device, ),
); ],
} else { ),
_showTabToRunDialog( onPressed: () {
context, if (isAutomation) {
functions[index], _showAutomationDialog(
device, context,
); functions[index],
} device,
}, );
); } else {
}, _showTabToRunDialog(
), context,
index != functions.length - 1 functions[index],
? SizedBox( device,
width: context.width * 0.8, );
child: const LightDivider()) }
: const SizedBox(), },
], );
), },
); ),
}, index != functions.length - 1
)); ? SizedBox(
width: context.width * 0.8, child: const LightDivider())
: const SizedBox(),
],
),
);
},
),
);
}
void _cancelOperation(
BuildContext context, DeviceModel device, bool isAutomation) {
final createSceneBloc = context.read<CreateSceneBloc>();
final automationSelectedValue = createSceneBloc.automationSelectedValues;
if (automationSelectedValue.isNotEmpty) {
for (var element in device.functions) {
if (automationSelectedValue.containsKey(element.code)) {
createSceneBloc.add(
RemoveTempTaskByIdEvent(code: element.code!, isAutomation: true));
createSceneBloc.add(RemoveFromSelectedValueById(
code: element.code!, isAutomation: true));
}
}
}
final selectedValue = createSceneBloc.selectedValues;
if (selectedValue.isNotEmpty) {
for (var element in device.functions) {
if (selectedValue.containsKey(element.code)) {
createSceneBloc.add(RemoveTempTaskByIdEvent(code: element.code!));
createSceneBloc.add(RemoveFromSelectedValueById(code: element.code!));
}
}
}
Navigator.pop(context);
createSceneBloc.add(const ClearTempTaskListEvent(isAutomation: false));
createSceneBloc.add(const ClearTempTaskListEvent(isAutomation: true));
} }
void _showTabToRunDialog( void _showTabToRunDialog(

View File

@ -1,9 +1,12 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
import 'package:syncrow_app/features/scene/view/scene_tasks_view.dart'; import 'package:syncrow_app/features/scene/view/scene_tasks_view.dart';
import 'package:syncrow_app/features/scene/widgets/effective_period_setting/effective_period_bottom_sheet.dart'; import 'package:syncrow_app/features/scene/widgets/effective_period_setting/effective_period_bottom_sheet.dart';
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart'; import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/utils/context_extension.dart'; import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import 'package:syncrow_app/utils/resource_manager/font_manager.dart'; import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
@ -17,7 +20,8 @@ class SceneAutoSettings extends StatelessWidget {
ModalRoute.of(context)!.settings.arguments as Map<String, dynamic>? ?? ModalRoute.of(context)!.settings.arguments as Map<String, dynamic>? ??
{}; {};
final sceneId = sceneSettings['sceneId'] as String? ?? ''; final sceneId = sceneSettings['sceneId'] as String? ?? '';
final isAutomation = sceneSettings['isAutomation'] as bool? ?? false; final isAutomation = context.read<CreateSceneBloc>().sceneType ==
CreateSceneEnum.deviceStatusChanges;
final sceneName = sceneSettings['sceneName'] as String? ?? ''; final sceneName = sceneSettings['sceneName'] as String? ?? '';
return Scaffold( return Scaffold(
@ -31,35 +35,79 @@ class SceneAutoSettings extends StatelessWidget {
fontWeight: FontsManager.bold, fontWeight: FontsManager.bold,
), ),
), ),
body: DefaultContainer( body: Stack(
padding: EdgeInsets.zero, children: [
child: Column( Container(
mainAxisSize: MainAxisSize.min, width: double.infinity,
mainAxisAlignment: MainAxisAlignment.center, height: context.height,
children: [ decoration: const BoxDecoration(
Visibility( color: ColorsManager.backgroundColor,
visible: isAutomation == true, image: DecorationImage(
child: SceneListTile( image: AssetImage(
padding: Assets.assetsImagesBackground,
const EdgeInsets.symmetric(horizontal: 16, vertical: 8), ),
titleString: "Effective Period", fit: BoxFit.cover,
trailingWidget: const Icon(Icons.arrow_forward_ios_rounded), opacity: 0.4,
onPressed: () {
context.customBottomSheet(
child: const EffectPeriodBottomSheetContent(),
);
},
), ),
), ),
Visibility( ),
visible: sceneName.isNotEmpty, Padding(
child: DeleteBottomSheetContent( padding: const EdgeInsets.symmetric(vertical: 16),
isAutomation: isAutomation, child: Container(
sceneId: sceneId, decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(16)),
),
constraints: const BoxConstraints(
maxWidth: 600,
maxHeight: 300,
),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: [
const SizedBox(
height: 8,
),
Visibility(
visible: isAutomation == true,
child: SceneListTile(
padding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 8),
titleString: "Effective Period",
trailingWidget:
const Icon(Icons.arrow_forward_ios_rounded),
onPressed: () {
context.customBottomSheet(
child: const EffectPeriodBottomSheetContent(),
);
},
),
),
Visibility(
visible: sceneName.isNotEmpty,
child: SizedBox(
width: context.width * 0.9,
child: const Divider(
color: ColorsManager.greyColor,
),
),
),
Visibility(
visible: sceneName.isNotEmpty,
child: DeleteBottomSheetContent(
isAutomation: isAutomation,
sceneId: sceneId,
),
),
const SizedBox(
height: 16,
),
],
), ),
), ),
], ),
), ],
), ),
); );
} }

View File

@ -11,7 +11,6 @@ import 'package:syncrow_app/features/scene/widgets/create_scene_save_button.dart
import 'package:syncrow_app/features/scene/widgets/if_then_containers/if_container.dart'; import 'package:syncrow_app/features/scene/widgets/if_then_containers/if_container.dart';
import 'package:syncrow_app/features/scene/widgets/if_then_containers/then_container.dart'; import 'package:syncrow_app/features/scene/widgets/if_then_containers/then_container.dart';
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart'; import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart'; import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
import 'package:syncrow_app/generated/assets.dart'; import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/navigation/navigate_to_route.dart'; import 'package:syncrow_app/navigation/navigate_to_route.dart';
@ -125,44 +124,39 @@ class DeleteBottomSheetContent extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DefaultContainer( return BlocConsumer<CreateSceneBloc, CreateSceneState>(
padding: EdgeInsets.zero, listener: (context, state) {
child: BlocConsumer<CreateSceneBloc, CreateSceneState>( if (state is DeleteSceneSuccess) {
listener: (context, state) { if (state.success) {
if (state is DeleteSceneSuccess) { navigateToRoute(context, Routes.homeRoute);
if (state.success) { BlocProvider.of<SceneBloc>(context)
navigateToRoute(context, Routes.homeRoute); .add(LoadScenes(HomeCubit.getInstance().selectedSpace!.id!));
BlocProvider.of<SceneBloc>(context).add( BlocProvider.of<SceneBloc>(context).add(
LoadScenes(HomeCubit.getInstance().selectedSpace!.id!)); LoadAutomation(HomeCubit.getInstance().selectedSpace!.id!));
BlocProvider.of<SceneBloc>(context).add( }
LoadAutomation(HomeCubit.getInstance().selectedSpace!.id!)); }
} },
} builder: (context, state) {
}, return SceneListTile(
builder: (context, state) { onPressed: () {
return DefaultContainer( context.read<CreateSceneBloc>().add(DeleteSceneEvent(
onTap: () { sceneId: sceneId,
context.read<CreateSceneBloc>().add(DeleteSceneEvent( unitUuid: HomeCubit.getInstance().selectedSpace!.id!,
sceneId: sceneId,
unitUuid: HomeCubit.getInstance().selectedSpace!.id!,
));
},
child: SceneListTile(
padding: const EdgeInsets.symmetric(horizontal: 8),
titleString: isAutomation
? StringsManager.deleteAutomation
: StringsManager.deleteScene,
leadingWidget: (state is DeleteSceneLoading)
? const SizedBox(
height: 24,
width: 24,
child: CircularProgressIndicator())
: SvgPicture.asset(
Assets.assetsDeleteIcon,
color: ColorsManager.red,
),
)); ));
}, },
)); padding: const EdgeInsets.symmetric(horizontal: 8),
titleString: isAutomation
? StringsManager.deleteAutomation
: StringsManager.deleteScene,
leadingWidget: (state is DeleteSceneLoading)
? const SizedBox(
height: 24, width: 24, child: CircularProgressIndicator())
: SvgPicture.asset(
Assets.assetsDeleteIcon,
color: ColorsManager.red,
),
);
},
);
} }
} }

View File

@ -39,11 +39,11 @@ class PeriodOptions extends StatelessWidget {
state.customStartTime != null && state.customEndTime != null state.customStartTime != null && state.customEndTime != null
? BodySmall( ? BodySmall(
text: text:
'${"${state.customStartTime} AM"} - ${"${state.customEndTime} PM"}', '${"${state.customStartTime}"} - ${"${state.customEndTime}"}',
style: context.bodySmall.copyWith(fontSize: 10), style: context.bodySmall.copyWith(fontSize: 10),
) )
: BodySmall( : BodySmall(
text: '00:00 AM - 11:59 PM', text: '00:00 - 23:59',
style: context.bodySmall.copyWith(fontSize: 10), style: context.bodySmall.copyWith(fontSize: 10),
), ),
trailing: Radio<EnumEffectivePeriodOptions>( trailing: Radio<EnumEffectivePeriodOptions>(

View File

@ -4,12 +4,14 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart'; import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart'; import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
import 'package:syncrow_app/features/scene/helper/scene_logic_helper.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/helper/scene_operations_data_helper.dart';
import 'package:syncrow_app/features/scene/model/scene_static_function.dart'; import 'package:syncrow_app/features/scene/model/scene_static_function.dart';
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart'; import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
import 'package:syncrow_app/features/scene/widgets/select_smart_scene/smart_automation_list.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/generated/assets.dart'; import 'package:syncrow_app/generated/assets.dart';
@ -63,7 +65,8 @@ class ThenAddedTasksContainer extends StatelessWidget
operationValue = functionValue.toString(); operationValue = functionValue.toString();
} }
return DefaultContainer( return DefaultContainer(
onTap: taskItem.code == CreateSceneEnum.smartSceneSelect.name onTap: taskItem.operationName == 'tap_to_run' ||
taskItem.operationName == 'scene'
? null ? null
: () { : () {
List<SceneStaticFunction> functionOperation = []; List<SceneStaticFunction> functionOperation = [];
@ -74,51 +77,77 @@ class ThenAddedTasksContainer extends StatelessWidget
deviceId: taskItem.deviceId, deviceId: taskItem.deviceId,
isAutomation: isAutomation ?? false)); isAutomation: isAutomation ?? false));
/// show alert dialog based on type if (taskItem.code == CreateSceneEnum.smartSceneSelect.name) {
context.customAlertDialog( context.customAlertDialog(
alertBody: getTheCorrectDialogBody( alertBody: EnableDisableAutomationDialog(
functionOperation.first, null, automationId: taskItem.deviceId,
isAutomation: isAutomation ?? false), descriptionSelected: taskItem.functionValue == 'rule_enable'
title: functionOperation.first.operationName, ? 'Enable'
onConfirm: () { : "Disable",
final savedCode = sceneORAutomationName: taskItem.deviceName,
functionOperation.first.deviceId.contains('delay') type: taskItem.operationName,
? 'delay' ),
: functionOperation.first.code; title: taskItem.deviceName,
if (isAutomation == true) { onConfirm: () {
final automationSelectedValue = context
createSceneBloc.automationSelectedValues[savedCode]; .read<SmartSceneSelectBloc>()
.add(const SmartSceneConfirmSelectionEvent());
Navigator.pop(context);
},
onDismiss: () {
context
.read<SmartSceneSelectBloc>()
.add(const SmartSceneClearEvent());
Navigator.pop(context);
},
);
} else {
/// show alert dialog based on type
context.customAlertDialog(
alertBody: getTheCorrectDialogBody(
functionOperation.first, null,
isAutomation: isAutomation ?? false),
title: functionOperation.first.operationName,
onConfirm: () {
final savedCode =
functionOperation.first.deviceId.contains('delay')
? 'delay'
: functionOperation.first.code;
if (isAutomation == true) {
final automationSelectedValue =
createSceneBloc.automationSelectedValues[savedCode];
try { try {
createSceneBloc.add( createSceneBloc.add(
UpdateTaskEvent( UpdateTaskEvent(
newValue: automationSelectedValue, newValue: automationSelectedValue,
taskId: taskItem.uniqueCustomId, taskId: taskItem.uniqueCustomId,
isAutomation: true, isAutomation: true,
), ),
); );
} catch (e) { } catch (e) {
debugPrint('Error adding UpdateTaskEvent: $e'); debugPrint('Error adding UpdateTaskEvent: $e');
}
} else {
final selectedValue =
createSceneBloc.selectedValues[savedCode];
try {
createSceneBloc.add(
UpdateTaskEvent(
newValue: selectedValue,
taskId: taskItem.uniqueCustomId,
),
);
} catch (e) {
debugPrint('Error adding UpdateTaskEvent: $e');
}
} }
} else {
final selectedValue =
createSceneBloc.selectedValues[savedCode];
try { Navigator.pop(context);
createSceneBloc.add( },
UpdateTaskEvent( );
newValue: selectedValue, }
taskId: taskItem.uniqueCustomId,
),
);
} catch (e) {
debugPrint('Error adding UpdateTaskEvent: $e');
}
}
Navigator.pop(context);
},
);
}, },
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
child: Dismissible( child: Dismissible(
@ -155,6 +184,9 @@ class ThenAddedTasksContainer extends StatelessWidget
taskId: removeFunctionById, taskId: removeFunctionById,
)); ));
} }
context
.read<SmartSceneSelectBloc>()
.add(const SmartSceneClearEvent());
String removeFunction = String removeFunction =
"${taskItem.operationName} with value ${taskItem.operationalValues.first.value}"; "${taskItem.operationName} with value ${taskItem.operationalValues.first.value}";
@ -177,17 +209,13 @@ class ThenAddedTasksContainer extends StatelessWidget
subtitleWidget: Row( subtitleWidget: Row(
children: [ children: [
BodyMedium( BodyMedium(
text: taskItem.code == CreateSceneEnum.smartSceneSelect.name text: getTaskDescription(taskItem),
? taskItem.icon.contains('player')
? 'Automation: '
: "Tab-To-Run: "
: "${taskItem.operationName}: ",
fontColor: ColorsManager.secondaryTextColor, fontColor: ColorsManager.secondaryTextColor,
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
), ),
BodyMedium( BodyMedium(
text: taskItem.code == CreateSceneEnum.smartSceneSelect.name text: taskItem.code == CreateSceneEnum.smartSceneSelect.name
? taskItem.operationName == 'rule_enable' ? taskItem.functionValue == 'rule_enable'
? 'Enable' ? 'Enable'
: "Disable" : "Disable"
: operationValue, : operationValue,

View File

@ -5,6 +5,7 @@ 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/bloc/create_scene/create_scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart'; import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart'; import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart'; import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
import 'package:syncrow_app/features/scene/model/scenes_model.dart'; import 'package:syncrow_app/features/scene/model/scenes_model.dart';
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart'; import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
@ -45,6 +46,7 @@ class SceneItem extends StatelessWidget {
sceneName: scene.name, sceneName: scene.name,
), ),
); );
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
if (disablePlayButton == false) { if (disablePlayButton == false) {
BlocProvider.of<CreateSceneBloc>(context) BlocProvider.of<CreateSceneBloc>(context)
.add(const SceneTypeEvent(CreateSceneEnum.tabToRun)); .add(const SceneTypeEvent(CreateSceneEnum.tabToRun));

View File

@ -126,9 +126,13 @@ class _SmartSceneSelectAutomationListState
automationId: automation.id, automationId: automation.id,
descriptionSelected: descriptionSelected, descriptionSelected: descriptionSelected,
sceneORAutomationName: automation.name, sceneORAutomationName: automation.name,
type: automation.type,
), ),
title: automation.name, title: automation.name,
onConfirm: () { onConfirm: () {
context
.read<SmartSceneSelectBloc>()
.add(const SmartSceneConfirmSelectionEvent());
Navigator.pop(context); Navigator.pop(context);
}, },
onDismiss: () { onDismiss: () {
@ -159,9 +163,13 @@ class _SmartSceneSelectAutomationListState
automationId: automation.id, automationId: automation.id,
descriptionSelected: descriptionSelected, descriptionSelected: descriptionSelected,
sceneORAutomationName: automation.name, sceneORAutomationName: automation.name,
type: automation.type,
), ),
title: automation.name, title: automation.name,
onConfirm: () { onConfirm: () {
context
.read<SmartSceneSelectBloc>()
.add(const SmartSceneConfirmSelectionEvent());
Navigator.pop(context); Navigator.pop(context);
}, },
onDismiss: () { onDismiss: () {
@ -194,11 +202,13 @@ class EnableDisableAutomationDialog extends StatefulWidget {
required this.automationId, required this.automationId,
required this.descriptionSelected, required this.descriptionSelected,
required this.sceneORAutomationName, required this.sceneORAutomationName,
required this.type,
}); });
final String automationId; final String automationId;
final String descriptionSelected; final String descriptionSelected;
final String sceneORAutomationName; final String sceneORAutomationName;
final String type;
@override @override
State<EnableDisableAutomationDialog> createState() => State<EnableDisableAutomationDialog> createState() =>
@ -226,6 +236,14 @@ class _EnableDisableAutomationDialogState
super.initState(); super.initState();
groupValue = groupValue =
widget.descriptionSelected == 'Enable' ? 'rule_enable' : 'rule_disable'; widget.descriptionSelected == 'Enable' ? 'rule_enable' : 'rule_disable';
context.read<SmartSceneSelectBloc>().add(SmartSceneEnableEvent(
SmartSceneEnable(
entityId: widget.automationId,
actionExecutor: groupValue!,
sceneORAutomationName: widget.sceneORAutomationName,
type: widget.type,
isAutomation: true)));
} }
@override @override
@ -259,6 +277,7 @@ class _EnableDisableAutomationDialogState
actionExecutor: value!, actionExecutor: value!,
sceneORAutomationName: sceneORAutomationName:
widget.sceneORAutomationName, widget.sceneORAutomationName,
type: widget.type,
isAutomation: true), isAutomation: true),
)); ));
}, },
@ -274,6 +293,7 @@ class _EnableDisableAutomationDialogState
entityId: widget.automationId, entityId: widget.automationId,
actionExecutor: operation.value, actionExecutor: operation.value,
sceneORAutomationName: widget.sceneORAutomationName, sceneORAutomationName: widget.sceneORAutomationName,
type: widget.type,
isAutomation: true, isAutomation: true,
), ),
)); ));

View File

@ -25,6 +25,7 @@ class SmartSceneSelectTabToRunList extends StatefulWidget {
class _SmartSceneSelectTabToRunListState class _SmartSceneSelectTabToRunListState
extends State<SmartSceneSelectTabToRunList> { extends State<SmartSceneSelectTabToRunList> {
String groupValue = ''; String groupValue = '';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(
@ -67,6 +68,13 @@ class _SmartSceneSelectTabToRunListState
itemCount: widget.scenes.length, itemCount: widget.scenes.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final scene = widget.scenes[index]; final scene = widget.scenes[index];
final selectedScene =
context.read<SmartSceneSelectBloc>().smartSceneEnable;
if (selectedScene != null) {
if (scene.id == selectedScene.entityId) {
groupValue = scene.id;
}
}
return SceneListTile( return SceneListTile(
padding: const EdgeInsets.symmetric(horizontal: 10), padding: const EdgeInsets.symmetric(horizontal: 10),
leadingWidget: Image.asset( leadingWidget: Image.asset(
@ -84,14 +92,19 @@ class _SmartSceneSelectTabToRunListState
setState(() { setState(() {
groupValue = value; groupValue = value;
}); });
context context
.read<SmartSceneSelectBloc>() .read<SmartSceneSelectBloc>()
.add(SmartSceneEnableEvent(SmartSceneEnable( .add(SmartSceneEnableEvent(SmartSceneEnable(
entityId: scene.id, entityId: scene.id,
actionExecutor: 'rule_enable', actionExecutor: 'rule_enable',
sceneORAutomationName: scene.name, sceneORAutomationName: scene.name,
type: scene.type,
isAutomation: false, isAutomation: false,
))); )));
context
.read<SmartSceneSelectBloc>()
.add(const SmartSceneConfirmSelectionEvent());
} }
}), }),
onPressed: () { onPressed: () {
@ -104,8 +117,12 @@ class _SmartSceneSelectTabToRunListState
entityId: scene.id, entityId: scene.id,
actionExecutor: 'rule_enable', actionExecutor: 'rule_enable',
sceneORAutomationName: scene.name, sceneORAutomationName: scene.name,
type: scene.type,
isAutomation: false, isAutomation: false,
))); )));
context
.read<SmartSceneSelectBloc>()
.add(const SmartSceneConfirmSelectionEvent());
}, },
); );
}), }),

View File

@ -27,13 +27,13 @@ class MyApp extends StatelessWidget {
return MultiBlocProvider( return MultiBlocProvider(
providers: [ providers: [
BlocProvider(create: (context) => AuthCubit()), BlocProvider(create: (context) => AuthCubit()),
BlocProvider(create: (context) => CreateSceneBloc()),
BlocProvider(create: (context) => SceneBloc()),
BlocProvider(create: (context) => ProfileBloc()),
BlocProvider(create: (context) => SmartSceneSelectBloc()),
BlocProvider( BlocProvider(
create: (context) => EffectPeriodBloc(), create: (context) => EffectPeriodBloc(),
), ),
BlocProvider(create: (context) => SmartSceneSelectBloc()),
BlocProvider(create: (context) => CreateSceneBloc()),
BlocProvider(create: (context) => SceneBloc()),
BlocProvider(create: (context) => ProfileBloc()),
], ],
child: MaterialApp( child: MaterialApp(
navigatorKey: NavigationService.navigatorKey, navigatorKey: NavigationService.navigatorKey,