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. 20
      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

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

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

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

@ -72,6 +72,7 @@ part 'utils/confirmation_dialog.dart';
part 'utils/env.dart';
part 'utils/global.dart';
part 'utils/global_options.dart';
part 'utils/global_popups.dart';
part 'utils/hex_color.dart';
part 'utils/localizations.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 AppsBloc _appsBloc;
late CapabilitiesBloc _capabilitiesBloc;
late FirstLaunchBloc _firstLaunchBloc;
late NextPushBloc _nextPushBloc;
@override
void initState() {
@ -35,8 +33,6 @@ class _HomePageState extends State<HomePage> {
_accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
_appsBloc = _accountsBloc.getAppsBloc(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 {
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());
}

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