mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 22:54:54 +00:00
Changed the action executor of the tab to run scenes and changed the order of the effective days
This commit is contained in:
@ -9,6 +9,16 @@ import 'package:syncrow_app/features/scene/model/create_automation_model.dart';
|
||||
import 'package:syncrow_app/navigation/navigation_service.dart';
|
||||
|
||||
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()) {
|
||||
on<SetPeriod>(_onSetPeriod);
|
||||
on<ToggleDay>(_onToggleDay);
|
||||
@ -43,20 +53,17 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
|
||||
break;
|
||||
}
|
||||
|
||||
BlocProvider.of<CreateSceneBloc>(
|
||||
NavigationService.navigatorKey.currentContext!)
|
||||
.add(EffectiveTimePeriodEvent(EffectiveTime(
|
||||
start: startTime, end: endTime, loops: state.selectedDaysBinary)));
|
||||
BlocProvider.of<CreateSceneBloc>(NavigationService.navigatorKey.currentContext!).add(
|
||||
EffectiveTimePeriodEvent(
|
||||
EffectiveTime(start: startTime, end: endTime, loops: state.selectedDaysBinary)));
|
||||
|
||||
emit(state.copyWith(
|
||||
selectedPeriod: event.period,
|
||||
customStartTime: startTime,
|
||||
customEndTime: endTime));
|
||||
selectedPeriod: event.period, customStartTime: startTime, customEndTime: endTime));
|
||||
}
|
||||
|
||||
void _onToggleDay(ToggleDay event, Emitter<EffectPeriodState> emit) {
|
||||
final daysList = state.selectedDaysBinary.split('');
|
||||
final dayIndex = _getDayIndex(event.day);
|
||||
final dayIndex = getDayIndex(event.day);
|
||||
if (daysList[dayIndex] == '1') {
|
||||
daysList[dayIndex] = '0';
|
||||
} else {
|
||||
@ -65,9 +72,8 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
|
||||
final newDaysBinary = daysList.join();
|
||||
emit(state.copyWith(selectedDaysBinary: newDaysBinary));
|
||||
|
||||
BlocProvider.of<CreateSceneBloc>(
|
||||
NavigationService.navigatorKey.currentContext!)
|
||||
.add(EffectiveTimePeriodEvent(EffectiveTime(
|
||||
BlocProvider.of<CreateSceneBloc>(NavigationService.navigatorKey.currentContext!).add(
|
||||
EffectiveTimePeriodEvent(EffectiveTime(
|
||||
start: state.customStartTime ?? '00:00',
|
||||
end: state.customEndTime ?? '23:59',
|
||||
loops: newDaysBinary)));
|
||||
@ -89,37 +95,31 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
|
||||
period = EnumEffectivePeriodOptions.custom;
|
||||
}
|
||||
|
||||
emit(state.copyWith(
|
||||
customStartTime: startTime,
|
||||
customEndTime: endTime,
|
||||
selectedPeriod: period));
|
||||
emit(
|
||||
state.copyWith(customStartTime: startTime, customEndTime: endTime, selectedPeriod: period));
|
||||
|
||||
BlocProvider.of<CreateSceneBloc>(
|
||||
NavigationService.navigatorKey.currentContext!)
|
||||
.add(EffectiveTimePeriodEvent(EffectiveTime(
|
||||
start: startTime, end: endTime, loops: state.selectedDaysBinary)));
|
||||
BlocProvider.of<CreateSceneBloc>(NavigationService.navigatorKey.currentContext!).add(
|
||||
EffectiveTimePeriodEvent(
|
||||
EffectiveTime(start: startTime, end: endTime, loops: state.selectedDaysBinary)));
|
||||
}
|
||||
|
||||
void _onResetEffectivePeriod(
|
||||
ResetEffectivePeriod event, Emitter<EffectPeriodState> emit) {
|
||||
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')));
|
||||
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) {
|
||||
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
int getDayIndex(String day) {
|
||||
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
return days.indexOf(day);
|
||||
}
|
||||
|
||||
|
||||
@ -13,16 +13,7 @@ class RepeatDays extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final daysMap = {
|
||||
'Mon': 'M',
|
||||
'Tue': 'T',
|
||||
'Wed': 'W',
|
||||
'Thu': 'T',
|
||||
'Fri': 'F',
|
||||
'Sat': 'S',
|
||||
'Sun': 'S',
|
||||
};
|
||||
|
||||
final effectiveBloc = context.read<EffectPeriodBloc>();
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
@ -37,25 +28,22 @@ class RepeatDays extends StatelessWidget {
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: daysMap.entries.map((entry) {
|
||||
children: effectiveBloc.daysMap.entries.map((entry) {
|
||||
final day = entry.key;
|
||||
final abbreviation = entry.value;
|
||||
final dayIndex = _getDayIndex(day);
|
||||
final isSelected =
|
||||
state.selectedDaysBinary[dayIndex] == '1';
|
||||
final dayIndex = effectiveBloc.getDayIndex(day);
|
||||
final isSelected = state.selectedDaysBinary[dayIndex] == '1';
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 3.0),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
context.read<EffectPeriodBloc>().add(ToggleDay(day));
|
||||
effectiveBloc.add(ToggleDay(day));
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: isSelected
|
||||
? Colors.grey
|
||||
: Colors.grey.shade300,
|
||||
color: isSelected ? Colors.grey : Colors.grey.shade300,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
@ -66,9 +54,7 @@ class RepeatDays extends StatelessWidget {
|
||||
abbreviation,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: isSelected
|
||||
? Colors.grey
|
||||
: Colors.grey.shade300,
|
||||
color: isSelected ? Colors.grey : Colors.grey.shade300,
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -83,8 +69,7 @@ class RepeatDays extends StatelessWidget {
|
||||
if (state.selectedDaysBinary == '0000000')
|
||||
BodySmall(
|
||||
text: 'At least one day must be selected',
|
||||
style:
|
||||
context.bodyMedium.copyWith(color: ColorsManager.red),
|
||||
style: 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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ class _SmartSceneSelectTabToRunListState extends State<SmartSceneSelectTabToRunL
|
||||
.read<SmartSceneSelectBloc>()
|
||||
.add(SmartSceneEnableEvent(SmartSceneEnable(
|
||||
entityId: scene.id,
|
||||
actionExecutor: 'rule_enable',
|
||||
actionExecutor: 'rule_trigger',
|
||||
sceneORAutomationName: scene.name,
|
||||
type: scene.type,
|
||||
isAutomation: false,
|
||||
@ -109,7 +109,7 @@ class _SmartSceneSelectTabToRunListState extends State<SmartSceneSelectTabToRunL
|
||||
});
|
||||
context.read<SmartSceneSelectBloc>().add(SmartSceneEnableEvent(SmartSceneEnable(
|
||||
entityId: scene.id,
|
||||
actionExecutor: 'rule_enable',
|
||||
actionExecutor: 'rule_trigger',
|
||||
sceneORAutomationName: scene.name,
|
||||
type: scene.type,
|
||||
isAutomation: false,
|
||||
|
||||
@ -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.
|
||||
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:
|
||||
sdk: ">=3.0.6 <4.0.0"
|
||||
|
||||
Reference in New Issue
Block a user