fluffychat/lib/pages/views/settings_notifications_view.dart

124 lines
4.9 KiB
Dart
Raw Normal View History

import 'dart:io';
import 'package:famedlysdk/famedlysdk.dart';
2021-05-22 08:53:52 +02:00
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
2020-12-25 09:58:34 +01:00
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import '../../utils/localized_exception_extension.dart';
2021-04-24 08:14:53 +02:00
import '../settings_notifications.dart';
2021-05-22 08:53:52 +02:00
import '../../widgets/matrix.dart';
2021-05-22 09:13:47 +02:00
class SettingsNotificationsView extends StatelessWidget {
2021-04-24 08:14:53 +02:00
final SettingsNotificationsController controller;
2021-05-22 09:13:47 +02:00
const SettingsNotificationsView(this.controller, {Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2021-01-16 14:24:52 +01:00
leading: BackButton(),
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: [
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 18:26:44 +02: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,
child: Icon(Icons.edit_outlined),
),
2021-04-24 08:14:53 +02:00
onTap: controller.openAndroidNotificationSettingsAction,
2021-04-09 18:26:44 +02:00
),
Divider(thickness: 1),
ListTile(
2021-04-09 18:26:44 +02:00
title: Text(
L10n.of(context).pushRules,
style: TextStyle(
color: Theme.of(context).accentColor,
fontWeight: FontWeight.bold,
),
),
),
2021-04-24 08:14:53 +02:00
for (var item in NotificationSettingsItem.items)
2021-04-09 18:26:44 +02:00
SwitchListTile(
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
),
},
Divider(thickness: 1),
ListTile(
title: Text(
2021-04-09 18:26:44 +02:00
L10n.of(context).devices,
style: TextStyle(
2021-02-07 09:31:24 +01:00
color: Theme.of(context).accentColor,
fontWeight: FontWeight.bold,
),
),
),
2021-04-09 18:26:44 +02: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(
snapshot.error.toLocalizedString(context),
),
);
}
2021-04-12 20:48:33 +02:00
if (snapshot.connectionState != ConnectionState.done) {
2021-04-09 18:26:44 +02:00
Center(child: CircularProgressIndicator());
}
2021-04-12 20:48:33 +02:00
final pushers = snapshot.data ?? [];
2021-04-09 18:26:44 +02:00
return ListView.builder(
physics: NeverScrollableScrollPhysics(),
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
},
),
],
);
}),
),
);
}
}