1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00
comunicmobile/lib/ui/routes/forez_presence_settings_route.dart

91 lines
2.6 KiB
Dart
Raw Normal View History

2021-04-22 13:54:30 +00:00
import 'package:comunic/helpers/forez_presence_helper.dart';
import 'package:comunic/lists/forez_presences_set.dart';
import 'package:comunic/ui/widgets/async_screen_widget.dart';
import 'package:comunic/ui/widgets/forez_presence_calendar_widget.dart';
import 'package:comunic/utils/account_utils.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/log_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
/// Forez presence settings route
///
/// On this route, users can change there presence settings
///
/// @author Pierre Hubert
/// Show presence settings route
Future<void> showPresenceSettingsRoute(
BuildContext context, int? groupID) async =>
2021-04-22 13:54:30 +00:00
await Navigator.push(context,
MaterialPageRoute(builder: (c) => PresenceSettings(groupID: groupID!)));
2021-04-22 13:54:30 +00:00
class PresenceSettings extends StatefulWidget {
final int groupID;
const PresenceSettings({
Key? key,
required this.groupID,
2022-03-11 16:02:06 +00:00
}) : super(key: key);
2021-04-22 13:54:30 +00:00
@override
_PresenceSettingsState createState() => _PresenceSettingsState();
}
class _PresenceSettingsState extends State<PresenceSettings> {
late PresenceSet _currPresences;
2021-04-22 13:54:30 +00:00
Future<void> _load() async {
await ForezPresenceHelper.refreshCache(widget.groupID);
_currPresences =
await ForezPresenceHelper.getForUser(widget.groupID, userID());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(tr("Presence settings")!),
2021-04-22 13:54:30 +00:00
),
body: AsyncScreenWidget(
onReload: _load,
onBuild: _buildScreen,
errorMessage: tr("Failed to load data!")!,
2021-04-22 13:54:30 +00:00
),
);
}
Widget _buildScreen() => ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
tr("Please click on the day you will be in the plain, so that everyone gets informed ! ;)")!,
2021-04-22 13:54:30 +00:00
textAlign: TextAlign.center,
),
),
PresenceCalendarWidget(
presenceSet: _currPresences,
onDayClicked: _toggleDay,
),
],
);
void _toggleDay(DateTime dt) async {
try {
// Update current list
_currPresences.toggleDate(dt, userID());
// Update on server
if (_currPresences.containsDate(dt))
await ForezPresenceHelper.addDay(widget.groupID, dt);
else
await ForezPresenceHelper.delDay(widget.groupID, dt);
} catch (e, s) {
logError(e, s);
_currPresences.toggleDate(dt, userID());
snack(context, tr("Failed to update information!")!);
2021-04-22 13:54:30 +00:00
}
}
}