mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-13 09:20:29 +00:00
feat: Add support for hash and private channels with corresponding UI updates
- Introduced new localization strings for channel types and their descriptions in Italian, German, Spanish, French, Croatian, Slovenian, and English. - Updated the `AppProvider` to handle channel info reception, including deletion of channels and updating the UI accordingly. - Enhanced `ChannelsProvider` to support channel removal and notify listeners. - Modified `ConnectionProvider` to include methods for checking empty channel slots and deleting channels. - Updated BLE service methods to handle channel deletion and verification. - Improved the `AddChannelDialog` to differentiate between hash and private channels, including dynamic UI elements based on channel type. - Added delete functionality for channels in the `ContactTile` widget with confirmation dialogs. - Adjusted permission request dialog behavior to allow dismissing by tapping outside.
This commit is contained in:
@@ -81,10 +81,14 @@ class _AddChannelDialogState extends State<AddChannelDialog> {
|
||||
});
|
||||
|
||||
try {
|
||||
await widget.onCreateChannel(
|
||||
_nameController.text.trim(),
|
||||
_secretController.text,
|
||||
);
|
||||
final channelName = _nameController.text.trim();
|
||||
final isHashChannel = channelName.startsWith('#');
|
||||
|
||||
// For hash channels, pass empty secret (will be auto-generated)
|
||||
// For private channels, use the provided secret
|
||||
final secret = isHashChannel ? '' : _secretController.text;
|
||||
|
||||
await widget.onCreateChannel(channelName, secret);
|
||||
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
@@ -101,6 +105,7 @@ class _AddChannelDialogState extends State<AddChannelDialog> {
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final theme = Theme.of(context);
|
||||
final isHashChannel = _nameController.text.startsWith('#');
|
||||
|
||||
return AlertDialog(
|
||||
title: Text(l10n.addChannel),
|
||||
@@ -111,6 +116,38 @@ class _AddChannelDialogState extends State<AddChannelDialog> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Info banner explaining channel types
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.primaryContainer.withOpacity(0.3),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: theme.colorScheme.primary.withOpacity(0.3),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
size: 20,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.channelTypesInfo,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Channel Name Field
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
@@ -118,38 +155,74 @@ class _AddChannelDialogState extends State<AddChannelDialog> {
|
||||
labelText: l10n.channelName,
|
||||
hintText: l10n.channelNameHint,
|
||||
border: const OutlineInputBorder(),
|
||||
prefixIcon: Icon(
|
||||
isHashChannel ? Icons.tag : Icons.lock_outline,
|
||||
color: isHashChannel ? Colors.blue : Colors.orange,
|
||||
),
|
||||
),
|
||||
enabled: !_isCreating,
|
||||
maxLength: 31,
|
||||
validator: _validateName,
|
||||
textInputAction: TextInputAction.next,
|
||||
onChanged: (_) => setState(() {}), // Rebuild to update icon
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Channel Secret Field
|
||||
TextFormField(
|
||||
controller: _secretController,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.channelSecret,
|
||||
hintText: l10n.channelSecretHint,
|
||||
border: const OutlineInputBorder(),
|
||||
// Channel Secret Field (only show for private channels)
|
||||
if (!isHashChannel) ...[
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _secretController,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.channelSecret,
|
||||
hintText: l10n.channelSecretHint,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
enabled: !_isCreating,
|
||||
maxLength: 32,
|
||||
validator: _validateSecret,
|
||||
textInputAction: TextInputAction.done,
|
||||
onFieldSubmitted: (_) => _handleCreate(),
|
||||
),
|
||||
obscureText: true,
|
||||
enabled: !_isCreating,
|
||||
maxLength: 32,
|
||||
validator: _validateSecret,
|
||||
textInputAction: TextInputAction.done,
|
||||
onFieldSubmitted: (_) => _handleCreate(),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Help Text
|
||||
Text(
|
||||
l10n.channelSecretHelp,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
const SizedBox(height: 8),
|
||||
// Help Text for private channels
|
||||
Text(
|
||||
l10n.channelSecretHelp,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
// Help Text for hash channels
|
||||
if (isHashChannel) ...[
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.primaryContainer.withOpacity(0.5),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.auto_awesome,
|
||||
size: 20,
|
||||
color: Colors.blue,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.hashChannelInfo,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -416,7 +416,31 @@ class ContactTile extends StatelessWidget {
|
||||
],
|
||||
],
|
||||
),
|
||||
trailing: null,
|
||||
trailing: contact.isChannel && !contact.isPublicChannel
|
||||
? PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
onSelected: (value) {
|
||||
if (value == 'delete') {
|
||||
_showDeleteChannelDialog(context, contact);
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
value: 'delete',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.delete, color: Colors.red, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.deleteChannel,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: null,
|
||||
onTap: () {
|
||||
// In simple mode, tap directly opens message sheet for chat contacts
|
||||
if (isSimpleMode && contact.type == ContactType.chat) {
|
||||
@@ -1201,4 +1225,57 @@ class ContactTile extends StatelessWidget {
|
||||
return '${diff.inDays}d ago';
|
||||
}
|
||||
}
|
||||
|
||||
/// Show delete channel confirmation dialog
|
||||
void _showDeleteChannelDialog(BuildContext context, Contact contact) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(l10n.deleteChannel),
|
||||
content: Text(l10n.deleteChannelConfirmation(contact.advName)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.of(dialogContext).pop();
|
||||
|
||||
try {
|
||||
// Extract channel index from pseudo public key
|
||||
// publicKey format: [0xFF, channelIdx, ...]
|
||||
final channelIdx = contact.publicKey[1];
|
||||
|
||||
final connectionProvider = context.read<ConnectionProvider>();
|
||||
await connectionProvider.deleteChannel(channelIdx);
|
||||
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(l10n.channelDeletedSuccessfully),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(l10n.channelDeletionFailed(e.toString())),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
style: TextButton.styleFrom(foregroundColor: Colors.red),
|
||||
child: Text(l10n.delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,8 +93,13 @@ class _PermissionRequestDialogState extends State<PermissionRequestDialog> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
// Prevent dismissing dialog by tapping outside
|
||||
canPop: false,
|
||||
// Allow dismissing dialog by back button or tapping outside
|
||||
canPop: true,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (didPop) {
|
||||
widget.onPermissionsDenied?.call();
|
||||
}
|
||||
},
|
||||
child: AlertDialog(
|
||||
title: Row(
|
||||
children: [
|
||||
@@ -162,14 +167,14 @@ class _PermissionRequestDialogState extends State<PermissionRequestDialog> {
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
if (_errorMessage != null && !_isRequesting)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
widget.onPermissionsDenied?.call();
|
||||
},
|
||||
child: const Text('Skip'),
|
||||
),
|
||||
// Always show a cancel/skip button
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
widget.onPermissionsDenied?.call();
|
||||
},
|
||||
child: const Text('Skip'),
|
||||
),
|
||||
if (_errorMessage != null && !_isRequesting)
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
|
||||
Reference in New Issue
Block a user