Skip to content

Commit ff0221e

Browse files
committed
Move confirm check into LiveControls rather than Grouped shockers
1 parent 41270ce commit ff0221e

2 files changed

Lines changed: 28 additions & 17 deletions

File tree

lib/screens/shockers/grouped/grouped_shockers.dart

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,8 @@ class _GroupedShockerScreenState extends State<GroupedShockerScreen> {
6767
void executeAllLive(ControlType type, int intensity) {
6868
// Enforce the limit of the confirm ui
6969
// If the hard limit is on we do not need to show the dialog. redundancy is the limit function of the Controls themselves
70-
if(!AlarmListManager.getInstance().settings.enforceHardLimitInsteadOfShock && type == ControlType.shock
71-
&& AlarmListManager.getInstance().settings.confirmShock
72-
&& (intensity >= AlarmListManager.getInstance().settings.confirmShockMinIntensity)) {
73-
if(widget.confirmedNumber != ShockerItem.runningConfirmNumber) {
74-
if(widget.dialogShowing) return;
75-
widget.dialogShowing = true;
76-
YesCancelDialog.show("Shock Confirmation", "Are you sure you want to shock at $intensity Intensity. If you press yes the limit of ${AlarmListManager.getInstance().settings.confirmShockMinIntensity} will be removed for the remaining session. DECIDE WITH CARE!!!", () {
77-
widget.confirmedNumber = ShockerItem.runningConfirmNumber;
78-
widget.dialogShowing = false;
79-
Navigator.of(context).pop();
80-
}, onCancel: () {
81-
widget.dialogShowing = false;
82-
Navigator.of(context).pop();
83-
});
84-
return;
85-
}
86-
}
70+
71+
// The cofirm limits check is now performed in the call to this method so it applies to everything that uses the live controls ui instead of just this view
8772
List<Control> controls = [];
8873
for (Shocker s in AlarmListManager.getInstance().getSelectedShockers()) {
8974
controls.add(s.getLimitedControls(type, intensity, 300));

lib/screens/shockers/live/live_controls.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import 'package:flutter/material.dart';
66
import 'package:flutter/scheduler.dart';
77
import 'package:shock_alarm_app/dialogs/error_dialog.dart';
88
import 'package:shock_alarm_app/dialogs/info_dialog.dart';
9+
import 'package:shock_alarm_app/dialogs/yes_cancel_dialog.dart';
910
import 'package:shock_alarm_app/screens/shockers/live/pattern_chooser.dart';
11+
import 'package:shock_alarm_app/screens/shockers/shocker_item.dart';
1012
import 'package:shock_alarm_app/services/alarm_list_manager.dart';
1113
import 'package:shock_alarm_app/services/openshock.dart';
1214
import 'package:shock_alarm_app/services/openshockws.dart';
@@ -63,6 +65,10 @@ class LiveControls extends StatefulWidget {
6365
Function(ControlType, int, int)? liveEventDone;
6466

6567
String saveId = "global";
68+
69+
int confirmedNumber = -1;
70+
71+
bool dialogShowing = false;
6672

6773
LiveControls(
6874
{super.key,
@@ -243,6 +249,26 @@ class _LiveControlsState extends State<LiveControls> {
243249
float:
244250
LiveControlWS.liveControlSettings[widget.saveId]!.float,
245251
onSendLive: (intensity) {
252+
if(!AlarmListManager.getInstance().settings.enforceHardLimitInsteadOfShock && type == ControlType.shock
253+
&& AlarmListManager.getInstance().settings.confirmShock
254+
&& (intensity >= AlarmListManager.getInstance().settings.confirmShockMinIntensity)) {
255+
if(widget.confirmedNumber != ShockerItem.runningConfirmNumber) {
256+
if(widget.dialogShowing) return;
257+
258+
// Stop everything as in case loop is on the shock would just continue
259+
forceStop();
260+
widget.dialogShowing = true;
261+
YesCancelDialog.show("Shock Confirmation", "Are you sure you want to shock at $intensity Intensity. If you press yes the limit of ${AlarmListManager.getInstance().settings.confirmShockMinIntensity} will be removed for the remaining session. DECIDE WITH CARE!!!", () {
262+
widget.confirmedNumber = ShockerItem.runningConfirmNumber;
263+
widget.dialogShowing = false;
264+
Navigator.of(context).pop();
265+
}, onCancel: () {
266+
widget.dialogShowing = false;
267+
Navigator.of(context).pop();
268+
});
269+
return;
270+
}
271+
}
246272
widget.onSendLive(type, intensity);
247273
},
248274
onPlayDone: () {

0 commit comments

Comments
 (0)