Skip to content

Commit

Permalink
feat(recap-notifications): improvements & add time edit (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
vareversat authored Apr 20, 2023
2 parents f960981 + 71f2e38 commit 38ec91f
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 35 deletions.
19 changes: 19 additions & 0 deletions lib/bloc/notification/notification_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationSate> {
on<DayNotificationValueEvent>(
_onDayNotificationValueEvent,
);
on<DayNotificationTimeValueEvent>(
_onDayNotificationTimeValueEvent,
);
on<TimeNotificationStateEvent>(
_onTimeNotificationStateEvent,
);
Expand Down Expand Up @@ -101,6 +104,17 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationSate> {
);
}

Future<void> _onDayNotificationTimeValueEvent(
DayNotificationTimeValueEvent event,
Emitter<NotificationSate> emit) async {
await storageService.saveTimeOfDay(
Const.notificationDayTimeValueKey, event.time);
HapticFeedback.lightImpact();
emit(
state.copyWith(dayNotificationTimeValue: event.time),
);
}

Future<void> _onTimeNotificationStateEvent(
TimeNotificationStateEvent event, Emitter<NotificationSate> emit) async {
await storageService.saveBool(
Expand Down Expand Up @@ -167,6 +181,10 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationSate> {
storageService.readDay(Const.notificationDayValueKey) ??
Const.notificationDayValueDefaultValue;

final dayNotificationTimeValue =
storageService.readTimeOfDay(Const.notificationDayTimeValueKey) ??
Const.notificationDayValueDefaultTimeValue;

final openingNotificationEnabled =
storageService.readBool(Const.notificationOpeningEnabledKey) ??
Const.notificationOpeningEnabledDefaultValue;
Expand All @@ -183,6 +201,7 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationSate> {
timeNotificationValue: timeNotificationValue,
dayNotificationEnabled: dayNotificationEnabled,
dayNotificationValue: dayNotificationValue,
dayNotificationTimeValue: dayNotificationTimeValue,
openingNotificationEnabled: openingNotificationEnabled,
closingNotificationEnabled: closingNotificationEnabled),
);
Expand Down
6 changes: 6 additions & 0 deletions lib/bloc/notification/notification_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class DayNotificationValueEvent extends NotificationEvent {
DayNotificationValueEvent({required this.day}) : super();
}

class DayNotificationTimeValueEvent extends NotificationEvent {
final TimeOfDay time;

DayNotificationTimeValueEvent({required this.time}) : super();
}

class DurationNotificationValueEvent extends NotificationEvent {
final Duration duration;

Expand Down
2 changes: 2 additions & 0 deletions lib/const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Const {
'NOTIFICATION_DAY_SETTINGS_ENABLED';
static const String notificationDayValueKey =
'NOTIFICATION_DAY_SETTINGS_VALUE';
static const String notificationDayTimeValueKey =
'NOTIFICATION_DAY_TIME_SETTINGS_VALUE';
static const String notificationOpeningEnabledKey =
'NOTIFICATION_OPENING_SETTINGS_ENABLED';
static const String notificationClosingEnabledKey =
Expand Down
108 changes: 76 additions & 32 deletions lib/dialogs/days_of_the_week_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:chabo/custom_properties.dart';
import 'package:chabo/bloc/notification/notification_bloc.dart';
import 'package:chabo/models/enums/day.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class DaysOfTheWeekDialog extends StatelessWidget {
final Day selectedDay;
Expand All @@ -11,46 +13,88 @@ class DaysOfTheWeekDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AlertDialog(
insetPadding: const EdgeInsets.symmetric(
horizontal: 20,
),
titlePadding: const EdgeInsets.all(0),
contentPadding: const EdgeInsets.all(20),
actionsPadding: const EdgeInsets.fromLTRB(
0,
0,
20,
10,
),
contentPadding: const EdgeInsets.all(15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
15,
),
),
content: Column(
mainAxisSize: MainAxisSize.min,
children: Day.values
.map(
(day) => RadioListTile<Day>(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
CustomProperties.borderRadius,
),
),
title: Text(
day.localizedName(context),
style: const TextStyle(
fontWeight: FontWeight.bold,
content: BlocBuilder<NotificationBloc, NotificationSate>(
builder: (context, state) {
return Wrap(
alignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 5,
runSpacing: 10,
children: [
ElevatedButton(
onPressed: () {},
child: DropdownButtonHideUnderline(
child: DropdownButton(
borderRadius: BorderRadius.circular(12.0),
onChanged: (Day? value) {
if (value != null) {
BlocProvider.of<NotificationBloc>(context).add(
DayNotificationValueEvent(
day: value,
),
);
}
},
value: state.dayNotificationValue,
items: Day.values
.map(
(day) => DropdownMenuItem<Day>(
value: day,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
day.localizedName(context),
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
),
),
)
.toList(),
),
),
value: day,
groupValue: selectedDay,
onChanged: (Day? value) {
Navigator.pop(context, value);
),
Text(
' ${AppLocalizations.of(context)!.dayNotificationAt} ',
style: Theme.of(context).textTheme.titleMedium,
),
ElevatedButton(
onPressed: () async {
var time = await showTimePicker(
initialEntryMode: TimePickerEntryMode.dialOnly,
context: context,
initialTime: state.dayNotificationTimeValue,
builder: (BuildContext context, Widget? child) {
return MediaQuery(
data: MediaQuery.of(context),
child: child!,
);
},
);
if (time != null) {
// ignore: use_build_context_synchronously
BlocProvider.of<NotificationBloc>(context).add(
DayNotificationTimeValueEvent(
time: time,
),
);
}
},
child: Text(
state.dayNotificationTimeValue.format(context),
style: Theme.of(context).textTheme.titleMedium,
),
),
)
.toList(),
],
);
},
),
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,6 @@
"leftHanded": "Left handed",
"rightHanded": "Right handed",
"statusLoadMessage": "Loading of the bridge's current status",
"loading": "Loading..."
"loading": "Loading...",
"dayNotificationAt": "at"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,6 @@
"leftHanded": "Zurdo.a",
"rightHanded": "Diestro.a",
"statusLoadMessage": "Carga del estado actual del puente",
"loading": "Cargando..."
"loading": "Cargando...",
"dayNotificationAt": "en las"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,6 @@
"leftHanded": "Gaucher.ère",
"rightHanded": "Droitier.ère",
"statusLoadMessage": "Chargement de l'état actuel du pont",
"loading": "Chargement..."
"loading": "Chargement...",
"dayNotificationAt": "à"
}

0 comments on commit 38ec91f

Please sign in to comment.