1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 14:29:22 +00:00

Can reconfigure push notifications

This commit is contained in:
Pierre HUBERT 2021-04-13 17:21:00 +02:00
parent db49b6fa6b
commit 7e9a594bae
3 changed files with 27 additions and 2 deletions

View File

@ -1,5 +1,7 @@
import 'package:comunic/helpers/preferences_helper.dart';
import 'package:comunic/helpers/server_config_helper.dart';
import 'package:comunic/models/api_request.dart';
import 'package:comunic/utils/flutter_utils.dart';
/// Push notifications helper
///
@ -65,4 +67,9 @@ class PushNotificationsHelper {
.key)
.addString("firebase_token", firebaseToken)
.execWithThrow();
/// Is true if possible if push notifications are configurable
static bool get arePushNotificationsAvailable =>
srvConfig.notificationsPolicy.hasFirebase ||
(isAndroid && srvConfig.notificationsPolicy.hasFirebase);
}

View File

@ -15,8 +15,8 @@ import 'package:flutter/material.dart';
Future<void> showInitialPushNotificationsConfiguration(
BuildContext context) async {
// Check if no notifications service are available
if (!srvConfig.notificationsPolicy.hasIndependent &&
(!isAndroid || !srvConfig.notificationsPolicy.hasFirebase)) return;
if (!PushNotificationsHelper.arePushNotificationsAvailable)
return;
await Navigator.of(context).push(
MaterialPageRoute(builder: (c) => PushNotificationsConfigurationRoute()));

View File

@ -1,5 +1,7 @@
import 'package:comunic/helpers/push_notifications_helper.dart';
import 'package:comunic/helpers/settings_helper.dart';
import 'package:comunic/models/notifications_settings.dart';
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';
@ -23,9 +25,11 @@ class _NotificationsSettingsScreenState
final key = GlobalKey<AsyncScreenWidgetState>();
NotificationsSettings _settings;
PushNotificationsStatus _pushNotificationsStatus;
Future<void> _loadSettings() async {
_settings = await SettingsHelper.getNotificationsSettings();
_pushNotificationsStatus = await PushNotificationsHelper.getLocalStatus();
}
@override
@ -41,6 +45,20 @@ class _NotificationsSettingsScreenState
SettingsSection(
title: tr("Push notifications"),
tiles: [
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) {