Merge dev; fix share-location and discovered-contact import/export; update docs
Merge dev (#588 share location, #436 discovered-contact import/export) into fix/review-fixes-and-issue-batch. Conflicts: keep the node-scan button alongside dev's import/export menu; take dev's marker label prompt. Share location (#588): - Never share a missing or 0,0 radio position; hide the chat action and show "Your radio has no location set" - Sanitise marker labels ('|' -> '/', newlines -> spaces) on every path - One shared MarkerLabelDialog owning its controller/focus node, with keyboard submit, replacing three copies - Map pins default to "Point of interest" again; "Share my location" uses the node name - Location shares honour the send cooldown and handle send errors Discovered-contact import/export (#436): - Per-entry decoding with imported/skipped/invalid counts; reject keys that are not 32 bytes; skip in-file duplicates and the radio's own key - Strip routing paths on import and stop exporting them; clamp future timestamps; enforce the discovered-contact cap; require a connection; 2 MB file limit - Export via in-memory XFile (fixes web); pass sharePositionOrigin for iPad (also GPX export and image save); macOS user-selected read-write entitlement for save dialogs Docs: cover share location, import/export, node scan, TCP reconnect, channel auto-resend options, arrival ordering, badge, password length and image limits. Translations for all new strings in every locale.
This commit is contained in:
commit
5fb67abdde
66 files changed
+3118
-168
No files matched your search
@@ -22,6 +22,9 @@ class ByteCountedTextField extends StatelessWidget {
|
||||
/// Optional focus node forwarded to the inner [TextField].
|
||||
final FocusNode? focusNode;
|
||||
|
||||
/// Whether the inner [TextField] requests focus when first built.
|
||||
final bool autofocus;
|
||||
|
||||
/// Hint text shown when the field is empty.
|
||||
final String? hintText;
|
||||
|
||||
@@ -64,6 +67,7 @@ class ByteCountedTextField extends StatelessWidget {
|
||||
required this.maxBytes,
|
||||
required this.controller,
|
||||
this.focusNode,
|
||||
this.autofocus = false,
|
||||
this.hintText,
|
||||
this.textInputAction = TextInputAction.send,
|
||||
this.onSubmitted,
|
||||
@@ -108,6 +112,7 @@ class ByteCountedTextField extends StatelessWidget {
|
||||
maxLines: null,
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
autofocus: autofocus,
|
||||
inputFormatters: [
|
||||
...extraFormatters,
|
||||
Utf8LengthLimitingTextInputFormatter(
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/guessed_location_estimator.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import 'byte_count_input.dart';
|
||||
|
||||
/// Makes [label] safe for the `m:lat,lon|label|flags` marker format: a `|`
|
||||
/// would split the label into the flags field and a line break would end the
|
||||
/// message, so both are replaced.
|
||||
String sanitizeMarkerLabel(String label) =>
|
||||
label.replaceAll('|', '/').replaceAll(RegExp(r'[\r\n]+'), ' ').trim();
|
||||
|
||||
/// The shared-marker message text parsed by `parseMarkerText`.
|
||||
String formatMarkerText(double lat, double lon, String label, String flags) =>
|
||||
'm:${lat.toStringAsFixed(6)},${lon.toStringAsFixed(6)}|'
|
||||
'${sanitizeMarkerLabel(label)}|$flags';
|
||||
|
||||
/// Bytes left for the label once the marker's fixed parts are counted, using
|
||||
/// the smaller of the contact and (worst-case sender name) channel limits so
|
||||
/// the marker fits either destination.
|
||||
int markerLabelByteBudget(double lat, double lon, String flags) {
|
||||
final maxPayload = [
|
||||
maxContactMessageBytes(),
|
||||
maxChannelMessageBytes(null),
|
||||
].reduce((a, b) => a < b ? a : b);
|
||||
final overhead = utf8ByteLength(formatMarkerText(lat, lon, '', flags));
|
||||
final budget = maxPayload - overhead;
|
||||
return budget > 0 ? budget : 0;
|
||||
}
|
||||
|
||||
/// Whether the radio reports a usable position. Firmware sends 0,0 when no
|
||||
/// location is set, which must not be shared as a real marker.
|
||||
bool hasShareableLocation(double? lat, double? lon) =>
|
||||
lat != null && lon != null && isPlausibleLocation(lat, lon);
|
||||
|
||||
/// Asks for a marker label. Returns the sanitised label (or the sanitised
|
||||
/// [defaultLabel] when left empty), or null when cancelled.
|
||||
Future<String?> showMarkerLabelDialog(
|
||||
BuildContext context, {
|
||||
required double lat,
|
||||
required double lon,
|
||||
required String defaultLabel,
|
||||
required String flags,
|
||||
required String confirmText,
|
||||
}) {
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
builder: (_) => MarkerLabelDialog(
|
||||
maxBytes: markerLabelByteBudget(lat, lon, flags),
|
||||
defaultLabel: defaultLabel,
|
||||
confirmText: confirmText,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Label prompt for a shared map marker. Owns its controller and focus node
|
||||
/// so they outlive the dialog's exit animation instead of being disposed
|
||||
/// while the field is still mounted.
|
||||
class MarkerLabelDialog extends StatefulWidget {
|
||||
const MarkerLabelDialog({
|
||||
super.key,
|
||||
required this.maxBytes,
|
||||
required this.defaultLabel,
|
||||
required this.confirmText,
|
||||
});
|
||||
|
||||
final int maxBytes;
|
||||
final String defaultLabel;
|
||||
final String confirmText;
|
||||
|
||||
@override
|
||||
State<MarkerLabelDialog> createState() => _MarkerLabelDialogState();
|
||||
}
|
||||
|
||||
class _MarkerLabelDialogState extends State<MarkerLabelDialog> {
|
||||
late final String _fittedDefault = truncateUtf8(
|
||||
sanitizeMarkerLabel(widget.defaultLabel),
|
||||
widget.maxBytes,
|
||||
);
|
||||
late final TextEditingController _controller =
|
||||
TextEditingController(text: _fittedDefault)
|
||||
..selection = TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset: _fittedDefault.length,
|
||||
);
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_focusNode.dispose();
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
final label = sanitizeMarkerLabel(_controller.text);
|
||||
Navigator.pop(context, label.isEmpty ? _fittedDefault : label);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final border = OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
borderSide: BorderSide(color: scheme.outlineVariant),
|
||||
);
|
||||
return AlertDialog(
|
||||
title: Text(l10n.map_pinLabel),
|
||||
content: ByteCountedTextField(
|
||||
autofocus: true,
|
||||
focusNode: _focusNode,
|
||||
maxBytes: widget.maxBytes,
|
||||
controller: _controller,
|
||||
decoration: InputDecoration(
|
||||
hintText: l10n.map_label,
|
||||
helperText: l10n.map_labelUpdateHint,
|
||||
helperMaxLines: 3,
|
||||
helperStyle: TextStyle(color: scheme.onSurfaceVariant, fontSize: 12),
|
||||
border: border,
|
||||
enabledBorder: border,
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
borderSide: BorderSide(color: scheme.primary, width: 1.5),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: scheme.surfaceContainerLow,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 18,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
onSubmitted: (_) => _submit(),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
FilledButton(onPressed: _submit, child: Text(widget.confirmText)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user