From 07fdfd16494711f09009826e1ac905d32609923b Mon Sep 17 00:00:00 2001 From: Krille Date: Wed, 5 Feb 2025 12:33:43 +0100 Subject: [PATCH] chore: Follow up push rule settings --- .../settings_notifications_view.dart | 200 +++++++++--------- 1 file changed, 102 insertions(+), 98 deletions(-) diff --git a/lib/pages/settings_notifications/settings_notifications_view.dart b/lib/pages/settings_notifications/settings_notifications_view.dart index b74157bcf..280ef26fc 100644 --- a/lib/pages/settings_notifications/settings_notifications_view.dart +++ b/lib/pages/settings_notifications/settings_notifications_view.dart @@ -43,117 +43,121 @@ class SettingsNotificationsView extends StatelessWidget { ), 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, + return SelectionArea( + child: 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( - title: Text(rule.getPushRuleName(L10n.of(context))), - subtitle: Text.rich( - TextSpan( - children: [ - TextSpan( - text: rule.getPushRuleDescription( - L10n.of(context), - ), - ), - const TextSpan(text: ' '), - WidgetSpan( - child: InkWell( - onTap: () => controller.editPushRule( - rule, - category.kind, + for (final rule in category.rules) + ListTile( + title: Text(rule.getPushRuleName(L10n.of(context))), + subtitle: Text.rich( + TextSpan( + children: [ + TextSpan( + text: rule.getPushRuleDescription( + L10n.of(context), ), - child: Text( - L10n.of(context).more, - style: TextStyle( - color: theme.colorScheme.primary, - decoration: TextDecoration.underline, - decorationColor: - theme.colorScheme.primary, + ), + const TextSpan(text: ' '), + WidgetSpan( + child: InkWell( + onTap: () => controller.editPushRule( + rule, + category.kind, + ), + child: Text( + L10n.of(context).more, + style: TextStyle( + color: theme.colorScheme.primary, + decoration: TextDecoration.underline, + decorationColor: + theme.colorScheme.primary, + ), ), ), ), - ), - ], + ], + ), ), - ), - value: rule.enabled, - onChanged: controller.isLoading - ? null - : rule.ruleId != '.m.rule.master' && - Matrix.of(context) - .client - .allPushNotificationsMuted + trailing: Switch.adaptive( + value: rule.enabled, + onChanged: controller.isLoading ? null - : (_) => controller.togglePushRule( - category.kind, - rule, - ), + : rule.ruleId != '.m.rule.master' && + 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, ), - Divider(color: theme.dividerColor), - ], - ListTile( - title: Text( - L10n.of(context).devices, - style: TextStyle( - color: theme.colorScheme.secondary, - fontWeight: FontWeight.bold, ), ), - ), - FutureBuilder?>( - 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), + FutureBuilder?>( + 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]), ), ); - } - 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]), - ), - ); - }, - ), - ], + }, + ), + ], + ), ); }, ),