Skip to content

Commit

Permalink
feat(ui): the color of the current status is managed by the Duration …
Browse files Browse the repository at this point in the history
…notification value
  • Loading branch information
vareversat committed Apr 16, 2023
1 parent 715261b commit 6fc0812
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 11 deletions.
28 changes: 24 additions & 4 deletions lib/bloc/chaban_bridge_status/chaban_bridge_status_bloc.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand All @@ -20,6 +22,18 @@ class ChabanBridgeStatusBloc
on<ChabanBridgeStatusRefresh>(
_onRefresh,
);
on<ChabanBridgeStatusDurationChanged>(
_onDurationChanged,
);
}

void _onDurationChanged(ChabanBridgeStatusDurationChanged event,
Emitter<ChabanBridgeStatusState> emit) {
emit(
state.copyWith(
durationForCloseClosing: event.duration,
),
);
}

void _onChabanBridgeStatusChanged(
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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}';
Expand Down
8 changes: 8 additions & 0 deletions lib/bloc/chaban_bridge_status/chaban_bridge_status_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ class ChabanBridgeStatusRefresh extends ChabanBridgeStatusEvent {
required this.context,
}) : super();
}

class ChabanBridgeStatusDurationChanged extends ChabanBridgeStatusEvent {
final Duration duration;

ChabanBridgeStatusDurationChanged({
required this.duration,
}) : super();
}
8 changes: 8 additions & 0 deletions lib/bloc/chaban_bridge_status/chaban_bridge_status_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -31,6 +33,7 @@ class ChabanBridgeStatusState extends Equatable {
AbstractChabanBridgeForecast? currentChabanBridgeForecast,
AbstractChabanBridgeForecast? previousChabanBridgeForecast,
Duration? durationUntilNextEvent,
Duration? durationForCloseClosing,
Duration? durationBetweenPreviousAndNextEvent,
double? completionPercentage,
String? mainMessageStatus,
Expand All @@ -46,6 +49,8 @@ class ChabanBridgeStatusState extends Equatable {
previousChabanBridgeForecast ?? this.previousChabanBridgeForecast,
durationUntilNextEvent:
durationUntilNextEvent ?? this.durationUntilNextEvent,
durationForCloseClosing:
durationForCloseClosing ?? this.durationForCloseClosing,
durationBetweenPreviousAndNextEvent:
durationBetweenPreviousAndNextEvent ??
this.durationBetweenPreviousAndNextEvent,
Expand All @@ -62,6 +67,7 @@ class ChabanBridgeStatusState extends Equatable {
currentChabanBridgeForecast,
previousChabanBridgeForecast,
durationUntilNextEvent,
durationForCloseClosing,
durationBetweenPreviousAndNextEvent,
completionPercentage,
mainMessageStatus,
Expand All @@ -78,6 +84,8 @@ class ChabanBridgeStatusStateInitial extends ChabanBridgeStatusState {
currentChabanBridgeForecast: null,
durationUntilNextEvent: Duration.zero,
durationBetweenPreviousAndNextEvent: null,
durationForCloseClosing:
Const.notificationDurationValueDefaultValue,
chabanBridgeStatusLifespan: ChabanBridgeStatusLifespan.empty,
completionPercentage: 0,
mainMessageStatus: '',
Expand Down
2 changes: 1 addition & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
Expand Down
2 changes: 1 addition & 1 deletion lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
Expand Down
2 changes: 1 addition & 1 deletion lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
Expand Down
4 changes: 0 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -18,8 +16,6 @@ void main() async {
);
MobileAds.instance.initialize();

Bloc.observer = SimpleBlocObserver();

runApp(
Chabo(
storageService: storageService,
Expand Down
6 changes: 6 additions & 0 deletions lib/screens/chaban_bridge_forecast_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class _ChabanBridgeForecastScreenState
),
BlocListener<NotificationBloc, NotificationSate>(
listener: (context, state) async {
BlocProvider.of<ChabanBridgeStatusBloc>(context)
.add(
ChabanBridgeStatusDurationChanged(
duration: state.durationNotificationValue,
),
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
Expand Down

0 comments on commit 6fc0812

Please sign in to comment.