diff --git a/assets/icons/emptySchedule.svg b/assets/icons/emptySchedule.svg
new file mode 100644
index 0000000..da72622
--- /dev/null
+++ b/assets/icons/emptySchedule.svg
@@ -0,0 +1,15 @@
+
diff --git a/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart b/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart
index 09829c7..6a1b3f8 100644
--- a/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart
+++ b/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart
@@ -7,6 +7,7 @@ import 'package:syncrow_app/features/devices/bloc/two_gang_bloc/two_gang_state.d
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/devices/model/groupTwoGangModel.dart';
+import 'package:syncrow_app/features/devices/model/schedule_model.dart';
import 'package:syncrow_app/features/devices/model/status_model.dart';
import 'package:syncrow_app/features/devices/model/two_gang_model.dart';
import 'package:syncrow_app/services/api/devices_api.dart';
@@ -14,11 +15,11 @@ import 'package:syncrow_app/services/api/devices_api.dart';
class TwoGangBloc extends Bloc {
final String twoGangId;
TwoGangModel deviceStatus = TwoGangModel(
- firstSwitch: false,
- secondSwitch: false,
- firstCountDown: 0,
- secondCountDown: 0,
- );
+ firstSwitch: false,
+ secondSwitch: false,
+ firstCountDown: 0,
+ secondCountDown: 0,
+ );
Timer? _timer;
// Timer? _firstSwitchTimer;
// Timer? _secondSwitchTimer;
@@ -28,6 +29,20 @@ class TwoGangBloc extends Bloc {
List devicesList = [];
List groupTwoGangList = [];
bool allSwitchesOn = true;
+ List selectedDays = [];
+
+ bool createSchedule = false;
+ List listSchedule = [
+ ScheduleModel(
+ id: '1',
+ category: 'category',
+ enable: true,
+ function: FunctionModel(code: 'code', value: true),
+ time: 'time',
+ timerId: 'timerId',
+ timezoneId: 'timezoneId',
+ days: ['S'])
+ ];
TwoGangBloc({required this.twoGangId}) : super(InitialState()) {
on(_fetchTwoGangStatus);
@@ -43,9 +58,20 @@ class TwoGangBloc extends Bloc {
on(_onClose);
on(_groupAllOn);
on(_groupAllOff);
+ on(toggleDaySelection);
}
- void _fetchTwoGangStatus(InitialEvent event, Emitter emit) async {
+ DateTime? selectedTime;
+
+ void toggleCreateSchedule() {
+ emit(LoadingInitialState());
+ createSchedule = !createSchedule;
+ emit(UpdateCreateScheduleState(createSchedule));
+ emit(ChangeSlidingSegmentState(value: 1));
+ }
+
+ void _fetchTwoGangStatus(
+ InitialEvent event, Emitter emit) async {
emit(LoadingInitialState());
try {
twoGangGroup = event.groupScreen;
@@ -57,7 +83,8 @@ class TwoGangBloc extends Bloc {
HomeCubit.getInstance().selectedSpace?.id ?? '', '2G');
for (int i = 0; i < devicesList.length; i++) {
- var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
+ var response =
+ await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
List statusModelList = [];
for (var status in response['status']) {
statusModelList.add(StatusModel.fromJson(status));
@@ -65,23 +92,23 @@ class TwoGangBloc extends Bloc {
deviceStatus = TwoGangModel.fromJson(statusModelList);
groupTwoGangList.add(GroupTwoGangModel(
- deviceId: devicesList[i].uuid ?? '',
- deviceName: devicesList[i].name ?? '',
- firstSwitch: deviceStatus.firstSwitch,
- secondSwitch: deviceStatus.secondSwitch,
- )
- );
+ deviceId: devicesList[i].uuid ?? '',
+ deviceName: devicesList[i].name ?? '',
+ firstSwitch: deviceStatus.firstSwitch,
+ secondSwitch: deviceStatus.secondSwitch,
+ ));
}
if (groupTwoGangList.isNotEmpty) {
groupTwoGangList.firstWhere((element) {
- if (!element.firstSwitch || !element.secondSwitch ) {
+ if (!element.firstSwitch || !element.secondSwitch) {
allSwitchesOn = false;
}
return true;
});
}
- emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesOn));
+ emit(UpdateGroupState(
+ twoGangList: groupTwoGangList, allSwitches: allSwitchesOn));
} else {
var response = await DevicesAPI.getDeviceStatus(twoGangId);
List statusModelList = [];
@@ -100,18 +127,21 @@ class TwoGangBloc extends Bloc {
_listenToChanges() {
try {
- DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$twoGangId');
+ DatabaseReference ref =
+ FirebaseDatabase.instance.ref('device-status/$twoGangId');
Stream stream = ref.onValue;
stream.listen((DatabaseEvent event) async {
if (_timer != null) {
await Future.delayed(const Duration(seconds: 2));
}
- Map usersMap = event.snapshot.value as Map;
+ Map usersMap =
+ event.snapshot.value as Map;
List statusList = [];
usersMap['status'].forEach((element) {
- statusList.add(StatusModel(code: element['code'], value: element['value']));
+ statusList
+ .add(StatusModel(code: element['code'], value: element['value']));
});
deviceStatus = TwoGangModel.fromJson(statusList);
@@ -126,7 +156,8 @@ class TwoGangBloc extends Bloc {
emit(UpdateState(twoGangModel: deviceStatus));
}
- void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter emit) async {
+ void _changeFirstSwitch(
+ ChangeFirstSwitchStatusEvent event, Emitter emit) async {
emit(LoadingNewSate(twoGangModel: deviceStatus));
try {
deviceStatus.firstSwitch = !event.value;
@@ -189,13 +220,16 @@ class TwoGangBloc extends Bloc {
final response = await Future.wait([
DevicesAPI.controlDevice(
DeviceControlModel(
- deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch),
+ deviceId: twoGangId,
+ code: 'switch_1',
+ value: deviceStatus.firstSwitch),
twoGangId),
DevicesAPI.controlDevice(
DeviceControlModel(
- deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch),
+ deviceId: twoGangId,
+ code: 'switch_2',
+ value: deviceStatus.secondSwitch),
twoGangId),
-
]);
if (response.every((element) => !element['success'])) {
@@ -216,16 +250,17 @@ class TwoGangBloc extends Bloc {
emit(UpdateState(twoGangModel: deviceStatus));
final response = await Future.wait([
DevicesAPI.controlDevice(
- DeviceControlModel(
- deviceId: twoGangId, code: 'switch_1',
- value: deviceStatus.firstSwitch),
+ DeviceControlModel(
+ deviceId: twoGangId,
+ code: 'switch_1',
+ value: deviceStatus.firstSwitch),
twoGangId),
DevicesAPI.controlDevice(
- DeviceControlModel(
- deviceId: twoGangId,
- code: 'switch_2',
- value: deviceStatus.secondSwitch),
- twoGangId),
+ DeviceControlModel(
+ deviceId: twoGangId,
+ code: 'switch_2',
+ value: deviceStatus.secondSwitch),
+ twoGangId),
]);
if (response.every((element) => !element['success'])) {
await Future.delayed(const Duration(milliseconds: 500));
@@ -243,7 +278,6 @@ class TwoGangBloc extends Bloc {
for (int i = 0; i < groupTwoGangList.length; i++) {
groupTwoGangList[i].firstSwitch = true;
groupTwoGangList[i].secondSwitch = true;
-
}
emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: true));
@@ -251,11 +285,15 @@ class TwoGangBloc extends Bloc {
final response = await Future.wait([
DevicesAPI.controlDevice(
DeviceControlModel(
- deviceId: groupTwoGangList[i].deviceId, code: 'switch_1', value: true),
+ deviceId: groupTwoGangList[i].deviceId,
+ code: 'switch_1',
+ value: true),
groupTwoGangList[i].deviceId),
DevicesAPI.controlDevice(
DeviceControlModel(
- deviceId: groupTwoGangList[i].deviceId, code: 'switch_2', value: true),
+ deviceId: groupTwoGangList[i].deviceId,
+ code: 'switch_2',
+ value: true),
groupTwoGangList[i].deviceId),
]);
@@ -284,13 +322,16 @@ class TwoGangBloc extends Bloc {
final response = await Future.wait([
DevicesAPI.controlDevice(
DeviceControlModel(
- deviceId: groupTwoGangList[i].deviceId, code: 'switch_1', value: false),
+ deviceId: groupTwoGangList[i].deviceId,
+ code: 'switch_1',
+ value: false),
groupTwoGangList[i].deviceId),
DevicesAPI.controlDevice(
DeviceControlModel(
- deviceId: groupTwoGangList[i].deviceId, code: 'switch_2', value: false),
+ deviceId: groupTwoGangList[i].deviceId,
+ code: 'switch_2',
+ value: false),
groupTwoGangList[i].deviceId),
-
]);
if (response.every((element) => !element['success'])) {
@@ -305,17 +346,20 @@ class TwoGangBloc extends Bloc {
}
}
- void _changeSliding(ChangeSlidingSegment event, Emitter emit) async {
+ void _changeSliding(
+ ChangeSlidingSegment event, Emitter emit) async {
emit(ChangeSlidingSegmentState(value: event.value));
}
- void _setCounterValue(SetCounterValue event, Emitter emit) async {
+ void _setCounterValue(
+ SetCounterValue event, Emitter emit) async {
emit(LoadingNewSate(twoGangModel: deviceStatus));
int seconds = 0;
try {
seconds = event.duration.inSeconds;
final response = await DevicesAPI.controlDevice(
- DeviceControlModel(deviceId: twoGangId, code: event.deviceCode, value: seconds),
+ DeviceControlModel(
+ deviceId: twoGangId, code: event.deviceCode, value: seconds),
twoGangId);
if (response['success'] ?? false) {
@@ -340,7 +384,8 @@ class TwoGangBloc extends Bloc {
}
}
- void _getCounterValue(GetCounterEvent event, Emitter emit) async {
+ void _getCounterValue(
+ GetCounterEvent event, Emitter emit) async {
emit(LoadingInitialState());
try {
var response = await DevicesAPI.getDeviceStatus(twoGangId);
@@ -387,4 +432,38 @@ class TwoGangBloc extends Bloc {
emit(TimerRunComplete());
}
}
+
+ List