Browse Source

neon: Move listeners for first launch and NextPush support to global level to avoid listening multiple times

pull/208/head
jld3103 2 years ago
parent
commit
17234d9d62
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 8
      packages/neon/lib/src/app.dart
  2. 1
      packages/neon/lib/src/neon.dart
  3. 50
      packages/neon/lib/src/pages/home.dart
  4. 72
      packages/neon/lib/src/utils/global_popups.dart

8
packages/neon/lib/src/app.dart

@ -27,6 +27,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
late NeonPlatform _platform; late NeonPlatform _platform;
late GlobalOptions _globalOptions; late GlobalOptions _globalOptions;
late AccountsBloc _accountsBloc; late AccountsBloc _accountsBloc;
final _globalPopups = const GlobalPopups();
NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming? _nextcloudTheme; NextcloudCoreServerCapabilities_Ocs_Data_Capabilities_Theming? _nextcloudTheme;
final _platformBrightness = BehaviorSubject<Brightness>.seeded(WidgetsBinding.instance.window.platformBrightness); final _platformBrightness = BehaviorSubject<Brightness>.seeded(WidgetsBinding.instance.window.platformBrightness);
@ -71,7 +72,10 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
name: 'home', name: 'home',
); );
Widget builder(final context) => Scaffold( Widget builder(final context) => Scaffold(
body: HomePage( body: Stack(
children: [
_globalPopups,
HomePage(
account: activeAccount, account: activeAccount,
onThemeChanged: (final nextcloudTheme) { onThemeChanged: (final nextcloudTheme) {
setState(() { setState(() {
@ -79,6 +83,8 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
}); });
}, },
), ),
],
),
); );
await _navigatorKey.currentState!.pushAndRemoveUntil( await _navigatorKey.currentState!.pushAndRemoveUntil(
widget.globalOptions.navigationMode.value == NavigationMode.drawer widget.globalOptions.navigationMode.value == NavigationMode.drawer

1
packages/neon/lib/src/neon.dart

@ -72,6 +72,7 @@ part 'utils/confirmation_dialog.dart';
part 'utils/env.dart'; part 'utils/env.dart';
part 'utils/global.dart'; part 'utils/global.dart';
part 'utils/global_options.dart'; part 'utils/global_options.dart';
part 'utils/global_popups.dart';
part 'utils/hex_color.dart'; part 'utils/hex_color.dart';
part 'utils/localizations.dart'; part 'utils/localizations.dart';
part 'utils/missing_permission_exception.dart'; part 'utils/missing_permission_exception.dart';

50
packages/neon/lib/src/pages/home.dart

@ -24,8 +24,6 @@ class _HomePageState extends State<HomePage> {
late AccountsBloc _accountsBloc; late AccountsBloc _accountsBloc;
late AppsBloc _appsBloc; late AppsBloc _appsBloc;
late CapabilitiesBloc _capabilitiesBloc; late CapabilitiesBloc _capabilitiesBloc;
late FirstLaunchBloc _firstLaunchBloc;
late NextPushBloc _nextPushBloc;
@override @override
void initState() { void initState() {
@ -35,8 +33,6 @@ class _HomePageState extends State<HomePage> {
_accountsBloc = Provider.of<AccountsBloc>(context, listen: false); _accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
_appsBloc = _accountsBloc.getAppsBloc(widget.account); _appsBloc = _accountsBloc.getAppsBloc(widget.account);
_capabilitiesBloc = _accountsBloc.getCapabilitiesBloc(widget.account); _capabilitiesBloc = _accountsBloc.getCapabilitiesBloc(widget.account);
_firstLaunchBloc = Provider.of<FirstLaunchBloc>(context, listen: false);
_nextPushBloc = Provider.of<NextPushBloc>(context, listen: false);
_appsBloc.openNotifications.listen((final _) async { _appsBloc.openNotifications.listen((final _) async {
final notificationsAppImplementation = _appsBloc.notificationsAppImplementation.valueOrNull; final notificationsAppImplementation = _appsBloc.notificationsAppImplementation.valueOrNull;
@ -100,52 +96,6 @@ class _HomePageState extends State<HomePage> {
} }
}); });
_firstLaunchBloc.onFirstLaunch.listen((final _) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(AppLocalizations.of(context).firstLaunchGoToSettingsToEnablePushNotifications),
action: SnackBarAction(
label: AppLocalizations.of(context).settings,
onPressed: () async {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (final context) => const SettingsPage(),
),
);
},
),
),
);
});
_nextPushBloc.onNextPushSupported.listen((final _) async {
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).no),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
launchUrlString(
'https://f-droid.org/packages/$unifiedPushNextPushID',
mode: LaunchMode.externalApplication,
);
},
child: Text(AppLocalizations.of(context).nextPushSupportedInstall),
),
],
),
);
});
unawaited(_checkMaintenanceMode()); unawaited(_checkMaintenanceMode());
} }

72
packages/neon/lib/src/utils/global_popups.dart

@ -0,0 +1,72 @@
part of '../neon.dart';
class GlobalPopups extends StatefulWidget {
const GlobalPopups({
super.key,
});
@override
State<GlobalPopups> createState() => _GlobalPopupsState();
}
class _GlobalPopupsState extends State<GlobalPopups> {
late FirstLaunchBloc _firstLaunchBloc;
late NextPushBloc _nextPushBloc;
@override
void initState() {
super.initState();
_firstLaunchBloc = Provider.of<FirstLaunchBloc>(context, listen: false);
_nextPushBloc = Provider.of<NextPushBloc>(context, listen: false);
_firstLaunchBloc.onFirstLaunch.listen((final _) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(AppLocalizations.of(context).firstLaunchGoToSettingsToEnablePushNotifications),
action: SnackBarAction(
label: AppLocalizations.of(context).settings,
onPressed: () async {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (final context) => const SettingsPage(),
),
);
},
),
),
);
});
_nextPushBloc.onNextPushSupported.listen((final _) async {
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).no),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
launchUrlString(
'https://f-droid.org/packages/$unifiedPushNextPushID',
mode: LaunchMode.externalApplication,
);
},
child: Text(AppLocalizations.of(context).nextPushSupportedInstall),
),
],
),
);
});
}
@override
Widget build(final BuildContext context) => Container();
}
Loading…
Cancel
Save