fluffychat/lib/pages/settings_notifications/settings_notifications_view.dart

114 lines
4.5 KiB
Dart
Raw Permalink Normal View History

import 'package:flutter/material.dart';
2021-10-26 18:50:34 +02:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-10-26 18:50:34 +02:00
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:matrix/matrix.dart';
2021-10-26 18:50:34 +02:00
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import '../../utils/localized_exception_extension.dart';
2021-05-22 08:53:52 +02:00
import '../../widgets/matrix.dart';
2021-11-09 21:32:16 +01:00
import 'settings_notifications.dart';
2021-05-22 09:13:47 +02:00
class SettingsNotificationsView extends StatelessWidget {
2021-04-24 08:14:53 +02:00
final SettingsNotificationsController controller;
2022-01-29 12:35:03 +01:00
const SettingsNotificationsView(this.controller, {Key? key})
: super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2021-10-14 18:09:30 +02:00
leading: const BackButton(),
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!.notifications),
),
2021-04-09 18:26:44 +02:00
body: MaxWidthBody(
withScrolling: true,
child: StreamBuilder(
stream: Matrix.of(context)
.client
.onAccountData
.stream
.where((event) => event.type == 'm.push_rules'),
builder: (BuildContext context, _) {
return Column(
children: [
2021-11-27 10:10:29 +01:00
SwitchListTile.adaptive(
2021-04-09 18:26:44 +02:00
value: !Matrix.of(context).client.allPushNotificationsMuted,
title: Text(
2022-01-29 12:35:03 +01:00
L10n.of(context)!.notificationsEnabledForThisAccount),
2021-04-09 18:26:44 +02:00
onChanged: (_) => showFutureLoadingDialog(
context: context,
future: () =>
Matrix.of(context).client.setMuteAllPushNotifications(
!Matrix.of(context)
.client
.allPushNotificationsMuted,
),
),
),
2021-04-09 18:26:44 +02:00
if (!Matrix.of(context).client.allPushNotificationsMuted) ...{
2021-10-14 18:09:30 +02:00
const Divider(thickness: 1),
ListTile(
2021-04-09 18:26:44 +02:00
title: Text(
2022-01-29 12:35:03 +01:00
L10n.of(context)!.pushRules,
2021-04-09 18:26:44 +02:00
style: TextStyle(
2021-05-24 10:59:00 +02:00
color: Theme.of(context).colorScheme.secondary,
2021-04-09 18:26:44 +02:00
fontWeight: FontWeight.bold,
),
),
),
2021-04-24 08:14:53 +02:00
for (var item in NotificationSettingsItem.items)
2021-11-27 10:10:29 +01:00
SwitchListTile.adaptive(
2021-04-24 08:14:53 +02:00
value: controller.getNotificationSetting(item) ?? true,
2021-04-09 18:26:44 +02:00
title: Text(item.title(context)),
onChanged: (bool enabled) =>
2021-04-24 08:14:53 +02:00
controller.setNotificationSetting(item, enabled),
2021-04-09 18:26:44 +02:00
),
},
2021-10-14 18:09:30 +02:00
const Divider(thickness: 1),
ListTile(
title: Text(
2022-01-29 12:35:03 +01:00
L10n.of(context)!.devices,
style: TextStyle(
2021-05-24 10:59:00 +02:00
color: Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
),
2022-01-29 12:35:03 +01:00
FutureBuilder<List<Pusher>?>(
2021-05-20 13:59:55 +02:00
future: Matrix.of(context).client.getPushers(),
2021-04-09 18:26:44 +02:00
builder: (context, snapshot) {
if (snapshot.hasError) {
Center(
child: Text(
2022-01-29 12:35:03 +01:00
snapshot.error!.toLocalizedString(context),
2021-04-09 18:26:44 +02:00
),
);
}
2021-04-12 20:48:33 +02:00
if (snapshot.connectionState != ConnectionState.done) {
2021-10-14 18:09:30 +02:00
const Center(
2021-10-10 13:38:06 +02:00
child: CircularProgressIndicator.adaptive(
strokeWidth: 2));
2021-04-09 18:26:44 +02:00
}
2021-04-12 20:48:33 +02:00
final pushers = snapshot.data ?? [];
2021-04-09 18:26:44 +02:00
return ListView.builder(
2021-10-14 18:09:30 +02:00
physics: const NeverScrollableScrollPhysics(),
2021-04-09 18:26:44 +02:00
shrinkWrap: true,
itemCount: pushers.length,
itemBuilder: (_, i) => ListTile(
title: Text(
'${pushers[i].appDisplayName} - ${pushers[i].appId}'),
subtitle: Text(pushers[i].data.url.toString()),
2021-03-27 20:05:51 +01:00
),
);
2021-04-09 18:26:44 +02:00
},
),
],
);
}),
),
);
}
}