fluffychat/lib/pages/views/settings_notifications_view...

127 lines
5.1 KiB
Dart
Raw Normal View History

import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
2021-10-26 16:50:34 +00:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-10-26 16:50:34 +00:00
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:matrix/matrix.dart';
2021-10-26 16:50:34 +00:00
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import '../../utils/localized_exception_extension.dart';
2021-05-22 06:53:52 +00:00
import '../../widgets/matrix.dart';
2021-10-26 16:50:34 +00:00
import '../settings_notifications.dart';
2021-05-22 07:13:47 +00:00
class SettingsNotificationsView extends StatelessWidget {
2021-04-24 06:14:53 +00:00
final SettingsNotificationsController controller;
2021-05-22 07:13:47 +00:00
const SettingsNotificationsView(this.controller, {Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2021-10-14 16:09:30 +00:00
leading: const BackButton(),
title: Text(L10n.of(context).notifications),
),
2021-04-09 16:26:44 +00: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: [
SwitchListTile(
value: !Matrix.of(context).client.allPushNotificationsMuted,
title: Text(
L10n.of(context).notificationsEnabledForThisAccount),
onChanged: (_) => showFutureLoadingDialog(
context: context,
future: () =>
Matrix.of(context).client.setMuteAllPushNotifications(
!Matrix.of(context)
.client
.allPushNotificationsMuted,
),
),
),
2021-04-09 16:26:44 +00:00
if (!Matrix.of(context).client.allPushNotificationsMuted) ...{
if (!kIsWeb && Platform.isAndroid)
ListTile(
title: Text(L10n.of(context).soundVibrationLedColor),
trailing: CircleAvatar(
backgroundColor:
Theme.of(context).scaffoldBackgroundColor,
foregroundColor: Colors.grey,
2021-10-14 16:09:30 +00:00
child: const Icon(Icons.edit_outlined),
2021-04-09 16:26:44 +00:00
),
2021-04-24 06:14:53 +00:00
onTap: controller.openAndroidNotificationSettingsAction,
2021-04-09 16:26:44 +00:00
),
2021-10-14 16:09:30 +00:00
const Divider(thickness: 1),
ListTile(
2021-04-09 16:26:44 +00:00
title: Text(
L10n.of(context).pushRules,
style: TextStyle(
2021-05-24 08:59:00 +00:00
color: Theme.of(context).colorScheme.secondary,
2021-04-09 16:26:44 +00:00
fontWeight: FontWeight.bold,
),
),
),
2021-04-24 06:14:53 +00:00
for (var item in NotificationSettingsItem.items)
2021-04-09 16:26:44 +00:00
SwitchListTile(
2021-04-24 06:14:53 +00:00
value: controller.getNotificationSetting(item) ?? true,
2021-04-09 16:26:44 +00:00
title: Text(item.title(context)),
onChanged: (bool enabled) =>
2021-04-24 06:14:53 +00:00
controller.setNotificationSetting(item, enabled),
2021-04-09 16:26:44 +00:00
),
},
2021-10-14 16:09:30 +00:00
const Divider(thickness: 1),
ListTile(
title: Text(
2021-04-09 16:26:44 +00:00
L10n.of(context).devices,
style: TextStyle(
2021-05-24 08:59:00 +00:00
color: Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
),
2021-04-09 16:26:44 +00:00
FutureBuilder<List<Pusher>>(
2021-05-20 11:59:55 +00:00
future: Matrix.of(context).client.getPushers(),
2021-04-09 16:26:44 +00:00
builder: (context, snapshot) {
if (snapshot.hasError) {
Center(
child: Text(
snapshot.error.toLocalizedString(context),
),
);
}
2021-04-12 18:48:33 +00:00
if (snapshot.connectionState != ConnectionState.done) {
2021-10-14 16:09:30 +00:00
const Center(
2021-10-10 11:38:06 +00:00
child: CircularProgressIndicator.adaptive(
strokeWidth: 2));
2021-04-09 16:26:44 +00:00
}
2021-04-12 18:48:33 +00:00
final pushers = snapshot.data ?? [];
2021-04-09 16:26:44 +00:00
return ListView.builder(
2021-10-14 16:09:30 +00:00
physics: const NeverScrollableScrollPhysics(),
2021-04-09 16:26:44 +00: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 19:05:51 +00:00
),
);
2021-04-09 16:26:44 +00:00
},
),
],
);
}),
),
);
}
}