diff --git a/assets/icons/pause_ic.svg b/assets/icons/pause_ic.svg
new file mode 100644
index 0000000..c6f6d5c
--- /dev/null
+++ b/assets/icons/pause_ic.svg
@@ -0,0 +1,55 @@
+
diff --git a/assets/icons/play_ic.svg b/assets/icons/play_ic.svg
new file mode 100644
index 0000000..e9242b0
--- /dev/null
+++ b/assets/icons/play_ic.svg
@@ -0,0 +1,55 @@
+
diff --git a/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart b/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart
index be2df58..e582850 100644
--- a/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart
+++ b/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart
@@ -1,3 +1,5 @@
+import 'dart:async';
+
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_event.dart';
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_state.dart';
@@ -9,6 +11,7 @@ import 'package:syncrow_app/services/api/devices_api.dart';
class ThreeGangBloc extends Bloc {
final String threeGangId;
late ThreeGangModel deviceStatus;
+ Timer? _timer;
ThreeGangBloc({required this.threeGangId}) : super(InitialState()) {
on(_fetchThreeGangStatus);
@@ -17,6 +20,10 @@ class ThreeGangBloc extends Bloc {
on(_changeThirdSwitch);
on(_allOff);
on(_allOn);
+ on(_changeSliding);
+ on(_setCounterValue);
+ on(_getCounterValue);
+ on(_onTickTimer);
}
void _fetchThreeGangStatus(InitialEvent event, Emitter emit) async {
@@ -121,4 +128,74 @@ class ThreeGangBloc extends Bloc {
} catch (_) {}
emit(UpdateState(threeGangModel: deviceStatus));
}
+
+ void _changeSliding(ChangeSlidingSegment event, Emitter emit) async {
+ emit(ChangeSlidingSegmentState(value: event.value));
+ }
+
+ void _setCounterValue(SetCounterValue event, Emitter emit) async {
+ emit(LoadingNewSate(threeGangModel: deviceStatus));
+ try {
+ int seconds = (event.duration.inHours * 60 * 60) + (event.duration.inMinutes * 60);
+ final response = await DevicesAPI.controlDevice(
+ DeviceControlModel(deviceId: threeGangId, code: event.deviceCode, value: seconds),
+ threeGangId);
+
+ if (response['success'] ?? false) {
+ if (event.deviceCode == 'countdown_1') {
+ deviceStatus.firstCountDown = seconds;
+ } else if (event.deviceCode == 'countdown_2') {
+ deviceStatus.secondCountDown = seconds;
+ } else if (event.deviceCode == 'countdown_3') {
+ deviceStatus.thirdCountDown = seconds;
+ }
+ }
+ } catch (_) {}
+ emit(UpdateState(threeGangModel: deviceStatus));
+ }
+
+ void _getCounterValue(GetCounterEvent event, Emitter emit) async {
+ emit(LoadingInitialState());
+ try {
+ var response = await DevicesAPI.getDeviceStatus(threeGangId);
+ List statusModelList = [];
+ for (var status in response['status']) {
+ statusModelList.add(StatusModel.fromJson(status));
+ }
+ deviceStatus = ThreeGangModel.fromJson(statusModelList);
+
+ if (event.deviceCode == 'countdown_1') {
+ deviceStatus.firstCountDown > 0
+ ? _onStartTimer(deviceStatus.firstCountDown)
+ : emit(UpdateTimerState(seconds: deviceStatus.firstCountDown));
+ } else if (event.deviceCode == 'countdown_2') {
+ deviceStatus.secondCountDown > 0
+ ? _onStartTimer(deviceStatus.secondCountDown)
+ : emit(UpdateTimerState(seconds: deviceStatus.secondCountDown));
+ } else if (event.deviceCode == 'countdown_3') {
+ deviceStatus.thirdCountDown > 0
+ ? _onStartTimer(deviceStatus.thirdCountDown)
+ : emit(UpdateTimerState(seconds: deviceStatus.thirdCountDown));
+ }
+ } catch (e) {
+ emit(FailedState(error: e.toString()));
+ return;
+ }
+ }
+
+ void _onStartTimer(int seconds) {
+ _timer?.cancel();
+ _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
+ add(TickTimer(seconds - timer.tick));
+ });
+ }
+
+ void _onTickTimer(TickTimer event, Emitter emit) {
+ if (event.remainingTime > 0) {
+ emit(TimerRunInProgress(event.remainingTime));
+ } else {
+ _timer?.cancel();
+ emit(TimerRunComplete());
+ }
+ }
}
diff --git a/lib/features/devices/bloc/three_gang_bloc/three_gang_event.dart b/lib/features/devices/bloc/three_gang_bloc/three_gang_event.dart
index b7e799c..a7ff0eb 100644
--- a/lib/features/devices/bloc/three_gang_bloc/three_gang_event.dart
+++ b/lib/features/devices/bloc/three_gang_bloc/three_gang_event.dart
@@ -35,3 +35,45 @@ class ChangeThirdSwitchStatusEvent extends ThreeGangEvent {
class AllOffEvent extends ThreeGangEvent {}
class AllOnEvent extends ThreeGangEvent {}
+
+class ChangeSlidingSegment extends ThreeGangEvent {
+ final int value;
+ const ChangeSlidingSegment({required this.value});
+ @override
+ List