diff --git a/lib/bloc/chaban_bridge_status/chaban_bridge_status_bloc.dart b/lib/bloc/chaban_bridge_status/chaban_bridge_status_bloc.dart index 2ab3a11f..cb424ae2 100644 --- a/lib/bloc/chaban_bridge_status/chaban_bridge_status_bloc.dart +++ b/lib/bloc/chaban_bridge_status/chaban_bridge_status_bloc.dart @@ -1,4 +1,5 @@ import 'package:chabo/bloc/chabo_event.dart'; +import 'package:chabo/const.dart'; import 'package:chabo/extensions/color_scheme_extension.dart'; import 'package:chabo/extensions/string_extension.dart'; import 'package:chabo/models/abstract_chaban_bridge_forecast.dart'; @@ -9,6 +10,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:intl/intl.dart'; part 'chaban_bridge_status_event.dart'; + part 'chaban_bridge_status_state.dart'; class ChabanBridgeStatusBloc @@ -20,6 +22,18 @@ class ChabanBridgeStatusBloc on( _onRefresh, ); + on( + _onDurationChanged, + ); + } + + void _onDurationChanged(ChabanBridgeStatusDurationChanged event, + Emitter emit) { + emit( + state.copyWith( + durationForCloseClosing: event.duration, + ), + ); } void _onChabanBridgeStatusChanged( @@ -58,7 +72,9 @@ class ChabanBridgeStatusBloc final currentChabanBridgeForecast = state.currentChabanBridgeForecast; if (currentChabanBridgeForecast != null) { final isOpen = !currentChabanBridgeForecast.isCurrentlyClosed(); - if (isOpen && state.durationUntilNextEvent.inMinutes < 120) { + if (isOpen && + state.durationUntilNextEvent.inMinutes < + state.durationForCloseClosing.inMinutes) { return Theme.of(context).colorScheme.warningColor; } else if (isOpen) { return Colors.green; @@ -74,7 +90,9 @@ class ChabanBridgeStatusBloc final currentChabanBridgeForecast = state.currentChabanBridgeForecast; if (currentChabanBridgeForecast != null) { final isOpen = !currentChabanBridgeForecast.isCurrentlyClosed(); - if (isOpen || state.durationUntilNextEvent.inMinutes < 120) { + if (isOpen || + state.durationUntilNextEvent.inMinutes < + state.durationForCloseClosing.inMinutes) { return Theme.of(context).colorScheme.background; } else { return Theme.of(context).colorScheme.onError; @@ -101,11 +119,13 @@ class ChabanBridgeStatusBloc final currentChabanBridgeForecast = state.currentChabanBridgeForecast; if (currentChabanBridgeForecast != null && !currentChabanBridgeForecast.isCurrentlyClosed() && - state.durationUntilNextEvent.inMinutes >= 120) { + state.durationUntilNextEvent.inMinutes >= + state.durationForCloseClosing.inMinutes) { return '${_getGreetings(context)}, ${AppLocalizations.of(context)!.theBridgeIsCurrently} ${AppLocalizations.of(context)!.open}'; } else if (currentChabanBridgeForecast != null && !currentChabanBridgeForecast.isCurrentlyClosed() && - state.durationUntilNextEvent.inMinutes < 120) { + state.durationUntilNextEvent.inMinutes < + state.durationForCloseClosing.inMinutes) { return '${_getGreetings(context)}, ${AppLocalizations.of(context)!.theBridgeIsCurrently} ${AppLocalizations.of(context)!.aboutToClose}'; } else { return '${_getGreetings(context)}, ${AppLocalizations.of(context)!.theBridgeIsCurrently} ${AppLocalizations.of(context)!.closed}'; diff --git a/lib/bloc/chaban_bridge_status/chaban_bridge_status_event.dart b/lib/bloc/chaban_bridge_status/chaban_bridge_status_event.dart index f5b76ef9..3f0ab772 100644 --- a/lib/bloc/chaban_bridge_status/chaban_bridge_status_event.dart +++ b/lib/bloc/chaban_bridge_status/chaban_bridge_status_event.dart @@ -19,3 +19,11 @@ class ChabanBridgeStatusRefresh extends ChabanBridgeStatusEvent { required this.context, }) : super(); } + +class ChabanBridgeStatusDurationChanged extends ChabanBridgeStatusEvent { + final Duration duration; + + ChabanBridgeStatusDurationChanged({ + required this.duration, + }) : super(); +} diff --git a/lib/bloc/chaban_bridge_status/chaban_bridge_status_state.dart b/lib/bloc/chaban_bridge_status/chaban_bridge_status_state.dart index dcc5f089..4ff6129e 100644 --- a/lib/bloc/chaban_bridge_status/chaban_bridge_status_state.dart +++ b/lib/bloc/chaban_bridge_status/chaban_bridge_status_state.dart @@ -7,6 +7,7 @@ class ChabanBridgeStatusState extends Equatable { final AbstractChabanBridgeForecast? currentChabanBridgeForecast; final AbstractChabanBridgeForecast? previousChabanBridgeForecast; final Duration durationUntilNextEvent; + final Duration durationForCloseClosing; final Duration? durationBetweenPreviousAndNextEvent; final double completionPercentage; final String mainMessageStatus; @@ -19,6 +20,7 @@ class ChabanBridgeStatusState extends Equatable { required this.currentChabanBridgeForecast, required this.previousChabanBridgeForecast, required this.durationUntilNextEvent, + required this.durationForCloseClosing, required this.durationBetweenPreviousAndNextEvent, required this.completionPercentage, required this.mainMessageStatus, @@ -31,6 +33,7 @@ class ChabanBridgeStatusState extends Equatable { AbstractChabanBridgeForecast? currentChabanBridgeForecast, AbstractChabanBridgeForecast? previousChabanBridgeForecast, Duration? durationUntilNextEvent, + Duration? durationForCloseClosing, Duration? durationBetweenPreviousAndNextEvent, double? completionPercentage, String? mainMessageStatus, @@ -46,6 +49,8 @@ class ChabanBridgeStatusState extends Equatable { previousChabanBridgeForecast ?? this.previousChabanBridgeForecast, durationUntilNextEvent: durationUntilNextEvent ?? this.durationUntilNextEvent, + durationForCloseClosing: + durationForCloseClosing ?? this.durationForCloseClosing, durationBetweenPreviousAndNextEvent: durationBetweenPreviousAndNextEvent ?? this.durationBetweenPreviousAndNextEvent, @@ -62,6 +67,7 @@ class ChabanBridgeStatusState extends Equatable { currentChabanBridgeForecast, previousChabanBridgeForecast, durationUntilNextEvent, + durationForCloseClosing, durationBetweenPreviousAndNextEvent, completionPercentage, mainMessageStatus, @@ -78,6 +84,8 @@ class ChabanBridgeStatusStateInitial extends ChabanBridgeStatusState { currentChabanBridgeForecast: null, durationUntilNextEvent: Duration.zero, durationBetweenPreviousAndNextEvent: null, + durationForCloseClosing: + Const.notificationDurationValueDefaultValue, chabanBridgeStatusLifespan: ChabanBridgeStatusLifespan.empty, completionPercentage: 0, mainMessageStatus: '', diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 4a5cf523..d439ba90 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -50,7 +50,7 @@ "duration": {} } }, - "durationNotificationExplanation": "Receive a notification {duration}before the next closing", + "durationNotificationExplanation": "Receive a notification {duration}before the next closing. This value also manages the color change of the current status", "@durationNotificationExplanation": { "placeholders": { "duration": {} diff --git a/lib/l10n/app_es.arb b/lib/l10n/app_es.arb index f9dbf339..74822f77 100644 --- a/lib/l10n/app_es.arb +++ b/lib/l10n/app_es.arb @@ -50,7 +50,7 @@ "duration": {} } }, - "durationNotificationExplanation": "Reciba una notificación {duration}antes del próximo cierre", + "durationNotificationExplanation": "Reciba una notificación {duration}antes del próximo cierre. Este valor también gestiona el cambio de color del estado actual", "@durationNotificationExplanation": { "placeholders": { "duration": {} diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index 57fb4f12..c4cbd3b4 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -50,7 +50,7 @@ "duration": {} } }, - "durationNotificationExplanation": "Recevoir une notification {duration}avant la prochaine fermeture", + "durationNotificationExplanation": "Recevoir une notification {duration}avant la prochaine fermeture. Cette valeur gère aussi le changement de couleur du statur actuel", "@durationNotificationExplanation": { "placeholders": { "duration": {} diff --git a/lib/main.dart b/lib/main.dart index d322d42b..2596d76e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,9 +1,7 @@ import 'package:chabo/chabo.dart'; import 'package:chabo/service/notification_service.dart'; import 'package:chabo/service/storage_service.dart'; -import 'package:chabo/simple_bloc_observer.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -18,8 +16,6 @@ void main() async { ); MobileAds.instance.initialize(); - Bloc.observer = SimpleBlocObserver(); - runApp( Chabo( storageService: storageService, diff --git a/lib/screens/chaban_bridge_forecast_screen.dart b/lib/screens/chaban_bridge_forecast_screen.dart index b31dbd40..f429ee75 100644 --- a/lib/screens/chaban_bridge_forecast_screen.dart +++ b/lib/screens/chaban_bridge_forecast_screen.dart @@ -71,6 +71,12 @@ class _ChabanBridgeForecastScreenState ), BlocListener( listener: (context, state) async { + BlocProvider.of(context) + .add( + ChabanBridgeStatusDurationChanged( + duration: state.durationNotificationValue, + ), + ); ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Row(