Merge upstream/dev (86 commits) into tth
Upstream redesigned the chat composer (bubble, round +/send button, ChatComposerQuote for the reply preview); our terminal theme had tweaked the old layout. Took upstream's structure and re-applied the terminal look to the new widgets: compact panel padding, square bubble, square button, square and one-line-low reply quote. The terminal reply padding in channel_chat_screen now lives in ChatComposerQuote, so DMs get it too. Also fixed for the merge: - mesh_ui: AvatarCircle uses upstream's avatarInitials() (nullable); the terminal glyph falls back to the person icon like upstream does; - chat_screen: upstream split maxMessageRetries into direct/flood limits, the terminal line now shows the bubble's maxSendAttempts; - test/screens/copy_messages_test.dart: the 1x1 PNG had a bad IDAT CRC. Its async decode failure leaked into the next test; upstream's real flutter_langdetect hides that by timing, our stub (instant init) does not, so the DM test failed ~3 of 5 runs. Replaced with a valid PNG. Checked in the CI image (Flutter 3.47.9): flutter analyze lib test clean; flutter test all green except settings_reveal_test "hides Image Messages sub-options", which fails the same way on plain upstream/dev. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
63907cb17d
210 files changed
+47623
-4900
No files matched your search
@@ -0,0 +1,493 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/contact_clipboard.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../utils/app_logger.dart';
|
||||
import '../utils/contact_qr.dart';
|
||||
import '../utils/radio_guard.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/mesh_nav_tile.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import 'contact_qr_scanner_screen.dart';
|
||||
import 'discovery_screen.dart';
|
||||
|
||||
/// Unified page for adding a contact manually by public key, from clipboard,
|
||||
/// from discovered contacts, or by scanning a QR code.
|
||||
class AddContactScreen extends StatefulWidget {
|
||||
const AddContactScreen({super.key});
|
||||
|
||||
@override
|
||||
State<AddContactScreen> createState() => _AddContactScreenState();
|
||||
}
|
||||
|
||||
class _AddContactScreenState extends State<AddContactScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _publicKeyFieldKey = GlobalKey<FormFieldState<String>>();
|
||||
final _nameController = TextEditingController();
|
||||
final _publicKeyController = TextEditingController();
|
||||
final _nameFocusNode = FocusNode();
|
||||
final _publicKeyFocusNode = FocusNode();
|
||||
|
||||
int _selectedType = advTypeChat;
|
||||
bool _isSaving = false;
|
||||
bool _isImporting = false;
|
||||
|
||||
bool get _isBusy => _isSaving || _isImporting;
|
||||
|
||||
static const List<int> _contactTypes = [
|
||||
advTypeChat,
|
||||
advTypeRepeater,
|
||||
advTypeRoom,
|
||||
advTypeSensor,
|
||||
];
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameController.dispose();
|
||||
_publicKeyController.dispose();
|
||||
_nameFocusNode.dispose();
|
||||
_publicKeyFocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String _typeLabel(AppLocalizations l10n, int type) {
|
||||
switch (type) {
|
||||
case advTypeChat:
|
||||
return l10n.contact_typeChat;
|
||||
case advTypeRepeater:
|
||||
return l10n.contact_typeRepeater;
|
||||
case advTypeRoom:
|
||||
return l10n.contact_typeRoom;
|
||||
case advTypeSensor:
|
||||
return l10n.contact_typeSensor;
|
||||
default:
|
||||
return l10n.contact_typeUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pickContactType() async {
|
||||
final chosen = await showMeshSheet<int>(
|
||||
context,
|
||||
builder: (sheetContext) {
|
||||
final l10n = sheetContext.l10n;
|
||||
return SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHeader(title: l10n.addContact_contactType),
|
||||
for (final type in _contactTypes)
|
||||
MeshSheetOption(
|
||||
label: _typeLabel(l10n, type),
|
||||
selected: type == _selectedType,
|
||||
onTap: () => Navigator.pop(sheetContext, type),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
if (!mounted || chosen == null) return;
|
||||
setState(() => _selectedType = chosen);
|
||||
}
|
||||
|
||||
Future<void> _saveContact() async {
|
||||
if (_isBusy) return;
|
||||
if (!(_formKey.currentState?.validate() ?? false)) return;
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
|
||||
final keyHex = normalizeContactPublicKeyHex(_publicKeyController.text);
|
||||
final publicKeyBytes = decodeContactPublicKeyHex(_publicKeyController.text);
|
||||
if (keyHex == null || publicKeyBytes == null) return;
|
||||
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
if (connector.selfPublicKeyHex.isNotEmpty &&
|
||||
keyHex == connector.selfPublicKeyHex.toLowerCase()) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contactShare_isYou),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _isSaving = true);
|
||||
try {
|
||||
await connector.addContactFromCard(
|
||||
ScannedContact(
|
||||
publicKey: publicKeyBytes,
|
||||
name: _nameController.text.trim(),
|
||||
type: _selectedType,
|
||||
),
|
||||
);
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.discoveredContacts_contactAdded),
|
||||
);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
appLogger.warn('Manual contact add failed: $e', tag: 'AddContactScreen');
|
||||
if (!mounted) return;
|
||||
setState(() => _isSaving = false);
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.addContact_saveFailed),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _importFromClipboard() async {
|
||||
if (_isBusy) return;
|
||||
final clipboardData = await Clipboard.getData('text/plain');
|
||||
if (!mounted) return;
|
||||
|
||||
final parsed = parseContactClipboard(clipboardData?.text);
|
||||
switch (parsed.kind) {
|
||||
case ContactClipboardKind.empty:
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_clipboardEmpty),
|
||||
);
|
||||
return;
|
||||
case ContactClipboardKind.invalid:
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_invalidAdvertFormat),
|
||||
);
|
||||
return;
|
||||
case ContactClipboardKind.publicKey:
|
||||
_publicKeyController.text = parsed.publicKeyHex!;
|
||||
if (_publicKeyFieldKey.currentState?.hasError == true) {
|
||||
_publicKeyFieldKey.currentState?.validate();
|
||||
}
|
||||
_nameFocusNode.requestFocus();
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.addContact_clipboardKeyLoaded),
|
||||
);
|
||||
return;
|
||||
case ContactClipboardKind.contact:
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
final scanned = parsed.contact!;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
if (scanned.publicKey != null &&
|
||||
connector.selfPublicKeyHex.isNotEmpty &&
|
||||
pubKeyToHex(scanned.publicKey!).toLowerCase() ==
|
||||
connector.selfPublicKeyHex.toLowerCase()) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contactShare_isYou),
|
||||
);
|
||||
return;
|
||||
}
|
||||
setState(() => _isImporting = true);
|
||||
try {
|
||||
await connector.addContactFromCard(scanned);
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImported),
|
||||
);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
appLogger.warn(
|
||||
'Clipboard contact import failed: $e',
|
||||
tag: 'AddContactScreen',
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() => _isImporting = false);
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImportFailed),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void _openDiscoveredContacts() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const DiscoveryScreen()),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _scanQrCode() async {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
final imported = await Navigator.push<bool>(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const ContactQrScannerScreen()),
|
||||
);
|
||||
if (imported == true && mounted) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: AdaptiveAppBarTitle(l10n.addContact_title),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: l10n.common_save,
|
||||
onPressed: _isBusy ? null : _saveContact,
|
||||
icon: _isSaving
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.check),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
|
||||
children: [
|
||||
MeshCard(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 14,
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
size: 24,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.addContact_infoBanner,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
_buildContactTypeRow(context),
|
||||
const Divider(height: 1, indent: 16),
|
||||
_buildNameRow(context),
|
||||
const Divider(height: 1, indent: 16),
|
||||
_buildPublicKeyRow(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: MeshNavTile(
|
||||
icon: Icons.content_paste,
|
||||
title: l10n.contacts_addContactFromClipboard,
|
||||
onTap: _isBusy ? null : _importFromClipboard,
|
||||
),
|
||||
),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: MeshNavTile(
|
||||
icon: Icons.person_add_rounded,
|
||||
title: l10n.addContact_fromDiscovered,
|
||||
onTap: _isBusy ? null : _openDiscoveredContacts,
|
||||
),
|
||||
),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: MeshNavTile(
|
||||
icon: Icons.qr_code_scanner,
|
||||
title: l10n.contacts_scanQrCode,
|
||||
onTap: _isBusy ? null : _scanQrCode,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContactTypeRow(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final label = _typeLabel(l10n, _selectedType);
|
||||
|
||||
return Semantics(
|
||||
button: true,
|
||||
enabled: !_isBusy,
|
||||
label: '${l10n.addContact_contactType}: $label',
|
||||
child: InkWell(
|
||||
onTap: _isBusy ? null : _pickContactType,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: 48),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
size: 24,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
l10n.addContact_contactType,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(label, style: theme.textTheme.bodyLarge),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
Icons.arrow_drop_down,
|
||||
size: 24,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNameRow(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.person_outline, size: 24, color: scheme.onSurfaceVariant),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: _nameController,
|
||||
focusNode: _nameFocusNode,
|
||||
enabled: !_isBusy,
|
||||
textInputAction: TextInputAction.next,
|
||||
onFieldSubmitted: (_) => _publicKeyFocusNode.requestFocus(),
|
||||
inputFormatters: [
|
||||
Utf8LengthLimitingTextInputFormatter(maxRadioNameBytes),
|
||||
],
|
||||
style: theme.textTheme.bodyLarge,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.addContact_name,
|
||||
filled: false,
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
errorBorder: InputBorder.none,
|
||||
focusedErrorBorder: InputBorder.none,
|
||||
disabledBorder: InputBorder.none,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 12),
|
||||
errorMaxLines: 4,
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return l10n.addContact_nameRequired;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPublicKeyRow(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.vpn_key_outlined,
|
||||
size: 24,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
key: _publicKeyFieldKey,
|
||||
controller: _publicKeyController,
|
||||
focusNode: _publicKeyFocusNode,
|
||||
enabled: !_isBusy,
|
||||
autocorrect: false,
|
||||
enableSuggestions: false,
|
||||
textInputAction: TextInputAction.done,
|
||||
onFieldSubmitted: (_) => _saveContact(),
|
||||
minLines: 1,
|
||||
maxLines: 3,
|
||||
style: MeshTheme.mono(fontSize: 15, color: scheme.onSurface),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.addContact_publicKeyHex,
|
||||
filled: false,
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
errorBorder: InputBorder.none,
|
||||
focusedErrorBorder: InputBorder.none,
|
||||
disabledBorder: InputBorder.none,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 12),
|
||||
errorMaxLines: 4,
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return l10n.addContact_publicKeyRequired;
|
||||
}
|
||||
if (decodeContactPublicKeyHex(value) == null) {
|
||||
return l10n.addContact_publicKeyInvalid;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -22,6 +22,7 @@ import '../utils/platform_info.dart';
|
||||
import '../utils/share_origin.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/model_download_list.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
|
||||
class BackupRestoreScreen extends StatefulWidget {
|
||||
@@ -630,12 +631,6 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
required ImageCodecService imageCodecService,
|
||||
}) async {
|
||||
final l10n = context.l10n;
|
||||
final modelNames = [
|
||||
if (translationModel != null)
|
||||
translationModelFriendlyName(translationModel),
|
||||
if (imageCodecModel != null)
|
||||
imageCodecSpec?.label ?? imageCodecModel.name,
|
||||
];
|
||||
var starting = false;
|
||||
var cancelRequested = false;
|
||||
var translationDone = translationModel == null;
|
||||
@@ -658,16 +653,9 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
starting ||
|
||||
translationService.isDownloading ||
|
||||
imageCodecService.isDownloading;
|
||||
final currentProgress = currentModel == translationModel?.name
|
||||
? translationService.downloadProgress
|
||||
: currentModel == imageCodecModel?.name
|
||||
? imageCodecService.downloadProgress
|
||||
: null;
|
||||
final currentFile = currentModel == translationModel?.name
|
||||
? translationService.downloadFileName
|
||||
: currentModel == imageCodecModel?.name
|
||||
? imageCodecService.downloadFileName
|
||||
: null;
|
||||
final translationCurrent = currentModel == translationModel?.name;
|
||||
final imageCurrent = currentModel == imageCodecModel?.name;
|
||||
final failure = downloadError;
|
||||
|
||||
void requestDownloadCancel() {
|
||||
cancelRequested = true;
|
||||
@@ -682,31 +670,73 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
},
|
||||
child: AlertDialog(
|
||||
title: Text(l10n.backupRestore_missingModelsTitle),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l10n.backupRestore_missingModelsMessage(
|
||||
modelNames.join('\n'),
|
||||
),
|
||||
),
|
||||
if (isDownloading) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(currentFile ?? currentModel ?? ''),
|
||||
const SizedBox(height: 8),
|
||||
LinearProgressIndicator(value: currentProgress),
|
||||
],
|
||||
if (downloadError != null) ...[
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(l10n.backupRestore_missingModelsMessage),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
l10n.backupRestore_failed(downloadError!),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
ModelDownloadList(
|
||||
rowPadding: const EdgeInsets.symmetric(vertical: 4),
|
||||
items: [
|
||||
if (translationModel != null)
|
||||
_missingModelItem(
|
||||
id: 'translation-${translationModel.id}',
|
||||
name: translationModelFriendlyName(
|
||||
translationModel,
|
||||
),
|
||||
sizeBytes: translationModel.fileSizeBytes,
|
||||
done: translationDone,
|
||||
current: translationCurrent,
|
||||
downloading:
|
||||
translationService.isDownloading ||
|
||||
(starting && translationCurrent),
|
||||
progress: translationService.downloadProgress,
|
||||
downloadedBytes:
|
||||
translationService.downloadedBytes,
|
||||
totalBytes: translationService.downloadTotalBytes,
|
||||
detail:
|
||||
translationService.downloadFileName ==
|
||||
'Merging chunks...'
|
||||
? l10n.translation_mergingChunks
|
||||
: null,
|
||||
error: failure == null
|
||||
? null
|
||||
: l10n.backupRestore_failed(failure),
|
||||
),
|
||||
if (imageCodecModel != null)
|
||||
_missingModelItem(
|
||||
id: 'image-${imageCodecModel.id}',
|
||||
name:
|
||||
imageCodecSpec?.label ??
|
||||
imageCodecModelFriendlyName(imageCodecModel),
|
||||
sizeBytes:
|
||||
imageCodecSpec?.totalSizeBytes ??
|
||||
imageCodecModel.fileSizeBytes,
|
||||
done: imageCodecDone,
|
||||
current: imageCurrent,
|
||||
downloading:
|
||||
imageCodecService.isDownloading ||
|
||||
(starting && imageCurrent),
|
||||
progress: imageCodecService.downloadProgress,
|
||||
downloadedBytes:
|
||||
imageCodecService.downloadedBytes,
|
||||
totalBytes: imageCodecService.downloadTotalBytes,
|
||||
detail:
|
||||
imageCodecService.downloadFileName
|
||||
?.startsWith('Verifying ') ==
|
||||
true
|
||||
? l10n.modelDownload_verifying
|
||||
: null,
|
||||
error: failure == null
|
||||
? null
|
||||
: l10n.backupRestore_failed(failure),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -830,3 +860,40 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
showDismissibleSnackBar(context, content: Text(message));
|
||||
}
|
||||
}
|
||||
|
||||
ModelDownloadItem _missingModelItem({
|
||||
required String id,
|
||||
required String name,
|
||||
required int sizeBytes,
|
||||
required bool done,
|
||||
required bool current,
|
||||
required bool downloading,
|
||||
required double? progress,
|
||||
required int downloadedBytes,
|
||||
required int? totalBytes,
|
||||
required String? detail,
|
||||
required String? error,
|
||||
}) {
|
||||
final inProgress = downloading && current && !done;
|
||||
final failed = error != null && current && !inProgress && !done;
|
||||
return ModelDownloadItem(
|
||||
id: id,
|
||||
name: name,
|
||||
sizeBytes: sizeBytes > 0 ? sizeBytes : null,
|
||||
status: done
|
||||
? ModelDownloadStatus.ready
|
||||
: failed
|
||||
? ModelDownloadStatus.error
|
||||
: inProgress
|
||||
? ModelDownloadStatus.downloading
|
||||
: ModelDownloadStatus.notDownloaded,
|
||||
progress: inProgress ? progress : null,
|
||||
downloadedBytes: inProgress ? downloadedBytes : 0,
|
||||
totalBytes: inProgress ? totalBytes : null,
|
||||
detail: failed
|
||||
? error
|
||||
: inProgress
|
||||
? detail
|
||||
: null,
|
||||
);
|
||||
}
|
||||
@@ -96,6 +96,9 @@ class _BookmarksScreenState extends State<BookmarksScreen> {
|
||||
: bookmark.text,
|
||||
style: textStyle,
|
||||
originalStyle: textStyle.copyWith(fontStyle: FontStyle.italic),
|
||||
backgroundColor:
|
||||
Theme.of(context).cardTheme.color ??
|
||||
Theme.of(context).colorScheme.surfaceContainerLow,
|
||||
);
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:image_picker/image_picker.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../games/chess/ui/chess_games_sheet.dart';
|
||||
import '../models/community.dart';
|
||||
import '../storage/community_store.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
@@ -53,6 +54,7 @@ import '../widgets/empty_state.dart';
|
||||
import '../widgets/filter_rule_dialog.dart';
|
||||
import '../widgets/filtered_message_ghost.dart';
|
||||
import '../widgets/chat_composer.dart';
|
||||
import '../widgets/chat_compression_selector.dart';
|
||||
import '../widgets/chat_send_pipeline.dart';
|
||||
import '../widgets/chat_zoom_wrapper.dart';
|
||||
import '../widgets/message_bubble_frame.dart';
|
||||
@@ -100,12 +102,15 @@ class ChannelChatScreen extends StatefulWidget {
|
||||
State<ChannelChatScreen> createState() => _ChannelChatScreenState();
|
||||
}
|
||||
|
||||
class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
with WidgetsBindingObserver {
|
||||
final _holidayWatcher = HolidayTriggerWatcher();
|
||||
final _messageAreaKey = GlobalKey();
|
||||
final TextEditingController _textController = TextEditingController();
|
||||
final ChatScrollController _scrollController = ChatScrollController();
|
||||
final FocusNode _textFieldFocusNode = FocusNode();
|
||||
bool _focusLostWhileAway = false;
|
||||
bool _focusLostToRoute = false;
|
||||
ChannelMessage? _replyingToMessage;
|
||||
bool _useReplyRegion = false;
|
||||
final CommunityStore _communityStore = CommunityStore();
|
||||
@@ -136,6 +141,13 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
MeshCoreConnector? _connector;
|
||||
final ChatSendGuard _sendGuard = ChatSendGuard();
|
||||
bool _channelSkipNextBottomSnap = false;
|
||||
|
||||
/// Newest entry and selection size seen by the last bottom-snap check, so
|
||||
/// a rebuild that only changed the selection is not mistaken for a new
|
||||
/// message.
|
||||
String? _snapNewestEntryId;
|
||||
int _snapSelectionCount = 0;
|
||||
|
||||
String? _unreadDividerMessageId;
|
||||
_TranscriptLayout? _transcriptLayout;
|
||||
ReceivedImageStore? _watchedImageStore;
|
||||
@@ -174,6 +186,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_textFieldFocusNode.addListener(_onTextFieldFocusChange);
|
||||
_scrollController.onScrollNearTop = _loadOlderMessages;
|
||||
_scrollController.showJumpToBottom.addListener(_clearDividerAtBottom);
|
||||
@@ -264,10 +277,28 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state != AppLifecycleState.resumed) return;
|
||||
// The focus manager observes the lifecycle from app start, so its restore
|
||||
// is already queued and runs first. Clearing afterwards keeps a focus
|
||||
// that was not restored (the user clicked elsewhere) from swallowing the
|
||||
// next real tap on the composer.
|
||||
scheduleMicrotask(() => _focusLostWhileAway = false);
|
||||
}
|
||||
|
||||
void _onTextFieldFocusChange() {
|
||||
if (_textFieldFocusNode.hasFocus && mounted) {
|
||||
_scrollController.handleKeyboardOpen();
|
||||
if (!mounted) return;
|
||||
if (!_textFieldFocusNode.hasFocus) {
|
||||
final state = WidgetsBinding.instance.lifecycleState;
|
||||
_focusLostWhileAway = state != null && state != AppLifecycleState.resumed;
|
||||
_focusLostToRoute = !(ModalRoute.of(context)?.isCurrent ?? true);
|
||||
return;
|
||||
}
|
||||
final restored = _focusLostWhileAway || _focusLostToRoute;
|
||||
_focusLostWhileAway = false;
|
||||
_focusLostToRoute = false;
|
||||
if (!restored) _scrollController.handleKeyboardOpen();
|
||||
}
|
||||
|
||||
Future<void> _loadOlderMessages() async {
|
||||
@@ -348,6 +379,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_route?.secondaryAnimation?.removeStatusListener(_onCoveringRouteStatus);
|
||||
_watchedImageStore?.removeListener(_onImageStoreChanged);
|
||||
_unregisterActive();
|
||||
@@ -700,7 +732,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
ChatSearchEntry(
|
||||
id: m.messageId,
|
||||
sender: m.senderName,
|
||||
text: m.text,
|
||||
text: m.fullText,
|
||||
translatedText: m.translatedText,
|
||||
time: m.receivedAt,
|
||||
matchSender: true,
|
||||
@@ -845,12 +877,17 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
? _buildSearchResults(_loadSearchEntries)
|
||||
: SafeArea(
|
||||
top: false,
|
||||
// The composer panel pads the bottom inset itself, so the
|
||||
// background runs behind it to the screen edge.
|
||||
bottom: false,
|
||||
child: Column(
|
||||
children: [
|
||||
_buildCompressionSelector(),
|
||||
Expanded(
|
||||
child: ChatBackdrop(
|
||||
key: _messageAreaKey,
|
||||
contentKey: _messageAreaKey,
|
||||
chatKey: ChatBackgroundService.channelKey(widget.channel),
|
||||
footer: _buildInputBar(),
|
||||
child: Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, child) {
|
||||
final messages = connector.getChannelMessages(
|
||||
@@ -925,12 +962,25 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
rowCount + (_isLoadingOlder ? 1 : 0);
|
||||
|
||||
// Auto-scroll to bottom if user is already at bottom
|
||||
final newestEntryId = layout.ids.first;
|
||||
final selectionCount = _selectedIds.length;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
final newEntry =
|
||||
newestEntryId != _snapNewestEntryId;
|
||||
final selectionChanged =
|
||||
selectionCount != _snapSelectionCount;
|
||||
_snapNewestEntryId = newestEntryId;
|
||||
_snapSelectionCount = selectionCount;
|
||||
if (_channelSkipNextBottomSnap) {
|
||||
_channelSkipNextBottomSnap = false;
|
||||
return;
|
||||
}
|
||||
// Picking or clearing messages is not a new
|
||||
// message: keep the reading position.
|
||||
if (!newEntry && (_selecting || selectionChanged)) {
|
||||
return;
|
||||
}
|
||||
_scrollController.scrollToBottomIfAtBottom();
|
||||
});
|
||||
|
||||
@@ -1070,7 +1120,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildInputBar(),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -1132,6 +1181,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
final publicIpfsGateway = settingsService.settings.publicIpfsGateway;
|
||||
final enableTracing = settingsService.settings.enableMessageTracing;
|
||||
final regionOnHopsLine = settingsService.settings.regionOnHopsLine;
|
||||
final showCompressionIndicator =
|
||||
settingsService.settings.showCompressionIndicator;
|
||||
final isOutgoing = message.isOutgoing;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final gifId = GifHelper.parseGif(message.text);
|
||||
@@ -1182,6 +1233,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
fontStyle: FontStyle.italic,
|
||||
color: textColor.withValues(alpha: 0.72),
|
||||
),
|
||||
backgroundColor: colors.background,
|
||||
onSecondaryTap: PlatformInfo.isDesktop
|
||||
? () => _showMessageActions(message)
|
||||
: null,
|
||||
@@ -1335,6 +1387,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
alpha: 0.72,
|
||||
),
|
||||
),
|
||||
backgroundColor: colors.background,
|
||||
onSecondaryTap: PlatformInfo.isDesktop
|
||||
? () => _showMessageActions(message)
|
||||
: null,
|
||||
@@ -1447,8 +1500,10 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
bottom: 4,
|
||||
)
|
||||
: EdgeInsets.zero,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
child: Wrap(
|
||||
spacing: 4,
|
||||
runSpacing: 2,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
formatChatTime(context, message.timestamp),
|
||||
@@ -1457,30 +1512,36 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
if (message.hasFutureTimestamp) ...[
|
||||
const SizedBox(width: 4),
|
||||
if (message.hasFutureTimestamp)
|
||||
FutureTimestampIndicator(size: 16 * textScale),
|
||||
],
|
||||
if (enableTracing &&
|
||||
!isOutgoing &&
|
||||
message.repeatCount > 0) ...[
|
||||
const SizedBox(width: 6),
|
||||
Icon(
|
||||
Icons.repeat,
|
||||
if (showCompressionIndicator &&
|
||||
message.isSmazCompressed)
|
||||
CompressionIndicator(
|
||||
size: 14 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
'${message.repeatCount}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
if (enableTracing &&
|
||||
!isOutgoing &&
|
||||
message.repeatCount > 0)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.repeat,
|
||||
size: 14 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
'${message.repeatCount}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
if (isOutgoing) ...[
|
||||
const SizedBox(width: 4),
|
||||
if (isOutgoing)
|
||||
MessageStatusIcon(
|
||||
size: 16 * textScale,
|
||||
isAcked: false,
|
||||
@@ -1500,7 +1561,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
ChannelMessageStatus.failed,
|
||||
onColor: metaColor,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -2519,6 +2579,14 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
),
|
||||
subtitle: _imageSenderLabel(entry),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.copy),
|
||||
title: Text(l10n.common_copy),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
copyChatMessageText(context, _imageCopyText(entry));
|
||||
},
|
||||
),
|
||||
if (canSave)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.save_alt),
|
||||
@@ -2571,6 +2639,17 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
String _imageCopyText(ReceivedImageEntry entry) {
|
||||
final l10n = context.l10n;
|
||||
final lines = <String>[
|
||||
'${_imageSenderLabel(entry)} (${formatChatTime(context, entry.firstSeen)})',
|
||||
l10n.receivedImage_awaiting(entry.bitstreamByteCount, entry.totalChunks),
|
||||
if (entry.state == ReceivedImageState.decoded && entry.synthesized)
|
||||
l10n.receivedImage_shareCaption(entry.bitstreamByteCount),
|
||||
];
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
Future<void> _saveImage(ReceivedImageEntry entry) async {
|
||||
final l10n = context.l10n;
|
||||
final shareOrigin = shareOriginOf(context);
|
||||
@@ -2665,49 +2744,23 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReplyBanner(double textScale) {
|
||||
Widget _buildComposerReplyQuote(double textScale) {
|
||||
final message = _replyingToMessage!;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final replyRegion = message.region;
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: MeshStyle.of(context).terminal
|
||||
? const EdgeInsets.symmetric(horizontal: 6, vertical: 0)
|
||||
: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.surfaceContainerHigh,
|
||||
border: Border(
|
||||
bottom: BorderSide(color: scheme.outlineVariant, width: 1),
|
||||
),
|
||||
return ChatComposerQuote(
|
||||
title: context.l10n.chat_replyingTo(message.senderName),
|
||||
content: _buildReplyContent(
|
||||
message.text,
|
||||
textScale,
|
||||
color: scheme.onSurfaceVariant,
|
||||
maxLines: 1,
|
||||
gifSize: 48,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.reply, size: 18, color: scheme.primary),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context.l10n.chat_replyingTo(message.senderName),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12 * textScale,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: scheme.primary,
|
||||
),
|
||||
),
|
||||
_buildReplyContent(
|
||||
message.text,
|
||||
textScale,
|
||||
color: scheme.onSurfaceVariant,
|
||||
maxLines: 1,
|
||||
gifSize: 48,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (replyRegion?.isNotEmpty ?? false)
|
||||
InkWell(
|
||||
onDismiss: _cancelReply,
|
||||
dismissTooltip: context.l10n.chat_cancelReply,
|
||||
trailing: (replyRegion?.isNotEmpty ?? false)
|
||||
? InkWell(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.xs),
|
||||
onTap: () => setState(() => _useReplyRegion = !_useReplyRegion),
|
||||
child: Container(
|
||||
@@ -2725,6 +2778,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
),
|
||||
child: Text(
|
||||
context.l10n.channels_regionSetTo(replyRegion!),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style:
|
||||
MeshTheme.mono(
|
||||
fontSize: 12 * textScale,
|
||||
@@ -2738,17 +2793,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2787,6 +2833,32 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
static String _replyPrefix(ChannelMessage replyTo) =>
|
||||
'@[${replyTo.senderName}] ';
|
||||
|
||||
/// Compression is stored on this phone under the channel's storage ID, so
|
||||
/// it can change while the radio is offline, but not before the slot has
|
||||
/// one.
|
||||
Widget _buildCompressionSelector() {
|
||||
final slot = widget.channel.index;
|
||||
return Consumer2<MeshCoreConnector, AppSettingsService>(
|
||||
builder: (context, connector, settingsService, _) {
|
||||
final hasStorageId = connector.channelIdForSlot(slot) != null;
|
||||
return ChatCompressionSelector(
|
||||
mode: connector.channelCompressionMode(slot),
|
||||
enabled: hasStorageId,
|
||||
disabledReason: hasStorageId
|
||||
? null
|
||||
: context.l10n.chatCompression_noStorageId,
|
||||
profiles: settingsService.settings.cyr2latProfiles,
|
||||
profileId: connector.getChannelCyr2LatProfileId(slot),
|
||||
defaultProfileId: settingsService.settings.selectedCyr2latProfileId,
|
||||
onModeChanged: (mode) =>
|
||||
connector.setChannelCompressionMode(slot, mode),
|
||||
onProfileChanged: (id) =>
|
||||
connector.setChannelCyr2LatProfileId(slot, id),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInputBar() {
|
||||
// Only the fields the composer depends on, so unrelated connector
|
||||
// notifications (adverts, other chats, radio stats) don't rebuild it.
|
||||
@@ -2824,18 +2896,17 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
: null,
|
||||
onSend: _sendMessage,
|
||||
sendTooltip: context.l10n.chat_sendMessage,
|
||||
header: [
|
||||
if (replyTo != null)
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final textScale = context.select<ChatTextScaleService, double>(
|
||||
(service) => service.scale,
|
||||
);
|
||||
return _buildReplyBanner(textScale);
|
||||
},
|
||||
),
|
||||
if (_imageSendTotal > 0) _buildImageSendProgress(scheme),
|
||||
],
|
||||
header: [if (_imageSendTotal > 0) _buildImageSendProgress(scheme)],
|
||||
replyPreview: replyTo == null
|
||||
? null
|
||||
: Builder(
|
||||
builder: (context) {
|
||||
final textScale = context.select<ChatTextScaleService, double>(
|
||||
(service) => service.scale,
|
||||
);
|
||||
return _buildComposerReplyQuote(textScale);
|
||||
},
|
||||
),
|
||||
actionsBuilder: () {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
return [
|
||||
@@ -2870,6 +2941,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
icon: Icons.person_add_alt,
|
||||
label: context.l10n.contactShare_shareAction,
|
||||
),
|
||||
ChatComposerAction(
|
||||
id: 'games',
|
||||
icon: Icons.sports_esports_outlined,
|
||||
label: chessMenuLabel(context, widget.channel),
|
||||
),
|
||||
];
|
||||
},
|
||||
onAction: (action) {
|
||||
@@ -2889,6 +2965,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
_textController,
|
||||
focusNode: _textFieldFocusNode,
|
||||
);
|
||||
case 'games':
|
||||
showChessGamesSheet(context, widget.channel);
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -2979,6 +3057,18 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
_sendGuard.markDispatched();
|
||||
}
|
||||
|
||||
/// Sends an own message again as a new message, e.g. when no repeats
|
||||
/// were heard.
|
||||
Future<void> _resendMessage(ChannelMessage message) {
|
||||
return _sendGuard.runExclusive(() async {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
if (!_sendGuard.checkCooldown(context)) return;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
unawaited(connector.resendChannelMessage(widget.channel, message));
|
||||
_sendGuard.markDispatched();
|
||||
});
|
||||
}
|
||||
|
||||
void _showMessagePathInfo(ChannelMessage message) {
|
||||
Navigator.push(
|
||||
context,
|
||||
@@ -3082,9 +3172,19 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
title: Text(context.l10n.common_copy),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
copyChatMessageText(context, message.text);
|
||||
copyChatMessageText(context, message.fullText);
|
||||
},
|
||||
),
|
||||
if (message.isOutgoing)
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: const Icon(Icons.replay),
|
||||
title: Text(context.l10n.chat_resend),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_resendMessage(message);
|
||||
},
|
||||
),
|
||||
if (canTranslateMessage)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.translate),
|
||||
@@ -3414,8 +3514,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
final text = messages
|
||||
.map(
|
||||
(m) => m.senderName.isEmpty || m.isOutgoing
|
||||
? m.text
|
||||
: '${m.senderName}: ${m.text}',
|
||||
? m.fullText
|
||||
: '${m.senderName}: ${m.fullText}',
|
||||
)
|
||||
.join('\n');
|
||||
setState(_selectedIds.clear);
|
||||
@@ -4190,8 +4290,10 @@ class _SwipeReplyBubbleState extends State<_SwipeReplyBubble> {
|
||||
onPointerMove: _handleSwipePointerMove,
|
||||
onPointerUp: (event) => _handleSwipePointerUp(event.position),
|
||||
onPointerCancel: (_) => _resetSwipe(),
|
||||
// Same insets as the plain row in _buildMessageBubble, so a bubble is
|
||||
// as wide whether or not it can be swiped (offline, desktop, outgoing).
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 8),
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
|
||||
@@ -21,6 +21,7 @@ import '../models/display_path.dart';
|
||||
import '../models/path_playback.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/contact_visuals.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/path_map_scaffold.dart';
|
||||
import '../widgets/path_map_ui.dart';
|
||||
@@ -356,7 +357,7 @@ class ChannelMessagePathScreen extends StatelessWidget {
|
||||
Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
AvatarCircle(name: hop.displayLabel, size: 36),
|
||||
AvatarCircle(name: hop.avatarName, size: 36),
|
||||
Positioned(
|
||||
right: -4,
|
||||
top: -4,
|
||||
@@ -1074,7 +1075,7 @@ class _ChannelMessagePathMapScreenState
|
||||
? l10n.channelPath_primaryPath(selectedIndex + 1)
|
||||
: l10n.channelPath_pathLabel(selectedIndex + 1);
|
||||
return Positioned(
|
||||
left: 16,
|
||||
left: pathMapTopOverlayInset(),
|
||||
right: 16,
|
||||
top: topOffset,
|
||||
child: SafeArea(
|
||||
@@ -1374,7 +1375,10 @@ class _ChannelMessagePathMapScreenState
|
||||
isImperial: isImperial,
|
||||
l10n: l10n,
|
||||
),
|
||||
style: MeshTheme.mono(fontSize: 12, color: MeshPalette.ink2),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1429,6 +1433,7 @@ class _ChannelMessagePathMapScreenState
|
||||
Map<int, int> hopUseCount,
|
||||
) {
|
||||
final l10n = context.l10n;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
if (hops.isEmpty) {
|
||||
return Center(child: Text(l10n.channelPath_noHopDetailsAvailable));
|
||||
}
|
||||
@@ -1458,7 +1463,7 @@ class _ChannelMessagePathMapScreenState
|
||||
color: index == highlightRow
|
||||
? highlightColor
|
||||
: isFocused
|
||||
? MeshPalette.blueBg
|
||||
? scheme.primary.withValues(alpha: 0.12)
|
||||
: Colors.transparent,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
@@ -1470,10 +1475,10 @@ class _ChannelMessagePathMapScreenState
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: MeshPalette.blueDim.withValues(alpha: 0.3),
|
||||
color: scheme.primary.withValues(alpha: 0.18),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: MeshPalette.blueDim.withValues(alpha: 0.5),
|
||||
color: scheme.primary.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
@@ -1481,8 +1486,8 @@ class _ChannelMessagePathMapScreenState
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
hop.index.toString(),
|
||||
style: const TextStyle(
|
||||
color: MeshPalette.ink,
|
||||
style: TextStyle(
|
||||
color: scheme.onSurface,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
@@ -1515,7 +1520,7 @@ class _ChannelMessagePathMapScreenState
|
||||
].join(' · '),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
color: MeshPalette.ink3,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
@@ -1616,14 +1621,23 @@ class _PathHop {
|
||||
|
||||
bool get hasLocation => position != null;
|
||||
|
||||
String get displayLabel {
|
||||
final prefixLabel = hopBytes != null && hopBytes!.isNotEmpty
|
||||
? hopBytes!
|
||||
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||
.join('')
|
||||
.toUpperCase()
|
||||
: _formatPrefix(prefix);
|
||||
return '($prefixLabel) ${_resolveName(contact, l10n)}';
|
||||
String get prefixLabel => hopBytes != null && hopBytes!.isNotEmpty
|
||||
? hopBytes!
|
||||
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||
.join('')
|
||||
.toUpperCase()
|
||||
: _formatPrefix(prefix);
|
||||
|
||||
String get displayLabel => '($prefixLabel) ${_resolveName(contact, l10n)}';
|
||||
|
||||
/// Avatar source: the repeater's own name, or the hop's hex prefix when
|
||||
/// the hop is unresolved or its name has nothing to make initials from.
|
||||
String get avatarName {
|
||||
final name = contact?.name.trim() ?? '';
|
||||
if (name.toLowerCase() == 'unknown' || avatarInitials(name) == null) {
|
||||
return prefixLabel;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,7 @@ import 'channel_chat_screen.dart';
|
||||
import 'community_qr_scanner_screen.dart';
|
||||
import 'contacts_screen.dart';
|
||||
import 'map_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
import '../review_mode/review_mode_banner.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
|
||||
class ChannelsScreen extends StatefulWidget {
|
||||
final bool hideBackButton;
|
||||
@@ -124,11 +122,11 @@ class _ChannelsScreenState extends State<ChannelsScreen> {
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
actions: [
|
||||
PopupMenuButton(
|
||||
tooltip: context.l10n.contacts_moreOptions,
|
||||
// onTap handlers run after the menu route pops, so they must
|
||||
// capture the screen's context — not the itemBuilder's menu
|
||||
// context, which is deactivated by then.
|
||||
itemBuilder: (menuContext) => [
|
||||
connectionMenuItem(context, menuContext),
|
||||
PopupMenuItem(
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.bookmark_border,
|
||||
@@ -146,18 +144,7 @@ class _ChannelsScreenState extends State<ChannelsScreen> {
|
||||
),
|
||||
onTap: () => _showManageCommunitiesDialog(context),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: MeshMenuItemRow(
|
||||
leading: const ThemedIcon(ThemeIconSlot.settings, size: 20),
|
||||
label: menuContext.l10n.settings_title,
|
||||
),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const SettingsScreen(),
|
||||
),
|
||||
),
|
||||
),
|
||||
...mainOverflowTrailingItems(context, menuContext),
|
||||
],
|
||||
icon: const Icon(Icons.more_vert),
|
||||
),
|
||||
@@ -783,13 +770,14 @@ class _ChannelsScreenState extends State<ChannelsScreen> {
|
||||
break;
|
||||
case ChannelSortOption.latestMessages:
|
||||
// Filtered messages don't bump a channel, matching the preview.
|
||||
// Ordered by local arrival time: sender clocks can be far off.
|
||||
// Looked up once per channel: the lookup can scan back through
|
||||
// filtered messages, and the comparator runs O(n log n) times.
|
||||
final epoch = DateTime(1970);
|
||||
final latest = <Channel, DateTime>{
|
||||
for (final channel in filtered)
|
||||
channel:
|
||||
connector.latestVisibleChannelMessage(channel)?.timestamp ??
|
||||
connector.latestVisibleChannelMessage(channel)?.receivedAt ??
|
||||
epoch,
|
||||
};
|
||||
filtered.sort((a, b) {
|
||||
@@ -1951,16 +1939,11 @@ void showEditChannelSheet(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
bool smazEnabled = connector.isChannelSmazEnabled(channel.index);
|
||||
bool cyr2latEnabled = connector.isChannelCyr2LatEnabled(channel.index);
|
||||
final initialUrlImagesEnabled = connector.isChannelUrlImagesEnabled(
|
||||
channel.index,
|
||||
);
|
||||
bool urlImagesEnabled = initialUrlImagesEnabled;
|
||||
final loadLinkImages = appSettingsService.settings.loadLinkImages;
|
||||
String? selectedCyr2LatProfileId = connector.getChannelCyr2LatProfileId(
|
||||
channel.index,
|
||||
);
|
||||
|
||||
showMeshSheet(
|
||||
context,
|
||||
@@ -2018,62 +2001,6 @@ void showEditChannelSheet(
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(sheetContext.l10n.channels_smazCompression),
|
||||
value: smazEnabled,
|
||||
onChanged: (value) => setSheetState(() {
|
||||
smazEnabled = value;
|
||||
if (smazEnabled) {
|
||||
cyr2latEnabled = false;
|
||||
}
|
||||
}),
|
||||
),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(
|
||||
sheetContext.l10n.channels_cyr2latCompression,
|
||||
),
|
||||
subtitle: Text(
|
||||
sheetContext.l10n.channels_cyr2latCompressionDscr,
|
||||
),
|
||||
value: cyr2latEnabled,
|
||||
onChanged: (value) => setSheetState(() {
|
||||
cyr2latEnabled = value;
|
||||
if (cyr2latEnabled) {
|
||||
smazEnabled = false;
|
||||
}
|
||||
}),
|
||||
),
|
||||
if (cyr2latEnabled) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 8),
|
||||
child: DropdownButtonFormField<String>(
|
||||
isExpanded: true,
|
||||
initialValue: selectedCyr2LatProfileId,
|
||||
decoration: InputDecoration(
|
||||
labelText: sheetContext
|
||||
.l10n
|
||||
.channels_cyr2latSettingsSubheading,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
items: appSettingsService.settings.cyr2latProfiles
|
||||
.map((profile) {
|
||||
return DropdownMenuItem(
|
||||
value: profile.id,
|
||||
child: Text(
|
||||
profile.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
})
|
||||
.toList(),
|
||||
onChanged: (value) => setSheetState(() {
|
||||
selectedCyr2LatProfileId = value;
|
||||
}),
|
||||
),
|
||||
),
|
||||
],
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(sheetContext.l10n.urlImage_enable),
|
||||
@@ -2135,30 +2062,38 @@ void showEditChannelSheet(
|
||||
}
|
||||
|
||||
Navigator.pop(sheetContext);
|
||||
// A new PSK gives the channel a new storage ID;
|
||||
// its compression settings move with it.
|
||||
final previousId = connector.channelIdForSlot(
|
||||
channel.index,
|
||||
);
|
||||
final compression = connector
|
||||
.channelCompressionMode(channel.index);
|
||||
final cyr2LatProfileId = connector
|
||||
.getChannelCyr2LatProfileId(channel.index);
|
||||
try {
|
||||
await connector.setChannel(
|
||||
channel.index,
|
||||
name,
|
||||
psk,
|
||||
);
|
||||
await connector.setChannelSmazEnabled(
|
||||
channel.index,
|
||||
smazEnabled,
|
||||
);
|
||||
await connector.setChannelCyr2LatEnabled(
|
||||
channel.index,
|
||||
cyr2latEnabled,
|
||||
);
|
||||
if (connector.channelIdForSlot(channel.index) !=
|
||||
previousId) {
|
||||
await connector.setChannelCompressionMode(
|
||||
channel.index,
|
||||
compression,
|
||||
);
|
||||
await connector.setChannelCyr2LatProfileId(
|
||||
channel.index,
|
||||
cyr2LatProfileId,
|
||||
);
|
||||
}
|
||||
if (urlImagesEnabled != initialUrlImagesEnabled) {
|
||||
await connector.setChannelUrlImagesEnabled(
|
||||
channel.index,
|
||||
urlImagesEnabled,
|
||||
);
|
||||
}
|
||||
await connector.setChannelCyr2LatProfileId(
|
||||
channel.index,
|
||||
selectedCyr2LatProfileId,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
|
||||
+104
-106
@@ -20,6 +20,7 @@ import '../helpers/path_helper.dart';
|
||||
import '../helpers/reaction_helper.dart';
|
||||
import '../widgets/message_status_icon.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../helpers/chat_scroll_anchor.dart';
|
||||
import '../helpers/chat_scroll_controller.dart';
|
||||
import '../helpers/gif_helper.dart';
|
||||
import '../helpers/ipfs_link_attach_flow.dart';
|
||||
@@ -37,6 +38,7 @@ import '../services/chat_text_scale_service.dart';
|
||||
import '../services/path_history_service.dart';
|
||||
import '../services/translation_service.dart';
|
||||
import '../widgets/chat_composer.dart';
|
||||
import '../widgets/chat_compression_selector.dart';
|
||||
import '../widgets/chat_send_pipeline.dart';
|
||||
import '../widgets/chat_zoom_wrapper.dart';
|
||||
import '../widgets/message_bubble_frame.dart';
|
||||
@@ -91,12 +93,16 @@ class ChatScreen extends StatefulWidget {
|
||||
State<ChatScreen> createState() => _ChatScreenState();
|
||||
}
|
||||
|
||||
class _ChatScreenState extends State<ChatScreen> {
|
||||
class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
final _holidayWatcher = HolidayTriggerWatcher();
|
||||
final _messageAreaKey = GlobalKey();
|
||||
final _textController = TextEditingController();
|
||||
final _scrollController = ChatScrollController();
|
||||
final _scrollAnchor = ChatScrollAnchor();
|
||||
({String id, bool bookmarksOnly})? _newestRow;
|
||||
final _textFieldFocusNode = FocusNode();
|
||||
bool _focusLostWhileAway = false;
|
||||
bool _focusLostToRoute = false;
|
||||
final GlobalKey _unreadScrollKey = GlobalKey();
|
||||
bool _isLoadingOlder = false;
|
||||
bool _showBookmarkedOnly = false;
|
||||
@@ -152,6 +158,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_textFieldFocusNode.addListener(_onTextFieldFocusChange);
|
||||
_scrollController.onScrollNearTop = _loadOlderMessages;
|
||||
_scrollController.showJumpToBottom.addListener(_clearDividerAtBottom);
|
||||
@@ -219,10 +226,28 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state != AppLifecycleState.resumed) return;
|
||||
// The focus manager observes the lifecycle from app start, so its restore
|
||||
// is already queued and runs first. Clearing afterwards keeps a focus
|
||||
// that was not restored (the user clicked elsewhere) from swallowing the
|
||||
// next real tap on the composer.
|
||||
scheduleMicrotask(() => _focusLostWhileAway = false);
|
||||
}
|
||||
|
||||
void _onTextFieldFocusChange() {
|
||||
if (_textFieldFocusNode.hasFocus && mounted) {
|
||||
_scrollController.handleKeyboardOpen();
|
||||
if (!mounted) return;
|
||||
if (!_textFieldFocusNode.hasFocus) {
|
||||
final state = WidgetsBinding.instance.lifecycleState;
|
||||
_focusLostWhileAway = state != null && state != AppLifecycleState.resumed;
|
||||
_focusLostToRoute = !(ModalRoute.of(context)?.isCurrent ?? true);
|
||||
return;
|
||||
}
|
||||
final restored = _focusLostWhileAway || _focusLostToRoute;
|
||||
_focusLostWhileAway = false;
|
||||
_focusLostToRoute = false;
|
||||
if (!restored) _scrollController.handleKeyboardOpen();
|
||||
}
|
||||
|
||||
Future<void> _loadOlderMessages() async {
|
||||
@@ -239,6 +264,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_route?.secondaryAnimation?.removeStatusListener(_onCoveringRouteStatus);
|
||||
_unregisterActive();
|
||||
_scrollController.showJumpToBottom.removeListener(_clearDividerAtBottom);
|
||||
@@ -624,12 +650,14 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
);
|
||||
return Column(
|
||||
children: [
|
||||
_buildCompressionSelector(connector),
|
||||
Expanded(
|
||||
child: ChatBackdrop(
|
||||
key: _messageAreaKey,
|
||||
contentKey: _messageAreaKey,
|
||||
chatKey: ChatBackgroundService.contactKey(
|
||||
widget.contact,
|
||||
),
|
||||
footer: _buildInputBar(connector),
|
||||
child: Stack(
|
||||
children: [
|
||||
messages.isEmpty
|
||||
@@ -642,7 +670,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildInputBar(connector),
|
||||
],
|
||||
);
|
||||
},
|
||||
@@ -650,6 +677,27 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Compression is stored on this phone per contact, so it can change
|
||||
/// while the radio is offline.
|
||||
Widget _buildCompressionSelector(MeshCoreConnector connector) {
|
||||
final keyHex = widget.contact.publicKeyHex;
|
||||
return Consumer<AppSettingsService>(
|
||||
builder: (context, settingsService, _) {
|
||||
return ChatCompressionSelector(
|
||||
mode: connector.contactCompressionMode(keyHex),
|
||||
enabled: true,
|
||||
profiles: settingsService.settings.cyr2latProfiles,
|
||||
profileId: connector.getContactCyr2LatProfileId(keyHex),
|
||||
defaultProfileId: settingsService.settings.selectedCyr2latProfileId,
|
||||
onModeChanged: (mode) =>
|
||||
connector.setContactCompressionMode(keyHex, mode),
|
||||
onProfileChanged: (id) =>
|
||||
connector.setContactCyr2LatProfileId(keyHex, id),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
if (_showBookmarkedOnly) return _buildBookmarkEmptyState();
|
||||
return EmptyState(
|
||||
@@ -680,15 +728,41 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
final reversedMessages = visibleMessages.reversed.toList();
|
||||
final itemCount = reversedMessages.length + (_isLoadingOlder ? 1 : 0);
|
||||
|
||||
// A reader scrolled up keeps their place when messages arrive below, as
|
||||
// a room's backlog does in a burst right after login.
|
||||
final previous = _newestRow;
|
||||
final newest = (
|
||||
id: reversedMessages.first.messageId,
|
||||
bookmarksOnly: _showBookmarkedOnly,
|
||||
);
|
||||
_newestRow = newest;
|
||||
if (previous != null &&
|
||||
previous.bookmarksOnly == newest.bookmarksOnly &&
|
||||
previous.id != newest.id &&
|
||||
_pendingUnreadScrollTarget == null &&
|
||||
_scrollController.showJumpToBottom.value) {
|
||||
final inserted = reversedMessages.indexWhere(
|
||||
(m) => m.messageId == previous.id,
|
||||
);
|
||||
if (inserted > 0) _scrollAnchor.rowsInsertedBelow(inserted);
|
||||
}
|
||||
|
||||
// Auto-scroll to bottom if user is already at bottom
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
if (_pendingUnreadScrollTarget != null) return;
|
||||
// Never take over a drag or fling: during a sync every update would
|
||||
// pull a reader who starts scrolling up back to the newest message.
|
||||
if (_scrollController.hasClients &&
|
||||
_scrollController.position.isScrollingNotifier.value) {
|
||||
return;
|
||||
}
|
||||
_scrollController.scrollToBottomIfAtBottom();
|
||||
});
|
||||
|
||||
return ChatZoomWrapper(
|
||||
child: ListView.builder(
|
||||
child: AnchoredChatListView.builder(
|
||||
scrollAnchor: _scrollAnchor,
|
||||
reverse: true, // List grows from bottom up
|
||||
controller: _scrollController,
|
||||
padding: MeshStyle.of(context).terminal
|
||||
@@ -711,6 +785,13 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
final messageIndex = index;
|
||||
Contact contact = _resolveContact(connector);
|
||||
final sendSettings = context.read<AppSettingsService>().settings;
|
||||
final retryLimit = sendSettings.sendAttemptLimit(
|
||||
rotating:
|
||||
sendSettings.autoRouteRotationEnabled &&
|
||||
contact.pathOverride == null,
|
||||
floodPath: (contact.pathOverride ?? contact.pathLength) < 0,
|
||||
);
|
||||
final bool isRoom = contact.type == advTypeRoom;
|
||||
final message = reversedMessages[messageIndex];
|
||||
String fourByteHex = '';
|
||||
@@ -740,6 +821,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
);
|
||||
final bubble = _MessageBubble(
|
||||
message: message,
|
||||
maxSendAttempts: retryLimit,
|
||||
senderName: isRoom
|
||||
? (roomAuthor != null
|
||||
? "${roomAuthor.name} [$fourByteHex]"
|
||||
@@ -1113,19 +1195,9 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
void _showContactSettings(BuildContext context) {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final appSettingsService = Provider.of<AppSettingsService>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
connector.ensureContactSmazSettingLoaded(widget.contact.publicKeyHex);
|
||||
connector.ensureContactCyr2LatSettingLoaded(widget.contact.publicKeyHex);
|
||||
// The live contact carries the current telemetry flags; widget.contact
|
||||
// is the snapshot this screen was opened with.
|
||||
final contact = _resolveContact(connector);
|
||||
bool smazEnabled = connector.isContactSmazEnabled(contact.publicKeyHex);
|
||||
bool cyr2latEnabled = connector.isContactCyr2LatEnabled(
|
||||
contact.publicKeyHex,
|
||||
);
|
||||
bool urlImagesEnabled = connector.isContactUrlImagesEnabled(
|
||||
contact.publicKeyHex,
|
||||
);
|
||||
@@ -1133,14 +1205,11 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
.read<AppSettingsService>()
|
||||
.settings
|
||||
.loadLinkImages;
|
||||
String? selectedCyr2LatProfileId = connector.getContactCyr2LatProfileId(
|
||||
contact.publicKeyHex,
|
||||
);
|
||||
bool teleBaseEnabled = contact.teleBaseEnabled;
|
||||
bool teleLocEnabled = contact.teleLocEnabled;
|
||||
bool teleEnvEnabled = contact.teleEnvEnabled;
|
||||
// Each toggle is committed immediately, like the compression switches,
|
||||
// so dismissing the dialog by tapping outside keeps the change. All three
|
||||
// Each toggle is committed immediately, like the link-image switch, so
|
||||
// dismissing the dialog by tapping outside keeps the change. All three
|
||||
// flags are sent every time so overlapping writes can't undo each other.
|
||||
void commitTelemetryFlags() {
|
||||
connector.setContactFlags(
|
||||
@@ -1168,86 +1237,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
),
|
||||
const Divider(height: 8),
|
||||
],
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(context.l10n.channels_smazCompression),
|
||||
subtitle: Text(context.l10n.chat_compressOutgoingMessages),
|
||||
value: smazEnabled,
|
||||
onChanged: (value) {
|
||||
connector.setContactSmazEnabled(
|
||||
contact.publicKeyHex,
|
||||
value,
|
||||
);
|
||||
connector.setContactCyr2LatEnabled(
|
||||
contact.publicKeyHex,
|
||||
false,
|
||||
);
|
||||
setDialogState(() {
|
||||
smazEnabled = value;
|
||||
if (smazEnabled) {
|
||||
cyr2latEnabled = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
const Divider(height: 8),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(context.l10n.channels_cyr2latCompression),
|
||||
subtitle: Text(context.l10n.channels_cyr2latCompressionDscr),
|
||||
value: cyr2latEnabled,
|
||||
onChanged: (value) {
|
||||
connector.setContactCyr2LatEnabled(
|
||||
contact.publicKeyHex,
|
||||
value,
|
||||
);
|
||||
connector.setContactSmazEnabled(
|
||||
contact.publicKeyHex,
|
||||
false,
|
||||
);
|
||||
setDialogState(() {
|
||||
cyr2latEnabled = value;
|
||||
if (cyr2latEnabled) {
|
||||
smazEnabled = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
if (cyr2latEnabled) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 8),
|
||||
child: DropdownButtonFormField<String>(
|
||||
isExpanded: true,
|
||||
initialValue: selectedCyr2LatProfileId,
|
||||
decoration: InputDecoration(
|
||||
labelText:
|
||||
context.l10n.channels_cyr2latSettingsSubheading,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
items: appSettingsService.settings.cyr2latProfiles.map((
|
||||
profile,
|
||||
) {
|
||||
return DropdownMenuItem(
|
||||
value: profile.id,
|
||||
child: Text(
|
||||
profile.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
connector.setContactCyr2LatProfileId(
|
||||
contact.publicKeyHex,
|
||||
value,
|
||||
);
|
||||
setDialogState(() {
|
||||
selectedCyr2LatProfileId = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
const Divider(height: 8),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(context.l10n.urlImage_enable),
|
||||
@@ -1627,6 +1616,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
class _MessageBubble extends StatelessWidget {
|
||||
final Message message;
|
||||
final int maxSendAttempts;
|
||||
final String senderName;
|
||||
final VoidCallback? onLongPress;
|
||||
final void Function(Message message, String emoji)? onRetryReaction;
|
||||
@@ -1636,6 +1626,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
|
||||
const _MessageBubble({
|
||||
required this.message,
|
||||
required this.maxSendAttempts,
|
||||
required this.senderName,
|
||||
required this.sourceId,
|
||||
required this.textScale,
|
||||
@@ -1649,6 +1640,8 @@ class _MessageBubble extends StatelessWidget {
|
||||
if (MeshStyle.of(context).terminal) return _buildTerminal(context);
|
||||
final settingsService = context.watch<AppSettingsService>();
|
||||
final enableTracing = settingsService.settings.enableMessageTracing;
|
||||
final showCompressionIndicator =
|
||||
settingsService.settings.showCompressionIndicator;
|
||||
final isOutgoing = message.isOutgoing;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final gifId = GifHelper.parseGif(message.text);
|
||||
@@ -1698,6 +1691,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
color: textColor.withValues(alpha: 0.72),
|
||||
fontSize: bodyFontSize * textScale,
|
||||
),
|
||||
backgroundColor: colors.background,
|
||||
onSecondaryTap: PlatformInfo.isDesktop ? onLongPress : null,
|
||||
),
|
||||
),
|
||||
@@ -1833,6 +1827,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
),
|
||||
fontSize: bodyFontSize * textScale,
|
||||
),
|
||||
backgroundColor: colors.background,
|
||||
onSecondaryTap: PlatformInfo.isDesktop
|
||||
? onLongPress
|
||||
: null,
|
||||
@@ -1877,10 +1872,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
child: Text(
|
||||
context.l10n.chat_retryCount(
|
||||
message.retryCount,
|
||||
context
|
||||
.read<AppSettingsService>()
|
||||
.settings
|
||||
.maxMessageRetries,
|
||||
maxSendAttempts,
|
||||
),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12 * textScale,
|
||||
@@ -1914,6 +1906,12 @@ class _MessageBubble extends StatelessWidget {
|
||||
FutureTimestampIndicator(
|
||||
size: 16 * textScale,
|
||||
),
|
||||
if (showCompressionIndicator &&
|
||||
message.isSmazCompressed)
|
||||
CompressionIndicator(
|
||||
size: 14 * textScale,
|
||||
color: metaColor,
|
||||
),
|
||||
if (isOutgoing) ...[
|
||||
const SizedBox(width: 2),
|
||||
MessageStatusIcon(
|
||||
@@ -2016,7 +2014,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
FutureTimestampIndicator(size: 14 * textScale),
|
||||
if (enableTracing && isOutgoing && message.retryCount > 0)
|
||||
Text(
|
||||
'↻${message.retryCount}/${settings.maxMessageRetries}',
|
||||
'↻${message.retryCount}/$maxSendAttempts',
|
||||
style: metaStyle,
|
||||
),
|
||||
if (isOutgoing)
|
||||
|
||||
@@ -190,7 +190,7 @@ class _ContactQrScannerScreenState extends State<ContactQrScannerScreen> {
|
||||
);
|
||||
// Keep _isProcessing set: resetting it would restart the camera on a
|
||||
// closing route and let a second detection import and pop again.
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
|
||||
+157
-425
@@ -26,6 +26,7 @@ import '../widgets/connect_sheet.dart';
|
||||
import '../utils/radio_guard.dart';
|
||||
import '../utils/emoji_utils.dart';
|
||||
import '../utils/route_transitions.dart';
|
||||
import '../widgets/contact_group_editor_dialog.dart';
|
||||
import '../widgets/contact_visuals.dart';
|
||||
import '../widgets/list_filter_widget.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
@@ -35,21 +36,18 @@ import '../widgets/repeater_login_dialog.dart';
|
||||
import '../widgets/room_login_dialog.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
import '../widgets/unread_badge.dart';
|
||||
import '../helpers/contact_share_message.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import 'add_contact_screen.dart';
|
||||
import 'channels_screen.dart';
|
||||
import 'chat_screen.dart';
|
||||
import 'contact_qr_scanner_screen.dart';
|
||||
import 'discovery_screen.dart';
|
||||
import 'map_screen.dart';
|
||||
import '../review_mode/review_mode_banner.dart';
|
||||
import 'repeater_hub_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
|
||||
enum RoomLoginDestination { chat, management }
|
||||
|
||||
enum ContactOperationType { import, export, zeroHopShare }
|
||||
enum ContactOperationType { export, zeroHopShare }
|
||||
|
||||
/// An export/import/share awaiting its generic OK/ERR ack. The timer drops
|
||||
/// it if no ack arrives, so a stuck op can't consume a later unrelated ack.
|
||||
@@ -81,6 +79,8 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
|
||||
final List<_PendingContactOperation> _pendingOperations = [];
|
||||
final DerivedListCache<Contact> _filteredCache = DerivedListCache<Contact>();
|
||||
final Map<String, _ContactTileEntrance> _rowCache = {};
|
||||
MeshCoreConnector? _rowCacheConnector;
|
||||
|
||||
StreamSubscription<Uint8List>? _frameSubscription;
|
||||
|
||||
@@ -158,10 +158,6 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
final l10n = context.l10n;
|
||||
final String message;
|
||||
switch (type) {
|
||||
case ContactOperationType.import:
|
||||
message = success
|
||||
? l10n.contacts_contactImported
|
||||
: l10n.contacts_contactImportFailed;
|
||||
case ContactOperationType.zeroHopShare:
|
||||
message = success
|
||||
? l10n.contacts_zeroHopContactAdvertSent
|
||||
@@ -344,85 +340,10 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _contactImport() async {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final clipboardData = await Clipboard.getData('text/plain');
|
||||
if (clipboardData == null || clipboardData.text == null) {
|
||||
if (mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_clipboardEmpty),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
final text = clipboardData.text!.trim();
|
||||
// A contact shared in chat (`<PUBKEY:TYPE:NAME>`) copied from the bubble.
|
||||
final share = findContactShare(text);
|
||||
if (share != null && !text.startsWith('meshcore://')) {
|
||||
await _importContactShare(connector, share);
|
||||
return;
|
||||
}
|
||||
if (!text.startsWith('meshcore://')) {
|
||||
if (mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_invalidAdvertFormat),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
final hexString = text.substring('meshcore://'.length);
|
||||
final Uint8List importContactFrame;
|
||||
try {
|
||||
final bytes = hex2Uint8List(hexString);
|
||||
importContactFrame = buildImportContactFrame(bytes);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_invalidAdvertFormat),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
_addPendingOperation(ContactOperationType.import);
|
||||
try {
|
||||
await connector.sendFrame(importContactFrame, expectsGenericAck: true);
|
||||
} catch (e) {
|
||||
_takePendingOperation(ContactOperationType.import);
|
||||
if (mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactImportFailed),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _importContactShare(
|
||||
MeshCoreConnector connector,
|
||||
ContactShare share,
|
||||
) async {
|
||||
if (!mounted) return;
|
||||
final l10n = context.l10n;
|
||||
if (share.publicKeyHex == connector.selfPublicKeyHex) {
|
||||
showDismissibleSnackBar(context, content: Text(l10n.contactShare_isYou));
|
||||
return;
|
||||
}
|
||||
var ok = true;
|
||||
try {
|
||||
await connector.addContactFromCard(share.toScannedContact());
|
||||
} catch (e) {
|
||||
appLogger.warn('Contact share import failed: $e', tag: 'ContactsScreen');
|
||||
ok = false;
|
||||
}
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
void _openAddContact() {
|
||||
Navigator.push(
|
||||
context,
|
||||
content: Text(
|
||||
ok ? l10n.contacts_contactImported : l10n.contacts_contactImportFailed,
|
||||
),
|
||||
MaterialPageRoute(builder: (context) => const AddContactScreen()),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -442,38 +363,26 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
actions: [
|
||||
PopupMenuButton(
|
||||
tooltip: context.l10n.contacts_moreOptions,
|
||||
itemBuilder: (context) => <PopupMenuEntry<dynamic>>[
|
||||
// onTap handlers run after the menu route pops, so they must
|
||||
// capture the screen's context — not the itemBuilder's menu
|
||||
// context, which is deactivated by then.
|
||||
itemBuilder: (menuContext) => <PopupMenuEntry<dynamic>>[
|
||||
PopupMenuItem(
|
||||
enabled: !readOnly,
|
||||
onTap: _openAddContact,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.person_add,
|
||||
label: menuContext.l10n.addContact_title,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.person_add_rounded,
|
||||
label: context.l10n.discoveredContacts_Title,
|
||||
label: menuContext.l10n.discoveredContacts_Title,
|
||||
),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const DiscoveryScreen(),
|
||||
),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.paste,
|
||||
label: context.l10n.contacts_addContactFromClipboard,
|
||||
),
|
||||
onTap: () => _contactImport(),
|
||||
),
|
||||
PopupMenuItem(
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.qr_code_scanner,
|
||||
label: context.l10n.contacts_scanQrCode,
|
||||
),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const ContactQrScannerScreen(),
|
||||
),
|
||||
MaterialPageRoute(builder: (_) => const DiscoveryScreen()),
|
||||
),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
@@ -481,7 +390,7 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.connect_without_contact,
|
||||
label: context.l10n.contacts_zeroHopAdvert,
|
||||
label: menuContext.l10n.contacts_zeroHopAdvert,
|
||||
),
|
||||
onTap: () => _sendSelfAdvert(connector, flood: false),
|
||||
),
|
||||
@@ -489,7 +398,7 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.cell_tower,
|
||||
label: context.l10n.contacts_floodAdvert,
|
||||
label: menuContext.l10n.contacts_floodAdvert,
|
||||
),
|
||||
onTap: () => _sendSelfAdvert(connector, flood: true),
|
||||
),
|
||||
@@ -497,7 +406,7 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.copy,
|
||||
label: context.l10n.contacts_copyAdvertToClipboard,
|
||||
label: menuContext.l10n.contacts_copyAdvertToClipboard,
|
||||
),
|
||||
onTap: () => _contactExport(Uint8List.fromList([])),
|
||||
),
|
||||
@@ -505,24 +414,11 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.radar,
|
||||
label: context.l10n.manualTrace_menuItem,
|
||||
label: menuContext.l10n.manualTrace_menuItem,
|
||||
),
|
||||
onTap: () => ManualPathTraceScreen.open(context),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
connectionMenuItem(this.context, context),
|
||||
PopupMenuItem(
|
||||
child: MeshMenuItemRow(
|
||||
leading: const ThemedIcon(ThemeIconSlot.settings, size: 20),
|
||||
label: context.l10n.settings_title,
|
||||
),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const SettingsScreen(),
|
||||
),
|
||||
),
|
||||
),
|
||||
...mainOverflowTrailingItems(context, menuContext),
|
||||
],
|
||||
icon: const Icon(Icons.more_vert),
|
||||
),
|
||||
@@ -537,7 +433,8 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
floatingActionButton: readOnly
|
||||
? null
|
||||
: FloatingActionButton(
|
||||
onPressed: () => _showAddContactSheet(context),
|
||||
tooltip: context.l10n.addContact_title,
|
||||
onPressed: _openAddContact,
|
||||
child: const Icon(Icons.person_add),
|
||||
),
|
||||
bottomNavigationBar: SafeArea(
|
||||
@@ -554,57 +451,6 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showAddContactSheet(BuildContext context) {
|
||||
showMeshSheet(
|
||||
context,
|
||||
builder: (sheetContext) => SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHeader(title: context.l10n.contacts_title),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.paste),
|
||||
title: Text(context.l10n.contacts_addContactFromClipboard),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_contactImport();
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.qr_code_scanner),
|
||||
title: Text(context.l10n.contacts_scanQrCode),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const ContactQrScannerScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.person_add_rounded),
|
||||
title: Text(context.l10n.discoveredContacts_Title),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const DiscoveryScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ContactGroup? _selectedGroupForName(String selectedGroupName) {
|
||||
if (selectedGroupName == contactsAllGroupsValue) return null;
|
||||
for (final group in _groups) {
|
||||
@@ -1099,21 +945,12 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
itemBuilder: (context, row) {
|
||||
if (row == 0) return discoveredTile;
|
||||
final index = row - 1;
|
||||
final contact = filteredAndSorted[index];
|
||||
final unreadCount = connector.getUnreadCountForContact(
|
||||
contact,
|
||||
);
|
||||
return _ContactTileEntrance(
|
||||
index: index,
|
||||
contact: contact,
|
||||
pathHashByteWidth: connector.pathHashByteWidth,
|
||||
lastSeen: resolveContactLastSeen(contact),
|
||||
unreadCount: unreadCount,
|
||||
isFavorite: contact.isFavorite,
|
||||
onTap: () => _openChat(context, contact),
|
||||
onLongPress: () =>
|
||||
_showContactOptions(context, connector, contact),
|
||||
onManage: _manageAction(context, contact),
|
||||
return _contactRow(
|
||||
context,
|
||||
connector,
|
||||
filteredAndSorted[index],
|
||||
index,
|
||||
filteredAndSorted.length,
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -1123,6 +960,54 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns the row built last time for [contact] when nothing it shows has
|
||||
/// changed. The connector notifies up to 20 times a second on a busy mesh
|
||||
/// and each notify rebuilds this screen; handing the list the same widget
|
||||
/// instance lets Flutter skip rebuilding those rows.
|
||||
_ContactTileEntrance _contactRow(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
Contact contact,
|
||||
int index,
|
||||
int rowCount,
|
||||
) {
|
||||
if (!identical(_rowCacheConnector, connector)) {
|
||||
_rowCache.clear();
|
||||
_rowCacheConnector = connector;
|
||||
}
|
||||
final unreadCount = connector.getUnreadCountForContact(contact);
|
||||
final pathHashByteWidth = connector.pathHashByteWidth;
|
||||
// Relative ("5 mins ago"), so it can change while the contact does not.
|
||||
final lastSeenLabel = formatContactLastSeen(
|
||||
context.l10n,
|
||||
resolveContactLastSeen(contact),
|
||||
);
|
||||
final cached = _rowCache[contact.publicKeyHex];
|
||||
if (cached != null &&
|
||||
identical(cached.contact, contact) &&
|
||||
cached.index == index &&
|
||||
cached.unreadCount == unreadCount &&
|
||||
cached.pathHashByteWidth == pathHashByteWidth &&
|
||||
cached.lastSeenLabel == lastSeenLabel) {
|
||||
return cached;
|
||||
}
|
||||
// Drop rows of contacts that left the list now and then.
|
||||
if (_rowCache.length > rowCount + 100) _rowCache.clear();
|
||||
return _rowCache[contact.publicKeyHex] = _ContactTileEntrance(
|
||||
index: index,
|
||||
contact: contact,
|
||||
pathHashByteWidth: pathHashByteWidth,
|
||||
lastSeenLabel: lastSeenLabel,
|
||||
unreadCount: unreadCount,
|
||||
isFavorite: contact.isFavorite,
|
||||
// The State's context: rows outlive the list's item context while the
|
||||
// list is swapped for an empty state.
|
||||
onTap: () => _openChat(this.context, contact),
|
||||
onLongPress: () => _showContactOptions(this.context, connector, contact),
|
||||
onManage: _manageAction(this.context, contact),
|
||||
);
|
||||
}
|
||||
|
||||
List<Contact> _filterAndSortContacts(
|
||||
List<Contact> contacts,
|
||||
MeshCoreConnector connector,
|
||||
@@ -1156,7 +1041,8 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
|
||||
DateTime _lastMessageTime(MeshCoreConnector connector, Contact contact) {
|
||||
final messages = connector.getMessages(contact);
|
||||
return messages.isEmpty ? DateTime(1970) : messages.last.timestamp;
|
||||
// Local arrival time: sender clocks can be far off.
|
||||
return messages.isEmpty ? DateTime(1970) : messages.last.receivedAt;
|
||||
}
|
||||
|
||||
List<Contact> _computeFilteredContacts(
|
||||
@@ -1202,26 +1088,38 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
switch (viewState.contactsSortOption) {
|
||||
case ContactSortOption.lastSeen:
|
||||
filtered.sort(
|
||||
(a, b) =>
|
||||
resolveContactLastSeen(b).compareTo(resolveContactLastSeen(a)),
|
||||
);
|
||||
break;
|
||||
case ContactSortOption.recentMessages:
|
||||
final lastMessageAt = {
|
||||
for (final c in filtered) c: _lastMessageTime(connector, c),
|
||||
};
|
||||
filtered.sort((a, b) => lastMessageAt[b]!.compareTo(lastMessageAt[a]!));
|
||||
break;
|
||||
case ContactSortOption.name:
|
||||
filtered.sort(
|
||||
(a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()),
|
||||
);
|
||||
break;
|
||||
final lastSeenAt =
|
||||
viewState.contactsSortOption == ContactSortOption.lastSeen
|
||||
? {
|
||||
for (final c in filtered)
|
||||
c: resolveContactLastSeen(
|
||||
c,
|
||||
addedAt: connector.contactAddedAt(c.publicKeyHex),
|
||||
),
|
||||
}
|
||||
: null;
|
||||
final lastMessageAt =
|
||||
viewState.contactsSortOption == ContactSortOption.recentMessages
|
||||
? {for (final c in filtered) c: _lastMessageTime(connector, c)}
|
||||
: null;
|
||||
int tieBreak(Contact a, Contact b) {
|
||||
switch (viewState.contactsSortOption) {
|
||||
case ContactSortOption.lastSeen:
|
||||
return lastSeenAt![b]!.compareTo(lastSeenAt[a]!);
|
||||
case ContactSortOption.recentMessages:
|
||||
final timeCompare = lastMessageAt![b]!.compareTo(lastMessageAt[a]!);
|
||||
if (timeCompare != 0) return timeCompare;
|
||||
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
|
||||
case ContactSortOption.name:
|
||||
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
filtered.sort(
|
||||
(a, b) =>
|
||||
compareContactQueryRank(a, b, viewState.contactsSearchText, tieBreak),
|
||||
);
|
||||
|
||||
return filtered;
|
||||
}
|
||||
|
||||
@@ -1396,182 +1294,44 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
return;
|
||||
}
|
||||
final isEditing = group != null;
|
||||
final nameController = TextEditingController(text: group?.name ?? '');
|
||||
final selectedKeys = <String>{...group?.memberKeys ?? []};
|
||||
String filterQuery = '';
|
||||
final sortedContacts = List<Contact>.from(contacts)
|
||||
..sort((a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()));
|
||||
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) => _DisposeControllerOnUnmount(
|
||||
controller: nameController,
|
||||
child: StatefulBuilder(
|
||||
builder: (builderContext, setDialogState) {
|
||||
final filteredContacts = filterQuery.isEmpty
|
||||
? sortedContacts
|
||||
: sortedContacts
|
||||
.where(
|
||||
(contact) => matchesContactQuery(contact, filterQuery),
|
||||
)
|
||||
.toList();
|
||||
return AlertDialog(
|
||||
title: Text(
|
||||
isEditing
|
||||
? context.l10n.contacts_editGroup
|
||||
: context.l10n.contacts_newGroup,
|
||||
),
|
||||
content: SizedBox(
|
||||
width: double.maxFinite,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.of(context).size.height * 0.8,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: nameController,
|
||||
decoration: InputDecoration(
|
||||
labelText: context.l10n.contacts_groupName,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
hintText: context.l10n.contacts_filterContacts,
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
border: const OutlineInputBorder(),
|
||||
isDense: true,
|
||||
),
|
||||
onChanged: (value) {
|
||||
setDialogState(() {
|
||||
filterQuery = value.toLowerCase();
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Expanded(
|
||||
child: filteredContacts.isEmpty
|
||||
? Center(
|
||||
child: Text(
|
||||
context.l10n.contacts_noContactsMatchFilter,
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
itemCount: filteredContacts.length,
|
||||
itemBuilder: (context, index) {
|
||||
final contact = filteredContacts[index];
|
||||
final isSelected = selectedKeys.contains(
|
||||
contact.publicKeyHex,
|
||||
);
|
||||
return CheckboxListTile(
|
||||
value: isSelected,
|
||||
title: Text(contact.name),
|
||||
subtitle: Text(
|
||||
contact.typeLabel(context.l10n),
|
||||
),
|
||||
onChanged: (value) {
|
||||
setDialogState(() {
|
||||
if (value == true) {
|
||||
selectedKeys.add(
|
||||
contact.publicKeyHex,
|
||||
);
|
||||
} else {
|
||||
selectedKeys.remove(
|
||||
contact.publicKeyHex,
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(context.l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
final name = nameController.text.trim();
|
||||
if (name.isEmpty) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_groupNameRequired),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (name.toLowerCase() ==
|
||||
contactsAllGroupsValue.toLowerCase()) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_groupNameReserved),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final exists = _groups.any((g) {
|
||||
if (isEditing && g.name == group.name) return false;
|
||||
return g.name.toLowerCase() == name.toLowerCase();
|
||||
});
|
||||
if (exists) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
context.l10n.contacts_groupAlreadyExists(name),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
final viewState = context.read<UiViewStateService>();
|
||||
if (isEditing) {
|
||||
final index = _groups.indexWhere(
|
||||
(g) => g.name == group.name,
|
||||
);
|
||||
if (index != -1) {
|
||||
final wasSelected =
|
||||
viewState.contactsSelectedGroupName == group.name;
|
||||
_groups[index] = ContactGroup(
|
||||
name: name,
|
||||
memberKeys: selectedKeys.toList(),
|
||||
);
|
||||
if (wasSelected) {
|
||||
viewState.setContactsSelectedGroupName(name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_groups.add(
|
||||
ContactGroup(
|
||||
name: name,
|
||||
memberKeys: selectedKeys.toList(),
|
||||
),
|
||||
);
|
||||
viewState.setContactsSelectedGroupName(name);
|
||||
}
|
||||
_ensureValidSelectedGroup();
|
||||
});
|
||||
await _saveGroups();
|
||||
if (dialogContext.mounted) {
|
||||
Navigator.pop(dialogContext);
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
isEditing
|
||||
? context.l10n.common_save
|
||||
: context.l10n.common_create,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
builder: (dialogContext) => ContactGroupEditorDialog(
|
||||
contacts: contacts,
|
||||
group: group,
|
||||
validateName: (name) {
|
||||
final l10n = dialogContext.l10n;
|
||||
if (name.isEmpty) return l10n.contacts_groupNameRequired;
|
||||
if (name.toLowerCase() == contactsAllGroupsValue.toLowerCase()) {
|
||||
return l10n.contacts_groupNameReserved;
|
||||
}
|
||||
final exists = _groups.any((g) {
|
||||
if (isEditing && g.name == group.name) return false;
|
||||
return g.name.toLowerCase() == name.toLowerCase();
|
||||
});
|
||||
return exists ? l10n.contacts_groupAlreadyExists(name) : null;
|
||||
},
|
||||
onSave: (updated) async {
|
||||
setState(() {
|
||||
final viewState = context.read<UiViewStateService>();
|
||||
if (isEditing) {
|
||||
final index = _groups.indexWhere((g) => g.name == group.name);
|
||||
if (index != -1) {
|
||||
final wasSelected =
|
||||
viewState.contactsSelectedGroupName == group.name;
|
||||
_groups[index] = updated;
|
||||
if (wasSelected) {
|
||||
viewState.setContactsSelectedGroupName(updated.name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_groups.add(updated);
|
||||
viewState.setContactsSelectedGroupName(updated.name);
|
||||
}
|
||||
_ensureValidSelectedGroup();
|
||||
});
|
||||
await _saveGroups();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1875,7 +1635,7 @@ void confirmRemoveContact(
|
||||
class _ContactTile extends StatelessWidget {
|
||||
final Contact contact;
|
||||
final int pathHashByteWidth;
|
||||
final DateTime lastSeen;
|
||||
final String lastSeenLabel;
|
||||
final int unreadCount;
|
||||
final bool isFavorite;
|
||||
final VoidCallback onTap;
|
||||
@@ -1885,7 +1645,7 @@ class _ContactTile extends StatelessWidget {
|
||||
const _ContactTile({
|
||||
required this.contact,
|
||||
required this.pathHashByteWidth,
|
||||
required this.lastSeen,
|
||||
required this.lastSeenLabel,
|
||||
required this.unreadCount,
|
||||
required this.isFavorite,
|
||||
required this.onTap,
|
||||
@@ -2022,7 +1782,7 @@ class _ContactTile extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
Text(
|
||||
formatContactLastSeen(context.l10n, lastSeen),
|
||||
lastSeenLabel,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: MeshTheme.mono(
|
||||
@@ -2094,40 +1854,12 @@ class _KeyPrefixBadge extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// Disposes [controller] when the dialog content unmounts, i.e. after the
|
||||
/// route's exit animation, so the TextField never sees a disposed controller.
|
||||
class _DisposeControllerOnUnmount extends StatefulWidget {
|
||||
final TextEditingController controller;
|
||||
final Widget child;
|
||||
|
||||
const _DisposeControllerOnUnmount({
|
||||
required this.controller,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
@override
|
||||
State<_DisposeControllerOnUnmount> createState() =>
|
||||
_DisposeControllerOnUnmountState();
|
||||
}
|
||||
|
||||
class _DisposeControllerOnUnmountState
|
||||
extends State<_DisposeControllerOnUnmount> {
|
||||
@override
|
||||
void dispose() {
|
||||
widget.controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => widget.child;
|
||||
}
|
||||
|
||||
// Wrap each contact tile with staggered entrance.
|
||||
class _ContactTileEntrance extends StatelessWidget {
|
||||
final int index;
|
||||
final Contact contact;
|
||||
final int pathHashByteWidth;
|
||||
final DateTime lastSeen;
|
||||
final String lastSeenLabel;
|
||||
final int unreadCount;
|
||||
final bool isFavorite;
|
||||
final VoidCallback onTap;
|
||||
@@ -2138,7 +1870,7 @@ class _ContactTileEntrance extends StatelessWidget {
|
||||
required this.index,
|
||||
required this.contact,
|
||||
required this.pathHashByteWidth,
|
||||
required this.lastSeen,
|
||||
required this.lastSeenLabel,
|
||||
required this.unreadCount,
|
||||
required this.isFavorite,
|
||||
required this.onTap,
|
||||
@@ -2153,7 +1885,7 @@ class _ContactTileEntrance extends StatelessWidget {
|
||||
child: _ContactTile(
|
||||
contact: contact,
|
||||
pathHashByteWidth: pathHashByteWidth,
|
||||
lastSeen: lastSeen,
|
||||
lastSeenLabel: lastSeenLabel,
|
||||
unreadCount: unreadCount,
|
||||
isFavorite: isFavorite,
|
||||
onTap: onTap,
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../helpers/link_handler.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../services/map_tile_cache_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
|
||||
/// Dedicated full-screen map centered on a tapped GPS coordinate.
|
||||
class CoordinateMapScreen extends StatefulWidget {
|
||||
final double latitude;
|
||||
final double longitude;
|
||||
final String? label;
|
||||
|
||||
const CoordinateMapScreen({
|
||||
super.key,
|
||||
required this.latitude,
|
||||
required this.longitude,
|
||||
this.label,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CoordinateMapScreen> createState() => _CoordinateMapScreenState();
|
||||
}
|
||||
|
||||
class _CoordinateMapScreenState extends State<CoordinateMapScreen> {
|
||||
static const double _initialZoom = 15.0;
|
||||
static const double _minZoom = 2.0;
|
||||
static const double _maxZoom = 18.0;
|
||||
|
||||
final MapController _mapController = MapController();
|
||||
|
||||
LatLng get _position => LatLng(widget.latitude, widget.longitude);
|
||||
|
||||
String get _coordinateText => widget.label?.trim().isNotEmpty == true
|
||||
? widget.label!.trim()
|
||||
: '${widget.latitude}, ${widget.longitude}';
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_mapController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _zoomBy(double delta) {
|
||||
final camera = _mapController.camera;
|
||||
final nextZoom = (camera.zoom + delta).clamp(_minZoom, _maxZoom).toDouble();
|
||||
_mapController.move(camera.center, nextZoom);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final mapTheme = MeshMapTheme.of(context);
|
||||
final tileCache = context.read<MapTileCacheService>();
|
||||
final isDesktop =
|
||||
defaultTargetPlatform == TargetPlatform.linux ||
|
||||
defaultTargetPlatform == TargetPlatform.windows ||
|
||||
defaultTargetPlatform == TargetPlatform.macOS;
|
||||
final labelSurface = scheme.surfaceContainerLow;
|
||||
final iconAccent = readableAccent(
|
||||
scheme.primary,
|
||||
labelSurface,
|
||||
minContrast: 3,
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
title: AdaptiveAppBarTitle(l10n.coordinateMap_title),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.copy),
|
||||
tooltip: l10n.coordinate_copyLocation,
|
||||
onPressed: () =>
|
||||
LinkHandler.copyCoordinateLocation(context, _coordinateText),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.open_in_new),
|
||||
tooltip: l10n.coordinate_openInMaps,
|
||||
onPressed: () => LinkHandler.openCoordinateInExternalMaps(
|
||||
context,
|
||||
widget.latitude,
|
||||
widget.longitude,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
FlutterMap(
|
||||
mapController: _mapController,
|
||||
options: MapOptions(
|
||||
initialCenter: _position,
|
||||
initialZoom: _initialZoom,
|
||||
minZoom: _minZoom,
|
||||
maxZoom: _maxZoom,
|
||||
interactionOptions: InteractionOptions(
|
||||
flags: ~InteractiveFlag.rotate,
|
||||
scrollWheelVelocity: isDesktop ? 0.012 : 0.005,
|
||||
cursorKeyboardRotationOptions:
|
||||
CursorKeyboardRotationOptions.disabled(),
|
||||
keyboardOptions: isDesktop
|
||||
? const KeyboardOptions(
|
||||
enableArrowKeysPanning: true,
|
||||
enableWASDPanning: true,
|
||||
enableRFZooming: true,
|
||||
)
|
||||
: const KeyboardOptions.disabled(),
|
||||
),
|
||||
),
|
||||
children: [
|
||||
tileCache.buildTileLayer(context),
|
||||
MarkerLayer(
|
||||
markers: [
|
||||
Marker(
|
||||
point: _position,
|
||||
width: 48,
|
||||
height: 48,
|
||||
child: IgnorePointer(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: mapTheme.followsTheme
|
||||
? mapTheme.accent
|
||||
: MapPalette.batteryLow,
|
||||
border: Border.all(
|
||||
color: MapPalette.markerOutline,
|
||||
width: 3,
|
||||
),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: MapPalette.markerShadow,
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.location_on,
|
||||
color: MapPalette.markerOutline,
|
||||
size: 26,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
top: 12,
|
||||
right: 12,
|
||||
child: Column(
|
||||
children: [
|
||||
_CoordinateMapControlButton(
|
||||
icon: Icons.add,
|
||||
tooltip: l10n.map_zoomIn,
|
||||
onPressed: () => _zoomBy(1),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_CoordinateMapControlButton(
|
||||
icon: Icons.remove,
|
||||
tooltip: l10n.map_zoomOut,
|
||||
onPressed: () => _zoomBy(-1),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_CoordinateMapControlButton(
|
||||
icon: Icons.my_location,
|
||||
tooltip: l10n.map_centerMap,
|
||||
onPressed: () => _mapController.move(_position, _initialZoom),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: 16,
|
||||
right: 16,
|
||||
bottom: 16,
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: Material(
|
||||
color: labelSurface,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
side: BorderSide(color: scheme.outlineVariant),
|
||||
),
|
||||
elevation: 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
vertical: 10,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.location_on_outlined,
|
||||
color: iconAccent,
|
||||
size: 22,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_coordinateText,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CoordinateMapControlButton extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String tooltip;
|
||||
final VoidCallback onPressed;
|
||||
|
||||
const _CoordinateMapControlButton({
|
||||
required this.icon,
|
||||
required this.tooltip,
|
||||
required this.onPressed,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Material(
|
||||
color: scheme.surfaceContainerLow,
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
side: BorderSide(color: scheme.outlineVariant),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: IconButton(
|
||||
icon: Icon(icon),
|
||||
tooltip: tooltip,
|
||||
onPressed: onPressed,
|
||||
iconSize: 22,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -662,17 +662,32 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
return _matchesTypeFilter(contact);
|
||||
}).toList();
|
||||
|
||||
switch (sortOption) {
|
||||
case ContactSortOption.lastSeen:
|
||||
filtered.sort((a, b) => b.lastSeen.compareTo(a.lastSeen));
|
||||
break;
|
||||
case ContactSortOption.name:
|
||||
filtered.sort(
|
||||
(a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
int tieBreak(Contact a, Contact b) {
|
||||
switch (sortOption) {
|
||||
case ContactSortOption.lastSeen:
|
||||
return b.lastSeen.compareTo(a.lastSeen);
|
||||
case ContactSortOption.name:
|
||||
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
|
||||
default:
|
||||
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
if (searchQuery.trim().isEmpty) {
|
||||
switch (sortOption) {
|
||||
case ContactSortOption.lastSeen:
|
||||
filtered.sort((a, b) => b.lastSeen.compareTo(a.lastSeen));
|
||||
case ContactSortOption.name:
|
||||
filtered.sort(
|
||||
(a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()),
|
||||
);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
filtered.sort(
|
||||
(a, b) => compareContactQueryRank(a, b, searchQuery, tieBreak),
|
||||
);
|
||||
}
|
||||
|
||||
return filtered;
|
||||
|
||||
@@ -12,6 +12,7 @@ import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/chat_send_pipeline.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/settings_reveal.dart';
|
||||
|
||||
/// Recent filtered channel messages across all channels, newest first.
|
||||
///
|
||||
@@ -286,7 +287,8 @@ class _FilteredMessageCard extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
AnimatedSize(
|
||||
duration: const Duration(milliseconds: 150),
|
||||
duration: RevealOnEnable.duration,
|
||||
curve: RevealOnEnable.curve,
|
||||
alignment: AlignmentDirectional.topStart,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(end: 8),
|
||||
|
||||
+51
-48
@@ -52,7 +52,6 @@ import '../helpers/guessed_location_estimator.dart';
|
||||
import '../helpers/marker_message.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
import 'settings_screen.dart';
|
||||
import 'line_of_sight_map_screen.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
|
||||
@@ -813,14 +812,18 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
actions: [
|
||||
PopupMenuButton(
|
||||
itemBuilder: (context) => [
|
||||
tooltip: context.l10n.contacts_moreOptions,
|
||||
// onTap handlers run after the menu route pops, so they must
|
||||
// capture the screen's context — not the itemBuilder's menu
|
||||
// context, which is deactivated by then.
|
||||
itemBuilder: (menuContext) => [
|
||||
if (!_isBuildingPathTrace &&
|
||||
connector.selfLatitude != null &&
|
||||
connector.selfLongitude != null)
|
||||
PopupMenuItem(
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.radar,
|
||||
label: context.l10n.contacts_pathTrace,
|
||||
label: menuContext.l10n.contacts_pathTrace,
|
||||
),
|
||||
onTap: () => _openPathTrace(
|
||||
connector,
|
||||
@@ -835,7 +838,7 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.radar,
|
||||
label: context.l10n.manualTrace_menuItem,
|
||||
label: menuContext.l10n.manualTrace_menuItem,
|
||||
),
|
||||
onTap: () => ManualPathTraceScreen.open(context),
|
||||
),
|
||||
@@ -843,7 +846,7 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
PopupMenuItem(
|
||||
child: MeshMenuItemRow(
|
||||
leading: const LosIcon(size: 20),
|
||||
label: context.l10n.map_lineOfSight,
|
||||
label: menuContext.l10n.map_lineOfSight,
|
||||
),
|
||||
onTap: () {
|
||||
final candidates = <LineOfSightEndpoint>[];
|
||||
@@ -874,7 +877,7 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => LineOfSightMapScreen(
|
||||
builder: (_) => LineOfSightMapScreen(
|
||||
title: context.l10n.map_losScreenTitle,
|
||||
candidates: candidates,
|
||||
),
|
||||
@@ -882,21 +885,10 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
);
|
||||
},
|
||||
),
|
||||
connectionMenuItem(this.context, context),
|
||||
PopupMenuItem(
|
||||
child: MeshMenuItemRow(
|
||||
leading: const ThemedIcon(
|
||||
ThemeIconSlot.settings,
|
||||
size: 20,
|
||||
),
|
||||
label: context.l10n.settings_title,
|
||||
),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const SettingsScreen(),
|
||||
),
|
||||
),
|
||||
...mainOverflowTrailingItems(
|
||||
context,
|
||||
menuContext,
|
||||
hasPrecedingItems: !_isBuildingPathTrace,
|
||||
),
|
||||
],
|
||||
icon: const Icon(Icons.more_vert),
|
||||
@@ -1211,6 +1203,9 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
showOtherNodes: settings.mapShowOtherNodes,
|
||||
isBuildingPathTrace: _isBuildingPathTrace,
|
||||
clusterNodes: settings.mapClusterNodes,
|
||||
// Node labels bake in the overlay colors, so a light/dark or theme
|
||||
// switch must rebuild them.
|
||||
colorScheme: Theme.of(context).colorScheme,
|
||||
);
|
||||
if (key != _nodeMarkersCacheKey) {
|
||||
_nodeMarkersCacheKey = key;
|
||||
@@ -2305,13 +2300,14 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
) {
|
||||
final query = _searchQuery.trim().toLowerCase();
|
||||
final matches =
|
||||
allContacts.where((c) => matchesContactQuery(c, query)).toList()
|
||||
..sort((a, b) {
|
||||
allContacts.where((c) => matchesContactQuery(c, query)).toList()..sort(
|
||||
(a, b) => compareContactQueryRank(a, b, query, (a, b) {
|
||||
if (a.hasLocation != b.hasLocation) {
|
||||
return a.hasLocation ? -1 : 1;
|
||||
}
|
||||
return b.lastHeard.compareTo(a.lastHeard);
|
||||
});
|
||||
}),
|
||||
);
|
||||
final results = matches.take(8).toList();
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(top: 6),
|
||||
@@ -3477,6 +3473,15 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
contact.type != advTypeRoom,
|
||||
)
|
||||
.toList();
|
||||
final people = allContacts
|
||||
.where(
|
||||
(contact) =>
|
||||
query.isEmpty || matchesContactQuery(contact, query),
|
||||
)
|
||||
.toList();
|
||||
if (query.isNotEmpty) {
|
||||
people.sort((a, b) => compareContactQueryRank(a, b, query));
|
||||
}
|
||||
return SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
@@ -3512,29 +3517,23 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
},
|
||||
),
|
||||
),
|
||||
...allContacts
|
||||
.where(
|
||||
(contact) =>
|
||||
query.isEmpty ||
|
||||
matchesContactQuery(contact, query),
|
||||
)
|
||||
.map((contact) {
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.person),
|
||||
title: Text(contact.name),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
if (!_markerFits(
|
||||
context,
|
||||
markerText,
|
||||
maxContactMessageBytes(),
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
liveConnector.sendMessage(contact, markerText);
|
||||
},
|
||||
);
|
||||
}),
|
||||
...people.map((contact) {
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.person),
|
||||
title: Text(contact.name),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
if (!_markerFits(
|
||||
context,
|
||||
markerText,
|
||||
maxContactMessageBytes(),
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
liveConnector.sendMessage(contact, markerText);
|
||||
},
|
||||
);
|
||||
}),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),
|
||||
child: Text(
|
||||
@@ -4398,6 +4397,7 @@ class _NodeMarkersCacheKey {
|
||||
final bool showOtherNodes;
|
||||
final bool isBuildingPathTrace;
|
||||
final bool clusterNodes;
|
||||
final ColorScheme colorScheme;
|
||||
|
||||
const _NodeMarkersCacheKey({
|
||||
required this.contactsSignature,
|
||||
@@ -4418,6 +4418,7 @@ class _NodeMarkersCacheKey {
|
||||
required this.showOtherNodes,
|
||||
required this.isBuildingPathTrace,
|
||||
required this.clusterNodes,
|
||||
required this.colorScheme,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -4440,7 +4441,8 @@ class _NodeMarkersCacheKey {
|
||||
showChatNodes == other.showChatNodes &&
|
||||
showOtherNodes == other.showOtherNodes &&
|
||||
isBuildingPathTrace == other.isBuildingPathTrace &&
|
||||
clusterNodes == other.clusterNodes;
|
||||
clusterNodes == other.clusterNodes &&
|
||||
colorScheme == other.colorScheme;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -4463,6 +4465,7 @@ class _NodeMarkersCacheKey {
|
||||
showOtherNodes,
|
||||
isBuildingPathTrace,
|
||||
clusterNodes,
|
||||
colorScheme,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+452
-285
@@ -8,6 +8,7 @@ import 'package:latlong2/latlong.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/helpers/path_helper.dart';
|
||||
import 'package:meshcore_open/helpers/path_hop_resolver.dart';
|
||||
import 'package:meshcore_open/l10n/l10n.dart';
|
||||
import 'package:meshcore_open/models/app_settings.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
@@ -24,6 +25,7 @@ import 'package:meshcore_open/widgets/path_map_ui.dart';
|
||||
import 'package:meshcore_open/widgets/snr_indicator.dart';
|
||||
import 'package:meshcore_open/widgets/set_my_location_dialog.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../theme/mesh_theme.dart';
|
||||
|
||||
export 'package:meshcore_open/widgets/path_map_ui.dart'
|
||||
@@ -95,8 +97,6 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
static const double _labelZoomThreshold = kPathMapLabelZoomThreshold;
|
||||
// Used when the radio never acknowledges the trace request.
|
||||
static const Duration _sendAckTimeout = Duration(seconds: 15);
|
||||
//miles to meters conversion for filtering out repeaters that are too far from the last known GPS hop to be a likely match, to avoid false matches that throw off the inferred positions of other hops in the path
|
||||
static const double _maxRepeaterMatchDistanceMeters = 40 * 1609.344;
|
||||
|
||||
final MapController _mapController = MapController();
|
||||
StreamSubscription<Uint8List>? _frameSubscription;
|
||||
@@ -143,9 +143,10 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
bool _animationEnabled = true;
|
||||
bool _followPacket = false;
|
||||
|
||||
// Hop-prefix -> contact lookups, invalidated when the contact list changes.
|
||||
final Map<String, Contact?> _hopContactCache = {};
|
||||
int? _hopContactCacheSignature;
|
||||
// Resolved hop contacts and inferred positions per display path id, used by
|
||||
// combined markers and the generic hop list.
|
||||
final Map<String, ({List<Contact?> contacts, List<LatLng?> inferred})>
|
||||
_resolvedDisplayPaths = {};
|
||||
|
||||
String _formatPathPrefixes(Uint8List pathBytes, [int? hashByteWidth]) {
|
||||
return PathHelper.splitPathBytes(
|
||||
@@ -584,213 +585,19 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
.map((snr) => snr.toSigned(8).toDouble() / 4)
|
||||
.toList();
|
||||
|
||||
Map<String, Contact> pathContacts = {};
|
||||
Contact lastContact = Contact(
|
||||
path: Uint8List(0),
|
||||
pathLength: 0,
|
||||
publicKey: connector.selfPublicKey ?? Uint8List(0),
|
||||
name: context.l10n.pathTrace_you,
|
||||
type: advTypeChat,
|
||||
latitude: connector.selfLatitude,
|
||||
longitude: connector.selfLongitude,
|
||||
lastSeen: DateTime.now(),
|
||||
);
|
||||
if (widget.pathContacts != null) {
|
||||
final hopWidth = width.clamp(1, pubKeySize).toInt();
|
||||
pathContacts = {
|
||||
for (var c in widget.pathContacts!)
|
||||
if (c.publicKey.length >= hopWidth)
|
||||
_hopKey(Uint8List.fromList(c.publicKey.sublist(0, hopWidth))): c,
|
||||
};
|
||||
} else {
|
||||
final contacts = connector.allContactsUnfiltered;
|
||||
contacts.where((c) => c.type != advTypeChat).forEach((repeater) {
|
||||
if (lastContact.latitude != null &&
|
||||
lastContact.longitude != null &&
|
||||
repeater.hasLocation &&
|
||||
lastContact.hasLocation &&
|
||||
Distance().distance(
|
||||
LatLng(lastContact.latitude!, lastContact.longitude!),
|
||||
LatLng(repeater.latitude!, repeater.longitude!),
|
||||
) >
|
||||
_maxRepeaterMatchDistanceMeters) {
|
||||
return; //skip reapeaters that are far away from the last one with known GPS, to avoid false matches
|
||||
}
|
||||
for (final repeaterData in pathData) {
|
||||
final hopWidth = repeaterData.length;
|
||||
if (repeater.publicKey.length < hopWidth) continue;
|
||||
if (listEquals(
|
||||
repeater.publicKey.sublist(0, hopWidth),
|
||||
repeaterData,
|
||||
)) {
|
||||
pathContacts[_hopKey(repeaterData)] = repeater;
|
||||
lastContact = repeater;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// For hops with no GPS contact, infer position from other contacts
|
||||
// with known GPS that share the same last-hop byte.
|
||||
final Map<String, LatLng> inferredPositions = {};
|
||||
for (final hop in pathData) {
|
||||
final hopKey = _hopKey(hop);
|
||||
final contact = pathContacts[hopKey];
|
||||
if (contact != null && contact.hasLocation) continue;
|
||||
final peers = connector.contacts
|
||||
.where(
|
||||
(c) =>
|
||||
c.hasLocation &&
|
||||
c.path.isNotEmpty &&
|
||||
_matchesHopPrefix(
|
||||
_lastHopChunk(c.path, c.pathHashWidth),
|
||||
hop,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
if (peers.isNotEmpty) {
|
||||
final lat =
|
||||
peers.map((c) => c.latitude!).reduce((a, b) => a + b) /
|
||||
peers.length;
|
||||
final lon =
|
||||
peers.map((c) => c.longitude!).reduce((a, b) => a + b) /
|
||||
peers.length;
|
||||
inferredPositions[hopKey] = LatLng(lat, lon);
|
||||
}
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_hasData = true;
|
||||
_inferredHopPositions = inferredPositions;
|
||||
_targetContact = widget.targetContact;
|
||||
_primaryOutboundHops = _outboundHops(pathData);
|
||||
_traceData = PathTraceData(
|
||||
pathData: pathData,
|
||||
snrData: snrData,
|
||||
pathContacts: pathContacts,
|
||||
pathContacts: const {},
|
||||
);
|
||||
// Compute endpoint position for the target contact.
|
||||
LatLng? targetPos;
|
||||
bool targetGuessed = false;
|
||||
_targetContact = widget.targetContact;
|
||||
|
||||
if (_targetContact != null) {
|
||||
final tc = _targetContact!;
|
||||
if (tc.hasLocation) {
|
||||
targetPos = LatLng(tc.latitude!, tc.longitude!);
|
||||
} else if (pathData.length > 1 || _tracedPath.isNotEmpty) {
|
||||
// Infer from the last hop: average GPS contacts sharing that hop.
|
||||
// For a round-trip path (flipPathAround/reversePathAround), the target-side hop
|
||||
// sits in the middle of the symmetric sequence; .last is the local side.
|
||||
final tracedHops = PathHelper.splitPathBytes(
|
||||
_tracedPath,
|
||||
_tracedPathHashWidth,
|
||||
);
|
||||
final hopsForEndpoint = tracedHops.isNotEmpty
|
||||
? tracedHops
|
||||
: pathData;
|
||||
final lastHop = widget.reversePathAround
|
||||
? hopsForEndpoint.first
|
||||
: hopsForEndpoint.last;
|
||||
final lastHopKey = _hopKey(lastHop);
|
||||
|
||||
final peers = connector.allContacts
|
||||
.where(
|
||||
(c) =>
|
||||
c.hasLocation &&
|
||||
c.path.isNotEmpty &&
|
||||
_matchesHopPrefix(
|
||||
_lastHopChunk(c.path, c.pathHashWidth),
|
||||
lastHop,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
if (peers.isNotEmpty) {
|
||||
final lat =
|
||||
peers.map((c) => c.latitude!).reduce((a, b) => a + b) /
|
||||
peers.length;
|
||||
final lon =
|
||||
peers.map((c) => c.longitude!).reduce((a, b) => a + b) /
|
||||
peers.length;
|
||||
const offsetDeg = 0.003;
|
||||
final angle = (tc.publicKey[1] / 255.0) * 2 * pi;
|
||||
targetPos = LatLng(
|
||||
lat + offsetDeg * cos(angle),
|
||||
lon + offsetDeg * sin(angle),
|
||||
);
|
||||
targetGuessed = true;
|
||||
} else if (inferredPositions.containsKey(lastHopKey)) {
|
||||
final lat = inferredPositions[lastHopKey]!.latitude;
|
||||
final lon = inferredPositions[lastHopKey]!.longitude;
|
||||
const offsetDeg = 0.003;
|
||||
final angle = (tc.publicKey[1] / 255.0) * 2 * pi;
|
||||
targetPos = LatLng(
|
||||
lat + offsetDeg * cos(angle),
|
||||
lon + offsetDeg * sin(angle),
|
||||
);
|
||||
targetGuessed = true;
|
||||
} else {
|
||||
// As a last resort, just place it at the same position as the last hop.
|
||||
final contact = pathContacts[lastHopKey];
|
||||
if (contact != null && contact.hasLocation) {
|
||||
const offsetDeg = 0.003;
|
||||
final angle = (tc.publicKey[1] / 255.0) * 2 * pi;
|
||||
targetPos = LatLng(
|
||||
contact.latitude! + offsetDeg * cos(angle),
|
||||
contact.longitude! + offsetDeg * sin(angle),
|
||||
);
|
||||
targetGuessed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_targetContactPosition = targetPos;
|
||||
_targetContactIsGuessed = targetGuessed;
|
||||
|
||||
_points = <LatLng>[];
|
||||
final selfPoint = plausibleSelfPoint(connector);
|
||||
if (selfPoint != null) _points.add(selfPoint);
|
||||
String hopLast = '';
|
||||
String hopLastLast = '';
|
||||
for (final hop in _traceData!.pathData) {
|
||||
final hopKey = _hopKey(hop);
|
||||
if (hopKey == hopLastLast && widget.flipPathAround) {
|
||||
break; //skip duplicate hops in round-trip paths
|
||||
}
|
||||
final contact = _traceData!.pathContacts[hopKey];
|
||||
if (contact != null && contact.hasLocation) {
|
||||
_points.add(LatLng(contact.latitude!, contact.longitude!));
|
||||
} else {
|
||||
final inferred = inferredPositions[hopKey];
|
||||
if (inferred != null) _points.add(inferred);
|
||||
}
|
||||
hopLastLast = hopLast;
|
||||
hopLast = hopKey;
|
||||
}
|
||||
if (targetPos != null) {
|
||||
if (_targetContact != null && _targetContact!.type == advTypeChat) {
|
||||
_points.add(targetPos);
|
||||
}
|
||||
}
|
||||
_polylines = _points.length > 1
|
||||
? [
|
||||
Polyline(
|
||||
points: _points,
|
||||
strokeWidth: 4,
|
||||
color: kPrimaryPathColor,
|
||||
),
|
||||
]
|
||||
: <Polyline>[];
|
||||
|
||||
_initialCenter = _points.isNotEmpty
|
||||
? _points.first
|
||||
: const LatLng(0, 0);
|
||||
_initialZoom = _points.isNotEmpty ? 13.0 : 2.0;
|
||||
_bounds = _points.length > 1 ? LatLngBounds.fromPoints(_points) : null;
|
||||
_mapKey = ValueKey(
|
||||
'${context.l10n.pathTrace_you},${_traceData!.pathData.map(PathHelper.formatHopHex).join(',')}',
|
||||
'${context.l10n.pathTrace_you},${pathData.map(PathHelper.formatHopHex).join(',')}',
|
||||
);
|
||||
_pathDistanceMeters = getPathDistanceMeters(_points);
|
||||
_primaryOutboundHops = _outboundHops(pathData);
|
||||
_rebuildDisplayPaths(connector);
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -823,54 +630,323 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
return hops;
|
||||
}
|
||||
|
||||
Contact? _contactForHop(Uint8List hop, MeshCoreConnector connector) {
|
||||
final hopKey = _hopKey(hop);
|
||||
final traced = _traceData?.pathContacts[hopKey];
|
||||
if (traced != null) return traced;
|
||||
_hopContactCacheSignature ??= _refreshHopContactCache(connector);
|
||||
return _hopContactCache.putIfAbsent(hopKey, () {
|
||||
for (final c in connector.allContactsUnfiltered) {
|
||||
if (c.type != advTypeChat &&
|
||||
c.publicKey.length >= hop.length &&
|
||||
listEquals(c.publicKey.sublist(0, hop.length), hop)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/// Drops cached hop -> contact lookups when the contact list changed;
|
||||
/// called once per build so per-hop lookups stay cheap.
|
||||
int _refreshHopContactCache(MeshCoreConnector connector) {
|
||||
final signature = contactListSignature(connector.allContactsUnfiltered);
|
||||
if (signature != _hopContactCacheSignature) {
|
||||
_hopContactCache.clear();
|
||||
_hopContactCacheSignature = signature;
|
||||
(LatLng?, bool) _resolveTargetContactPosition({
|
||||
required MeshCoreConnector connector,
|
||||
required List<Uint8List> pathData,
|
||||
required List<Uint8List> outboundHops,
|
||||
required List<Contact?> resolvedOutbound,
|
||||
required List<LatLng?> inferredOutbound,
|
||||
required Map<String, Contact> pathContacts,
|
||||
required Map<String, LatLng> inferredPositions,
|
||||
required LatLng? selfPoint,
|
||||
}) {
|
||||
final tc = _targetContact;
|
||||
if (tc == null) return (null, false);
|
||||
if (tc.hasLocation) {
|
||||
return (LatLng(tc.latitude!, tc.longitude!), false);
|
||||
}
|
||||
if (pathData.length <= 1 && _tracedPath.isEmpty) {
|
||||
return (null, false);
|
||||
}
|
||||
return signature;
|
||||
}
|
||||
|
||||
LatLng? _inferredPositionForHop(Uint8List hop, MeshCoreConnector connector) {
|
||||
final hopKey = _hopKey(hop);
|
||||
final cached = _inferredHopPositions[hopKey];
|
||||
if (cached != null) return cached;
|
||||
final peers = connector.contacts
|
||||
// Infer from the last hop: average GPS contacts sharing that hop.
|
||||
// For a round-trip path (flipPathAround/reversePathAround), the target-side hop
|
||||
// sits in the middle of the symmetric sequence; .last is the local side.
|
||||
final tracedHops = PathHelper.splitPathBytes(
|
||||
_tracedPath,
|
||||
_tracedPathHashWidth,
|
||||
);
|
||||
final hopsForEndpoint = tracedHops.isNotEmpty ? tracedHops : pathData;
|
||||
final lastHop = widget.reversePathAround
|
||||
? hopsForEndpoint.first
|
||||
: hopsForEndpoint.last;
|
||||
final lastHopKey = _hopKey(lastHop);
|
||||
|
||||
final rawPeers = connector.allContacts
|
||||
.where(
|
||||
(c) =>
|
||||
c.hasLocation &&
|
||||
c.path.isNotEmpty &&
|
||||
_matchesHopPrefix(_lastHopChunk(c.path, c.pathHashWidth), hop),
|
||||
_matchesHopPrefix(
|
||||
_lastHopChunk(c.path, c.pathHashWidth),
|
||||
lastHop,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
if (peers.isEmpty) return null;
|
||||
final lat =
|
||||
peers.map((c) => c.latitude!).reduce((a, b) => a + b) / peers.length;
|
||||
final lon =
|
||||
peers.map((c) => c.longitude!).reduce((a, b) => a + b) / peers.length;
|
||||
final pos = LatLng(lat, lon);
|
||||
_inferredHopPositions[hopKey] = pos;
|
||||
return pos;
|
||||
final (anchorPos, anchorGap) = _lastPlausibleAnchor(
|
||||
outboundHops: outboundHops,
|
||||
resolvedOutbound: resolvedOutbound,
|
||||
inferredOutbound: inferredOutbound,
|
||||
selfPoint: selfPoint,
|
||||
);
|
||||
final peers = _filterPlausiblePeers(
|
||||
rawPeers,
|
||||
prevPos: anchorPos,
|
||||
prevMaxMeters: anchorPos != null
|
||||
? anchorGap * PathHopResolver.maxSingleHopDistanceMeters
|
||||
: null,
|
||||
);
|
||||
const offsetDeg = 0.003;
|
||||
final angle = (tc.publicKey[1] / 255.0) * 2 * pi;
|
||||
if (peers.isNotEmpty) {
|
||||
final lat =
|
||||
peers.map((c) => c.latitude!).reduce((a, b) => a + b) / peers.length;
|
||||
final lon =
|
||||
peers.map((c) => c.longitude!).reduce((a, b) => a + b) / peers.length;
|
||||
return (
|
||||
LatLng(lat + offsetDeg * cos(angle), lon + offsetDeg * sin(angle)),
|
||||
true,
|
||||
);
|
||||
}
|
||||
if (inferredPositions.containsKey(lastHopKey)) {
|
||||
final inferred = inferredPositions[lastHopKey]!;
|
||||
return (
|
||||
LatLng(
|
||||
inferred.latitude + offsetDeg * cos(angle),
|
||||
inferred.longitude + offsetDeg * sin(angle),
|
||||
),
|
||||
true,
|
||||
);
|
||||
}
|
||||
// As a last resort, just place it at the same position as the last hop.
|
||||
final contact = pathContacts[lastHopKey];
|
||||
if (contact != null && contact.hasLocation) {
|
||||
return (
|
||||
LatLng(
|
||||
contact.latitude! + offsetDeg * cos(angle),
|
||||
contact.longitude! + offsetDeg * sin(angle),
|
||||
),
|
||||
true,
|
||||
);
|
||||
}
|
||||
return (null, false);
|
||||
}
|
||||
|
||||
void _syncPrimaryTraceState({
|
||||
required MeshCoreConnector connector,
|
||||
required PathTraceData traceData,
|
||||
required List<Contact?> resolvedOutbound,
|
||||
required List<LatLng?> inferredOutbound,
|
||||
required LatLng? selfPoint,
|
||||
}) {
|
||||
final pathContacts = <String, Contact>{};
|
||||
for (var i = 0; i < _primaryOutboundHops.length; i++) {
|
||||
final contact = resolvedOutbound[i];
|
||||
if (contact != null) {
|
||||
pathContacts[_hopKey(_primaryOutboundHops[i])] = contact;
|
||||
}
|
||||
}
|
||||
|
||||
final inferredPositions = <String, LatLng>{};
|
||||
for (var i = 0; i < _primaryOutboundHops.length; i++) {
|
||||
final inferred = inferredOutbound[i];
|
||||
if (inferred != null) {
|
||||
inferredPositions[_hopKey(_primaryOutboundHops[i])] = inferred;
|
||||
}
|
||||
}
|
||||
|
||||
_inferredHopPositions = inferredPositions;
|
||||
_traceData = PathTraceData(
|
||||
pathData: traceData.pathData,
|
||||
snrData: traceData.snrData,
|
||||
pathContacts: pathContacts,
|
||||
);
|
||||
|
||||
final (targetPos, targetGuessed) = _resolveTargetContactPosition(
|
||||
connector: connector,
|
||||
pathData: traceData.pathData,
|
||||
outboundHops: _primaryOutboundHops,
|
||||
resolvedOutbound: resolvedOutbound,
|
||||
inferredOutbound: inferredOutbound,
|
||||
pathContacts: pathContacts,
|
||||
inferredPositions: inferredPositions,
|
||||
selfPoint: selfPoint,
|
||||
);
|
||||
_targetContactPosition = targetPos;
|
||||
_targetContactIsGuessed = targetGuessed;
|
||||
|
||||
final points = <LatLng>[?selfPoint];
|
||||
String hopLast = '';
|
||||
String hopLastLast = '';
|
||||
for (final hop in traceData.pathData) {
|
||||
final hopKey = _hopKey(hop);
|
||||
if (hopKey == hopLastLast && widget.flipPathAround) {
|
||||
break; //skip duplicate hops in round-trip paths
|
||||
}
|
||||
final contact = pathContacts[hopKey];
|
||||
if (contact != null && contact.hasLocation) {
|
||||
points.add(LatLng(contact.latitude!, contact.longitude!));
|
||||
} else {
|
||||
final inferred = inferredPositions[hopKey];
|
||||
if (inferred != null) points.add(inferred);
|
||||
}
|
||||
hopLastLast = hopLast;
|
||||
hopLast = hopKey;
|
||||
}
|
||||
if (targetPos != null &&
|
||||
_targetContact != null &&
|
||||
_targetContact!.type == advTypeChat) {
|
||||
points.add(targetPos);
|
||||
}
|
||||
|
||||
_points = points;
|
||||
_polylines = points.length > 1
|
||||
? [Polyline(points: points, strokeWidth: 4, color: kPrimaryPathColor)]
|
||||
: <Polyline>[];
|
||||
_initialCenter = points.isNotEmpty ? points.first : const LatLng(0, 0);
|
||||
_initialZoom = points.isNotEmpty ? 13.0 : 2.0;
|
||||
_bounds = points.length > 1 ? LatLngBounds.fromPoints(points) : null;
|
||||
_pathDistanceMeters = getPathDistanceMeters(points);
|
||||
}
|
||||
|
||||
LatLng? _contactLatLng(Contact? contact) {
|
||||
if (contact == null ||
|
||||
!contact.hasLocation ||
|
||||
contact.latitude == null ||
|
||||
contact.longitude == null) {
|
||||
return null;
|
||||
}
|
||||
return LatLng(contact.latitude!, contact.longitude!);
|
||||
}
|
||||
|
||||
List<Contact> _filterPlausiblePeers(
|
||||
List<Contact> peers, {
|
||||
LatLng? prevPos,
|
||||
double? prevMaxMeters,
|
||||
LatLng? nextPos,
|
||||
double? nextMaxMeters,
|
||||
}) {
|
||||
if (peers.isEmpty) return const [];
|
||||
const distance = Distance();
|
||||
var filtered = peers;
|
||||
if (prevPos != null && prevMaxMeters != null) {
|
||||
filtered = filtered
|
||||
.where(
|
||||
(c) =>
|
||||
distance(prevPos, LatLng(c.latitude!, c.longitude!)) <=
|
||||
prevMaxMeters,
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
if (nextPos != null && nextMaxMeters != null) {
|
||||
filtered = filtered
|
||||
.where(
|
||||
(c) =>
|
||||
distance(nextPos, LatLng(c.latitude!, c.longitude!)) <=
|
||||
nextMaxMeters,
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
if (prevPos == null && nextPos == null && filtered.length > 1) {
|
||||
// Without a neighboring anchor, keep only the largest consistent peer
|
||||
// cluster so a single distant prefix match does not skew the average.
|
||||
const maxPeerSpreadMeters =
|
||||
2 * PathHopResolver.maxSingleHopDistanceMeters;
|
||||
var bestCluster = <Contact>[filtered.first];
|
||||
for (final seed in filtered) {
|
||||
final seedPos = LatLng(seed.latitude!, seed.longitude!);
|
||||
final cluster = filtered.where((other) {
|
||||
final otherPos = LatLng(other.latitude!, other.longitude!);
|
||||
return distance(seedPos, otherPos) <= maxPeerSpreadMeters;
|
||||
}).toList();
|
||||
if (cluster.length > bestCluster.length ||
|
||||
(cluster.length == bestCluster.length &&
|
||||
seed.lastSeen.isAfter(bestCluster.first.lastSeen))) {
|
||||
bestCluster = cluster;
|
||||
}
|
||||
}
|
||||
return bestCluster;
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
List<LatLng?> _inferHopPositions({
|
||||
required List<Uint8List> hops,
|
||||
required List<Contact?> resolvedContacts,
|
||||
required LatLng? selfPoint,
|
||||
required List<Contact> peerContacts,
|
||||
}) {
|
||||
final inferred = List<LatLng?>.filled(hops.length, null);
|
||||
if (hops.isEmpty) return inferred;
|
||||
|
||||
final anchorPositions = <LatLng?>[
|
||||
for (var i = 0; i < hops.length; i++)
|
||||
i < resolvedContacts.length
|
||||
? _contactLatLng(resolvedContacts[i])
|
||||
: null,
|
||||
];
|
||||
|
||||
LatLng? prevPos = selfPoint;
|
||||
int prevStep = -1;
|
||||
|
||||
for (var i = 0; i < hops.length; i++) {
|
||||
final knownPos = anchorPositions[i];
|
||||
if (knownPos != null) {
|
||||
prevPos = knownPos;
|
||||
prevStep = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
LatLng? nextPos;
|
||||
int? nextStep;
|
||||
for (var j = i + 1; j < hops.length; j++) {
|
||||
if (anchorPositions[j] != null) {
|
||||
nextPos = anchorPositions[j];
|
||||
nextStep = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final hop = hops[i];
|
||||
final rawPeers = peerContacts
|
||||
.where(
|
||||
(c) =>
|
||||
c.hasLocation &&
|
||||
c.path.isNotEmpty &&
|
||||
_matchesHopPrefix(_lastHopChunk(c.path, c.pathHashWidth), hop),
|
||||
)
|
||||
.toList();
|
||||
final plausiblePeers = _filterPlausiblePeers(
|
||||
rawPeers,
|
||||
prevPos: prevPos,
|
||||
prevMaxMeters: prevPos != null
|
||||
? (i - prevStep) * PathHopResolver.maxSingleHopDistanceMeters
|
||||
: null,
|
||||
nextPos: nextPos,
|
||||
nextMaxMeters: nextPos != null && nextStep != null
|
||||
? (nextStep - i) * PathHopResolver.maxSingleHopDistanceMeters
|
||||
: null,
|
||||
);
|
||||
if (plausiblePeers.isNotEmpty) {
|
||||
final lat =
|
||||
plausiblePeers.map((c) => c.latitude!).reduce((a, b) => a + b) /
|
||||
plausiblePeers.length;
|
||||
final lon =
|
||||
plausiblePeers.map((c) => c.longitude!).reduce((a, b) => a + b) /
|
||||
plausiblePeers.length;
|
||||
final pos = LatLng(lat, lon);
|
||||
inferred[i] = pos;
|
||||
prevPos = pos;
|
||||
prevStep = i;
|
||||
}
|
||||
}
|
||||
|
||||
return inferred;
|
||||
}
|
||||
|
||||
(LatLng?, int) _lastPlausibleAnchor({
|
||||
required List<Uint8List> outboundHops,
|
||||
required List<Contact?> resolvedOutbound,
|
||||
required List<LatLng?> inferredOutbound,
|
||||
required LatLng? selfPoint,
|
||||
}) {
|
||||
for (var i = outboundHops.length - 1; i >= 0; i--) {
|
||||
final pos = _contactLatLng(resolvedOutbound[i]) ?? inferredOutbound[i];
|
||||
if (pos != null) {
|
||||
return (pos, outboundHops.length - i);
|
||||
}
|
||||
}
|
||||
return (selfPoint, max(1, outboundHops.length));
|
||||
}
|
||||
|
||||
String _pathKeyForHops(List<Uint8List> hops) {
|
||||
@@ -880,15 +956,48 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
/// Rebuilds the renderable paths: the traced path as primary plus up to
|
||||
/// four distinct alternates from the target contact's path history.
|
||||
void _rebuildDisplayPaths(MeshCoreConnector connector) {
|
||||
_refreshHopContactCache(connector);
|
||||
final selfPoint = plausibleSelfPoint(connector);
|
||||
final paths = <DisplayPath>[];
|
||||
final resolvedMap =
|
||||
<String, ({List<Contact?> contacts, List<LatLng?> inferred})>{};
|
||||
|
||||
final resolvedPrimary = PathHopResolver.resolveHops(
|
||||
hops: _primaryOutboundHops,
|
||||
preferredContacts: widget.pathContacts,
|
||||
contacts: connector.allContactsUnfiltered,
|
||||
endpoint: selfPoint,
|
||||
contactFilter: (c) => c.type != advTypeChat,
|
||||
);
|
||||
final inferredPrimary = _inferHopPositions(
|
||||
hops: _primaryOutboundHops,
|
||||
resolvedContacts: resolvedPrimary,
|
||||
selfPoint: selfPoint,
|
||||
peerContacts: connector.contacts,
|
||||
);
|
||||
final traceData = _traceData;
|
||||
if (traceData != null) {
|
||||
_syncPrimaryTraceState(
|
||||
connector: connector,
|
||||
traceData: traceData,
|
||||
resolvedOutbound: resolvedPrimary,
|
||||
inferredOutbound: inferredPrimary,
|
||||
selfPoint: selfPoint,
|
||||
);
|
||||
}
|
||||
resolvedMap['primary'] = (
|
||||
contacts: resolvedPrimary,
|
||||
inferred: inferredPrimary,
|
||||
);
|
||||
|
||||
final primary = _buildDisplayPath(
|
||||
id: 'primary',
|
||||
label: context.l10n.pathMap_primary,
|
||||
color: kPrimaryPathColor,
|
||||
isPrimary: true,
|
||||
hops: _primaryOutboundHops,
|
||||
connector: connector,
|
||||
resolvedContacts: resolvedPrimary,
|
||||
inferredPositions: inferredPrimary,
|
||||
selfPoint: selfPoint,
|
||||
);
|
||||
if (primary != null) paths.add(primary);
|
||||
|
||||
@@ -905,14 +1014,30 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
);
|
||||
if (!seen.add(_pathKeyForHops(recordHops))) continue;
|
||||
if (altIndex >= kAlternatePathColors.length) break;
|
||||
final altId = 'alt-${_pathKeyForHops(recordHops)}';
|
||||
final altResolved = PathHopResolver.resolveHops(
|
||||
hops: recordHops,
|
||||
contacts: connector.allContactsUnfiltered,
|
||||
endpoint: selfPoint,
|
||||
contactFilter: (c) => c.type != advTypeChat,
|
||||
);
|
||||
final altInferred = _inferHopPositions(
|
||||
hops: recordHops,
|
||||
resolvedContacts: altResolved,
|
||||
selfPoint: selfPoint,
|
||||
peerContacts: connector.contacts,
|
||||
);
|
||||
resolvedMap[altId] = (contacts: altResolved, inferred: altInferred);
|
||||
final alt = _buildDisplayPath(
|
||||
id: 'alt-${_pathKeyForHops(recordHops)}',
|
||||
id: altId,
|
||||
label: context.l10n.pathMap_alternate(altIndex + 1),
|
||||
color: kAlternatePathColors[altIndex],
|
||||
isPrimary: false,
|
||||
hops: recordHops,
|
||||
resolvedContacts: altResolved,
|
||||
inferredPositions: altInferred,
|
||||
selfPoint: selfPoint,
|
||||
record: record,
|
||||
connector: connector,
|
||||
);
|
||||
if (alt != null) {
|
||||
paths.add(alt);
|
||||
@@ -921,6 +1046,9 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
}
|
||||
}
|
||||
|
||||
_resolvedDisplayPaths
|
||||
..clear()
|
||||
..addAll(resolvedMap);
|
||||
_displayPaths = paths;
|
||||
_hiddenPathIds.removeWhere((id) => !paths.any((p) => p.id == id));
|
||||
if (!paths.any((p) => p.id == _selectedPathId)) {
|
||||
@@ -936,12 +1064,13 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
required Color color,
|
||||
required bool isPrimary,
|
||||
required List<Uint8List> hops,
|
||||
required MeshCoreConnector connector,
|
||||
required List<Contact?> resolvedContacts,
|
||||
required List<LatLng?> inferredPositions,
|
||||
required LatLng? selfPoint,
|
||||
PathRecord? record,
|
||||
}) {
|
||||
// Without a GPS fix for the local radio the path starts at the first
|
||||
// located hop instead of a bogus "You" at 0,0.
|
||||
final selfPoint = plausibleSelfPoint(connector);
|
||||
final points = <LatLng>[?selfPoint];
|
||||
final labels = <String>[if (selfPoint != null) context.l10n.pathTrace_you];
|
||||
final confirmed = <bool>[if (selfPoint != null) true];
|
||||
@@ -954,15 +1083,14 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
for (var i = 0; i < hops.length; i++) {
|
||||
final hop = hops[i];
|
||||
final hex = PathHelper.formatHopHex(hop);
|
||||
final contact = _contactForHop(hop, connector);
|
||||
LatLng? pos;
|
||||
final contact = i < resolvedContacts.length ? resolvedContacts[i] : null;
|
||||
LatLng? pos = _contactLatLng(contact);
|
||||
var isGps = false;
|
||||
if (contact != null && contact.hasLocation) {
|
||||
pos = LatLng(contact.latitude!, contact.longitude!);
|
||||
if (pos != null) {
|
||||
isGps = true;
|
||||
gpsConfirmedHops++;
|
||||
} else {
|
||||
pos = _inferredPositionForHop(hop, connector);
|
||||
} else if (i < inferredPositions.length) {
|
||||
pos = inferredPositions[i];
|
||||
}
|
||||
if (pos == null) {
|
||||
unresolvedHops++;
|
||||
@@ -1074,7 +1202,6 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, _) {
|
||||
if (_hasData) _refreshHopContactCache(connector);
|
||||
final settings = context.watch<AppSettingsService>().settings;
|
||||
final isImperial = settings.unitSystem == UnitSystem.imperial;
|
||||
final tileCache = context.read<MapTileCacheService>();
|
||||
@@ -1108,7 +1235,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (_isLoading)
|
||||
CircularProgressIndicator(color: MeshPalette.blue),
|
||||
CircularProgressIndicator(color: scheme.primary),
|
||||
const SizedBox(height: 16),
|
||||
if (!_isLoading && _failed2Loaded)
|
||||
Text(
|
||||
@@ -1364,32 +1491,58 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
required bool showLabels,
|
||||
required Contact? target,
|
||||
}) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final markers = <Marker>[];
|
||||
|
||||
// Hop prefix -> paths that use it, in display order.
|
||||
final hopPaths = <String, List<DisplayPath>>{};
|
||||
final hopsByKey = <String, Uint8List>{};
|
||||
// Hop prefix + resolved position -> paths that use it, in display order.
|
||||
final hopNodes =
|
||||
<
|
||||
String,
|
||||
({
|
||||
Uint8List hop,
|
||||
Contact? contact,
|
||||
LatLng point,
|
||||
bool hasGps,
|
||||
List<DisplayPath> paths,
|
||||
})
|
||||
>{};
|
||||
for (final path in _visiblePaths) {
|
||||
for (final hop in path.hopBytes) {
|
||||
final hopKey = _hopKey(hop);
|
||||
hopsByKey[hopKey] = hop;
|
||||
final list = hopPaths.putIfAbsent(hopKey, () => []);
|
||||
if (!list.contains(path)) list.add(path);
|
||||
final resolved = _resolvedDisplayPaths[path.id];
|
||||
for (var i = 0; i < path.hopBytes.length; i++) {
|
||||
final hop = path.hopBytes[i];
|
||||
final contact = resolved != null && i < resolved.contacts.length
|
||||
? resolved.contacts[i]
|
||||
: null;
|
||||
final inferred = resolved != null && i < resolved.inferred.length
|
||||
? resolved.inferred[i]
|
||||
: null;
|
||||
final gpsPos = _contactLatLng(contact);
|
||||
final hasGps = gpsPos != null;
|
||||
final point = gpsPos ?? inferred;
|
||||
if (point == null) continue;
|
||||
final hopKey =
|
||||
'${_hopKey(hop)}|${point.latitude.toStringAsFixed(5)},'
|
||||
'${point.longitude.toStringAsFixed(5)}';
|
||||
final existing = hopNodes[hopKey];
|
||||
if (existing == null) {
|
||||
hopNodes[hopKey] = (
|
||||
hop: hop,
|
||||
contact: contact,
|
||||
point: point,
|
||||
hasGps: hasGps,
|
||||
paths: [path],
|
||||
);
|
||||
} else if (!existing.paths.contains(path)) {
|
||||
existing.paths.add(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (final entry in hopPaths.entries) {
|
||||
final hopKey = entry.key;
|
||||
final hop = hopsByKey[hopKey];
|
||||
if (hop == null) continue;
|
||||
final paths = entry.value;
|
||||
final contact = _contactForHop(hop, connector);
|
||||
final hasGps = contact != null && contact.hasLocation;
|
||||
final point = hasGps
|
||||
? LatLng(contact.latitude!, contact.longitude!)
|
||||
: _inferredPositionForHop(hop, connector);
|
||||
if (point == null) continue;
|
||||
for (final entry in hopNodes.values) {
|
||||
final hop = entry.hop;
|
||||
final paths = entry.paths;
|
||||
final contact = entry.contact;
|
||||
final hasGps = entry.hasGps;
|
||||
final point = entry.point;
|
||||
final label = PathHelper.formatHopHex(hop);
|
||||
final baseColor = hasGps ? MeshPalette.signal : MeshPalette.warn;
|
||||
final shared = paths.length > 1;
|
||||
@@ -1650,7 +1803,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
style: MeshTheme.mono(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 13,
|
||||
color: MeshPalette.ink,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
combined: combined,
|
||||
@@ -1727,6 +1880,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
itemCount: pathTraceData.pathData.length + 1,
|
||||
separatorBuilder: (_, _) => const Divider(height: 1),
|
||||
itemBuilder: (context, index) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final snrUi = snrUiFromSNR(
|
||||
index < pathTraceData.snrData.length
|
||||
? pathTraceData.snrData[index]
|
||||
@@ -1741,15 +1895,18 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
index >= pathTraceData.snrData.length / 2
|
||||
? Icons.call_received
|
||||
: Icons.call_made,
|
||||
color: MeshPalette.ink2,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
title: Text(
|
||||
formatDirectionText(pathTraceData, index),
|
||||
style: MeshTheme.mono(fontSize: 13, color: MeshPalette.ink),
|
||||
style: MeshTheme.mono(fontSize: 13, color: scheme.onSurface),
|
||||
),
|
||||
subtitle: Text(
|
||||
formatDirectionSubText(pathTraceData, index),
|
||||
style: MeshTheme.mono(fontSize: 12, color: MeshPalette.ink3),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
trailing: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -1790,19 +1947,26 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
itemCount: path.totalTransmissions,
|
||||
separatorBuilder: (_, _) => const Divider(height: 1),
|
||||
itemBuilder: (context, index) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
String title;
|
||||
String subtitle;
|
||||
Widget? trailing;
|
||||
if (index < path.hopBytes.length) {
|
||||
final hop = path.hopBytes[index];
|
||||
final hex = PathHelper.formatHopHex(hop);
|
||||
final contact = _contactForHop(hop, connector);
|
||||
final resolved = _resolvedDisplayPaths[path.id];
|
||||
final contact = resolved != null && index < resolved.contacts.length
|
||||
? resolved.contacts[index]
|
||||
: null;
|
||||
title = contact != null
|
||||
? '$hex: ${contact.name}'
|
||||
: '$hex: ${l10n.channelPath_unknownRepeater}';
|
||||
final hasGps = contact != null && contact.hasLocation;
|
||||
final inferred =
|
||||
!hasGps && _inferredPositionForHop(hop, connector) != null;
|
||||
!hasGps &&
|
||||
resolved != null &&
|
||||
index < resolved.inferred.length &&
|
||||
resolved.inferred[index] != null;
|
||||
final status = hasGps
|
||||
? l10n.pathTrace_legendGpsConfirmed
|
||||
: inferred
|
||||
@@ -1858,11 +2022,14 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
),
|
||||
title: Text(
|
||||
title,
|
||||
style: MeshTheme.mono(fontSize: 13, color: MeshPalette.ink),
|
||||
style: MeshTheme.mono(fontSize: 13, color: scheme.onSurface),
|
||||
),
|
||||
subtitle: Text(
|
||||
subtitle,
|
||||
style: MeshTheme.mono(fontSize: 12, color: MeshPalette.ink3),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
trailing: trailing,
|
||||
);
|
||||
|
||||
@@ -112,7 +112,8 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
int? _spreadingFactor;
|
||||
int? _codingRate;
|
||||
|
||||
bool _autoClockSyncAfterLogin = false;
|
||||
RepeaterClockSyncOverride _clockSyncOverride =
|
||||
RepeaterClockSyncOverride.followDefault;
|
||||
|
||||
// Identity keys
|
||||
final TextEditingController _prvKeyController = TextEditingController();
|
||||
@@ -527,13 +528,12 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
}
|
||||
});
|
||||
|
||||
final autoClockSync = await _storage
|
||||
.getRepeaterAutoClockSyncAfterLoginEnabled(
|
||||
widget.repeater.publicKeyHex,
|
||||
);
|
||||
final clockSync = await _storage.getRepeaterClockSyncOverride(
|
||||
widget.repeater.publicKeyHex,
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_autoClockSyncAfterLogin = autoClockSync;
|
||||
_clockSyncOverride = clockSync;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -953,7 +953,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
_buildSectionCard(
|
||||
l10n.repeater_features,
|
||||
RepeaterSettingSection.features,
|
||||
extra: [_buildClockSyncToggle()],
|
||||
extra: [_buildClockSyncChoice()],
|
||||
),
|
||||
_buildSectionCard(
|
||||
l10n.repeater_networkHealth,
|
||||
@@ -1366,22 +1366,75 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
];
|
||||
}
|
||||
|
||||
Widget _buildClockSyncToggle() {
|
||||
Widget _buildClockSyncChoice() {
|
||||
final l10n = context.l10n;
|
||||
return SwitchListTile(
|
||||
title: Text(l10n.repeater_clockSyncAfterLogin),
|
||||
subtitle: Text(l10n.repeater_clockSyncAfterLoginSubtitle),
|
||||
value: _autoClockSyncAfterLogin,
|
||||
onChanged: (value) async {
|
||||
setState(() {
|
||||
_autoClockSyncAfterLogin = value;
|
||||
});
|
||||
await _storage.setRepeaterAutoClockSyncAfterLoginEnabled(
|
||||
widget.repeater.publicKeyHex,
|
||||
value,
|
||||
);
|
||||
},
|
||||
contentPadding: EdgeInsets.zero,
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
ButtonSegment<RepeaterClockSyncOverride> segment(
|
||||
RepeaterClockSyncOverride value,
|
||||
String label,
|
||||
) => ButtonSegment(value: value, label: MeshSegmentLabel(label));
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.schedule, size: 24, color: scheme.onSurfaceVariant),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l10n.repeater_clockSyncAfterLogin,
|
||||
style: textTheme.bodyLarge?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
l10n.repeater_clockSyncAfterLoginSubtitle,
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SegmentedButton<RepeaterClockSyncOverride>(
|
||||
showSelectedIcon: false,
|
||||
style: const ButtonStyle(
|
||||
minimumSize: WidgetStatePropertyAll(Size.fromHeight(40)),
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
segments: [
|
||||
segment(
|
||||
RepeaterClockSyncOverride.followDefault,
|
||||
l10n.repeater_clockSyncDefault,
|
||||
),
|
||||
segment(RepeaterClockSyncOverride.on, l10n.repeater_clockSyncOn),
|
||||
segment(
|
||||
RepeaterClockSyncOverride.off,
|
||||
l10n.repeater_clockSyncOff,
|
||||
),
|
||||
],
|
||||
selected: {_clockSyncOverride},
|
||||
onSelectionChanged: (selected) async {
|
||||
final value = selected.first;
|
||||
setState(() => _clockSyncOverride = value);
|
||||
await _storage.setRepeaterClockSyncOverride(
|
||||
widget.repeater.publicKeyHex,
|
||||
value,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/device_tile.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/settings_reveal.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../review_mode/review_mode_entry.dart';
|
||||
import '../utils/main_navigation.dart';
|
||||
@@ -150,17 +151,13 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||
builder: (context, connector, child) {
|
||||
return Column(
|
||||
children: [
|
||||
// Bluetooth off warning — slides in/out with AnimatedSize
|
||||
AnimatedSize(
|
||||
duration: const Duration(milliseconds: 250),
|
||||
curve: Curves.easeInOut,
|
||||
child: _bluetoothState == BluetoothAdapterState.off
|
||||
? _BluetoothOffBanner(
|
||||
onEnable: PlatformInfo.isAndroid
|
||||
? () => FlutterBluePlus.turnOn()
|
||||
: null,
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
RevealOnEnable(
|
||||
visible: _bluetoothState == BluetoothAdapterState.off,
|
||||
child: _BluetoothOffBanner(
|
||||
onEnable: PlatformInfo.isAndroid
|
||||
? () => FlutterBluePlus.turnOn()
|
||||
: null,
|
||||
),
|
||||
),
|
||||
|
||||
// Connection status header
|
||||
|
||||
@@ -14,6 +14,7 @@ import '../helpers/snack_bar_builder.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
import '../widgets/mesh_nav_tile.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/settings_reveal.dart';
|
||||
import '../widgets/radio_settings_dialog.dart';
|
||||
import 'app_settings_screen.dart';
|
||||
import 'app_debug_log_screen.dart';
|
||||
@@ -301,62 +302,58 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
),
|
||||
),
|
||||
|
||||
// Expandable detail rows
|
||||
AnimatedSize(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
alignment: Alignment.topCenter,
|
||||
child: _deviceInfoExpanded
|
||||
? Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 14),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Divider(height: 1),
|
||||
const SizedBox(height: 10),
|
||||
_infoRow(
|
||||
context,
|
||||
label: l10n.settings_infoId,
|
||||
value: connector.deviceIdLabel,
|
||||
),
|
||||
_buildBatteryInfoRow(context, connector),
|
||||
if (connector.manufacturerName != null)
|
||||
_infoRow(
|
||||
context,
|
||||
label: l10n.settings_infoHardware,
|
||||
value: connector.manufacturerName!,
|
||||
),
|
||||
if (connector.firmwareVersionString != null)
|
||||
_infoRow(
|
||||
context,
|
||||
label: l10n.settings_infoFirmware,
|
||||
value: connector.firmwareVersionString!,
|
||||
),
|
||||
if (connector.selfName != null)
|
||||
_infoRow(
|
||||
context,
|
||||
label: l10n.settings_nodeName,
|
||||
value: connector.selfName!,
|
||||
),
|
||||
if (connector.selfPublicKey != null)
|
||||
_publicKeyRow(
|
||||
context,
|
||||
label: l10n.settings_infoPublicKey,
|
||||
publicKeyHex: pubKeyToHex(connector.selfPublicKey!),
|
||||
),
|
||||
_infoRow(
|
||||
context,
|
||||
label: l10n.settings_infoContactsCount,
|
||||
value: '${connector.contacts.length}',
|
||||
),
|
||||
_infoRow(
|
||||
context,
|
||||
label: l10n.settings_infoChannelCount,
|
||||
value: '${connector.channels.length}',
|
||||
),
|
||||
],
|
||||
RevealOnEnable(
|
||||
visible: _deviceInfoExpanded,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 14),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Divider(height: 1),
|
||||
const SizedBox(height: 10),
|
||||
_infoRow(
|
||||
context,
|
||||
label: l10n.settings_infoId,
|
||||
value: connector.deviceIdLabel,
|
||||
),
|
||||
_buildBatteryInfoRow(context, connector),
|
||||
if (connector.manufacturerName != null)
|
||||
_infoRow(
|
||||
context,
|
||||
label: l10n.settings_infoHardware,
|
||||
value: connector.manufacturerName!,
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
if (connector.firmwareVersionString != null)
|
||||
_infoRow(
|
||||
context,
|
||||
label: l10n.settings_infoFirmware,
|
||||
value: connector.firmwareVersionString!,
|
||||
),
|
||||
if (connector.selfName != null)
|
||||
_infoRow(
|
||||
context,
|
||||
label: l10n.settings_nodeName,
|
||||
value: connector.selfName!,
|
||||
),
|
||||
if (connector.selfPublicKey != null)
|
||||
_publicKeyRow(
|
||||
context,
|
||||
label: l10n.settings_infoPublicKey,
|
||||
publicKeyHex: pubKeyToHex(connector.selfPublicKey!),
|
||||
),
|
||||
_infoRow(
|
||||
context,
|
||||
label: l10n.settings_infoContactsCount,
|
||||
value: '${connector.contacts.length}',
|
||||
),
|
||||
_infoRow(
|
||||
context,
|
||||
label: l10n.settings_infoChannelCount,
|
||||
value: '${connector.channels.length}',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user