Add unit tests for ChannelMessage replies and update untranslated.json with new translations
This commit is contained in:
1 parent
c1680208d8
commit
0e8a8bd8c4
61 files changed
+9701
-1140
No files matched your search
@@ -9,11 +9,13 @@ import '../models/app_settings.dart';
|
||||
import '../models/image_codec_support.dart';
|
||||
import '../models/translation_support.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../services/background_service.dart';
|
||||
import '../services/image_codec_service.dart';
|
||||
import '../services/map_tile_cache_service.dart';
|
||||
import '../services/notification_service.dart';
|
||||
import '../services/translation_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
@@ -320,6 +322,22 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
? (value) => settingsService.setNotifyOnNewMessage(value)
|
||||
: null,
|
||||
),
|
||||
if (PlatformInfo.isAndroid) ...[
|
||||
const Divider(height: 1, indent: 16),
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
leading: const Icon(Icons.battery_saver_outlined, size: 20),
|
||||
title: Text(context.l10n.appSettings_batteryOptimization),
|
||||
subtitle: Text(
|
||||
context.l10n.appSettings_batteryOptimizationSubtitle,
|
||||
),
|
||||
trailing: const Icon(Icons.open_in_new, size: 18),
|
||||
onTap: BackgroundService.openBatteryOptimizationSettings,
|
||||
),
|
||||
],
|
||||
const Divider(height: 1, indent: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
@@ -610,6 +628,52 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
secondary: const Icon(Icons.cell_tower, size: 20),
|
||||
title: Text(context.l10n.appSettings_channelMinHops),
|
||||
subtitle: Text(context.l10n.appSettings_channelMinHopsSubtitle),
|
||||
value: settingsService.settings.channelMinHopsEnabled,
|
||||
onChanged: settingsService.setChannelMinHopsEnabled,
|
||||
),
|
||||
if (settingsService.settings.channelMinHopsEnabled) ...[
|
||||
ListTile(
|
||||
title: Text(
|
||||
context.l10n.appSettings_channelMinHopsCount(
|
||||
settingsService.settings.channelMinHops,
|
||||
),
|
||||
),
|
||||
subtitle: Slider(
|
||||
value: settingsService.settings.channelMinHops.toDouble(),
|
||||
min: 1,
|
||||
max: 8,
|
||||
divisions: 7,
|
||||
label: settingsService.settings.channelMinHops.toString(),
|
||||
onChanged: (value) =>
|
||||
settingsService.setChannelMinHops(value.toInt()),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text(
|
||||
context.l10n.appSettings_channelMinHopsRetries(
|
||||
settingsService.settings.channelMinHopsRetries,
|
||||
),
|
||||
),
|
||||
subtitle: Slider(
|
||||
value: settingsService.settings.channelMinHopsRetries.toDouble(),
|
||||
min: 1,
|
||||
max: 5,
|
||||
divisions: 4,
|
||||
label: settingsService.settings.channelMinHopsRetries.toString(),
|
||||
onChanged: (value) =>
|
||||
settingsService.setChannelMinHopsRetries(value.toInt()),
|
||||
),
|
||||
),
|
||||
],
|
||||
const Divider(height: 1, indent: 16),
|
||||
_ScrollIntoViewOnce(
|
||||
enabled: focusImageMessages,
|
||||
child: SwitchListTile(
|
||||
@@ -1557,7 +1621,11 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
for (final model in settings.translationDownloadedModels)
|
||||
DropdownMenuItem(
|
||||
value: model.id,
|
||||
child: Text(translationModelFriendlyName(model)),
|
||||
child: Text(
|
||||
translationModelFriendlyName(model),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: settings.translationDownloadedModels.isEmpty
|
||||
@@ -1580,7 +1648,11 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
for (final preset in translationPresetModels)
|
||||
DropdownMenuItem(
|
||||
value: preset.sourceUrl,
|
||||
child: Text(translationModelFriendlyName(preset)),
|
||||
child: Text(
|
||||
translationModelFriendlyName(preset),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: translationService.isBusy
|
||||
@@ -1741,6 +1813,7 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
const SizedBox(height: 8),
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: settingsService.settings.selectedCyr2latProfileId,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: context.l10n.channels_cyr2latSettingsSubheading,
|
||||
border: const OutlineInputBorder(),
|
||||
@@ -1748,7 +1821,11 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
items: settingsService.settings.cyr2latProfiles.map((profile) {
|
||||
return DropdownMenuItem(
|
||||
value: profile.id,
|
||||
child: Text(profile.name),
|
||||
child: Text(
|
||||
profile.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:intl/intl.dart' hide TextDirection;
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
@@ -33,9 +32,11 @@ import '../services/image_chunk_transport.dart';
|
||||
import '../services/image_codec_service.dart';
|
||||
import '../services/received_image_store.dart';
|
||||
import '../services/translation_service.dart';
|
||||
import '../utils/image_save.dart';
|
||||
import '../utils/lora_airtime.dart';
|
||||
import '../widgets/received_image_message.dart';
|
||||
import '../widgets/byte_count_input.dart';
|
||||
import '../widgets/chat_day_separator.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../widgets/chat_zoom_wrapper.dart';
|
||||
import '../widgets/emoji_picker.dart';
|
||||
@@ -98,10 +99,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
bool _channelSkipNextBottomSnap = false;
|
||||
String? _unreadDividerMessageId;
|
||||
|
||||
String? _cachedFormatLocale;
|
||||
late DateFormat _hmFormat;
|
||||
late DateFormat _mdFormat;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -321,21 +318,32 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
),
|
||||
Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, _) {
|
||||
final unreadCount = connector
|
||||
.getUnreadCountForChannelIndex(
|
||||
widget.channel.index,
|
||||
);
|
||||
final privacy = widget.channel.isPublicChannel
|
||||
? context.l10n.channels_public
|
||||
: context.l10n.channels_private;
|
||||
final region = connector.getChannelRegion(
|
||||
final privacy = switch (Channel.getChannelType(
|
||||
widget.channel,
|
||||
_communityIndex,
|
||||
)) {
|
||||
ChannelType.public => context.l10n.channels_public,
|
||||
ChannelType.hashtag => context.l10n.channels_hashtag,
|
||||
ChannelType.private => context.l10n.channels_private,
|
||||
ChannelType.communityPublic =>
|
||||
context.l10n.community_publicChannel,
|
||||
ChannelType.communityHashtag =>
|
||||
context.l10n.community_hashtagChannel,
|
||||
};
|
||||
final ownRegion = connector.getChannelRegion(
|
||||
widget.channel.index,
|
||||
);
|
||||
final region = connector.getEffectiveChannelRegion(
|
||||
widget.channel.index,
|
||||
);
|
||||
final defaultSuffix = ownRegion.isEmpty
|
||||
? ' ${context.l10n.channels_regionDefaultSuffix}'
|
||||
: '';
|
||||
final regionText = region.isNotEmpty
|
||||
? ' • ${context.l10n.channels_regionSetTo(region)}'
|
||||
? ' • ${context.l10n.channels_regionSetTo(region)}$defaultSuffix'
|
||||
: '';
|
||||
return Text(
|
||||
'$privacy • ${context.l10n.chat_unread(unreadCount)}$regionText',
|
||||
'$privacy$regionText',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
);
|
||||
@@ -513,10 +521,22 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
row.image!,
|
||||
textScale,
|
||||
);
|
||||
if (isUnreadAnchor) {
|
||||
final startsDay =
|
||||
index == reversedRows.length - 1 ||
|
||||
!isSameChatDay(
|
||||
reversedRows[index + 1].timestamp,
|
||||
row.timestamp,
|
||||
);
|
||||
if (isUnreadAnchor || startsDay) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [const UnreadDivider(), bubble],
|
||||
children: [
|
||||
if (startsDay)
|
||||
ChatDaySeparator(day: row.timestamp),
|
||||
if (isUnreadAnchor)
|
||||
const UnreadDivider(),
|
||||
bubble,
|
||||
],
|
||||
);
|
||||
}
|
||||
return bubble;
|
||||
@@ -799,7 +819,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
buildTextContent(),
|
||||
],
|
||||
),
|
||||
if (enableTracing && displayPath.isNotEmpty) ...[
|
||||
if (displayPath.isNotEmpty) ...[
|
||||
const SizedBox(height: 3),
|
||||
Padding(
|
||||
padding: gifId != null
|
||||
@@ -813,21 +833,25 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
isDirect: (message.pathLength ?? -1) >= 0,
|
||||
hops: displayHopCount,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Flexible(
|
||||
child: Text(
|
||||
context.l10n.channels_via(
|
||||
_formatPathPrefixes(
|
||||
displayPath,
|
||||
displayPathHashWidth,
|
||||
if (enableTracing) ...[
|
||||
const SizedBox(width: 4),
|
||||
Flexible(
|
||||
child: Text(
|
||||
context.l10n.channels_via(
|
||||
_formatPathPrefixes(
|
||||
displayPath,
|
||||
displayPathHashWidth,
|
||||
),
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 9.5 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 9.5 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -845,13 +869,15 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
_formatTime(context, message.timestamp),
|
||||
formatChatTime(context, message.timestamp),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 10 * textScale,
|
||||
fontSize: 12 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
if (enableTracing && message.repeatCount > 0) ...[
|
||||
if (enableTracing &&
|
||||
!isOutgoing &&
|
||||
message.repeatCount > 0) ...[
|
||||
const SizedBox(width: 6),
|
||||
Icon(
|
||||
Icons.repeat,
|
||||
@@ -862,7 +888,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
Text(
|
||||
'${message.repeatCount}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 10 * textScale,
|
||||
fontSize: 12 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
@@ -870,13 +896,16 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
if (isOutgoing) ...[
|
||||
const SizedBox(width: 4),
|
||||
MessageStatusIcon(
|
||||
isAcked:
|
||||
message.status ==
|
||||
ChannelMessageStatus.sent,
|
||||
isRepeated:
|
||||
message.status ==
|
||||
ChannelMessageStatus.sent &&
|
||||
displayPath.isNotEmpty,
|
||||
size: 16 * textScale,
|
||||
isAcked: false,
|
||||
isChannel: true,
|
||||
repeatCount: message.repeatCount,
|
||||
resendProgress: context
|
||||
.read<MeshCoreConnector>()
|
||||
.channelResendProgress(message.messageId),
|
||||
hopShortfall: context
|
||||
.read<MeshCoreConnector>()
|
||||
.channelHopShortfall(message.messageId),
|
||||
isPending:
|
||||
message.status ==
|
||||
ChannelMessageStatus.pending,
|
||||
@@ -1224,16 +1253,37 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the image codec model is currently downloading.
|
||||
///
|
||||
/// This must be read while [context] is building; popup item builders run
|
||||
/// from an overlay and cannot listen to a provider.
|
||||
bool _isImageCodecDownloading(BuildContext context) {
|
||||
try {
|
||||
return context.watch<ImageCodecService>().isDownloading;
|
||||
} on ProviderNotFoundException {
|
||||
return false;
|
||||
void _explainImageCodecNotReady(ImageCodecService codec) {
|
||||
final l10n = context.l10n;
|
||||
final availability = codec.availability;
|
||||
final String message;
|
||||
switch (availability) {
|
||||
case ImageCodecAvailability.downloading:
|
||||
message = l10n.imageSend_codecDownloading;
|
||||
case ImageCodecAvailability.unavailable:
|
||||
message = codec.unavailableReason ?? l10n.imageSend_codecUnavailable;
|
||||
case ImageCodecAvailability.disabled:
|
||||
message = codec.needsModelDownload
|
||||
? l10n.imageSend_modelNotDownloaded
|
||||
: codec.statusReason ?? l10n.imageSend_codecDisabled;
|
||||
case ImageCodecAvailability.ready:
|
||||
return;
|
||||
}
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(message),
|
||||
action: availability == ImageCodecAvailability.disabled
|
||||
? SnackBarAction(
|
||||
label: l10n.receivedImage_openSettings,
|
||||
onPressed: () => Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) =>
|
||||
const AppSettingsScreen(focusImageMessages: true),
|
||||
),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
/// Takes no [BuildContext]: it uses the [State]'s own, so the `mounted`
|
||||
@@ -1241,6 +1291,10 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
Future<void> _showImageSendPreview() async {
|
||||
final codec = _imageCodec;
|
||||
if (codec == null) return;
|
||||
if (codec.availability != ImageCodecAvailability.ready) {
|
||||
_explainImageCodecNotReady(codec);
|
||||
return;
|
||||
}
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
|
||||
// The picked bytes are kept past the preview on purpose: the sender's own
|
||||
@@ -1545,7 +1599,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
final textColor = isOutgoing ? MeshPalette.meInk : scheme.onSurface;
|
||||
final metaColor = textColor.withValues(alpha: 0.65);
|
||||
|
||||
return Padding(
|
||||
final bubble = Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
mainAxisAlignment: isOutgoing
|
||||
@@ -1612,9 +1666,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
bottom: 4,
|
||||
),
|
||||
child: Text(
|
||||
_formatTime(context, entry.firstSeen),
|
||||
formatChatTime(context, entry.firstSeen),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 10 * textScale,
|
||||
fontSize: 12 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
@@ -1626,6 +1680,123 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
],
|
||||
),
|
||||
);
|
||||
return GestureDetector(
|
||||
onLongPress: () => _showImageActions(entry),
|
||||
onSecondaryTap: () => _showImageActions(entry),
|
||||
child: bubble,
|
||||
);
|
||||
}
|
||||
|
||||
void _showImageActions(ReceivedImageEntry entry) {
|
||||
final l10n = context.l10n;
|
||||
final canSave = entry.state == ReceivedImageState.decoded;
|
||||
showMeshSheet(
|
||||
context,
|
||||
builder: (sheetContext) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHeader(
|
||||
title: l10n.receivedImage_awaiting(
|
||||
entry.bitstreamByteCount,
|
||||
entry.totalChunks,
|
||||
),
|
||||
subtitle: _imageSenderLabel(entry),
|
||||
),
|
||||
if (canSave)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.save_alt),
|
||||
title: Text(l10n.receivedImage_save),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_saveImage(entry);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.info_outline),
|
||||
title: Text(l10n.receivedImage_packetInfo),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_showImagePacketInfo(entry);
|
||||
},
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
leading: Icon(
|
||||
Icons.delete_outline,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
title: Text(
|
||||
l10n.common_delete,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
onTap: () async {
|
||||
Navigator.pop(sheetContext);
|
||||
await context.read<ReceivedImageStore>().deleteImage(
|
||||
entry.streamId,
|
||||
);
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.chat_messageDeleted),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _saveImage(ReceivedImageEntry entry) async {
|
||||
final l10n = context.l10n;
|
||||
final png = await context.read<ReceivedImageStore>().ensurePng(
|
||||
entry.streamId,
|
||||
);
|
||||
if (!mounted) return;
|
||||
final shareText = l10n.receivedImage_shareCaption(entry.bitstreamByteCount);
|
||||
if (png == null || !await saveImagePng(png, entry, shareText: shareText)) {
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.receivedImage_saveFailed),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _showImagePacketInfo(ReceivedImageEntry entry) {
|
||||
final l10n = context.l10n;
|
||||
final decodeMs = entry.decodeMs;
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(l10n.receivedImage_packetInfo),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(_imageSenderLabel(entry)),
|
||||
Text(formatChatTime(context, entry.firstSeen)),
|
||||
Text(
|
||||
l10n.receivedImage_awaiting(
|
||||
entry.bitstreamByteCount,
|
||||
entry.totalChunks,
|
||||
),
|
||||
),
|
||||
if (entry.recoveredWithParity)
|
||||
Text(l10n.receivedImage_parityRecovered),
|
||||
if (decodeMs != null) Text(l10n.receivedImage_decodeTime(decodeMs)),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(l10n.common_close),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// GRP_DATA carries no sender name — only the 2-byte public-key prefix the
|
||||
@@ -1709,6 +1880,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, size: 18),
|
||||
tooltip: context.l10n.chat_cancelReply,
|
||||
onPressed: _cancelReply,
|
||||
color: scheme.onSurfaceVariant,
|
||||
constraints: const BoxConstraints(minWidth: 44, minHeight: 44),
|
||||
@@ -1753,9 +1925,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final maxBytes = maxChannelMessageBytes(connector.selfName);
|
||||
final settings = context.watch<AppSettingsService>().settings;
|
||||
final imageCodecDownloading = _isImageCodecDownloading(context);
|
||||
final showImageAction =
|
||||
settings.imageMessagesEnabled && !imageCodecDownloading;
|
||||
final showImageAction = settings.imageMessagesEnabled;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
@@ -1811,13 +1981,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
if (showImageAction)
|
||||
PopupMenuItem(
|
||||
value: 'meshcore-image',
|
||||
// Gated on the codec, not just the setting. The preview
|
||||
// sheet explains why a send is impossible, but a fully
|
||||
// live button in a build that cannot encode invites the
|
||||
// tap that produces that explanation.
|
||||
enabled:
|
||||
_imageCodec?.availability ==
|
||||
ImageCodecAvailability.ready,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.image_outlined),
|
||||
@@ -1872,6 +2035,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
tooltip: context.l10n.chat_removeGif,
|
||||
onPressed: () {
|
||||
_textController.clear();
|
||||
_textFieldFocusNode.requestFocus();
|
||||
@@ -2055,6 +2219,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
}
|
||||
// end transform
|
||||
|
||||
final replyTo = _replyingToMessage;
|
||||
_textController.clear();
|
||||
_cancelReply();
|
||||
_textFieldFocusNode.requestFocus();
|
||||
@@ -2064,27 +2229,10 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
originalText: originalText,
|
||||
translatedLanguageCode: translatedLanguageCode,
|
||||
translationModelId: translationModelId,
|
||||
replyTo: replyTo,
|
||||
);
|
||||
}
|
||||
|
||||
String _formatTime(BuildContext context, DateTime time) {
|
||||
final now = DateTime.now();
|
||||
final diff = now.difference(time);
|
||||
final locale = Localizations.localeOf(context).toString();
|
||||
if (locale != _cachedFormatLocale) {
|
||||
_cachedFormatLocale = locale;
|
||||
_hmFormat = DateFormat.Hm(locale);
|
||||
_mdFormat = DateFormat.Md(locale);
|
||||
}
|
||||
final hm = _hmFormat.format(time);
|
||||
|
||||
if (diff.inDays > 0) {
|
||||
return '${_mdFormat.format(time)} $hm';
|
||||
} else {
|
||||
return hm;
|
||||
}
|
||||
}
|
||||
|
||||
void _showMessagePathInfo(ChannelMessage message) {
|
||||
Navigator.push(
|
||||
context,
|
||||
@@ -2135,6 +2283,23 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
_showMessagePathInfo(message);
|
||||
},
|
||||
),
|
||||
if (message.pathBytes.isNotEmpty)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.map_outlined),
|
||||
title: Text(context.l10n.chat_viewPathOnMap),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChannelMessagePathMapScreen(
|
||||
message: message,
|
||||
channelMessage: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
// Can't react to your own messages
|
||||
if (!message.isOutgoing)
|
||||
ListTile(
|
||||
@@ -2344,57 +2509,77 @@ class _RegionSelectDialogState extends State<_RegionSelectDialog> {
|
||||
backgroundColor: Colors.transparent,
|
||||
title: Text(context.l10n.channels_regionSelect_Title),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: context.l10n.channels_clearRegion,
|
||||
icon: const Icon(Icons.backspace_outlined),
|
||||
onPressed: () {
|
||||
context.read<MeshCoreConnector>().setChannelRegion(
|
||||
widget.channel.index,
|
||||
'',
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Text(
|
||||
context.l10n.channels_regionSelectExplanation,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (regions.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Text(context.l10n.channels_regionEmpty),
|
||||
)
|
||||
else
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: regions.length,
|
||||
itemBuilder: (context, index) {
|
||||
final selected = selectedIndex == index;
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
Icons.landscape,
|
||||
color: selected ? MeshPalette.blue : null,
|
||||
),
|
||||
title: Text(regions[index]),
|
||||
trailing: selected
|
||||
? const Icon(Icons.check, color: MeshPalette.blue)
|
||||
: null,
|
||||
tileColor: selected ? MeshPalette.blueBg : null,
|
||||
onTap: () {
|
||||
// Tapping the already-selected region clears it.
|
||||
context.read<MeshCoreConnector>().setChannelRegion(
|
||||
widget.channel.index,
|
||||
selected ? '' : regions[index],
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
tooltip: context.l10n.settings_regionSettingsSubtitle,
|
||||
icon: const Icon(Icons.settings),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed:
|
||||
context
|
||||
.read<MeshCoreConnector>()
|
||||
.getChannelRegion(widget.channel.index)
|
||||
.isEmpty
|
||||
? null
|
||||
: () {
|
||||
context.read<MeshCoreConnector>().setChannelRegion(
|
||||
widget.channel.index,
|
||||
'',
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text(context.l10n.common_clear),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await pushRegionManagementScreen(context);
|
||||
if (!mounted) return;
|
||||
loadRegions();
|
||||
},
|
||||
child: Text(context.l10n.channels_manageRegions),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: regions.length,
|
||||
itemBuilder: (context, index) {
|
||||
final selected = selectedIndex == index;
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
Icons.landscape,
|
||||
color: selected ? MeshPalette.blue : null,
|
||||
),
|
||||
title: Text(regions[index]),
|
||||
trailing: selected
|
||||
? const Icon(Icons.check, color: MeshPalette.blue)
|
||||
: null,
|
||||
tileColor: selected ? MeshPalette.blueBg : null,
|
||||
onTap: () {
|
||||
// Tapping the already-selected region clears it.
|
||||
context.read<MeshCoreConnector>().setChannelRegion(
|
||||
widget.channel.index,
|
||||
selected ? '' : regions[index],
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -222,6 +222,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
if (viewState.channelsSearchText.isNotEmpty)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
tooltip: context.l10n.common_clearSearch,
|
||||
onPressed: () {
|
||||
_searchDebounce?.cancel();
|
||||
_searchDebounce = null;
|
||||
@@ -403,7 +404,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
iconColor = MeshPalette.signal;
|
||||
case ChannelType.hashtag:
|
||||
icon = Icons.tag;
|
||||
iconColor = MeshPalette.blue;
|
||||
iconColor = MeshPalette.warn;
|
||||
case ChannelType.private:
|
||||
icon = Icons.lock;
|
||||
iconColor = MeshPalette.blue;
|
||||
@@ -517,14 +518,18 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'CH ${channel.index}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
color: scheme.onSurfaceVariant.withValues(alpha: 0.7),
|
||||
if (showDragHandle) ...[
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'CH ${channel.index}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 11,
|
||||
color: scheme.onSurfaceVariant.withValues(
|
||||
alpha: 0.7,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
if (subtitle.isNotEmpty) ...[
|
||||
@@ -585,17 +590,21 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
],
|
||||
),
|
||||
if (showDragHandle && dragIndex != null) ...[
|
||||
const SizedBox(width: 4),
|
||||
ReorderableDragStartListener(
|
||||
index: dragIndex,
|
||||
// Top-aligned with the "CH n" / time line. Bottom padding keeps
|
||||
// a comfortable drag target without pushing the icon down.
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 16),
|
||||
child: Icon(
|
||||
Icons.drag_handle,
|
||||
size: 18,
|
||||
color: scheme.onSurfaceVariant,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.grab,
|
||||
child: Tooltip(
|
||||
message: context.l10n.channels_dragToReorder,
|
||||
child: SizedBox(
|
||||
width: 48,
|
||||
height: 48,
|
||||
child: Icon(
|
||||
Icons.drag_indicator,
|
||||
size: 28,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1463,24 +1472,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
controller: scrollController,
|
||||
padding: const EdgeInsets.only(bottom: 24),
|
||||
children: [
|
||||
buildOptionCard(
|
||||
optionIndex: 0,
|
||||
icon: Icons.add,
|
||||
title: sheetContext.l10n.channels_createPrivateChannel,
|
||||
subtitle:
|
||||
sheetContext.l10n.channels_createPrivateChannelDesc,
|
||||
),
|
||||
if (selectedOption == 0)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
buildOptionCard(
|
||||
optionIndex: 1,
|
||||
icon: Icons.lock,
|
||||
title: sheetContext.l10n.channels_joinPrivateChannel,
|
||||
subtitle:
|
||||
sheetContext.l10n.channels_joinPrivateChannelDesc,
|
||||
),
|
||||
if (selectedOption == 1)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
SectionHeader(sheetContext.l10n.channels_addSectionJoin),
|
||||
if (!hasPublicChannel) ...[
|
||||
buildOptionCard(
|
||||
optionIndex: 2,
|
||||
@@ -1501,6 +1493,15 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
),
|
||||
if (selectedOption == 3)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
buildOptionCard(
|
||||
optionIndex: 1,
|
||||
icon: Icons.lock,
|
||||
title: sheetContext.l10n.channels_joinPrivateChannel,
|
||||
subtitle:
|
||||
sheetContext.l10n.channels_joinPrivateChannelDesc,
|
||||
),
|
||||
if (selectedOption == 1)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
buildOptionCard(
|
||||
optionIndex: 4,
|
||||
icon: Icons.qr_code_scanner,
|
||||
@@ -1509,6 +1510,18 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
),
|
||||
if (selectedOption == 4)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
SectionHeader(
|
||||
sheetContext.l10n.channels_addSectionCreate,
|
||||
),
|
||||
buildOptionCard(
|
||||
optionIndex: 0,
|
||||
icon: Icons.add,
|
||||
title: sheetContext.l10n.channels_createPrivateChannel,
|
||||
subtitle:
|
||||
sheetContext.l10n.channels_createPrivateChannelDesc,
|
||||
),
|
||||
if (selectedOption == 0)
|
||||
buildExpandedContent(_channelMessageStore)!,
|
||||
buildOptionCard(
|
||||
optionIndex: 5,
|
||||
icon: Icons.groups,
|
||||
|
||||
@@ -31,6 +31,7 @@ import '../services/path_history_service.dart';
|
||||
import '../services/translation_service.dart';
|
||||
import '../widgets/chat_zoom_wrapper.dart';
|
||||
import '../widgets/byte_count_input.dart';
|
||||
import '../widgets/chat_day_separator.dart';
|
||||
import 'channel_message_path_screen.dart';
|
||||
import 'map_screen.dart';
|
||||
import '../widgets/emoji_picker.dart';
|
||||
@@ -189,10 +190,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
title: Consumer2<PathHistoryService, MeshCoreConnector>(
|
||||
builder: (context, pathService, connector, _) {
|
||||
final contact = _resolveContact(connector);
|
||||
final unreadCount = connector.getUnreadCountForContactKey(
|
||||
widget.contact.publicKeyHex,
|
||||
);
|
||||
final unreadLabel = context.l10n.chat_unread(unreadCount);
|
||||
final pathLabel = _currentPathLabel(contact);
|
||||
|
||||
return Column(
|
||||
@@ -211,7 +208,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Text(
|
||||
'$pathLabel • $unreadLabel',
|
||||
pathLabel,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
@@ -435,10 +432,20 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
final isUnreadAnchor =
|
||||
_unreadDividerMessageId != null &&
|
||||
message.messageId == _unreadDividerMessageId;
|
||||
final child = isUnreadAnchor
|
||||
final startsDay =
|
||||
messageIndex == reversedMessages.length - 1 ||
|
||||
!isSameChatDay(
|
||||
reversedMessages[messageIndex + 1].timestamp,
|
||||
message.timestamp,
|
||||
);
|
||||
final child = isUnreadAnchor || startsDay
|
||||
? Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [const UnreadDivider(), bubble],
|
||||
children: [
|
||||
if (startsDay) ChatDaySeparator(day: message.timestamp),
|
||||
if (isUnreadAnchor) const UnreadDivider(),
|
||||
bubble,
|
||||
],
|
||||
)
|
||||
: bubble;
|
||||
if (identical(message, _pendingUnreadScrollTarget)) {
|
||||
@@ -479,26 +486,10 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.add_circle_outline),
|
||||
position: PopupMenuPosition.over,
|
||||
offset: const Offset(0, -64),
|
||||
tooltip: context.l10n.chat_selectSendAction,
|
||||
onSelected: (action) {
|
||||
if (action == 'gif') _showGifPicker(context);
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
value: 'gif',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.gif_box),
|
||||
const SizedBox(width: 12),
|
||||
Text(context.l10n.chat_sendGif),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
IconButton(
|
||||
icon: const Icon(Icons.gif_box_outlined),
|
||||
tooltip: context.l10n.chat_sendGif,
|
||||
onPressed: () => _showGifPicker(context),
|
||||
),
|
||||
if (settings.translationEnabled)
|
||||
MessageTranslationButton(
|
||||
@@ -546,6 +537,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
tooltip: context.l10n.chat_removeGif,
|
||||
onPressed: () {
|
||||
_textController.clear();
|
||||
_textFieldFocusNode.requestFocus();
|
||||
@@ -1121,7 +1113,11 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _openMessagePath(Message message, Contact contact) {
|
||||
void _openMessagePath(
|
||||
Message message,
|
||||
Contact contact, {
|
||||
bool openMap = false,
|
||||
}) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final fourByteHex = message.fourByteRoomContactKey
|
||||
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||
@@ -1153,7 +1149,9 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChannelMessagePathScreen(message: pathMessage),
|
||||
builder: (context) => openMap
|
||||
? ChannelMessagePathMapScreen(message: pathMessage)
|
||||
: ChannelMessagePathScreen(message: pathMessage),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1197,6 +1195,15 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
_openMessagePath(message, contact);
|
||||
},
|
||||
),
|
||||
if (message.pathBytes.isNotEmpty)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.map_outlined),
|
||||
title: Text(context.l10n.chat_viewPathOnMap),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_openMessagePath(message, contact, openMap: true);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.copy),
|
||||
title: Text(context.l10n.common_copy),
|
||||
@@ -1628,16 +1635,16 @@ class _MessageBubble extends StatelessWidget {
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
_formatTime(message.timestamp),
|
||||
formatChatTime(context, message.timestamp),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 10 * textScale,
|
||||
fontSize: 12 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
if (isOutgoing) ...[
|
||||
const SizedBox(width: 2),
|
||||
MessageStatusIcon(
|
||||
size: 12 * textScale,
|
||||
size: 16 * textScale,
|
||||
onColor: metaColor,
|
||||
isAcked:
|
||||
message.status ==
|
||||
@@ -1663,7 +1670,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
Text(
|
||||
'${(message.tripTimeMs! / 1000).toStringAsFixed(1)}s',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 9 * textScale,
|
||||
fontSize: 11 * textScale,
|
||||
color: isOutgoing
|
||||
? metaColor
|
||||
: scheme.tertiary,
|
||||
@@ -1842,12 +1849,6 @@ class _MessageBubble extends StatelessWidget {
|
||||
Widget _buildAvatar(String senderName) {
|
||||
return AvatarCircle(name: senderName, size: 32);
|
||||
}
|
||||
|
||||
String _formatTime(DateTime time) {
|
||||
final hour = time.hour.toString().padLeft(2, '0');
|
||||
final minute = time.minute.toString().padLeft(2, '0');
|
||||
return '$hour:$minute';
|
||||
}
|
||||
}
|
||||
|
||||
/// Deterministic name-to-hue mapping consistent with [AvatarCircle].
|
||||
|
||||
@@ -109,8 +109,8 @@ class _CompanionRadioStatsScreenState extends State<CompanionRadioStatsScreen> {
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
children: [
|
||||
if (stats != null) ...[
|
||||
const SectionHeader(
|
||||
'Signal',
|
||||
SectionHeader(
|
||||
l10n.radioStats_sectionSignal,
|
||||
padding: EdgeInsets.fromLTRB(16, 16, 16, 8),
|
||||
),
|
||||
MeshCard(
|
||||
@@ -144,8 +144,8 @@ class _CompanionRadioStatsScreenState extends State<CompanionRadioStatsScreen> {
|
||||
],
|
||||
),
|
||||
),
|
||||
const SectionHeader(
|
||||
'Airtime',
|
||||
SectionHeader(
|
||||
l10n.radioStats_sectionAirtime,
|
||||
padding: EdgeInsets.fromLTRB(16, 16, 16, 8),
|
||||
),
|
||||
MeshCard(
|
||||
|
||||
@@ -712,7 +712,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
return EmptyState(
|
||||
icon: Icons.people_outline,
|
||||
title: context.l10n.contacts_noContacts,
|
||||
subtitle: context.l10n.contacts_contactsWillAppear,
|
||||
subtitle: context.l10n.contacts_noContactsDiscoveredHint,
|
||||
action: FilledButton.icon(
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
@@ -890,6 +890,20 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
],
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
dense: true,
|
||||
leading: const Icon(Icons.person_add_rounded),
|
||||
title: Text(
|
||||
context.l10n.contacts_discoveredNearby(
|
||||
connector.discoveredContacts.where((c) => !c.isActive).length,
|
||||
),
|
||||
),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const DiscoveryScreen()),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () => connector.getContacts(),
|
||||
@@ -930,6 +944,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
onTap: () => _openChat(context, contact),
|
||||
onLongPress: () =>
|
||||
_showContactOptions(context, connector, contact),
|
||||
onManage: _manageAction(context, contact),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -1055,6 +1070,17 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
}
|
||||
}
|
||||
|
||||
VoidCallback? _manageAction(BuildContext context, Contact contact) {
|
||||
if (contact.type == advTypeRepeater) {
|
||||
return () => _showRepeaterLogin(context, contact);
|
||||
}
|
||||
if (contact.type == advTypeRoom) {
|
||||
return () =>
|
||||
_showRoomLogin(context, contact, RoomLoginDestination.management);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void _handleQuickSwitch(int index, BuildContext context) {
|
||||
if (index == 0) return;
|
||||
switch (index) {
|
||||
@@ -1513,7 +1539,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
title: Text(
|
||||
context.l10n.contacts_deleteContact,
|
||||
context.l10n.contacts_removeFromContacts,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
onTap: () {
|
||||
@@ -1543,27 +1569,46 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
MeshCoreConnector connector,
|
||||
Contact contact,
|
||||
) {
|
||||
var keepHistory = false;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(context.l10n.contacts_deleteContact),
|
||||
content: Text(context.l10n.contacts_removeConfirm(contact.name)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(context.l10n.common_cancel),
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (dialogContext, setDialogState) => AlertDialog(
|
||||
title: Text(context.l10n.contacts_removeFromContacts),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context.l10n.contacts_removeFromContactsConfirm(contact.name),
|
||||
),
|
||||
CheckboxListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
value: keepHistory,
|
||||
title: Text(context.l10n.contacts_keepChatHistory),
|
||||
onChanged: (value) =>
|
||||
setDialogState(() => keepHistory = value ?? false),
|
||||
),
|
||||
],
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext);
|
||||
connector.removeContact(contact);
|
||||
},
|
||||
child: Text(
|
||||
context.l10n.common_delete,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(context.l10n.common_cancel),
|
||||
),
|
||||
),
|
||||
],
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext);
|
||||
connector.removeContact(contact, keepMessages: keepHistory);
|
||||
},
|
||||
child: Text(
|
||||
context.l10n.contacts_remove,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1577,6 +1622,7 @@ class _ContactTile extends StatelessWidget {
|
||||
final bool isFavorite;
|
||||
final VoidCallback onTap;
|
||||
final VoidCallback onLongPress;
|
||||
final VoidCallback? onManage;
|
||||
|
||||
const _ContactTile({
|
||||
required this.contact,
|
||||
@@ -1586,6 +1632,7 @@ class _ContactTile extends StatelessWidget {
|
||||
required this.isFavorite,
|
||||
required this.onTap,
|
||||
required this.onLongPress,
|
||||
this.onManage,
|
||||
});
|
||||
|
||||
/// Node-type avatar color per design language.
|
||||
@@ -1622,9 +1669,6 @@ class _ContactTile extends StatelessWidget {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final emoji = firstEmoji(contact.name);
|
||||
final isChat = contact.type == advTypeChat;
|
||||
final pathLen = contact.pathBytesForDisplay.length;
|
||||
final isDirect = contact.pathLength >= 0;
|
||||
final hasPath = pathLen > 0 || contact.pathLength == 0;
|
||||
|
||||
return GestureDetector(
|
||||
onSecondaryTapUp: PlatformInfo.isDesktop ? (_) => onLongPress() : null,
|
||||
@@ -1712,13 +1756,6 @@ class _ContactTile extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (hasPath) ...[
|
||||
const SizedBox(width: 6),
|
||||
RouteChip(
|
||||
isDirect: isDirect,
|
||||
hops: isDirect ? contact.pathLength : null,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -1757,6 +1794,15 @@ class _ContactTile extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
if (onManage != null)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.admin_panel_settings_outlined),
|
||||
tooltip: contact.type == advTypeRoom
|
||||
? context.l10n.room_management
|
||||
: context.l10n.contacts_manageRepeater,
|
||||
visualDensity: VisualDensity.compact,
|
||||
onPressed: onManage,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -1796,6 +1842,7 @@ class _ContactTileEntrance extends StatelessWidget {
|
||||
final bool isFavorite;
|
||||
final VoidCallback onTap;
|
||||
final VoidCallback onLongPress;
|
||||
final VoidCallback? onManage;
|
||||
|
||||
const _ContactTileEntrance({
|
||||
required this.index,
|
||||
@@ -1806,6 +1853,7 @@ class _ContactTileEntrance extends StatelessWidget {
|
||||
required this.isFavorite,
|
||||
required this.onTap,
|
||||
required this.onLongPress,
|
||||
this.onManage,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -1820,6 +1868,7 @@ class _ContactTileEntrance extends StatelessWidget {
|
||||
isFavorite: isFavorite,
|
||||
onTap: onTap,
|
||||
onLongPress: onLongPress,
|
||||
onManage: onManage,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -34,9 +34,17 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
ContactTypeFilter typeFilter = ContactTypeFilter.all;
|
||||
DiscoverySortOption discoverySortOption = DiscoverySortOption.lastSeen;
|
||||
Timer? _searchDebounce;
|
||||
ScaffoldMessengerState? _messenger;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_messenger = ScaffoldMessenger.maybeOf(context);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_messenger?.hideCurrentSnackBar();
|
||||
_searchController.dispose();
|
||||
_searchDebounce?.cancel();
|
||||
super.dispose();
|
||||
@@ -169,33 +177,7 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
return ListEntrance(
|
||||
index: index,
|
||||
child: MeshCard(
|
||||
onTap: () async {
|
||||
try {
|
||||
final imported = await connector.importDiscoveredContact(contact);
|
||||
if (!context.mounted) return;
|
||||
if (!imported) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImportFailed),
|
||||
);
|
||||
return;
|
||||
}
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.discoveredContacts_contactAdded),
|
||||
action: SnackBarAction(
|
||||
label: context.l10n.common_undo,
|
||||
onPressed: () => connector.removeContact(contact),
|
||||
),
|
||||
);
|
||||
} catch (_) {
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImportFailed),
|
||||
);
|
||||
}
|
||||
},
|
||||
onTap: () => _addContact(context, contact, connector),
|
||||
onLongPress: () => _showContactContextMenu(contact, connector),
|
||||
onSecondaryTap: PlatformInfo.isDesktop
|
||||
? () => _showContactContextMenu(contact, connector)
|
||||
@@ -296,12 +278,49 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: context.l10n.discoveredContacts_addContact,
|
||||
icon: const Icon(Icons.person_add_alt_1),
|
||||
onPressed: () => _addContact(context, contact, connector),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _addContact(
|
||||
BuildContext context,
|
||||
Contact contact,
|
||||
MeshCoreConnector connector,
|
||||
) async {
|
||||
try {
|
||||
final imported = await connector.importDiscoveredContact(contact);
|
||||
if (!context.mounted) return;
|
||||
if (!imported) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImportFailed),
|
||||
);
|
||||
return;
|
||||
}
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.discoveredContacts_contactAdded),
|
||||
action: SnackBarAction(
|
||||
label: context.l10n.common_undo,
|
||||
onPressed: () => connector.removeContact(contact),
|
||||
),
|
||||
);
|
||||
} catch (_) {
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImportFailed),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _showContactContextMenu(
|
||||
Contact contact,
|
||||
MeshCoreConnector connector,
|
||||
@@ -431,6 +450,7 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
if (searchQuery.isNotEmpty)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
tooltip: context.l10n.common_clearSearch,
|
||||
onPressed: () {
|
||||
_searchController.clear();
|
||||
setState(() {
|
||||
|
||||
+314
-257
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
@@ -16,11 +17,13 @@ import '../l10n/l10n.dart';
|
||||
import '../models/app_settings.dart';
|
||||
import '../models/channel.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../models/path_history.dart';
|
||||
import '../l10n/contact_localization.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../services/path_history_service.dart';
|
||||
import '../services/map_marker_service.dart';
|
||||
import '../services/map_tile_cache_service.dart';
|
||||
import '../storage/prefs_manager.dart';
|
||||
import '../utils/contact_search.dart';
|
||||
import '../utils/disconnect_navigation_mixin.dart';
|
||||
import '../utils/battery_utils.dart';
|
||||
@@ -35,6 +38,7 @@ import '../theme/mesh_theme.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/repeater_login_dialog.dart';
|
||||
import '../widgets/room_login_dialog.dart';
|
||||
import '../helpers/guessed_location_estimator.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import 'repeater_hub_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
@@ -60,8 +64,7 @@ class MapScreen extends StatefulWidget {
|
||||
State<MapScreen> createState() => _MapScreenState();
|
||||
}
|
||||
|
||||
class _MapScreenState extends State<MapScreen>
|
||||
with DisconnectNavigationMixin {
|
||||
class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
// Zoom level at which node labels start to appear
|
||||
static const double _labelZoomThreshold = 14.0;
|
||||
// Below this zoom, nearby nodes collapse into clusters.
|
||||
@@ -95,15 +98,51 @@ class _MapScreenState extends State<MapScreen>
|
||||
final FocusNode _searchFocus = FocusNode();
|
||||
String _searchQuery = '';
|
||||
List<_GuessedLocation> _cachedGuessedLocations = [];
|
||||
String _guessedLocationsCacheKey = '';
|
||||
int? _guessedLocationsCacheKey;
|
||||
static const Duration _guessMaxAge = Duration(days: 7);
|
||||
({LatLng center, double zoom})? _cachedFallbackCamera;
|
||||
bool _guessInFlight = false;
|
||||
VoidCallback? _guessRerun;
|
||||
// Saved paths for contacts outside the path-history cache, read once.
|
||||
final Map<String, List<PathRecord>> _storedPaths = {};
|
||||
int? _sharedMarkersCacheSignature;
|
||||
Locale? _sharedMarkersCacheLocale;
|
||||
List<_SharedMarker> _cachedSharedMarkers = const [];
|
||||
_NodeMarkersCacheKey? _nodeMarkersCacheKey;
|
||||
List<Marker> _cachedNodeMarkers = const [];
|
||||
|
||||
static const String _lastCameraKey = 'map_last_camera';
|
||||
|
||||
({LatLng center, double zoom}) _fallbackCamera(MeshCoreConnector connector) {
|
||||
final lat = connector.selfLatitude;
|
||||
final lon = connector.selfLongitude;
|
||||
if (lat != null && lon != null && isPlausibleLocation(lat, lon)) {
|
||||
return (center: LatLng(lat, lon), zoom: 12.0);
|
||||
}
|
||||
final saved = PrefsManager.instance.getStringList(_lastCameraKey);
|
||||
if (saved != null && saved.length == 3) {
|
||||
final values = saved.map(double.tryParse).toList();
|
||||
if (!values.contains(null)) {
|
||||
return (center: LatLng(values[0]!, values[1]!), zoom: values[2]!);
|
||||
}
|
||||
}
|
||||
return (center: const LatLng(20, 0), zoom: _mapMinZoom);
|
||||
}
|
||||
|
||||
void _saveLastCamera() {
|
||||
try {
|
||||
final camera = _mapController.camera;
|
||||
PrefsManager.instance.setStringList(_lastCameraKey, [
|
||||
camera.center.latitude.toString(),
|
||||
camera.center.longitude.toString(),
|
||||
camera.zoom.toString(),
|
||||
]);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_saveLastCamera();
|
||||
_searchController.dispose();
|
||||
_searchFocus.dispose();
|
||||
_mapController.dispose();
|
||||
@@ -196,15 +235,6 @@ class _MapScreenState extends State<MapScreen>
|
||||
}
|
||||
}
|
||||
|
||||
bool _checkLocationPlausibility(double lat, double lon) {
|
||||
const double epsilon = 1e-6;
|
||||
return (lat.abs() > epsilon || lon.abs() > epsilon) &&
|
||||
lat >= -90.0 &&
|
||||
lat <= 90.0 &&
|
||||
lon >= -180.0 &&
|
||||
lon <= 180.0;
|
||||
}
|
||||
|
||||
double _standardDeviation(List<double> values) {
|
||||
if (values.length <= 1) {
|
||||
return 0.0;
|
||||
@@ -300,7 +330,7 @@ class _MapScreenState extends State<MapScreen>
|
||||
IconButton(
|
||||
color: MapPalette.selected,
|
||||
icon: const Icon(Icons.my_location),
|
||||
tooltip: context.l10n.map_setAsMyLocation,
|
||||
tooltip: context.l10n.map_centerOnMe,
|
||||
onPressed: () => _mapController.move(
|
||||
LatLng(connector.selfLatitude!, connector.selfLongitude!),
|
||||
max(_zoom, 14),
|
||||
@@ -431,29 +461,42 @@ class _MapScreenState extends State<MapScreen>
|
||||
noLocations: true,
|
||||
);
|
||||
|
||||
// Compute guessed locations with caching
|
||||
// Guessed locations are computed in a background isolate; the last
|
||||
// result stays on screen until the new one arrives.
|
||||
final maxRangeKm = _estimateLoRaRangeKm(connector);
|
||||
final filteredKeys = guessCandidates
|
||||
.map((c) => '${c.publicKeyHex}:${c.path.join("-")}')
|
||||
.join(',');
|
||||
final anchorKeys = allContactsWithLocation
|
||||
.map(
|
||||
final cacheKey = Object.hash(
|
||||
Object.hashAll(
|
||||
guessCandidates.map(
|
||||
(c) => Object.hash(c.publicKeyHex, _bytesSignature(c.path)),
|
||||
),
|
||||
),
|
||||
Object.hashAll(
|
||||
allContactsWithLocation.map(
|
||||
(c) =>
|
||||
'${c.publicKeyHex}:${c.latitude}:${c.longitude}:${PathHelper.formatHopHex(c.path.isNotEmpty ? c.path.sublist(max(0, c.path.length - c.pathHashWidth)) : const [])}',
|
||||
)
|
||||
.join(',');
|
||||
final cacheKey =
|
||||
'$filteredKeys|$anchorKeys|$pathHistoryVersion:${connector.currentFreqHz}:${connector.currentSf}:${connector.currentBwHz}:${connector.currentTxPower}:${settings.mapShowGuessedLocations}';
|
||||
Object.hash(c.publicKeyHex, c.latitude, c.longitude, c.type),
|
||||
),
|
||||
),
|
||||
pathHistoryVersion,
|
||||
maxRangeKm,
|
||||
connector.selfLatitude,
|
||||
connector.selfLongitude,
|
||||
settings.mapShowGuessedLocations,
|
||||
);
|
||||
if (cacheKey != _guessedLocationsCacheKey) {
|
||||
_guessedLocationsCacheKey = cacheKey;
|
||||
_cachedGuessedLocations = settings.mapShowGuessedLocations
|
||||
? _computeGuessedLocations(
|
||||
guessCandidates,
|
||||
allContactsWithLocation,
|
||||
pathHistory,
|
||||
maxRangeKm,
|
||||
)
|
||||
: [];
|
||||
if (settings.mapShowGuessedLocations) {
|
||||
unawaited(
|
||||
_startGuessedLocations(
|
||||
cacheKey,
|
||||
guessCandidates,
|
||||
allContactsWithLocation,
|
||||
pathHistory,
|
||||
maxRangeKm,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
_cachedGuessedLocations = [];
|
||||
}
|
||||
}
|
||||
final guessedLocations = settings.mapShowGuessedLocations
|
||||
? _cachedGuessedLocations
|
||||
@@ -492,14 +535,13 @@ class _MapScreenState extends State<MapScreen>
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate center and zoom of all nodes, or default to (0, 0)
|
||||
LatLng center = const LatLng(0, 0);
|
||||
double initialZoom = 10.0;
|
||||
final hasMapContent =
|
||||
contactsWithLocation.isNotEmpty ||
|
||||
sharedMarkers.isNotEmpty ||
|
||||
_isSelectingPoi ||
|
||||
highlightPosition != null;
|
||||
// Only the first frame's camera matters; afterwards reuse it instead
|
||||
// of re-reading prefs on every rebuild.
|
||||
final (center: fallbackCenter, zoom: fallbackZoom) = _hasInitializedMap
|
||||
? (_cachedFallbackCamera ??= _fallbackCamera(connector))
|
||||
: _fallbackCamera(connector);
|
||||
LatLng center = fallbackCenter;
|
||||
double initialZoom = fallbackZoom;
|
||||
if (contactsWithLocation.isNotEmpty || sharedMarkers.isNotEmpty) {
|
||||
final allPoints = [
|
||||
...contactsWithLocation.map(
|
||||
@@ -574,13 +616,11 @@ class _MapScreenState extends State<MapScreen>
|
||||
_hasInitializedMap = true;
|
||||
_showNodeLabels = initialZoom >= _labelZoomThreshold;
|
||||
_zoom = initialZoom;
|
||||
if (hasMapContent) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
_mapController.move(center, initialZoom);
|
||||
}
|
||||
});
|
||||
}
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
_mapController.move(center, initialZoom);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final allowBack = !connector.isConnected;
|
||||
@@ -770,6 +810,12 @@ class _MapScreenState extends State<MapScreen>
|
||||
onSecondaryTap: (_, latLng) {
|
||||
_handleMapContextPress(context, connector, latLng);
|
||||
},
|
||||
onMapEvent: (event) {
|
||||
if (event is MapEventMoveEnd ||
|
||||
event is MapEventFlingAnimationEnd) {
|
||||
_saveLastCamera();
|
||||
}
|
||||
},
|
||||
onPositionChanged: (camera, hasGesture) {
|
||||
// Track zoom in half-step buckets so cluster/marker
|
||||
// detail levels update without rebuilding every frame.
|
||||
@@ -926,6 +972,20 @@ class _MapScreenState extends State<MapScreen>
|
||||
pinCount: sharedMarkers.length,
|
||||
),
|
||||
if (_isBuildingPathTrace) _buildPathTraceOverlay(),
|
||||
if (contactsWithLocation.isEmpty &&
|
||||
selectedContact == null &&
|
||||
!_isBuildingPathTrace)
|
||||
Positioned(
|
||||
left: 16,
|
||||
right: 88,
|
||||
bottom: 16,
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Text(context.l10n.map_noNodesLocationHint),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (selectedContact != null && !_isBuildingPathTrace)
|
||||
_buildSelectedNodeCard(context, selectedContact, connector),
|
||||
],
|
||||
@@ -993,6 +1053,7 @@ class _MapScreenState extends State<MapScreen>
|
||||
showChatNodes: settings.mapShowChatNodes,
|
||||
showOtherNodes: settings.mapShowOtherNodes,
|
||||
isBuildingPathTrace: _isBuildingPathTrace,
|
||||
clusterNodes: settings.mapClusterNodes,
|
||||
);
|
||||
if (key != _nodeMarkersCacheKey) {
|
||||
_nodeMarkersCacheKey = key;
|
||||
@@ -1008,141 +1069,100 @@ class _MapScreenState extends State<MapScreen>
|
||||
return _cachedNodeMarkers;
|
||||
}
|
||||
|
||||
List<_GuessedLocation> _computeGuessedLocations(
|
||||
List<Contact> allContacts,
|
||||
Future<void> _startGuessedLocations(
|
||||
int cacheKey,
|
||||
List<Contact> candidates,
|
||||
List<Contact> withLocation,
|
||||
PathHistoryService pathHistory,
|
||||
double? maxRangeKm,
|
||||
) {
|
||||
final result = <_GuessedLocation>[];
|
||||
// Paths keep the width they were learned with, so index every width.
|
||||
final anchorsByPrefix = <String, List<Contact>>{};
|
||||
for (final repeater in withLocation) {
|
||||
if (repeater.type != advTypeRepeater) continue;
|
||||
for (var width = 1; width <= 3; width++) {
|
||||
if (repeater.publicKey.length < width) continue;
|
||||
final prefix = PathHelper.formatHopHex(
|
||||
repeater.publicKey.sublist(0, width),
|
||||
);
|
||||
anchorsByPrefix.putIfAbsent(prefix, () => []).add(repeater);
|
||||
}
|
||||
}
|
||||
|
||||
for (final contact in allContacts) {
|
||||
if (contact.hasLocation) continue;
|
||||
if (contact.lastSeen.isBefore(
|
||||
DateTime.now().subtract(const Duration(hours: 24)),
|
||||
)) {
|
||||
continue; // skip stale contacts
|
||||
}
|
||||
|
||||
final anchorSet = <LatLng>{};
|
||||
|
||||
// Collect the contact-side (last-hop) repeater from every known path.
|
||||
// path = [device-side hop, ..., contact-side hop]
|
||||
// Only the last hop chunk is actually within radio range of the contact.
|
||||
final pathSets = <(List<int>, int)>[
|
||||
(contact.path.toList(), contact.pathHashWidth),
|
||||
...pathHistory
|
||||
.getRecentPaths(contact.publicKeyHex)
|
||||
.map(
|
||||
(r) => (
|
||||
r.pathBytes,
|
||||
Contact.inferPathHashWidth(r.hopCount, r.pathBytes.length),
|
||||
),
|
||||
),
|
||||
];
|
||||
for (final (pathBytes, hopWidth) in pathSets) {
|
||||
if (pathBytes.isEmpty) continue;
|
||||
final lastHop = pathBytes.sublist(max(0, pathBytes.length - hopWidth));
|
||||
if (lastHop.isEmpty) continue;
|
||||
|
||||
final repeaters = anchorsByPrefix[PathHelper.formatHopHex(lastHop)];
|
||||
if (repeaters != null && repeaters.isNotEmpty) {
|
||||
final repeater = repeaters.first;
|
||||
anchorSet.add(LatLng(repeater.latitude!, repeater.longitude!));
|
||||
}
|
||||
}
|
||||
|
||||
// Filter anchors that are geometrically inconsistent with radio range.
|
||||
// Two anchors more than 2 * maxRange apart cannot both be in direct radio
|
||||
// range of the same node, so isolated outliers are removed.
|
||||
final anchors = maxRangeKm != null && anchorSet.length > 1
|
||||
? _filterConsistentAnchors(anchorSet.toList(), maxRangeKm)
|
||||
: anchorSet.toList();
|
||||
|
||||
if (anchors.isEmpty) continue;
|
||||
|
||||
final LatLng position;
|
||||
if (anchors.length == 1) {
|
||||
// Spread single-anchor guesses around the anchor so they remain visible.
|
||||
position = _offsetGuessedPosition(
|
||||
anchors[0],
|
||||
contact,
|
||||
radiusMeters: 330,
|
||||
);
|
||||
if (!_checkLocationPlausibility(
|
||||
position.latitude,
|
||||
position.longitude,
|
||||
)) {
|
||||
continue; // discard implausible guesses near (0, 0)
|
||||
}
|
||||
} else {
|
||||
double lat = 0, lon = 0, weight = 1.0, totalWeight = 0;
|
||||
for (final a in anchors) {
|
||||
lat += a.latitude * weight;
|
||||
lon += a.longitude * weight;
|
||||
totalWeight += weight;
|
||||
// weight subsequent anchors less to create a bias towards the first (if more than 2)
|
||||
weight = weight / 2;
|
||||
}
|
||||
position = _offsetGuessedPosition(
|
||||
LatLng(lat / totalWeight, lon / totalWeight),
|
||||
contact,
|
||||
radiusMeters: anchors.length >= 3 ? 80 : 120,
|
||||
);
|
||||
if (!_checkLocationPlausibility(
|
||||
position.latitude,
|
||||
position.longitude,
|
||||
)) {
|
||||
continue; // discard implausible guesses near (0, 0
|
||||
}
|
||||
}
|
||||
result.add(
|
||||
_GuessedLocation(
|
||||
contact: contact,
|
||||
position: position,
|
||||
highConfidence: anchors.length >= 2,
|
||||
),
|
||||
) async {
|
||||
if (_guessInFlight) {
|
||||
_guessRerun = () => _startGuessedLocations(
|
||||
cacheKey,
|
||||
candidates,
|
||||
withLocation,
|
||||
pathHistory,
|
||||
maxRangeKm,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
LatLng _offsetGuessedPosition(
|
||||
LatLng anchor,
|
||||
Contact contact, {
|
||||
required double radiusMeters,
|
||||
}) {
|
||||
final seed = _guessSeed(contact.publicKey);
|
||||
final angle = ((seed & 0xFFFF) / 0x10000) * 2 * pi;
|
||||
final latOffsetDeg = (radiusMeters / 111320.0) * cos(angle);
|
||||
final lonScale = max(cos(anchor.latitude * pi / 180.0).abs(), 0.2);
|
||||
final lonOffsetDeg = (radiusMeters / (111320.0 * lonScale)) * sin(angle);
|
||||
return LatLng(
|
||||
anchor.latitude + latOffsetDeg,
|
||||
anchor.longitude + lonOffsetDeg,
|
||||
_guessInFlight = true;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final selfLat = connector.selfLatitude;
|
||||
final selfLon = connector.selfLongitude;
|
||||
// Old paths say little about where a node is now.
|
||||
final cutoff = DateTime.now().subtract(_guessMaxAge);
|
||||
final eligible = candidates
|
||||
.where((c) => !c.hasLocation && c.lastSeen.isAfter(cutoff))
|
||||
.toList();
|
||||
for (final c in eligible) {
|
||||
final key = c.publicKeyHex;
|
||||
if (pathHistory.isCached(key) || _storedPaths.containsKey(key)) continue;
|
||||
_storedPaths[key] = await pathHistory.readStoredPaths(key);
|
||||
}
|
||||
if (!mounted) {
|
||||
_guessInFlight = false;
|
||||
return;
|
||||
}
|
||||
List<PathRecord> pathsFor(String key) => pathHistory.isCached(key)
|
||||
? pathHistory.peekRecentPaths(key)
|
||||
: _storedPaths[key] ?? const [];
|
||||
final input = (
|
||||
candidates: [
|
||||
for (final c in eligible)
|
||||
(
|
||||
publicKey: c.publicKey,
|
||||
paths: [
|
||||
(c.path.toList(), c.pathHashWidth),
|
||||
for (final r in pathsFor(c.publicKeyHex))
|
||||
(
|
||||
r.pathBytes,
|
||||
Contact.inferPathHashWidth(r.hopCount, r.pathBytes.length),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
anchors: [
|
||||
for (final r in withLocation)
|
||||
if (r.type == advTypeRepeater || r.type == advTypeRoom)
|
||||
(r.publicKey, r.latitude!, r.longitude!),
|
||||
],
|
||||
selfPosition:
|
||||
selfLat != null &&
|
||||
selfLon != null &&
|
||||
isPlausibleLocation(selfLat, selfLon)
|
||||
? (selfLat, selfLon)
|
||||
: null,
|
||||
maxRangeKm: maxRangeKm,
|
||||
);
|
||||
}
|
||||
|
||||
int _guessSeed(Uint8List publicKey) {
|
||||
var seed = 0x811C9DC5;
|
||||
for (final byte in publicKey) {
|
||||
seed ^= byte;
|
||||
seed = (seed * 0x01000193) & 0x7FFFFFFF;
|
||||
List<(int, double, double, bool)> placed;
|
||||
try {
|
||||
placed = await compute(estimateGuessedLocations, input);
|
||||
} catch (e) {
|
||||
debugPrint('Guessed location estimate failed: $e');
|
||||
placed = const [];
|
||||
} finally {
|
||||
_guessInFlight = false;
|
||||
}
|
||||
return seed;
|
||||
final rerun = _guessRerun;
|
||||
_guessRerun = null;
|
||||
if (!mounted) return;
|
||||
if (!context.read<AppSettingsService>().settings.mapShowGuessedLocations) {
|
||||
return;
|
||||
}
|
||||
// Show this result even if inputs moved on; it is newer than what is on
|
||||
// screen, and the queued rerun replaces it shortly.
|
||||
rerun?.call();
|
||||
setState(() {
|
||||
_cachedGuessedLocations = [
|
||||
for (final (index, lat, lon, highConfidence) in placed)
|
||||
_GuessedLocation(
|
||||
contact: eligible[index],
|
||||
position: LatLng(lat, lon),
|
||||
highConfidence: highConfidence,
|
||||
),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/// Estimates the free-space maximum LoRa range in km from the connected
|
||||
@@ -1191,20 +1211,6 @@ class _MapScreenState extends State<MapScreen>
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes anchors that have no neighbour within 2 * maxRangeKm.
|
||||
/// A node cannot be simultaneously in radio range of two points farther apart
|
||||
/// than twice the expected maximum range.
|
||||
List<LatLng> _filterConsistentAnchors(
|
||||
List<LatLng> anchors,
|
||||
double maxRangeKm,
|
||||
) {
|
||||
const distance = Distance();
|
||||
final maxDistM = maxRangeKm * 2000;
|
||||
return anchors
|
||||
.where((a) => anchors.any((b) => b != a && distance(a, b) <= maxDistM))
|
||||
.toList();
|
||||
}
|
||||
|
||||
List<Marker> _buildGuessedMarker(
|
||||
List<_GuessedLocation> guessed, {
|
||||
required bool showLabels,
|
||||
@@ -1381,7 +1387,10 @@ class _MapScreenState extends State<MapScreen>
|
||||
}
|
||||
}
|
||||
|
||||
if (_zoom >= _clusterOffZoom || overlapsMode || _isBuildingPathTrace) {
|
||||
if (!settings.mapClusterNodes ||
|
||||
_zoom >= _clusterOffZoom ||
|
||||
overlapsMode ||
|
||||
_isBuildingPathTrace) {
|
||||
for (final contact in items) {
|
||||
addNode(contact);
|
||||
}
|
||||
@@ -1833,6 +1842,7 @@ class _MapScreenState extends State<MapScreen>
|
||||
? IconButton(
|
||||
color: _overlayPrimaryTextColor,
|
||||
icon: const Icon(Icons.close, size: 18),
|
||||
tooltip: context.l10n.common_clearSearch,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_searchQuery = '';
|
||||
@@ -1954,6 +1964,14 @@ class _MapScreenState extends State<MapScreen>
|
||||
!settings.mapShowChatNodes,
|
||||
),
|
||||
),
|
||||
_mapChip(
|
||||
label: context.l10n.map_groupChip,
|
||||
selected: settings.mapClusterNodes,
|
||||
color: MapPalette.cluster,
|
||||
onTap: () => settingsService.setMapClusterNodes(
|
||||
!settings.mapClusterNodes,
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
if (constraints.maxWidth < 600) {
|
||||
@@ -1996,45 +2014,53 @@ class _MapScreenState extends State<MapScreen>
|
||||
final accent = color ?? MapPalette.selected;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
child: Material(
|
||||
color: selected
|
||||
? Color.alphaBlend(
|
||||
accent.withValues(alpha: 0.34),
|
||||
_overlayPanelColor,
|
||||
)
|
||||
: _overlayPanelColor,
|
||||
shape: StadiumBorder(
|
||||
side: BorderSide(
|
||||
color: selected ? accent : _overlayBorderColor,
|
||||
width: selected ? 1.5 : 1,
|
||||
child: Semantics(
|
||||
button: true,
|
||||
selected: selected,
|
||||
child: Material(
|
||||
color: selected
|
||||
? Color.alphaBlend(
|
||||
accent.withValues(alpha: 0.34),
|
||||
_overlayPanelColor,
|
||||
)
|
||||
: _overlayPanelColor,
|
||||
shape: StadiumBorder(
|
||||
side: BorderSide(
|
||||
color: selected ? accent : _overlayBorderColor,
|
||||
width: selected ? 1.5 : 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
HapticFeedback.selectionClick();
|
||||
onTap();
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 7),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (selected) ...[
|
||||
Icon(Icons.check, size: 13, color: _overlayPrimaryTextColor),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: selected
|
||||
? _overlayPrimaryTextColor
|
||||
: _overlaySecondaryTextColor,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
HapticFeedback.selectionClick();
|
||||
onTap();
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 7),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (selected) ...[
|
||||
Icon(
|
||||
Icons.check,
|
||||
size: 13,
|
||||
color: _overlayPrimaryTextColor,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: selected
|
||||
? _overlayPrimaryTextColor
|
||||
: _overlaySecondaryTextColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -2393,6 +2419,7 @@ class _MapScreenState extends State<MapScreen>
|
||||
IconButton(
|
||||
color: _overlayPrimaryTextColor,
|
||||
icon: const Icon(Icons.close, size: 20),
|
||||
tooltip: context.l10n.common_close,
|
||||
onPressed: _clearSelection,
|
||||
),
|
||||
],
|
||||
@@ -2527,6 +2554,12 @@ class _MapScreenState extends State<MapScreen>
|
||||
}
|
||||
_showRoomLogin(context, contact);
|
||||
}),
|
||||
action(context.l10n.map_manageServer, Icons.room_preferences, () {
|
||||
if (!contact.isActive) {
|
||||
connector.importDiscoveredContact(contact);
|
||||
}
|
||||
_showRoomLogin(context, contact, manage: true);
|
||||
}),
|
||||
];
|
||||
default:
|
||||
return const [];
|
||||
@@ -2706,13 +2739,16 @@ class _MapScreenState extends State<MapScreen>
|
||||
);
|
||||
}
|
||||
|
||||
void _showRoomLogin(BuildContext context, Contact room) {
|
||||
void _showRoomLogin(
|
||||
BuildContext context,
|
||||
Contact room, {
|
||||
bool manage = false,
|
||||
}) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => RoomLoginDialog(
|
||||
room: room,
|
||||
// onLogin(password, isAdmin) isAdmin not used for room caht screen
|
||||
onLogin: (password, _) {
|
||||
onLogin: (password, isAdmin) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final unread = connector.getUnreadCountForContactKey(
|
||||
room.publicKeyHex,
|
||||
@@ -2721,8 +2757,13 @@ class _MapScreenState extends State<MapScreen>
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
ChatScreen(contact: room, initialUnreadCount: unread),
|
||||
builder: (context) => manage
|
||||
? RepeaterHubScreen(
|
||||
repeater: room,
|
||||
password: password,
|
||||
isAdmin: isAdmin,
|
||||
)
|
||||
: ChatScreen(contact: room, initialUnreadCount: unread),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -2792,6 +2833,18 @@ class _MapScreenState extends State<MapScreen>
|
||||
child: Text(context.l10n.map_joinRoom),
|
||||
),
|
||||
);
|
||||
actions.add(
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
if (!contact.isActive) {
|
||||
connector.importDiscoveredContact(contact);
|
||||
}
|
||||
Navigator.pop(sheetContext);
|
||||
_showRoomLogin(context, contact, manage: true);
|
||||
},
|
||||
child: Text(context.l10n.map_manageServer),
|
||||
),
|
||||
);
|
||||
}
|
||||
return SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
@@ -3438,6 +3491,16 @@ class _MapScreenState extends State<MapScreen>
|
||||
onChanged: (value) =>
|
||||
service.setMapShowMarkers(value),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: Text(sheetContext.l10n.map_clusterNodes),
|
||||
subtitle: Text(
|
||||
sheetContext.l10n.map_clusterNodesSubtitle,
|
||||
),
|
||||
value: settings.mapClusterNodes,
|
||||
dense: true,
|
||||
onChanged: (value) =>
|
||||
service.setMapClusterNodes(value),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: Text(
|
||||
sheetContext.l10n.map_showGuessedLocations,
|
||||
@@ -3838,42 +3901,32 @@ class _MapConnectorSnapshot {
|
||||
),
|
||||
);
|
||||
|
||||
// Only detect that a conversation changed; _collectSharedMarkers does the
|
||||
// per-message scan when this signature moves.
|
||||
final markerParts = <Object?>[connector.selfName];
|
||||
for (final contact in connector.contacts) {
|
||||
markerParts.add(contact.publicKeyHex);
|
||||
markerParts.add(contact.name);
|
||||
for (final message in connector.getMessages(contact)) {
|
||||
if (!message.text.trimLeft().startsWith('m:')) continue;
|
||||
markerParts.add(
|
||||
Object.hash(
|
||||
message.messageId,
|
||||
message.text,
|
||||
message.timestamp.millisecondsSinceEpoch,
|
||||
message.isOutgoing,
|
||||
),
|
||||
);
|
||||
}
|
||||
final messages = connector.getMessages(contact);
|
||||
markerParts.add(
|
||||
Object.hash(
|
||||
contact.publicKeyHex,
|
||||
contact.name,
|
||||
messages.length,
|
||||
messages.isEmpty ? null : messages.last.messageId,
|
||||
),
|
||||
);
|
||||
}
|
||||
for (final channel in connector.channels) {
|
||||
final messages = connector.getChannelMessages(channel);
|
||||
markerParts.add(
|
||||
Object.hash(
|
||||
channel.index,
|
||||
channel.name,
|
||||
channel.isPublicChannel,
|
||||
channel.isEmpty,
|
||||
messages.length,
|
||||
messages.isEmpty ? null : messages.last.messageId,
|
||||
),
|
||||
);
|
||||
for (final message in connector.getChannelMessages(channel)) {
|
||||
if (!message.text.trimLeft().startsWith('m:')) continue;
|
||||
markerParts.add(
|
||||
Object.hash(
|
||||
message.messageId,
|
||||
message.text,
|
||||
message.senderName,
|
||||
message.timestamp.millisecondsSinceEpoch,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return _MapConnectorSnapshot(
|
||||
@@ -3931,6 +3984,7 @@ class _NodeMarkersCacheKey {
|
||||
final bool showChatNodes;
|
||||
final bool showOtherNodes;
|
||||
final bool isBuildingPathTrace;
|
||||
final bool clusterNodes;
|
||||
|
||||
const _NodeMarkersCacheKey({
|
||||
required this.contactsSignature,
|
||||
@@ -3950,6 +4004,7 @@ class _NodeMarkersCacheKey {
|
||||
required this.showChatNodes,
|
||||
required this.showOtherNodes,
|
||||
required this.isBuildingPathTrace,
|
||||
required this.clusterNodes,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -3971,7 +4026,8 @@ class _NodeMarkersCacheKey {
|
||||
showRepeaters == other.showRepeaters &&
|
||||
showChatNodes == other.showChatNodes &&
|
||||
showOtherNodes == other.showOtherNodes &&
|
||||
isBuildingPathTrace == other.isBuildingPathTrace;
|
||||
isBuildingPathTrace == other.isBuildingPathTrace &&
|
||||
clusterNodes == other.clusterNodes;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -3993,6 +4049,7 @@ class _NodeMarkersCacheKey {
|
||||
showChatNodes,
|
||||
showOtherNodes,
|
||||
isBuildingPathTrace,
|
||||
clusterNodes,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,13 +78,82 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView.builder(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 88),
|
||||
itemCount: _regions.length,
|
||||
itemBuilder: (context, index) {
|
||||
final region = _regions[index];
|
||||
return _buildRegionTile(context, region);
|
||||
},
|
||||
body: _regions.isEmpty
|
||||
? _buildEmptyState(context)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: 8,
|
||||
bottom: 88,
|
||||
),
|
||||
itemCount: _regions.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0) return _buildDefaultRegionTile(context);
|
||||
return _buildRegionTile(context, _regions[index - 1]);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.landscape, size: 48, color: MeshPalette.blue),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
l10n.settings_regionEmptyExplanation,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton.icon(
|
||||
icon: const Icon(Icons.travel_explore),
|
||||
label: Text(l10n.settings_regionFetchFromRepeaters),
|
||||
onPressed: _isFetchingRegions ? null : _showFetchRegionsDialog,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
OutlinedButton.icon(
|
||||
icon: const Icon(Icons.add),
|
||||
label: Text(l10n.settings_regionAddRegion),
|
||||
onPressed: () => _showAddRegionDialog(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDefaultRegionTile(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final current = _regions.contains(connector.defaultRegion)
|
||||
? connector.defaultRegion
|
||||
: '';
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: DropdownButtonFormField<Region>(
|
||||
key: ValueKey(current),
|
||||
initialValue: current,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_regionDefault,
|
||||
helperText: l10n.settings_regionDefaultSubtitle,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
items: [
|
||||
DropdownMenuItem(
|
||||
value: '',
|
||||
child: Text(l10n.settings_regionDefaultNone),
|
||||
),
|
||||
for (final region in _regions)
|
||||
DropdownMenuItem(value: region, child: Text(region)),
|
||||
],
|
||||
onChanged: (value) => connector.setDefaultRegion(value ?? ''),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,9 @@ class RepeaterHubScreen extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
StatusChip(
|
||||
label: isAdmin ? 'ADMIN' : 'GUEST',
|
||||
label: isAdmin
|
||||
? l10n.repeater_roleAdmin
|
||||
: l10n.repeater_roleGuest,
|
||||
color: isAdmin
|
||||
? MeshPalette.blue
|
||||
: scheme.onSurfaceVariant,
|
||||
@@ -308,46 +310,53 @@ class _HubActionTile extends StatelessWidget {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return ListEntrance(
|
||||
index: index,
|
||||
child: MeshCard(
|
||||
onTap: onTap,
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: accentColor.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
border: Border.all(color: accentColor.withValues(alpha: 0.3)),
|
||||
child: Semantics(
|
||||
button: true,
|
||||
child: MeshCard(
|
||||
onTap: onTap,
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: accentColor.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
border: Border.all(color: accentColor.withValues(alpha: 0.3)),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Icon(icon, size: 22, color: accentColor),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Icon(icon, size: 22, color: accentColor),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 15,
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
subtitle,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: scheme.onSurfaceVariant,
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
subtitle,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Icon(Icons.chevron_right, color: scheme.onSurfaceVariant, size: 20),
|
||||
],
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
color: scheme.onSurfaceVariant,
|
||||
size: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -113,6 +113,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
bool _refreshingIntThresh = false;
|
||||
bool _refreshingAgcResetInterval = false;
|
||||
bool _runningAction = false;
|
||||
bool _loadingAll = false;
|
||||
int _unansweredSections = 0;
|
||||
double _loadAllProgress = 0;
|
||||
final Set<String> _loadedKeys = {};
|
||||
bool _searchingForKeyPair = false;
|
||||
bool _stopSearchingForKeyPair = false;
|
||||
StreamSubscription<Uint8List>? _frameSubscription;
|
||||
@@ -441,10 +445,15 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
final key = normalized.substring(4).trim();
|
||||
final value = _extractGetValue(response);
|
||||
if (value == null) return false;
|
||||
setState(() => _applyGetValue(key, value));
|
||||
setState(() {
|
||||
_applyGetValue(key, value);
|
||||
_loadedKeys.add(key);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _loaded(String key) => _loadedKeys.contains(key);
|
||||
|
||||
/// Firmware GET replies are always `> <value>` (CommonCLI.cpp `sprintf(reply, "> %s", ...)`).
|
||||
/// Returns the first such value, trimmed; null if none found.
|
||||
String? _extractGetValue(String response) {
|
||||
@@ -469,6 +478,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
setState(() => setRefreshing(true));
|
||||
|
||||
var successCount = 0;
|
||||
var answered = false;
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final repeater = _resolveRepeater(connector);
|
||||
for (final command in commands) {
|
||||
@@ -478,14 +488,22 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
command,
|
||||
retries: 1,
|
||||
);
|
||||
if (!mounted) return;
|
||||
answered = true;
|
||||
if (_handleGetResponse(command, response)) successCount += 1;
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
} catch (e) {
|
||||
debugPrint('Error fetching $command: $e');
|
||||
}
|
||||
if (!mounted) return;
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
if (_loadingAll) {
|
||||
// A reply we can't use usually means older firmware without that
|
||||
// setting; only a section that never answered counts as a failure.
|
||||
if (!answered) _unansweredSections += 1;
|
||||
setState(() => setRefreshing(false));
|
||||
} else {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
@@ -720,9 +738,52 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _refreshAll() async {
|
||||
if (_loadingAll) return;
|
||||
final sections = <Future<void> Function()>[
|
||||
_refreshBasicSettings,
|
||||
_refreshRadioSettings,
|
||||
_refreshTxPower,
|
||||
_refreshRxGain,
|
||||
_refreshLat,
|
||||
_refreshLon,
|
||||
_refreshRepeat,
|
||||
_refreshAllowReadOnly,
|
||||
_refreshMultiAcks,
|
||||
_refreshLoopDetect,
|
||||
_refreshDutyCycle,
|
||||
_refreshAdvertInterval,
|
||||
_refreshFloodAdvertInterval,
|
||||
_refreshFloodMax,
|
||||
_refreshOwnerInfo,
|
||||
_refreshPathHashMode,
|
||||
_refreshTxDelay,
|
||||
_refreshDirectTxDelay,
|
||||
_refreshIntThresh,
|
||||
_refreshAgcResetInterval,
|
||||
];
|
||||
_unansweredSections = 0;
|
||||
setState(() {
|
||||
_loadingAll = true;
|
||||
_loadAllProgress = 0;
|
||||
});
|
||||
for (var i = 0; i < sections.length; i++) {
|
||||
if (!mounted) return;
|
||||
await sections[i]();
|
||||
if (!mounted) return;
|
||||
setState(() => _loadAllProgress = (i + 1) / sections.length);
|
||||
}
|
||||
setState(() => _loadingAll = false);
|
||||
if (_unansweredSections > 0) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.repeater_settingsLoadIncomplete),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadSettings() async {
|
||||
// Just populate with current repeater data on initial load
|
||||
// User must click sync button to fetch from device
|
||||
setState(() {
|
||||
_nameController.text = widget.repeater.name;
|
||||
|
||||
@@ -1173,13 +1234,24 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
onPressed: () =>
|
||||
ContactRoutingSheet.show(context, contact: repeater),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
tooltip: l10n.repeater_refreshAll,
|
||||
onPressed: _loadingAll || _isLoading ? null : _refreshAll,
|
||||
),
|
||||
if (_hasChanges)
|
||||
TextButton.icon(
|
||||
onPressed: _isLoading ? null : _saveSettings,
|
||||
onPressed: _isLoading || _loadingAll ? null : _saveSettings,
|
||||
icon: const Icon(Icons.save),
|
||||
label: Text(l10n.common_save),
|
||||
),
|
||||
],
|
||||
bottom: _loadingAll
|
||||
? PreferredSize(
|
||||
preferredSize: const Size.fromHeight(4),
|
||||
child: LinearProgressIndicator(value: _loadAllProgress),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
@@ -1188,6 +1260,27 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
: ListView(
|
||||
padding: const EdgeInsets.only(bottom: 32),
|
||||
children: [
|
||||
if (_loadedKeys.isEmpty && !_loadingAll)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: MeshCard(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
context.l10n.repeater_settingsNotLoaded,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _isLoading ? null : _refreshAll,
|
||||
child: Text(context.l10n.repeater_refreshAll),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildBasicSettingsCard(),
|
||||
_buildRadioSettingsCard(),
|
||||
_buildLocationSettingsCard(),
|
||||
@@ -1231,6 +1324,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
children: [
|
||||
TextField(
|
||||
controller: _nameController,
|
||||
enabled: _loaded('name'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_repeaterName,
|
||||
helperText: l10n.repeater_repeaterNameHelper,
|
||||
@@ -1298,6 +1392,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
children: [
|
||||
TextField(
|
||||
controller: _freqController,
|
||||
enabled: _loaded('radio'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_frequencyMhz,
|
||||
helperText: l10n.repeater_frequencyRangeHelper,
|
||||
@@ -1315,6 +1410,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _txPowerController,
|
||||
enabled: _loaded('tx'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_txPower,
|
||||
helperText: l10n.repeater_txPowerRangeHelper,
|
||||
@@ -1343,14 +1439,16 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
child: Text(_formatBandwidthLabel(bw)),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_bandwidth = value;
|
||||
});
|
||||
_markChanged(_SettingField.radio);
|
||||
}
|
||||
},
|
||||
onChanged: !_loaded('radio')
|
||||
? null
|
||||
: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_bandwidth = value;
|
||||
});
|
||||
_markChanged(_SettingField.radio);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<int>(
|
||||
@@ -1361,14 +1459,16 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
items: _spreadingFactorOptions.map((sf) {
|
||||
return DropdownMenuItem(value: sf, child: Text('SF$sf'));
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_spreadingFactor = value;
|
||||
});
|
||||
_markChanged(_SettingField.radio);
|
||||
}
|
||||
},
|
||||
onChanged: !_loaded('radio')
|
||||
? null
|
||||
: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_spreadingFactor = value;
|
||||
});
|
||||
_markChanged(_SettingField.radio);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<int>(
|
||||
@@ -1379,20 +1479,23 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
items: _codingRateOptions.map((cr) {
|
||||
return DropdownMenuItem(value: cr, child: Text('4/$cr'));
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_codingRate = value;
|
||||
});
|
||||
_markChanged(_SettingField.radio);
|
||||
}
|
||||
},
|
||||
onChanged: !_loaded('radio')
|
||||
? null
|
||||
: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_codingRate = value;
|
||||
});
|
||||
_markChanged(_SettingField.radio);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
_buildFeatureToggleRow(
|
||||
title: l10n.repeater_rxGain,
|
||||
subtitle: l10n.repeater_rxGainHelper,
|
||||
value: _rxGainBoosted,
|
||||
loaded: _loaded('radio.rxgain'),
|
||||
isRefreshing: _refreshingRxGain,
|
||||
onChanged: (v) {
|
||||
setState(() => _rxGainBoosted = v);
|
||||
@@ -1424,6 +1527,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _latController,
|
||||
enabled: _loaded('lat'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_latitude,
|
||||
helperText: l10n.repeater_latitudeHelper,
|
||||
@@ -1458,6 +1562,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _lonController,
|
||||
enabled: _loaded('lon'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_longitude,
|
||||
helperText: l10n.repeater_longitudeHelper,
|
||||
@@ -1506,6 +1611,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
title: l10n.repeater_packetForwarding,
|
||||
subtitle: l10n.repeater_packetForwardingSubtitle,
|
||||
value: _repeatEnabled,
|
||||
loaded: _loaded('repeat'),
|
||||
isRefreshing: _refreshingRepeat,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
@@ -1520,6 +1626,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
title: l10n.repeater_guestAccess,
|
||||
subtitle: l10n.repeater_guestAccessSubtitle,
|
||||
value: _allowReadOnly,
|
||||
loaded: _loaded('allow.read.only'),
|
||||
isRefreshing: _refreshingAllowReadOnly,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
@@ -1534,6 +1641,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
title: l10n.repeater_multiAcks,
|
||||
subtitle: l10n.repeater_multiAcksSubtitle,
|
||||
value: _multiAcks,
|
||||
loaded: _loaded('multi.acks'),
|
||||
isRefreshing: _refreshingMultiAcks,
|
||||
onChanged: (v) {
|
||||
setState(() => _multiAcks = v);
|
||||
@@ -1568,6 +1676,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required bool value,
|
||||
required bool loaded,
|
||||
required bool isRefreshing,
|
||||
required ValueChanged<bool> onChanged,
|
||||
required VoidCallback onRefresh,
|
||||
@@ -1579,8 +1688,8 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
child: SwitchListTile(
|
||||
title: Text(title),
|
||||
subtitle: Text(subtitle),
|
||||
value: value,
|
||||
onChanged: onChanged,
|
||||
value: loaded && value,
|
||||
onChanged: loaded ? onChanged : null,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
),
|
||||
@@ -1616,19 +1725,23 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
child: ListTile(
|
||||
title: Text(l10n.repeater_localAdvertInterval),
|
||||
subtitle: Text(
|
||||
l10n.repeater_localAdvertIntervalMinutes(
|
||||
_advertInterval,
|
||||
),
|
||||
_loaded('advert.interval')
|
||||
? l10n.repeater_localAdvertIntervalMinutes(
|
||||
_advertInterval,
|
||||
)
|
||||
: '—',
|
||||
),
|
||||
trailing: Switch(
|
||||
value: _advertEnable,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_advertInterval = value ? 60 : 0;
|
||||
_advertEnable = value;
|
||||
});
|
||||
_markChanged(_SettingField.advertInterval);
|
||||
},
|
||||
value: _loaded('advert.interval') && _advertEnable,
|
||||
onChanged: !_loaded('advert.interval')
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_advertInterval = value ? 60 : 0;
|
||||
_advertEnable = value;
|
||||
});
|
||||
_markChanged(_SettingField.advertInterval);
|
||||
},
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
@@ -1657,7 +1770,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
label: l10n.repeater_localAdvertIntervalMinutes(
|
||||
_advertInterval,
|
||||
),
|
||||
onChanged: _advertEnable
|
||||
onChanged: _advertEnable && _loaded('advert.interval')
|
||||
? (value) {
|
||||
setState(() {
|
||||
_advertInterval = value.toInt();
|
||||
@@ -1673,19 +1786,25 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
child: ListTile(
|
||||
title: Text(l10n.repeater_floodAdvertInterval),
|
||||
subtitle: Text(
|
||||
l10n.repeater_floodAdvertIntervalHours(
|
||||
_floodAdvertInterval,
|
||||
),
|
||||
_loaded('flood.advert.interval')
|
||||
? l10n.repeater_floodAdvertIntervalHours(
|
||||
_floodAdvertInterval,
|
||||
)
|
||||
: '—',
|
||||
),
|
||||
trailing: Switch(
|
||||
value: _floodAdvertEnable,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_floodAdvertInterval = value ? 3 : 0;
|
||||
_floodAdvertEnable = value;
|
||||
});
|
||||
_markChanged(_SettingField.floodAdvertInterval);
|
||||
},
|
||||
value:
|
||||
_loaded('flood.advert.interval') &&
|
||||
_floodAdvertEnable,
|
||||
onChanged: !_loaded('flood.advert.interval')
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_floodAdvertInterval = value ? 3 : 0;
|
||||
_floodAdvertEnable = value;
|
||||
});
|
||||
_markChanged(_SettingField.floodAdvertInterval);
|
||||
},
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
@@ -1714,7 +1833,8 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
label: l10n.repeater_floodAdvertIntervalHours(
|
||||
_floodAdvertInterval,
|
||||
),
|
||||
onChanged: _floodAdvertEnable
|
||||
onChanged:
|
||||
_floodAdvertEnable && _loaded('flood.advert.interval')
|
||||
? (value) {
|
||||
setState(() {
|
||||
_floodAdvertInterval = value.toInt();
|
||||
@@ -1731,7 +1851,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
title: Text(l10n.repeater_floodMax),
|
||||
subtitle: Text(l10n.repeater_floodMaxHelper),
|
||||
trailing: Text(
|
||||
'$_floodMax',
|
||||
_loaded('flood.max') ? '$_floodMax' : '—',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
@@ -1757,10 +1877,12 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
max: 64,
|
||||
divisions: 64,
|
||||
label: '$_floodMax',
|
||||
onChanged: (v) {
|
||||
setState(() => _floodMax = v.toInt());
|
||||
_markChanged(_SettingField.floodMax);
|
||||
},
|
||||
onChanged: !_loaded('flood.max')
|
||||
? null
|
||||
: (v) {
|
||||
setState(() => _floodMax = v.toInt());
|
||||
_markChanged(_SettingField.floodMax);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1784,7 +1906,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<String>(
|
||||
initialValue: _loopDetect,
|
||||
initialValue: _loaded('loop.detect') ? _loopDetect : null,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_loopDetect,
|
||||
helperText: l10n.repeater_loopDetectHelper,
|
||||
@@ -1808,12 +1930,14 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
child: Text(l10n.repeater_loopDetectStrict),
|
||||
),
|
||||
],
|
||||
onChanged: (v) {
|
||||
if (v != null) {
|
||||
setState(() => _loopDetect = v);
|
||||
_markChanged(_SettingField.loopDetect);
|
||||
}
|
||||
},
|
||||
onChanged: !_loaded('loop.detect')
|
||||
? null
|
||||
: (v) {
|
||||
if (v != null) {
|
||||
setState(() => _loopDetect = v);
|
||||
_markChanged(_SettingField.loopDetect);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
_buildInlineRefreshButton(
|
||||
@@ -1831,7 +1955,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
title: Text(l10n.repeater_dutyCycle),
|
||||
subtitle: Text(l10n.repeater_dutyCycleHelper),
|
||||
trailing: Text(
|
||||
l10n.repeater_dutyCyclePercent(_dutyCycle),
|
||||
_loaded('dutycycle')
|
||||
? l10n.repeater_dutyCyclePercent(_dutyCycle)
|
||||
: '—',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
@@ -1857,10 +1983,12 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
max: 100,
|
||||
divisions: 99,
|
||||
label: l10n.repeater_dutyCyclePercent(_dutyCycle),
|
||||
onChanged: (v) {
|
||||
setState(() => _dutyCycle = v.toInt());
|
||||
_markChanged(_SettingField.dutyCycle);
|
||||
},
|
||||
onChanged: !_loaded('dutycycle')
|
||||
? null
|
||||
: (v) {
|
||||
setState(() => _dutyCycle = v.toInt());
|
||||
_markChanged(_SettingField.dutyCycle);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1891,6 +2019,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
MeshCard(
|
||||
child: TextField(
|
||||
controller: _ownerInfoController,
|
||||
enabled: _loaded('owner.info'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_ownerInfo,
|
||||
helperText: l10n.repeater_ownerInfoHelper,
|
||||
@@ -1975,23 +2104,36 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<int>(
|
||||
initialValue: _pathHashMode,
|
||||
initialValue: _loaded('path.hash.mode')
|
||||
? _pathHashMode
|
||||
: null,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_pathHashMode,
|
||||
helperText: l10n.repeater_pathHashModeHelper,
|
||||
helperMaxLines: 5,
|
||||
),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 0, child: Text('0')),
|
||||
DropdownMenuItem(value: 1, child: Text('1')),
|
||||
DropdownMenuItem(value: 2, child: Text('2')),
|
||||
items: [
|
||||
DropdownMenuItem(
|
||||
value: 0,
|
||||
child: Text(l10n.repeater_pathHashModeOption0),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 1,
|
||||
child: Text(l10n.repeater_pathHashModeOption1),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 2,
|
||||
child: Text(l10n.repeater_pathHashModeOption2),
|
||||
),
|
||||
],
|
||||
onChanged: (v) {
|
||||
if (v != null) {
|
||||
setState(() => _pathHashMode = v);
|
||||
_markChanged(_SettingField.pathHashMode);
|
||||
}
|
||||
},
|
||||
onChanged: !_loaded('path.hash.mode')
|
||||
? null
|
||||
: (v) {
|
||||
if (v != null) {
|
||||
setState(() => _pathHashMode = v);
|
||||
_markChanged(_SettingField.pathHashMode);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
_buildInlineRefreshButton(
|
||||
@@ -2008,6 +2150,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _txDelayController,
|
||||
enabled: _loaded('txdelay'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_txDelay,
|
||||
helperText: l10n.repeater_txDelayHelper,
|
||||
@@ -2033,6 +2176,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _directTxDelayController,
|
||||
enabled: _loaded('direct.txdelay'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_directTxDelay,
|
||||
helperText: l10n.repeater_directTxDelayHelper,
|
||||
@@ -2058,6 +2202,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _intThreshController,
|
||||
enabled: _loaded('int.thresh'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_intThresh,
|
||||
helperText: l10n.repeater_intThreshHelper,
|
||||
@@ -2082,7 +2227,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
title: Text(l10n.repeater_agcResetInterval),
|
||||
subtitle: Text(l10n.repeater_agcResetIntervalHelper),
|
||||
trailing: Text(
|
||||
'${_agcResetInterval}s',
|
||||
_loaded('agc.reset.interval')
|
||||
? '${_agcResetInterval}s'
|
||||
: '—',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
@@ -2110,13 +2257,15 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
max: _maxAgcResetInterval.toDouble(),
|
||||
divisions: _maxAgcResetInterval ~/ 4,
|
||||
label: '${_agcResetInterval}s',
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
// Clamp to multiple of 4 to match firmware semantics.
|
||||
_agcResetInterval = (v.toInt() ~/ 4) * 4;
|
||||
});
|
||||
_markChanged(_SettingField.agcResetInterval);
|
||||
},
|
||||
onChanged: !_loaded('agc.reset.interval')
|
||||
? null
|
||||
: (v) {
|
||||
setState(() {
|
||||
// Clamp to multiple of 4 to match firmware semantics.
|
||||
_agcResetInterval = (v.toInt() ~/ 4) * 4;
|
||||
});
|
||||
_markChanged(_SettingField.agcResetInterval);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -614,23 +614,33 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
}
|
||||
|
||||
Widget _buildStatGrid(List<_StatItem> items) {
|
||||
return GridView.count(
|
||||
crossAxisCount: 2,
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
mainAxisSpacing: 8,
|
||||
crossAxisSpacing: 8,
|
||||
childAspectRatio: 2.2,
|
||||
children: items
|
||||
.map(
|
||||
(item) => StatTile(
|
||||
final textScaler = MediaQuery.textScalerOf(context);
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final columns = constraints.maxWidth / textScaler.scale(1) < 320
|
||||
? 1
|
||||
: 2;
|
||||
return GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: items.length,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: columns,
|
||||
mainAxisSpacing: 8,
|
||||
crossAxisSpacing: 8,
|
||||
mainAxisExtent: textScaler.scale(52) + 28,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final item = items[index];
|
||||
return StatTile(
|
||||
icon: item.icon,
|
||||
label: item.label,
|
||||
value: item.value,
|
||||
color: item.color,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,7 +508,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
context,
|
||||
icon: Icons.sensors_outlined,
|
||||
title: l10n.radioStats_settingsTile,
|
||||
subtitle: l10n.radioStats_settingsSubtitle,
|
||||
subtitle:
|
||||
connector.isConnected && !connector.supportsCompanionRadioStats
|
||||
? l10n.settings_requiresFirmware('v1.10')
|
||||
: l10n.radioStats_settingsSubtitle,
|
||||
onTap: connector.isConnected && connector.supportsCompanionRadioStats
|
||||
? () => pushCompanionRadioStatsScreen(context)
|
||||
: null,
|
||||
@@ -518,7 +521,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
context,
|
||||
icon: Icons.route_outlined,
|
||||
title: l10n.repeater_pathHashMode,
|
||||
subtitle: _pathHashModeSubtitle(context, connector.pathHashByteWidth),
|
||||
subtitle:
|
||||
connector.isConnected &&
|
||||
(connector.firmwareVerCode ?? 0) <
|
||||
_minFirmwareVerCodeForPathHashMode
|
||||
? l10n.settings_requiresFirmware('v1.14')
|
||||
: _pathHashModeSubtitle(context, connector.pathHashByteWidth),
|
||||
onTap:
|
||||
connector.isConnected &&
|
||||
(connector.firmwareVerCode ?? 0) >=
|
||||
@@ -868,7 +876,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
l10n.repeater_pathHashModeHelper,
|
||||
l10n.settings_pathHashModeHelper,
|
||||
style: Theme.of(builderContext).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
@@ -1334,14 +1342,29 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
settingsService.settings.autoSendZeroHopAdvertOnGpsUpdate;
|
||||
|
||||
final telemModeBase = [
|
||||
DropdownMenuItem(value: teleModeDeny, child: Text(l10n.settings_denyAll)),
|
||||
DropdownMenuItem(
|
||||
value: teleModeDeny,
|
||||
child: Text(
|
||||
l10n.settings_denyAll,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: teleModeAllowFlags,
|
||||
child: Text(l10n.settings_allowByContact),
|
||||
child: Text(
|
||||
l10n.settings_allowByContact,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: teleModeAllowAll,
|
||||
child: Text(l10n.settings_allowAll),
|
||||
child: Text(
|
||||
l10n.settings_allowAll,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
@@ -1349,6 +1372,7 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (builderContext, setDialogState) => AlertDialog(
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
|
||||
title: Text(l10n.settings_privacy),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
@@ -1382,6 +1406,7 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
const SizedBox(height: 8),
|
||||
SwitchListTile(
|
||||
title: Text(l10n.settings_multiAck),
|
||||
subtitle: Text(l10n.settings_multiAckSubtitle),
|
||||
value: multiAcks == 1,
|
||||
onChanged: (value) {
|
||||
setDialogState(() => multiAcks = value ? 1 : 0);
|
||||
@@ -1391,6 +1416,7 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<int>(
|
||||
initialValue: telemetryMode,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_telemetryBaseMode,
|
||||
border: const OutlineInputBorder(),
|
||||
@@ -1405,6 +1431,7 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<int>(
|
||||
initialValue: telemetryLocMode,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_telemetryLocationMode,
|
||||
border: const OutlineInputBorder(),
|
||||
@@ -1419,6 +1446,7 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<int>(
|
||||
initialValue: telemetryEnvMode,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_telemetryEnvironmentMode,
|
||||
border: const OutlineInputBorder(),
|
||||
@@ -1430,6 +1458,11 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
l10n.settings_telemetryPerContactHint,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -1583,8 +1616,7 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
if (preset.frequencyHz == snapshot.frequencyHz &&
|
||||
preset.bandwidth == snapshot.bandwidth &&
|
||||
preset.spreadingFactor == snapshot.spreadingFactor &&
|
||||
preset.codingRate == snapshot.codingRate &&
|
||||
preset.txPowerDbm == snapshot.txPowerDbm) {
|
||||
preset.codingRate == snapshot.codingRate) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -1671,14 +1703,13 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
if (offGridFreqHz == current.frequencyHz &&
|
||||
preset.bandwidth == current.bandwidth &&
|
||||
preset.spreadingFactor == current.spreadingFactor &&
|
||||
preset.codingRate == current.codingRate &&
|
||||
preset.txPowerDbm == current.txPowerDbm) {
|
||||
preset.codingRate == current.codingRate) {
|
||||
return _RadioSettingsSnapshot(
|
||||
frequencyMHz: preset.frequencyMHz,
|
||||
bandwidth: preset.bandwidth,
|
||||
spreadingFactor: preset.spreadingFactor,
|
||||
codingRate: preset.codingRate,
|
||||
txPowerDbm: preset.txPowerDbm,
|
||||
txPowerDbm: current.txPowerDbm,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1987,20 +2018,30 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
children: [
|
||||
DropdownButtonFormField<int>(
|
||||
key: ValueKey<int?>(_selectedPresetIndex),
|
||||
initialValue: _selectedPresetIndex,
|
||||
initialValue: _selectedPresetIndex ?? -1,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_presets,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
items: [
|
||||
if (_selectedPresetIndex == null)
|
||||
DropdownMenuItem(
|
||||
value: -1,
|
||||
child: Text(l10n.settings_presetCustom),
|
||||
),
|
||||
for (final i in _visiblePresetIndexes())
|
||||
DropdownMenuItem(
|
||||
value: i,
|
||||
child: Text(RadioSettings.presets[i].$1),
|
||||
child: Text(
|
||||
RadioSettings.presets[i].$1,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (index) {
|
||||
if (index != null) {
|
||||
if (index != null && index >= 0) {
|
||||
_applyPreset(index);
|
||||
}
|
||||
},
|
||||
@@ -2012,7 +2053,11 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_frequency,
|
||||
border: const OutlineInputBorder(),
|
||||
helperText: l10n.settings_frequencyHelper,
|
||||
helperText: _clientRepeat
|
||||
? l10n.settings_clientRepeatFrequencyNote(
|
||||
_frequencyController.text,
|
||||
)
|
||||
: l10n.settings_frequencyHelper,
|
||||
errorText: _frequencyError,
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
@@ -2094,9 +2139,10 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_txPower,
|
||||
border: const OutlineInputBorder(),
|
||||
helperText: widget.connector.maxTxPower != null
|
||||
? '${l10n.settings_txPowerHelper} (max: ${widget.connector.maxTxPower} dBm)'
|
||||
: l10n.settings_txPowerHelper,
|
||||
helperText: l10n.settings_txPowerRangeHelper(
|
||||
_minTxPowerDbm,
|
||||
widget.connector.maxTxPower ?? 22,
|
||||
),
|
||||
errorText: _txPowerError,
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
@@ -2111,6 +2157,11 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
l10n.settings_radioMatchWarning,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -917,10 +917,12 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
value,
|
||||
style: MeshTheme.mono(fontSize: 13, color: scheme.onSurface),
|
||||
textAlign: TextAlign.end,
|
||||
Flexible(
|
||||
child: Text(
|
||||
value,
|
||||
style: MeshTheme.mono(fontSize: 13, color: scheme.onSurface),
|
||||
textAlign: TextAlign.end,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user