mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 04:49:21 +00:00
Can reconfigure push notifications
This commit is contained in:
parent
db49b6fa6b
commit
7e9a594bae
@ -1,5 +1,7 @@
|
|||||||
import 'package:comunic/helpers/preferences_helper.dart';
|
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/models/api_request.dart';
|
||||||
|
import 'package:comunic/utils/flutter_utils.dart';
|
||||||
|
|
||||||
/// Push notifications helper
|
/// Push notifications helper
|
||||||
///
|
///
|
||||||
@ -65,4 +67,9 @@ class PushNotificationsHelper {
|
|||||||
.key)
|
.key)
|
||||||
.addString("firebase_token", firebaseToken)
|
.addString("firebase_token", firebaseToken)
|
||||||
.execWithThrow();
|
.execWithThrow();
|
||||||
|
|
||||||
|
/// Is true if possible if push notifications are configurable
|
||||||
|
static bool get arePushNotificationsAvailable =>
|
||||||
|
srvConfig.notificationsPolicy.hasFirebase ||
|
||||||
|
(isAndroid && srvConfig.notificationsPolicy.hasFirebase);
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,8 @@ import 'package:flutter/material.dart';
|
|||||||
Future<void> showInitialPushNotificationsConfiguration(
|
Future<void> showInitialPushNotificationsConfiguration(
|
||||||
BuildContext context) async {
|
BuildContext context) async {
|
||||||
// Check if no notifications service are available
|
// Check if no notifications service are available
|
||||||
if (!srvConfig.notificationsPolicy.hasIndependent &&
|
if (!PushNotificationsHelper.arePushNotificationsAvailable)
|
||||||
(!isAndroid || !srvConfig.notificationsPolicy.hasFirebase)) return;
|
return;
|
||||||
|
|
||||||
await Navigator.of(context).push(
|
await Navigator.of(context).push(
|
||||||
MaterialPageRoute(builder: (c) => PushNotificationsConfigurationRoute()));
|
MaterialPageRoute(builder: (c) => PushNotificationsConfigurationRoute()));
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
import 'package:comunic/helpers/push_notifications_helper.dart';
|
||||||
import 'package:comunic/helpers/settings_helper.dart';
|
import 'package:comunic/helpers/settings_helper.dart';
|
||||||
import 'package:comunic/models/notifications_settings.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/async_screen_widget.dart';
|
||||||
import 'package:comunic/ui/widgets/settings/header_spacer_section.dart';
|
import 'package:comunic/ui/widgets/settings/header_spacer_section.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
@ -23,9 +25,11 @@ class _NotificationsSettingsScreenState
|
|||||||
final key = GlobalKey<AsyncScreenWidgetState>();
|
final key = GlobalKey<AsyncScreenWidgetState>();
|
||||||
|
|
||||||
NotificationsSettings _settings;
|
NotificationsSettings _settings;
|
||||||
|
PushNotificationsStatus _pushNotificationsStatus;
|
||||||
|
|
||||||
Future<void> _loadSettings() async {
|
Future<void> _loadSettings() async {
|
||||||
_settings = await SettingsHelper.getNotificationsSettings();
|
_settings = await SettingsHelper.getNotificationsSettings();
|
||||||
|
_pushNotificationsStatus = await PushNotificationsHelper.getLocalStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -41,6 +45,20 @@ class _NotificationsSettingsScreenState
|
|||||||
SettingsSection(
|
SettingsSection(
|
||||||
title: tr("Push notifications"),
|
title: tr("Push notifications"),
|
||||||
tiles: [
|
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(
|
SettingsTile.switchTile(
|
||||||
title: tr("Allow conversations notification"),
|
title: tr("Allow conversations notification"),
|
||||||
onToggle: (v) {
|
onToggle: (v) {
|
||||||
|
Loading…
Reference in New Issue
Block a user