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<String?> get activeAppID;
BehaviorSubject get openNotifications;
}
class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates {
@ -88,6 +90,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
unawaited(appImplementations.close());
unawaited(notificationsAppImplementation.close());
unawaited(activeAppID.close());
unawaited(openNotifications.close());
for (final key in _blocs.keys) {
_blocs[key]!.dispose();
}
@ -107,6 +110,9 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
BehaviorSubject<Result<NotificationsApp?>> notificationsAppImplementation =
BehaviorSubject<Result<NotificationsApp?>>();
@override
BehaviorSubject openNotifications = BehaviorSubject();
@override
Future refresh() async {
await _requestManager.wrapNextcloud<List<NextcloudApp>, NextcloudCoreNavigationApps>(
@ -128,7 +134,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
activeAppID.add(appID);
}
} else if (appID == 'notifications') {
// TODO: Open notifications page
openNotifications.add(null);
} else {
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>();
late GlobalOptions _globalOptions;
late CapabilitiesBloc _capabilitiesBloc;
late AccountsBloc _accountsBloc;
late AppsBloc _appsBloc;
late CapabilitiesBloc _capabilitiesBloc;
late FirstLaunchBloc _firstLaunchBloc;
@override
@ -30,10 +31,22 @@ class _HomePageState extends State<HomePage> {
super.initState();
_globalOptions = Provider.of<GlobalOptions>(context, listen: false);
_appsBloc = Provider.of<AccountsBloc>(context, listen: false).getAppsBloc(widget.account);
_capabilitiesBloc = Provider.of<AccountsBloc>(context, listen: false).getCapabilitiesBloc(widget.account);
_accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
_appsBloc = _accountsBloc.getAppsBloc(widget.account);
_capabilitiesBloc = _accountsBloc.getCapabilitiesBloc(widget.account);
_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 {
if (result.data != null) {
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
void dispose() {
_capabilitiesBloc.dispose();
@ -160,9 +201,7 @@ class _HomePageState extends State<HomePage> {
}
@override
Widget build(final BuildContext context) {
final accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
return ResultBuilder<CapabilitiesBloc, Capabilities>(
Widget build(final BuildContext context) => ResultBuilder<CapabilitiesBloc, Capabilities>(
stream: _capabilitiesBloc.capabilities,
builder: (final context, final capabilities) => ResultBuilder<AppsBloc, List<AppImplementation>>(
stream: _appsBloc.appImplementations,
@ -175,7 +214,7 @@ class _HomePageState extends State<HomePage> {
final activeAppIDSnapshot,
) =>
StreamBuilder<List<Account>>(
stream: accountsBloc.accounts,
stream: _accountsBloc.accounts,
builder: (
final context,
final accountsSnapshot,
@ -227,7 +266,7 @@ class _HomePageState extends State<HomePage> {
message: account.client.humanReadableID,
child: IconButton(
onPressed: () {
accountsBloc.setActiveAccount(account);
_accountsBloc.setActiveAccount(account);
},
icon: IntrinsicHeight(
child: AccountAvatar(
@ -289,7 +328,8 @@ class _HomePageState extends State<HomePage> {
child: DropdownButton<String>(
isExpanded: true,
dropdownColor: Theme.of(context).colorScheme.primary,
iconEnabledColor: Theme.of(context).colorScheme.onBackground,
iconEnabledColor:
Theme.of(context).colorScheme.onBackground,
value: widget.account.id,
items: accounts
.map<DropdownMenuItem<String>>(
@ -307,7 +347,7 @@ class _HomePageState extends State<HomePage> {
onChanged: (final id) {
for (final account in accounts) {
if (account.id == id) {
accountsBloc.setActiveAccount(account);
_accountsBloc.setActiveAccount(account);
break;
}
}
@ -506,27 +546,10 @@ class _HomePageState extends State<HomePage> {
height: kAvatarSize * 2 / 3,
),
onPressed: () async {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (final context) => Scaffold(
appBar: AppBar(
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),
),
),
await _openNotifications(
notificationsAppImplementation.data!,
accounts,
account,
);
},
);
@ -543,7 +566,7 @@ class _HomePageState extends State<HomePage> {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (final context) => AccountSettingsPage(
bloc: accountsBloc,
bloc: _accountsBloc,
account: account,
),
),
@ -569,7 +592,8 @@ class _HomePageState extends State<HomePage> {
Expanded(
child: Center(
child: Text(
AppLocalizations.of(context).errorNoCompatibleNextcloudAppsFound,
AppLocalizations.of(context)
.errorNoCompatibleNextcloudAppsFound,
textAlign: TextAlign.center,
),
),
@ -605,5 +629,4 @@ class _HomePageState extends State<HomePage> {
),
),
);
}
}

Loading…
Cancel
Save