Browse Source

neon: Open notifications page on unknown push notification

pull/162/head
jld3103 2 years ago
parent
commit
e2ac5e3e26
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 8
      packages/neon/lib/src/blocs/apps.dart
  2. 91
      packages/neon/lib/src/pages/home.dart

8
packages/neon/lib/src/blocs/apps.dart

@ -14,6 +14,8 @@ abstract class AppsBlocStates {
BehaviorSubject<Result<NotificationsApp?>> get notificationsAppImplementation; BehaviorSubject<Result<NotificationsApp?>> get notificationsAppImplementation;
BehaviorSubject<String?> get activeAppID; BehaviorSubject<String?> get activeAppID;
BehaviorSubject get openNotifications;
} }
class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates { class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates {
@ -88,6 +90,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
unawaited(appImplementations.close()); unawaited(appImplementations.close());
unawaited(notificationsAppImplementation.close()); unawaited(notificationsAppImplementation.close());
unawaited(activeAppID.close()); unawaited(activeAppID.close());
unawaited(openNotifications.close());
for (final key in _blocs.keys) { for (final key in _blocs.keys) {
_blocs[key]!.dispose(); _blocs[key]!.dispose();
} }
@ -107,6 +110,9 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
BehaviorSubject<Result<NotificationsApp?>> notificationsAppImplementation = BehaviorSubject<Result<NotificationsApp?>> notificationsAppImplementation =
BehaviorSubject<Result<NotificationsApp?>>(); BehaviorSubject<Result<NotificationsApp?>>();
@override
BehaviorSubject openNotifications = BehaviorSubject();
@override @override
Future refresh() async { Future refresh() async {
await _requestManager.wrapNextcloud<List<NextcloudApp>, NextcloudCoreNavigationApps>( await _requestManager.wrapNextcloud<List<NextcloudApp>, NextcloudCoreNavigationApps>(
@ -128,7 +134,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
activeAppID.add(appID); activeAppID.add(appID);
} }
} else if (appID == 'notifications') { } else if (appID == 'notifications') {
// TODO: Open notifications page openNotifications.add(null);
} else { } else {
throw Exception('App $appID not found'); throw Exception('App $appID not found');
} }

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

@ -21,8 +21,9 @@ class _HomePageState extends State<HomePage> {
final _scaffoldKey = GlobalKey<ScaffoldState>(); final _scaffoldKey = GlobalKey<ScaffoldState>();
late GlobalOptions _globalOptions; late GlobalOptions _globalOptions;
late CapabilitiesBloc _capabilitiesBloc; late AccountsBloc _accountsBloc;
late AppsBloc _appsBloc; late AppsBloc _appsBloc;
late CapabilitiesBloc _capabilitiesBloc;
late FirstLaunchBloc _firstLaunchBloc; late FirstLaunchBloc _firstLaunchBloc;
@override @override
@ -30,10 +31,22 @@ class _HomePageState extends State<HomePage> {
super.initState(); super.initState();
_globalOptions = Provider.of<GlobalOptions>(context, listen: false); _globalOptions = Provider.of<GlobalOptions>(context, listen: false);
_appsBloc = Provider.of<AccountsBloc>(context, listen: false).getAppsBloc(widget.account); _accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
_capabilitiesBloc = Provider.of<AccountsBloc>(context, listen: false).getCapabilitiesBloc(widget.account); _appsBloc = _accountsBloc.getAppsBloc(widget.account);
_capabilitiesBloc = _accountsBloc.getCapabilitiesBloc(widget.account);
_firstLaunchBloc = Provider.of<FirstLaunchBloc>(context, listen: false); _firstLaunchBloc = Provider.of<FirstLaunchBloc>(context, listen: false);
_appsBloc.openNotifications.listen((final _) async {
final notificationsAppImplementation = _appsBloc.notificationsAppImplementation.valueOrNull;
if (notificationsAppImplementation != null) {
await _openNotifications(
notificationsAppImplementation.data!,
_accountsBloc.accounts.value,
_accountsBloc.activeAccount.value!,
);
}
});
_capabilitiesBloc.capabilities.listen((final result) async { _capabilitiesBloc.capabilities.listen((final result) async {
if (result.data != null) { if (result.data != null) {
widget.onThemeChanged(result.data!.capabilities.theming); widget.onThemeChanged(result.data!.capabilities.theming);
@ -153,6 +166,34 @@ class _HomePageState extends State<HomePage> {
); );
} }
Future _openNotifications(
final NotificationsApp app,
final List<Account> accounts,
final Account account,
) async {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (final context) => Scaffold(
appBar: AppBar(
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(app.name(context)),
if (accounts.length > 1) ...[
Text(
account.client.humanReadableID,
style: Theme.of(context).textTheme.bodySmall,
),
],
],
),
),
body: app.buildPage(context, _appsBloc),
),
),
);
}
@override @override
void dispose() { void dispose() {
_capabilitiesBloc.dispose(); _capabilitiesBloc.dispose();
@ -160,9 +201,7 @@ class _HomePageState extends State<HomePage> {
} }
@override @override
Widget build(final BuildContext context) { Widget build(final BuildContext context) => ResultBuilder<CapabilitiesBloc, Capabilities>(
final accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
return ResultBuilder<CapabilitiesBloc, Capabilities>(
stream: _capabilitiesBloc.capabilities, stream: _capabilitiesBloc.capabilities,
builder: (final context, final capabilities) => ResultBuilder<AppsBloc, List<AppImplementation>>( builder: (final context, final capabilities) => ResultBuilder<AppsBloc, List<AppImplementation>>(
stream: _appsBloc.appImplementations, stream: _appsBloc.appImplementations,
@ -175,7 +214,7 @@ class _HomePageState extends State<HomePage> {
final activeAppIDSnapshot, final activeAppIDSnapshot,
) => ) =>
StreamBuilder<List<Account>>( StreamBuilder<List<Account>>(
stream: accountsBloc.accounts, stream: _accountsBloc.accounts,
builder: ( builder: (
final context, final context,
final accountsSnapshot, final accountsSnapshot,
@ -227,7 +266,7 @@ class _HomePageState extends State<HomePage> {
message: account.client.humanReadableID, message: account.client.humanReadableID,
child: IconButton( child: IconButton(
onPressed: () { onPressed: () {
accountsBloc.setActiveAccount(account); _accountsBloc.setActiveAccount(account);
}, },
icon: IntrinsicHeight( icon: IntrinsicHeight(
child: AccountAvatar( child: AccountAvatar(
@ -289,7 +328,8 @@ class _HomePageState extends State<HomePage> {
child: DropdownButton<String>( child: DropdownButton<String>(
isExpanded: true, isExpanded: true,
dropdownColor: Theme.of(context).colorScheme.primary, dropdownColor: Theme.of(context).colorScheme.primary,
iconEnabledColor: Theme.of(context).colorScheme.onBackground, iconEnabledColor:
Theme.of(context).colorScheme.onBackground,
value: widget.account.id, value: widget.account.id,
items: accounts items: accounts
.map<DropdownMenuItem<String>>( .map<DropdownMenuItem<String>>(
@ -307,7 +347,7 @@ class _HomePageState extends State<HomePage> {
onChanged: (final id) { onChanged: (final id) {
for (final account in accounts) { for (final account in accounts) {
if (account.id == id) { if (account.id == id) {
accountsBloc.setActiveAccount(account); _accountsBloc.setActiveAccount(account);
break; break;
} }
} }
@ -506,27 +546,10 @@ class _HomePageState extends State<HomePage> {
height: kAvatarSize * 2 / 3, height: kAvatarSize * 2 / 3,
), ),
onPressed: () async { onPressed: () async {
await Navigator.of(context).push( await _openNotifications(
MaterialPageRoute( notificationsAppImplementation.data!,
builder: (final context) => Scaffold( accounts,
appBar: AppBar( account,
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(notificationsAppImplementation.data!.name(context)),
if (accounts.length > 1) ...[
Text(
account.client.humanReadableID,
style: Theme.of(context).textTheme.bodySmall,
),
],
],
),
),
body: notificationsAppImplementation.data!
.buildPage(context, _appsBloc),
),
),
); );
}, },
); );
@ -543,7 +566,7 @@ class _HomePageState extends State<HomePage> {
await Navigator.of(context).push( await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (final context) => AccountSettingsPage( builder: (final context) => AccountSettingsPage(
bloc: accountsBloc, bloc: _accountsBloc,
account: account, account: account,
), ),
), ),
@ -569,7 +592,8 @@ class _HomePageState extends State<HomePage> {
Expanded( Expanded(
child: Center( child: Center(
child: Text( child: Text(
AppLocalizations.of(context).errorNoCompatibleNextcloudAppsFound, AppLocalizations.of(context)
.errorNoCompatibleNextcloudAppsFound,
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
), ),
@ -606,4 +630,3 @@ class _HomePageState extends State<HomePage> {
), ),
); );
} }
}

Loading…
Cancel
Save