You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
4.1 KiB
128 lines
4.1 KiB
2 years ago
|
part of '../neon_notifications.dart';
|
||
2 years ago
|
|
||
|
class NotificationsMainPage extends StatefulWidget {
|
||
|
const NotificationsMainPage({
|
||
|
required this.bloc,
|
||
|
super.key,
|
||
|
});
|
||
|
|
||
|
final NotificationsBloc bloc;
|
||
|
|
||
|
@override
|
||
|
State<NotificationsMainPage> createState() => _NotificationsMainPageState();
|
||
|
}
|
||
|
|
||
|
class _NotificationsMainPageState extends State<NotificationsMainPage> {
|
||
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
|
||
|
widget.bloc.errors.listen((final error) {
|
||
|
ExceptionWidget.showSnackbar(context, error);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
@override
|
||
2 years ago
|
Widget build(final BuildContext context) =>
|
||
|
ResultBuilder<NotificationsBloc, List<NextcloudNotificationsNotification>>(
|
||
2 years ago
|
stream: widget.bloc.notifications,
|
||
|
builder: (final context, final notifications) => Scaffold(
|
||
2 years ago
|
resizeToAvoidBottomInset: false,
|
||
|
floatingActionButton: FloatingActionButton(
|
||
|
onPressed: () async {
|
||
|
widget.bloc.deleteAllNotifications();
|
||
|
},
|
||
|
child: const Icon(MdiIcons.checkAll),
|
||
|
),
|
||
2 years ago
|
body: CustomListView<NextcloudNotificationsNotification>(
|
||
2 years ago
|
scrollKey: 'notifications-notifications',
|
||
|
withFloatingActionButton: true,
|
||
2 years ago
|
items: notifications.data,
|
||
|
isLoading: notifications.loading,
|
||
|
error: notifications.error,
|
||
2 years ago
|
onRefresh: widget.bloc.refresh,
|
||
2 years ago
|
builder: _buildNotification,
|
||
2 years ago
|
),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
Widget _buildNotification(
|
||
|
final BuildContext context,
|
||
2 years ago
|
final NextcloudNotificationsNotification notification,
|
||
2 years ago
|
) {
|
||
|
final matchingAppImplementations = Provider.of<List<AppImplementation>>(context, listen: false)
|
||
|
.where((final a) => a.id == notification.app)
|
||
|
.toList();
|
||
|
|
||
|
return ListTile(
|
||
2 years ago
|
title: Text(notification.subject),
|
||
2 years ago
|
subtitle: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
2 years ago
|
if (notification.message.isNotEmpty) ...[
|
||
2 years ago
|
Text(
|
||
2 years ago
|
notification.message,
|
||
2 years ago
|
overflow: TextOverflow.ellipsis,
|
||
|
),
|
||
|
const SizedBox(
|
||
|
height: 5,
|
||
|
),
|
||
|
],
|
||
2 years ago
|
RelativeTime(
|
||
2 years ago
|
date: DateTime.parse(notification.datetime),
|
||
2 years ago
|
),
|
||
2 years ago
|
],
|
||
|
),
|
||
|
leading: matchingAppImplementations.isNotEmpty
|
||
|
? matchingAppImplementations.single.buildIcon(
|
||
|
context,
|
||
|
width: 40,
|
||
|
height: 40,
|
||
|
)
|
||
|
: SizedBox(
|
||
|
width: 40,
|
||
|
height: 40,
|
||
|
child: CachedURLImage(
|
||
2 years ago
|
url: notification.icon,
|
||
2 years ago
|
width: 40,
|
||
|
height: 40,
|
||
2 years ago
|
svgColor: Theme.of(context).colorScheme.primary,
|
||
2 years ago
|
),
|
||
|
),
|
||
|
onTap: () async {
|
||
2 years ago
|
if (notification.app == 'notifications') {
|
||
|
return;
|
||
|
}
|
||
2 years ago
|
final allAppImplementations = Provider.of<List<AppImplementation>>(context, listen: false);
|
||
|
final matchingAppImplementations = allAppImplementations.where((final a) => a.id == notification.app);
|
||
|
if (matchingAppImplementations.isNotEmpty) {
|
||
2 years ago
|
final accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
|
||
2 years ago
|
await accountsBloc.getAppsBloc(accountsBloc.activeAccount.value!).setActiveApp(notification.app);
|
||
2 years ago
|
} else {
|
||
2 years ago
|
await showDialog(
|
||
|
context: context,
|
||
|
builder: (final context) => AlertDialog(
|
||
|
title: Text(AppLocalizations.of(context).notificationsNextcloudAppNotImplementedYet),
|
||
|
actions: [
|
||
|
ElevatedButton(
|
||
|
style: ElevatedButton.styleFrom(
|
||
2 years ago
|
backgroundColor: Colors.red,
|
||
2 years ago
|
foregroundColor: Theme.of(context).colorScheme.onPrimary,
|
||
2 years ago
|
),
|
||
|
onPressed: () {
|
||
|
Navigator.of(context).pop();
|
||
|
},
|
||
|
child: Text(AppLocalizations.of(context).close),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
},
|
||
|
onLongPress: () {
|
||
2 years ago
|
widget.bloc.deleteNotification(notification.notificationId);
|
||
2 years ago
|
},
|
||
|
);
|
||
|
}
|
||
|
}
|