1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-23 05:19:22 +00:00
comunicmobile/lib/ui/routes/settings/notifications_settings.dart

88 lines
3.0 KiB
Dart
Raw Normal View History

2021-04-13 15:21:00 +00:00
import 'package:comunic/helpers/push_notifications_helper.dart';
import 'package:comunic/helpers/settings_helper.dart';
import 'package:comunic/models/notifications_settings.dart';
2021-04-13 15:21:00 +00:00
import 'package:comunic/ui/routes/push_notifications_route.dart';
import 'package:comunic/ui/widgets/async_screen_widget.dart';
import 'package:comunic/ui/widgets/settings/header_spacer_section.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';
import 'package:settings_ui/settings_ui.dart';
/// Notifications settings
///
/// @author Pierre Hubert
class NotificationsSettingsScreen extends StatefulWidget {
@override
_NotificationsSettingsScreenState createState() =>
_NotificationsSettingsScreenState();
}
class _NotificationsSettingsScreenState
extends State<NotificationsSettingsScreen> {
final key = GlobalKey<AsyncScreenWidgetState>();
NotificationsSettings _settings;
2021-04-13 15:21:00 +00:00
PushNotificationsStatus _pushNotificationsStatus;
Future<void> _loadSettings() async {
_settings = await SettingsHelper.getNotificationsSettings();
2021-04-13 15:21:00 +00:00
_pushNotificationsStatus = await PushNotificationsHelper.getLocalStatus();
}
@override
Widget build(BuildContext context) => AsyncScreenWidget(
key: key,
onReload: _loadSettings,
onBuild: _buildScreen,
errorMessage: tr("Failed to load notifications settings!"),
);
Widget _buildScreen() => SettingsList(sections: [
HeadSpacerSection(),
SettingsSection(
title: tr("Push notifications"),
tiles: [
2021-04-13 15:21:00 +00:00
SettingsTile(
title: tr("Push notifications status"),
subtitle: !PushNotificationsHelper.arePushNotificationsAvailable
? tr("Unavailable")
: (_pushNotificationsStatus ==
PushNotificationsStatus.DISABLED
? tr("Disabled")
: (_pushNotificationsStatus ==
PushNotificationsStatus.FIREBASE
? tr("Use Google services")
: tr("Use independent service"))),
onPressed: (c) =>
showInitialPushNotificationsConfiguration(context),
),
SettingsTile.switchTile(
title: tr("Allow conversations notification"),
onToggle: (v) {
_settings.allowConversations = v;
_updatedSettings();
},
switchValue: _settings.allowConversations,
subtitle:
tr("Receive notifications for the conversations you follow."),
2021-04-17 06:40:33 +00:00
titleMaxLines: 2,
subtitleMaxLines: 2,
)
],
)
]);
void _updatedSettings() async {
try {
await SettingsHelper.setNotificationsSettings(_settings);
setState(() {});
} catch (e, s) {
logError(e, s);
snack(context, tr("Failed to update settings!"));
}
}
}