design: Adjust settings design
This commit is contained in:
parent
23f4c64e50
commit
e11195f4fc
14 changed files with 217 additions and 116 deletions
|
|
@ -6,6 +6,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||
import '../../widgets/matrix.dart';
|
||||
import 'settings_notifications_view.dart';
|
||||
|
||||
|
|
@ -89,16 +90,52 @@ class SettingsNotificationsController extends State<SettingsNotifications> {
|
|||
}
|
||||
}
|
||||
|
||||
void setNotificationSetting(NotificationSettingsItem item, bool enabled) {
|
||||
showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(context).client.setPushRuleEnabled(
|
||||
bool isLoading = false;
|
||||
|
||||
void setNotificationSetting(
|
||||
NotificationSettingsItem item,
|
||||
bool enabled,
|
||||
) async {
|
||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
try {
|
||||
await Matrix.of(context).client.setPushRuleEnabled(
|
||||
'global',
|
||||
item.type,
|
||||
item.key,
|
||||
enabled,
|
||||
),
|
||||
);
|
||||
);
|
||||
} catch (e, s) {
|
||||
Logs().w('Unable to change notification settings', e, s);
|
||||
scaffoldMessenger
|
||||
.showSnackBar(SnackBar(content: Text(e.toLocalizedString(context))));
|
||||
} finally {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void onToggleMuteAllNotifications() async {
|
||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
try {
|
||||
await Matrix.of(context).client.setMuteAllPushNotifications(
|
||||
!Matrix.of(context).client.allPushNotificationsMuted,
|
||||
);
|
||||
} catch (e, s) {
|
||||
Logs().w('Unable to change notification settings', e, s);
|
||||
scaffoldMessenger
|
||||
.showSnackBar(SnackBar(content: Text(e.toLocalizedString(context))));
|
||||
} finally {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void onPusherTap(Pusher pusher) async {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||
|
|
@ -36,13 +35,18 @@ class SettingsNotificationsView extends StatelessWidget {
|
|||
title: Text(
|
||||
L10n.of(context)!.notificationsEnabledForThisAccount,
|
||||
),
|
||||
onChanged: (_) => showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(context)
|
||||
.client
|
||||
.setMuteAllPushNotifications(
|
||||
!Matrix.of(context).client.allPushNotificationsMuted,
|
||||
),
|
||||
onChanged: controller.isLoading
|
||||
? null
|
||||
: (_) => controller.onToggleMuteAllNotifications(),
|
||||
),
|
||||
Divider(color: Theme.of(context).dividerColor),
|
||||
ListTile(
|
||||
title: Text(
|
||||
L10n.of(context)!.notifyMeFor,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
for (final item in NotificationSettingsItem.items)
|
||||
|
|
@ -51,14 +55,14 @@ class SettingsNotificationsView extends StatelessWidget {
|
|||
? false
|
||||
: controller.getNotificationSetting(item) ?? true,
|
||||
title: Text(item.title(context)),
|
||||
onChanged: Matrix.of(context)
|
||||
.client
|
||||
.allPushNotificationsMuted
|
||||
onChanged: controller.isLoading
|
||||
? null
|
||||
: (bool enabled) =>
|
||||
controller.setNotificationSetting(item, enabled),
|
||||
: Matrix.of(context).client.allPushNotificationsMuted
|
||||
? null
|
||||
: (bool enabled) => controller
|
||||
.setNotificationSetting(item, enabled),
|
||||
),
|
||||
const Divider(),
|
||||
Divider(color: Theme.of(context).dividerColor),
|
||||
ListTile(
|
||||
title: Text(
|
||||
L10n.of(context)!.devices,
|
||||
|
|
@ -87,6 +91,14 @@ class SettingsNotificationsView extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue