You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
meshcore-client/lib/widgets/channel_notify_mode.dart

72 lines
2.4 KiB

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../connector/meshcore_connector.dart';
import '../l10n/l10n.dart';
import '../models/app_settings.dart';
import '../models/channel.dart';
import '../services/app_settings_service.dart';
/// Shared per-channel notify-mode affordance (#262), reachable both from the
/// Channels list and from inside a channel's chat (#275). Single implementation
/// so the two entry points cannot drift.
IconData channelNotifyModeIcon(ChannelNotifyMode mode) {
switch (mode) {
case ChannelNotifyMode.all:
return Icons.notifications_outlined;
case ChannelNotifyMode.mentionsOnly:
return Icons.alternate_email;
case ChannelNotifyMode.off:
return Icons.notifications_off_outlined;
}
}
String channelNotifyModeLabel(BuildContext context, ChannelNotifyMode mode) {
switch (mode) {
case ChannelNotifyMode.all:
return context.l10n.channels_notifyAll;
case ChannelNotifyMode.mentionsOnly:
return context.l10n.channels_notifyMentionsOnly;
case ChannelNotifyMode.off:
return context.l10n.channels_notifyOff;
}
}
void showChannelNotifyModeDialog(BuildContext context, Channel channel) {
final settingsService = context.read<AppSettingsService>();
final devicePrefix = context.read<MeshCoreConnector>().selfPublicKeyHex;
final current = settingsService.channelNotifyMode(
devicePrefix: devicePrefix,
pskHex: channel.pskHex,
);
showDialog<void>(
context: context,
builder: (dialogContext) => AlertDialog(
title: Text(dialogContext.l10n.channels_notifications),
contentPadding: const EdgeInsets.symmetric(vertical: 8),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
for (final mode in ChannelNotifyMode.values)
ListTile(
leading: Icon(channelNotifyModeIcon(mode)),
title: Text(channelNotifyModeLabel(dialogContext, mode)),
trailing: mode == current ? const Icon(Icons.check) : null,
onTap: () async {
Navigator.pop(dialogContext);
await settingsService.setChannelNotifyMode(
devicePrefix: devicePrefix,
pskHex: channel.pskHex,
channelName: channel.name,
mode: mode,
);
},
),
],
),
),
);
}

Powered by TurnKey Linux.