Changed the action executor of the tab to run scenes and changed the order of the effective days

This commit is contained in:
Abdullah Alassaf
2024-08-07 15:52:27 +03:00
parent afe37dd68a
commit a32d885e50
4 changed files with 38 additions and 58 deletions

View File

@ -9,6 +9,16 @@ import 'package:syncrow_app/features/scene/model/create_automation_model.dart';
import 'package:syncrow_app/navigation/navigation_service.dart'; import 'package:syncrow_app/navigation/navigation_service.dart';
class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> { class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
final daysMap = {
'Sun': 'S',
'Mon': 'M',
'Tue': 'T',
'Wed': 'W',
'Thu': 'T',
'Fri': 'F',
'Sat': 'S',
};
EffectPeriodBloc() : super(EffectPeriodState.initial()) { EffectPeriodBloc() : super(EffectPeriodState.initial()) {
on<SetPeriod>(_onSetPeriod); on<SetPeriod>(_onSetPeriod);
on<ToggleDay>(_onToggleDay); on<ToggleDay>(_onToggleDay);
@ -43,20 +53,17 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
break; break;
} }
BlocProvider.of<CreateSceneBloc>( BlocProvider.of<CreateSceneBloc>(NavigationService.navigatorKey.currentContext!).add(
NavigationService.navigatorKey.currentContext!) EffectiveTimePeriodEvent(
.add(EffectiveTimePeriodEvent(EffectiveTime( EffectiveTime(start: startTime, end: endTime, loops: state.selectedDaysBinary)));
start: startTime, end: endTime, loops: state.selectedDaysBinary)));
emit(state.copyWith( emit(state.copyWith(
selectedPeriod: event.period, selectedPeriod: event.period, customStartTime: startTime, customEndTime: endTime));
customStartTime: startTime,
customEndTime: endTime));
} }
void _onToggleDay(ToggleDay event, Emitter<EffectPeriodState> emit) { void _onToggleDay(ToggleDay event, Emitter<EffectPeriodState> emit) {
final daysList = state.selectedDaysBinary.split(''); final daysList = state.selectedDaysBinary.split('');
final dayIndex = _getDayIndex(event.day); final dayIndex = getDayIndex(event.day);
if (daysList[dayIndex] == '1') { if (daysList[dayIndex] == '1') {
daysList[dayIndex] = '0'; daysList[dayIndex] = '0';
} else { } else {
@ -65,9 +72,8 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
final newDaysBinary = daysList.join(); final newDaysBinary = daysList.join();
emit(state.copyWith(selectedDaysBinary: newDaysBinary)); emit(state.copyWith(selectedDaysBinary: newDaysBinary));
BlocProvider.of<CreateSceneBloc>( BlocProvider.of<CreateSceneBloc>(NavigationService.navigatorKey.currentContext!).add(
NavigationService.navigatorKey.currentContext!) 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',
loops: newDaysBinary))); loops: newDaysBinary)));
@ -89,37 +95,31 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
period = EnumEffectivePeriodOptions.custom; period = EnumEffectivePeriodOptions.custom;
} }
emit(state.copyWith( emit(
customStartTime: startTime, state.copyWith(customStartTime: startTime, customEndTime: endTime, selectedPeriod: period));
customEndTime: endTime,
selectedPeriod: period));
BlocProvider.of<CreateSceneBloc>( BlocProvider.of<CreateSceneBloc>(NavigationService.navigatorKey.currentContext!).add(
NavigationService.navigatorKey.currentContext!) EffectiveTimePeriodEvent(
.add(EffectiveTimePeriodEvent(EffectiveTime( EffectiveTime(start: startTime, end: endTime, loops: state.selectedDaysBinary)));
start: startTime, end: endTime, loops: state.selectedDaysBinary)));
} }
void _onResetEffectivePeriod( void _onResetEffectivePeriod(ResetEffectivePeriod event, Emitter<EffectPeriodState> emit) {
ResetEffectivePeriod event, Emitter<EffectPeriodState> emit) {
emit(state.copyWith( emit(state.copyWith(
selectedPeriod: EnumEffectivePeriodOptions.allDay, selectedPeriod: EnumEffectivePeriodOptions.allDay,
customStartTime: '00:00', customStartTime: '00:00',
customEndTime: '23:59', customEndTime: '23:59',
selectedDaysBinary: '1111111')); selectedDaysBinary: '1111111'));
BlocProvider.of<CreateSceneBloc>( BlocProvider.of<CreateSceneBloc>(NavigationService.navigatorKey.currentContext!).add(
NavigationService.navigatorKey.currentContext!) EffectiveTimePeriodEvent(EffectiveTime(start: '00:00', end: '23:59', loops: '1111111')));
.add(EffectiveTimePeriodEvent(
EffectiveTime(start: '00:00', end: '23:59', loops: '1111111')));
} }
void _onResetDays(ResetDays event, Emitter<EffectPeriodState> emit) { void _onResetDays(ResetDays event, Emitter<EffectPeriodState> emit) {
emit(state.copyWith(selectedDaysBinary: '1111111')); emit(state.copyWith(selectedDaysBinary: '1111111'));
} }
int _getDayIndex(String day) { int getDayIndex(String day) {
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
return days.indexOf(day); return days.indexOf(day);
} }

