|
|
@ -1,3 +1,5 @@ |
|
|
|
|
|
|
|
import 'dart:async'; |
|
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:meta/meta.dart'; |
|
|
|
import 'package:meta/meta.dart'; |
|
|
|
import 'package:neon/l10n/localizations.dart'; |
|
|
|
import 'package:neon/l10n/localizations.dart'; |
|
|
@ -23,8 +25,19 @@ class GlobalPopups { |
|
|
|
static GlobalPopups? instance; |
|
|
|
static GlobalPopups? instance; |
|
|
|
|
|
|
|
|
|
|
|
bool _registered = false; |
|
|
|
bool _registered = false; |
|
|
|
|
|
|
|
late BuildContext _context; |
|
|
|
|
|
|
|
final _subscriptions = <StreamSubscription>[]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void dispose() { |
|
|
|
|
|
|
|
for (final subscription in _subscriptions) { |
|
|
|
|
|
|
|
unawaited(subscription.cancel()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_subscriptions.clear(); |
|
|
|
|
|
|
|
_registered = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void register(final BuildContext context) { |
|
|
|
void register(final BuildContext context) { |
|
|
|
|
|
|
|
_context = context; |
|
|
|
if (_registered) { |
|
|
|
if (_registered) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -34,55 +47,60 @@ class GlobalPopups { |
|
|
|
final nextPushBloc = Provider.of<NextPushBloc>(context, listen: false); |
|
|
|
final nextPushBloc = Provider.of<NextPushBloc>(context, listen: false); |
|
|
|
final platform = Provider.of<NeonPlatform>(context, listen: false); |
|
|
|
final platform = Provider.of<NeonPlatform>(context, listen: false); |
|
|
|
|
|
|
|
|
|
|
|
firstLaunchBloc.onFirstLaunch.listen((final _) { |
|
|
|
_subscriptions.addAll([ |
|
|
|
if (!platform.canUsePushNotifications || !globalOptions.pushNotificationsEnabled.enabled) { |
|
|
|
if (platform.canUsePushNotifications) ...[ |
|
|
|
return; |
|
|
|
firstLaunchBloc.onFirstLaunch.listen((final _) { |
|
|
|
} |
|
|
|
assert(context.mounted, 'Context should be mounted'); |
|
|
|
|
|
|
|
if (!globalOptions.pushNotificationsEnabled.enabled) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar( |
|
|
|
ScaffoldMessenger.of(_context).showSnackBar( |
|
|
|
SnackBar( |
|
|
|
SnackBar( |
|
|
|
content: Text(AppLocalizations.of(context).firstLaunchGoToSettingsToEnablePushNotifications), |
|
|
|
content: Text(AppLocalizations.of(_context).firstLaunchGoToSettingsToEnablePushNotifications), |
|
|
|
action: SnackBarAction( |
|
|
|
action: SnackBarAction( |
|
|
|
label: AppLocalizations.of(context).settings, |
|
|
|
label: AppLocalizations.of(_context).settings, |
|
|
|
onPressed: () { |
|
|
|
onPressed: () { |
|
|
|
const SettingsRoute(initialCategory: SettingsCageories.pushNotifications).go(context); |
|
|
|
const SettingsRoute(initialCategory: SettingsCageories.pushNotifications).go(_context); |
|
|
|
}, |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nextPushBloc.onNextPushSupported.listen((final _) async { |
|
|
|
|
|
|
|
if (!platform.canUsePushNotifications || !globalOptions.pushNotificationsEnabled.enabled) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await showDialog( |
|
|
|
|
|
|
|
context: context, |
|
|
|
|
|
|
|
builder: (final context) => AlertDialog( |
|
|
|
|
|
|
|
title: Text(AppLocalizations.of(context).nextPushSupported), |
|
|
|
|
|
|
|
content: Text(AppLocalizations.of(context).nextPushSupportedText), |
|
|
|
|
|
|
|
actions: [ |
|
|
|
|
|
|
|
OutlinedButton( |
|
|
|
|
|
|
|
onPressed: () { |
|
|
|
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
child: Text(AppLocalizations.of(context).actionNo), |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
ElevatedButton( |
|
|
|
); |
|
|
|
onPressed: () { |
|
|
|
}), |
|
|
|
Navigator.of(context).pop(); |
|
|
|
nextPushBloc.onNextPushSupported.listen((final _) async { |
|
|
|
launchUrlString( |
|
|
|
assert(context.mounted, 'Context should be mounted'); |
|
|
|
'https://f-droid.org/packages/$unifiedPushNextPushID', |
|
|
|
if (!globalOptions.pushNotificationsEnabled.enabled) { |
|
|
|
mode: LaunchMode.externalApplication, |
|
|
|
return; |
|
|
|
); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
child: Text(AppLocalizations.of(context).nextPushSupportedInstall), |
|
|
|
await showDialog( |
|
|
|
|
|
|
|
context: _context, |
|
|
|
|
|
|
|
builder: (final context) => AlertDialog( |
|
|
|
|
|
|
|
title: Text(AppLocalizations.of(context).nextPushSupported), |
|
|
|
|
|
|
|
content: Text(AppLocalizations.of(context).nextPushSupportedText), |
|
|
|
|
|
|
|
actions: [ |
|
|
|
|
|
|
|
OutlinedButton( |
|
|
|
|
|
|
|
onPressed: () { |
|
|
|
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
child: Text(AppLocalizations.of(context).actionNo), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
ElevatedButton( |
|
|
|
|
|
|
|
onPressed: () { |
|
|
|
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
|
|
|
launchUrlString( |
|
|
|
|
|
|
|
'https://f-droid.org/packages/$unifiedPushNextPushID', |
|
|
|
|
|
|
|
mode: LaunchMode.externalApplication, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
child: Text(AppLocalizations.of(context).nextPushSupportedInstall), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
); |
|
|
|
), |
|
|
|
}), |
|
|
|
); |
|
|
|
], |
|
|
|
}); |
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
_registered = true; |
|
|
|
_registered = true; |
|
|
|
} |
|
|
|
} |
|
|
|