diff --git a/lib/helpers/push_notifications_helper.dart b/lib/helpers/push_notifications_helper.dart index a92c181..f8037da 100644 --- a/lib/helpers/push_notifications_helper.dart +++ b/lib/helpers/push_notifications_helper.dart @@ -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); } diff --git a/lib/ui/routes/push_notifications_route.dart b/lib/ui/routes/push_notifications_route.dart index 6a4686f..bd66dc7 100644 --- a/lib/ui/routes/push_notifications_route.dart +++ b/lib/ui/routes/push_notifications_route.dart @@ -15,8 +15,8 @@ import 'package:flutter/material.dart'; Future 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())); diff --git a/lib/ui/routes/settings/notifications_settings.dart b/lib/ui/routes/settings/notifications_settings.dart index b52f162..d5a85b5 100644 --- a/lib/ui/routes/settings/notifications_settings.dart +++ b/lib/ui/routes/settings/notifications_settings.dart @@ -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(); NotificationsSettings _settings; + PushNotificationsStatus _pushNotificationsStatus; Future _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) {