View File

@ -13,16 +13,7 @@ class RepeatDays extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final daysMap = { final effectiveBloc = context.read<EffectPeriodBloc>();
'Mon': 'M',
'Tue': 'T',
'Wed': 'W',
'Thu': 'T',
'Fri': 'F',
'Sat': 'S',
'Sun': 'S',
};
return Row( return Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
@ -37,25 +28,22 @@ class RepeatDays extends StatelessWidget {
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: daysMap.entries.map((entry) { children: effectiveBloc.daysMap.entries.map((entry) {
final day = entry.key; final day = entry.key;
final abbreviation = entry.value; final abbreviation = entry.value;
final dayIndex = _getDayIndex(day); final dayIndex = effectiveBloc.getDayIndex(day);
final isSelected = final isSelected = state.selectedDaysBinary[dayIndex] == '1';
state.selectedDaysBinary[dayIndex] == '1';
return Padding( return Padding(
padding: const EdgeInsets.symmetric(horizontal: 3.0), padding: const EdgeInsets.symmetric(horizontal: 3.0),
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
context.read<EffectPeriodBloc>().add(ToggleDay(day)); effectiveBloc.add(ToggleDay(day));
}, },
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.circle,
border: Border.all( border: Border.all(
color: isSelected color: isSelected ? Colors.grey : Colors.grey.shade300,
? Colors.grey
: Colors.grey.shade300,
width: 1, width: 1,
), ),
), ),
@ -66,9 +54,7 @@ class RepeatDays extends StatelessWidget {
abbreviation, abbreviation,
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
color: isSelected color: isSelected ? Colors.grey : Colors.grey.shade300,
? Colors.grey
: Colors.grey.shade300,
), ),
), ),
), ),
@ -83,8 +69,7 @@ class RepeatDays extends StatelessWidget {
if (state.selectedDaysBinary == '0000000') if (state.selectedDaysBinary == '0000000')
BodySmall( BodySmall(
text: 'At least one day must be selected', text: 'At least one day must be selected',
style: style: context.bodyMedium.copyWith(color: ColorsManager.red),
context.bodyMedium.copyWith(color: ColorsManager.red),
), ),
], ],
); );
@ -93,9 +78,4 @@ class RepeatDays extends StatelessWidget {
], ],
); );
} }
int _getDayIndex(String day) {
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
return days.indexOf(day);
}
} }

View File

@ -93,7 +93,7 @@ class _SmartSceneSelectTabToRunListState extends State<SmartSceneSelectTabToRunL
.read<SmartSceneSelectBloc>() .read<SmartSceneSelectBloc>()
.add(SmartSceneEnableEvent(SmartSceneEnable( .add(SmartSceneEnableEvent(SmartSceneEnable(
entityId: scene.id, entityId: scene.id,
actionExecutor: 'rule_enable', actionExecutor: 'rule_trigger',
sceneORAutomationName: scene.name, sceneORAutomationName: scene.name,
type: scene.type, type: scene.type,
isAutomation: false, isAutomation: false,
@ -109,7 +109,7 @@ class _SmartSceneSelectTabToRunListState extends State<SmartSceneSelectTabToRunL
}); });
context.read<SmartSceneSelectBloc>().add(SmartSceneEnableEvent(SmartSceneEnable( context.read<SmartSceneSelectBloc>().add(SmartSceneEnableEvent(SmartSceneEnable(
entityId: scene.id, entityId: scene.id,
actionExecutor: 'rule_enable', actionExecutor: 'rule_trigger',
sceneORAutomationName: scene.name, sceneORAutomationName: scene.name,
type: scene.type, type: scene.type,
isAutomation: false, isAutomation: false,

View File

@ -5,7 +5,7 @@ description: This is the mobile application project, developed with Flutter for
# pub.dev using `flutter pub publish`. This is preferred for private packages. # pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: "none" # Remove this line if you wish to publish to pub.dev publish_to: "none" # Remove this line if you wish to publish to pub.dev
version: 1.0.2+18 version: 1.0.2+19
environment: environment:
sdk: ">=3.0.6 <4.0.0" sdk: ">=3.0.6 <4.0.0"