You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
5.3 KiB
Dart
136 lines
5.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
import 'package:fluffychat/pages/settings_notifications/push_rule_extensions.dart';
|
|
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
|
import '../../utils/localized_exception_extension.dart';
|
|
import '../../widgets/matrix.dart';
|
|
import 'settings_notifications.dart';
|
|
|
|
class SettingsNotificationsView extends StatelessWidget {
|
|
final SettingsNotificationsController controller;
|
|
|
|
const SettingsNotificationsView(this.controller, {super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final pushRules = Matrix.of(context).client.globalPushRules;
|
|
final pushCategories = [
|
|
if (pushRules?.override?.isNotEmpty ?? false)
|
|
(rules: pushRules?.override ?? [], kind: PushRuleKind.override),
|
|
if (pushRules?.content?.isNotEmpty ?? false)
|
|
(rules: pushRules?.content ?? [], kind: PushRuleKind.content),
|
|
if (pushRules?.sender?.isNotEmpty ?? false)
|
|
(rules: pushRules?.sender ?? [], kind: PushRuleKind.sender),
|
|
if (pushRules?.underride?.isNotEmpty ?? false)
|
|
(rules: pushRules?.underride ?? [], kind: PushRuleKind.underride),
|
|
];
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
leading: const Center(child: BackButton()),
|
|
title: Text(L10n.of(context).notifications),
|
|
),
|
|
body: MaxWidthBody(
|
|
child: StreamBuilder(
|
|
stream: Matrix.of(context).client.onSync.stream.where(
|
|
(syncUpdate) =>
|
|
syncUpdate.accountData?.any(
|
|
(accountData) => accountData.type == 'm.push_rules',
|
|
) ??
|
|
false,
|
|
),
|
|
builder: (BuildContext context, _) {
|
|
final theme = Theme.of(context);
|
|
return Column(
|
|
children: [
|
|
if (pushRules != null)
|
|
for (final category in pushCategories) ...[
|
|
ListTile(
|
|
title: Text(
|
|
category.kind.localized(L10n.of(context)),
|
|
style: TextStyle(
|
|
color: theme.colorScheme.secondary,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
for (final rule in category.rules)
|
|
SwitchListTile.adaptive(
|
|
value: rule.enabled,
|
|
title: Text(rule.getPushRuleName(L10n.of(context))),
|
|
subtitle:
|
|
Text(rule.getPushRuleDescription(L10n.of(context))),
|
|
onChanged: controller.isLoading
|
|
? null
|
|
: Matrix.of(context)
|
|
.client
|
|
.allPushNotificationsMuted
|
|
? null
|
|
: (_) => controller.togglePushRule(
|
|
category.kind,
|
|
rule,
|
|
),
|
|
),
|
|
Divider(color: theme.dividerColor),
|
|
],
|
|
ListTile(
|
|
title: Text(
|
|
L10n.of(context).devices,
|
|
style: TextStyle(
|
|
color: theme.colorScheme.secondary,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
FutureBuilder<List<Pusher>?>(
|
|
future: controller.pusherFuture ??=
|
|
Matrix.of(context).client.getPushers(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasError) {
|
|
Center(
|
|
child: Text(
|
|
snapshot.error!.toLocalizedString(context),
|
|
),
|
|
);
|
|
}
|
|
if (snapshot.connectionState != ConnectionState.done) {
|
|
const Center(
|
|
child: CircularProgressIndicator.adaptive(
|
|
strokeWidth: 2,
|
|
),
|
|
);
|
|
}
|
|
final pushers = snapshot.data ?? [];
|
|
if (pushers.isEmpty) {
|
|
return Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(bottom: 16.0),
|
|
child: Text(L10n.of(context).noOtherDevicesFound),
|
|
),
|
|
);
|
|
}
|
|
return ListView.builder(
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
shrinkWrap: true,
|
|
itemCount: pushers.length,
|
|
itemBuilder: (_, i) => ListTile(
|
|
title: Text(
|
|
'${pushers[i].appDisplayName} - ${pushers[i].appId}',
|
|
),
|
|
subtitle: Text(pushers[i].data.url.toString()),
|
|
onTap: () => controller.onPusherTap(pushers[i]),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|