diff --git a/assets/icons/flush_icon.svg b/assets/icons/flush_icon.svg new file mode 100644 index 0000000..7ab3c69 --- /dev/null +++ b/assets/icons/flush_icon.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_bloc.dart b/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_bloc.dart index 28fafce..7790881 100644 --- a/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_bloc.dart +++ b/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_bloc.dart @@ -5,6 +5,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/flush_sensor_bloc/flush_sensor_event.dart'; import 'package:syncrow_app/features/devices/bloc/flush_sensor_bloc/flush_sensor_state.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; +import 'package:syncrow_app/features/devices/model/device_info_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/flush_sensor_model.dart'; import 'package:syncrow_app/features/devices/model/status_model.dart'; @@ -15,17 +16,17 @@ class FlushSensorBloc extends Bloc { late DeviceModel deviceModel; late FlushSensorModel deviceStatus; - FlushSensorBloc({required this.deviceId}) : super(InitialState()) { - on(_fetchFlushSensorStatus); - on(_changeIndicator); - on(_changeValue); - on(_flushSensorUpdated); - on(_getDeviceReports); + FlushSensorBloc({required this.deviceId}) : super(FlushSensorInitialState()) { + on(_fetchFlushSensorStatus); + on(_changeIndicator); + on(_changeValue); + on(_flushSensorUpdated); + on(_getDeviceReports); } void _fetchFlushSensorStatus( - InitialEvent event, Emitter emit) async { - emit(LoadingInitialState()); + FlushSensorInitialEvent event, Emitter emit) async { + emit(FlushSensorLoadingInitialState()); try { var response = await DevicesAPI.getDeviceStatus(deviceId); List statusModelList = []; @@ -33,10 +34,10 @@ class FlushSensorBloc extends Bloc { statusModelList.add(StatusModel.fromJson(status)); } deviceStatus = FlushSensorModel.fromJson(statusModelList); - emit(UpdateState(flushSensorModel: deviceStatus)); + emit(FlushSensorUpdateState(flushSensorModel: deviceStatus)); _listenToChanges(); } catch (e) { - emit(FailedState(error: e.toString())); + emit(FlushSensorFailedState(error: e.toString())); return; } } @@ -60,7 +61,7 @@ class FlushSensorBloc extends Bloc { }); deviceStatus = FlushSensorModel.fromJson(statusList); if (!isClosed) { - add(WallSensorUpdatedEvent()); + add(FlushSensorUpdatedEvent()); } }); } catch (_) { @@ -79,51 +80,53 @@ class FlushSensorBloc extends Bloc { } _flushSensorUpdated( - WallSensorUpdatedEvent event, Emitter emit) { - emit(UpdateState(flushSensorModel: deviceStatus)); + FlushSensorUpdatedEvent event, Emitter emit) { + emit(FlushSensorUpdateState(flushSensorModel: deviceStatus)); } - void _changeIndicator( - ChangeIndicatorEvent event, Emitter emit) async { - emit(LoadingNewSate(flushSensorModel: deviceStatus)); + void _changeIndicator(FlushSensorChangeIndicatorEvent event, + Emitter emit) async { + emit(FlushSensorLoadingNewSate(flushSensorModel: deviceStatus)); try { final response = await DevicesAPI.controlDevice( DeviceControlModel( deviceId: deviceId, code: 'indicator', value: !event.value), deviceId); - } catch (e) { - emit(FailedState(error: e.toString())); + emit(FlushSensorFailedState(error: e.toString())); return; } - emit(UpdateState(flushSensorModel: deviceStatus)); + emit(FlushSensorUpdateState(flushSensorModel: deviceStatus)); } void _changeValue( - ChangeValueEvent event, Emitter emit) async { - emit(LoadingNewSate(flushSensorModel: deviceStatus)); + FlushSensorChangeValueEvent event, Emitter emit) async { + emit(FlushSensorLoadingNewSate(flushSensorModel: deviceStatus)); try { final response = await DevicesAPI.controlDevice( DeviceControlModel( deviceId: deviceId, code: event.code, value: event.value), deviceId); } catch (e) { - emit(FailedState(error: e.toString())); + emit(FlushSensorFailedState(error: e.toString())); return; } - emit(UpdateState(flushSensorModel: deviceStatus)); + emit(FlushSensorUpdateState(flushSensorModel: deviceStatus)); } - void _getDeviceReports( - GetDeviceReportsEvent event, Emitter emit) async { - emit(LoadingInitialState()); + void _getDeviceReports(FlushSensorGetDeviceReportsEvent event, + Emitter emit) async { + emit(FlushSensorLoadingInitialState()); try { await DevicesAPI.getDeviceReports(deviceId, event.code).then((value) { - emit(DeviceReportsState(deviceReport: value, code: event.code)); + emit(FlushSensorDeviceReportsState( + deviceReport: value, code: event.code)); }); } catch (e) { - emit(FailedState(error: e.toString())); + emit(FlushSensorFailedState(error: e.toString())); return; } } + + } diff --git a/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_event.dart b/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_event.dart index 99c5aa5..ddcd0d1 100644 --- a/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_event.dart +++ b/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_event.dart @@ -7,33 +7,35 @@ abstract class FlushSensorEvent extends Equatable { List get props => []; } -class LoadingEvent extends FlushSensorEvent {} +class FlushSensorLoadingEvent extends FlushSensorEvent {} -class InitialEvent extends FlushSensorEvent {} +class FlushSensorInitialEvent extends FlushSensorEvent {} -class WallSensorUpdatedEvent extends FlushSensorEvent {} +class FlushSensorInitialDeviseInfo extends FlushSensorEvent {} -class ChangeIndicatorEvent extends FlushSensorEvent { +class FlushSensorUpdatedEvent extends FlushSensorEvent {} + +class FlushSensorChangeIndicatorEvent extends FlushSensorEvent { final bool value; - const ChangeIndicatorEvent({required this.value}); + const FlushSensorChangeIndicatorEvent({required this.value}); @override List get props => [value]; } -class ChangeValueEvent extends FlushSensorEvent { +class FlushSensorChangeValueEvent extends FlushSensorEvent { final dynamic value; final String code; - const ChangeValueEvent({required this.value, required this.code}); + const FlushSensorChangeValueEvent({required this.value, required this.code}); @override List get props => [value, code]; } -class GetDeviceReportsEvent extends FlushSensorEvent { +class FlushSensorGetDeviceReportsEvent extends FlushSensorEvent { final String deviceUuid; final String code; - const GetDeviceReportsEvent({ + const FlushSensorGetDeviceReportsEvent({ required this.deviceUuid, required this.code, }); diff --git a/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_state.dart b/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_state.dart index 5bbac2c..8fbc563 100644 --- a/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_state.dart +++ b/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_state.dart @@ -1,4 +1,5 @@ import 'package:equatable/equatable.dart'; +import 'package:syncrow_app/features/devices/model/device_info_model.dart'; import 'package:syncrow_app/features/devices/model/device_report_model.dart'; import 'package:syncrow_app/features/devices/model/flush_sensor_model.dart'; @@ -9,37 +10,43 @@ class FlushSensorState extends Equatable { List get props => []; } -class InitialState extends FlushSensorState {} +class FlushSensorInitialState extends FlushSensorState {} -class LoadingInitialState extends FlushSensorState {} +class FlushSensorLoadingInitialState extends FlushSensorState {} -class UpdateState extends FlushSensorState { +class FlushSensorUpdateState extends FlushSensorState { final FlushSensorModel flushSensorModel; - const UpdateState({required this.flushSensorModel}); + const FlushSensorUpdateState({required this.flushSensorModel}); @override List get props => [flushSensorModel]; } -class LoadingNewSate extends FlushSensorState { +class FlushSensorLoadingNewSate extends FlushSensorState { final FlushSensorModel flushSensorModel; - const LoadingNewSate({required this.flushSensorModel}); + const FlushSensorLoadingNewSate({required this.flushSensorModel}); @override List get props => [flushSensorModel]; } -class FailedState extends FlushSensorState { +class FlushSensorFailedState extends FlushSensorState { final String error; - const FailedState({required this.error}); + const FlushSensorFailedState({required this.error}); @override List get props => [error]; } -class DeviceReportsState extends FlushSensorState { +class FlushSensorDeviceReportsState extends FlushSensorState { final DeviceReport deviceReport; final String code; - const DeviceReportsState({required this.deviceReport, required this.code}); + const FlushSensorDeviceReportsState( + {required this.deviceReport, required this.code}); +} + +class FlushSensorLoadingDeviceInfo extends FlushSensorState { + final DeviceInfoModel? deviceInfo; + const FlushSensorLoadingDeviceInfo({this.deviceInfo}); } diff --git a/lib/features/devices/model/device_model.dart b/lib/features/devices/model/device_model.dart index 7abeb9e..79c2b9c 100644 --- a/lib/features/devices/model/device_model.dart +++ b/lib/features/devices/model/device_model.dart @@ -93,7 +93,7 @@ class DeviceModel { } else if (type == DeviceType.SOS) { tempIcon = Assets.sosHomeIcon; } else if (type == DeviceType.FlushMountedSensor) { - tempIcon = Assets.sosHomeIcon; + tempIcon = Assets.flushIcon; } else { tempIcon = Assets.assetsIconsLogo; } diff --git a/lib/features/devices/view/widgets/flush_sensor/flush_persence_records.dart b/lib/features/devices/view/widgets/flush_sensor/flush_persence_records.dart index a68535f..a86a160 100644 --- a/lib/features/devices/view/widgets/flush_sensor/flush_persence_records.dart +++ b/lib/features/devices/view/widgets/flush_sensor/flush_persence_records.dart @@ -15,7 +15,10 @@ class FlushPresenceRecords extends StatelessWidget { final String code; final String title; const FlushPresenceRecords( - {super.key, required this.deviceId, required this.code, required this.title}); + {super.key, + required this.deviceId, + required this.code, + required this.title}); @override Widget build(BuildContext context) { @@ -23,18 +26,23 @@ class FlushPresenceRecords extends StatelessWidget { title: title, child: BlocProvider( create: (context) => FlushSensorBloc(deviceId: deviceId) - ..add(GetDeviceReportsEvent(deviceUuid: deviceId, code: code)), - child: BlocBuilder(builder: (context, state) { + ..add(FlushSensorGetDeviceReportsEvent( + deviceUuid: deviceId, code: code)), + child: BlocBuilder( + builder: (context, state) { final Map> groupedRecords = {}; - if (state is LoadingInitialState) { + if (state is FlushSensorLoadingInitialState) { return const Center( - child: DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()), + child: DefaultContainer( + width: 50, height: 50, child: CircularProgressIndicator()), ); - } else if (state is DeviceReportsState) { + } else if (state is FlushSensorDeviceReportsState) { for (var record in state.deviceReport.data ?? []) { - final DateTime eventDateTime = DateTime.fromMillisecondsSinceEpoch(record.eventTime!); - final String formattedDate = DateFormat('EEEE, dd/MM/yyyy').format(eventDateTime); + final DateTime eventDateTime = + DateTime.fromMillisecondsSinceEpoch(record.eventTime!); + final String formattedDate = + DateFormat('EEEE, dd/MM/yyyy').format(eventDateTime); // Group by formatted date if (groupedRecords.containsKey(formattedDate)) { @@ -52,7 +60,8 @@ class FlushPresenceRecords extends StatelessWidget { itemCount: groupedRecords.length, itemBuilder: (context, index) { final String date = groupedRecords.keys.elementAt(index); - final List recordsForDate = groupedRecords[date]!; + final List recordsForDate = + groupedRecords[date]!; return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -75,9 +84,11 @@ class FlushPresenceRecords extends StatelessWidget { final int idx = entry.key; final DeviceEvent record = entry.value; final DateTime eventDateTime = - DateTime.fromMillisecondsSinceEpoch(record.eventTime!); + DateTime.fromMillisecondsSinceEpoch( + record.eventTime!); final String formattedTime = - DateFormat('HH:mm:ss').format(eventDateTime); + DateFormat('HH:mm:ss') + .format(eventDateTime); return Column( children: [ @@ -87,10 +98,14 @@ class FlushPresenceRecords extends StatelessWidget { record.value == 'true' ? Icons.radio_button_checked : Icons.radio_button_unchecked, - color: record.value == 'true' ? Colors.blue : Colors.grey, + color: record.value == 'true' + ? Colors.blue + : Colors.grey, ), title: Text( - record.value == 'true' ? "Opened" : "Closed", + record.value == 'true' + ? "Opened" + : "Closed", style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 18, diff --git a/lib/features/devices/view/widgets/flush_sensor/flush_sensor_interface.dart b/lib/features/devices/view/widgets/flush_sensor/flush_sensor_interface.dart index 085f173..341ccc7 100644 --- a/lib/features/devices/view/widgets/flush_sensor/flush_sensor_interface.dart +++ b/lib/features/devices/view/widgets/flush_sensor/flush_sensor_interface.dart @@ -8,9 +8,11 @@ import 'package:syncrow_app/features/devices/bloc/flush_sensor_bloc/flush_sensor import 'package:syncrow_app/features/devices/bloc/flush_sensor_bloc/flush_sensor_state.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/flush_sensor_model.dart'; +import 'package:syncrow_app/features/devices/view/device_settings/settings_page.dart'; import 'package:syncrow_app/features/devices/view/widgets/device_appbar.dart'; import 'package:syncrow_app/features/devices/view/widgets/flush_sensor/flush_persence_records.dart'; import 'package:syncrow_app/features/devices/view/widgets/flush_sensor/flush_sensor_option.dart'; +import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart'; import 'package:syncrow_app/generated/assets.dart'; @@ -31,7 +33,7 @@ class FlushMountedInterface extends StatelessWidget { Widget build(BuildContext context) { return BlocProvider( create: (context) => FlushSensorBloc(deviceId: deviceModel.uuid ?? '') - ..add(InitialEvent()), + ..add(FlushSensorInitialEvent()), child: BlocBuilder( builder: (context, state) { final bloc = BlocProvider.of(context); @@ -47,28 +49,23 @@ class FlushMountedInterface extends StatelessWidget { sensiReduce: 0, sensitivity: 0); - if (state is UpdateState) { + if (state is FlushSensorUpdateState) { flushSensorModel = state.flushSensorModel; - } else if (state is LoadingNewSate) { + } else if (state is FlushSensorLoadingNewSate) { flushSensorModel = state.flushSensorModel; } + return AnnotatedRegion( value: SystemUiOverlayStyle( statusBarColor: ColorsManager.primaryColor.withOpacity(0.5), statusBarIconBrightness: Brightness.light, ), - child: Scaffold( - backgroundColor: ColorsManager.backgroundColor, - extendBodyBehindAppBar: true, - extendBody: true, - appBar: DeviceAppbar( - deviceName: deviceModel.name!, - deviceUuid: deviceModel.uuid!, - ), - body: Container( + child: DefaultScaffold( + title: deviceModel.name!, + + child: Container( width: MediaQuery.sizeOf(context).width, height: MediaQuery.sizeOf(context).height, - padding: const EdgeInsets.all(Constants.defaultPadding), decoration: const BoxDecoration( image: DecorationImage( image: AssetImage( @@ -78,14 +75,14 @@ class FlushMountedInterface extends StatelessWidget { opacity: 0.4, ), ), - child: state is LoadingInitialState + child: state is FlushSensorLoadingInitialState ? const Center( child: RefreshProgressIndicator(), ) : SafeArea( child: RefreshIndicator( onRefresh: () async { - bloc.add(InitialEvent()); + bloc.add(FlushSensorInitialEvent()); }, child: ListView(children: [ SizedBox( diff --git a/lib/features/devices/view/widgets/flush_sensor/flush_sensor_options_list.dart b/lib/features/devices/view/widgets/flush_sensor/flush_sensor_options_list.dart index 38f8ffb..1619d7d 100644 --- a/lib/features/devices/view/widgets/flush_sensor/flush_sensor_options_list.dart +++ b/lib/features/devices/view/widgets/flush_sensor/flush_sensor_options_list.dart @@ -186,7 +186,7 @@ class FlushSensorOptionsList extends StatelessWidget { result = (result * 10).toInt(); } bloc.add( - ChangeValueEvent(value: result, code: controlCode), + FlushSensorChangeValueEvent(value: result, code: controlCode), ); } } diff --git a/lib/features/devices/view/widgets/flush_sensor/flush_sensor_parameter_control_dialog.dart b/lib/features/devices/view/widgets/flush_sensor/flush_sensor_parameter_control_dialog.dart index 1b4a052..ce12324 100644 --- a/lib/features/devices/view/widgets/flush_sensor/flush_sensor_parameter_control_dialog.dart +++ b/lib/features/devices/view/widgets/flush_sensor/flush_sensor_parameter_control_dialog.dart @@ -153,14 +153,10 @@ class FlushParameterControlDialogState ), InkWell( onTap: () { - if (widget.sensor.isOnline == null) { + if (widget.sensor.isOnline == null || !widget.sensor.isOnline!) { CustomSnackBar.displaySnackBar('The device is offline'); return; - } - if (!widget.sensor.isOnline!) { - CustomSnackBar.displaySnackBar('The device is offline'); - return; - } + } Navigator.pop(context, _value); }, child: Center( diff --git a/lib/generated/assets.dart b/lib/generated/assets.dart index 53cd6ae..700c631 100644 --- a/lib/generated/assets.dart +++ b/lib/generated/assets.dart @@ -1155,4 +1155,5 @@ class Assets { static const String targetConfirmTimeIcon = 'assets/icons/target_confirm_time_icon.svg'; static const String disappeDelayIcon = 'assets/icons/disappe_delay_icon.svg'; + static const String flushIcon = 'assets/icons/flush_icon.svg'; }