Merge branch 'dev' into feat/dns-node-banner
This commit is contained in:
50 files changed
+3085
-731
No files matched your search
@@ -9,6 +9,7 @@ import '../theme/mesh_theme.dart';
|
||||
import 'byte_count_input.dart';
|
||||
import 'gif_message.dart';
|
||||
import 'gif_picker.dart';
|
||||
import 'mesh_ui.dart';
|
||||
import 'message_translation_button.dart';
|
||||
|
||||
/// One entry of the composer's "+" menu.
|
||||
@@ -27,9 +28,8 @@ class ChatComposerAction {
|
||||
|
||||
/// Opens the GIF picker and puts the chosen GIF into [controller].
|
||||
void showChatGifPicker(BuildContext context, TextEditingController controller) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
showMeshSheet<void>(
|
||||
context,
|
||||
builder: (context) => GifPicker(
|
||||
onGifSelected: (gifId) {
|
||||
controller.text = GifHelper.encodeGif(gifId);
|
||||
|
||||
@@ -210,12 +210,8 @@ class EmojiPicker extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final emojiCategories = _emojiCategories(l10n);
|
||||
return Container(
|
||||
return SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.5,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
|
||||
@@ -117,7 +117,9 @@ class _GifPickerState extends State<GifPicker> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: MediaQuery.of(context).size.height * 0.7,
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.of(context).size.height * 0.7,
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
|
||||
@@ -0,0 +1,282 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
import '../l10n/contact_localization.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../screens/chat_screen.dart';
|
||||
import '../screens/repeater_hub_screen.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import 'mesh_ui.dart';
|
||||
import 'repeater_login_dialog.dart';
|
||||
import 'room_login_dialog.dart';
|
||||
|
||||
/// Map accent colour for a node type.
|
||||
Color mapNodeTypeColor(int type) {
|
||||
switch (type) {
|
||||
case advTypeChat:
|
||||
return MapPalette.selected;
|
||||
case advTypeRepeater:
|
||||
return MapPalette.repeater;
|
||||
case advTypeRoom:
|
||||
return MapPalette.router;
|
||||
case advTypeSensor:
|
||||
return MapPalette.sensor;
|
||||
default:
|
||||
return MapPalette.offline;
|
||||
}
|
||||
}
|
||||
|
||||
/// Map icon for a node type.
|
||||
IconData mapNodeTypeIcon(int type) {
|
||||
switch (type) {
|
||||
case advTypeChat:
|
||||
return Icons.person;
|
||||
case advTypeRepeater:
|
||||
return Icons.router;
|
||||
case advTypeRoom:
|
||||
return Icons.meeting_room;
|
||||
case advTypeSensor:
|
||||
return Icons.sensors;
|
||||
default:
|
||||
return Icons.device_unknown;
|
||||
}
|
||||
}
|
||||
|
||||
String formatNodeLastSeen(AppLocalizations l10n, DateTime lastSeen) {
|
||||
final difference = DateTime.now().difference(lastSeen);
|
||||
if (difference.inSeconds < 60) {
|
||||
return l10n.time_justNow;
|
||||
} else if (difference.inMinutes < 60) {
|
||||
return l10n.time_minutesAgo(difference.inMinutes);
|
||||
} else if (difference.inHours < 24) {
|
||||
return l10n.time_hoursAgo(difference.inHours);
|
||||
} else {
|
||||
return l10n.time_daysAgo(difference.inDays);
|
||||
}
|
||||
}
|
||||
|
||||
/// Label above a selectable mono value, as used in node detail sheets.
|
||||
class NodeInfoRow extends StatelessWidget {
|
||||
final String label;
|
||||
final String value;
|
||||
|
||||
const NodeInfoRow({super.key, required this.label, required this.value});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: scheme.onSurfaceVariant,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
SelectableText(
|
||||
value,
|
||||
style: MeshTheme.mono(fontSize: 13, color: scheme.onSurface),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Repeater login, then the repeater hub on success.
|
||||
void showRepeaterLoginDialog(BuildContext context, Contact repeater) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => RepeaterLoginDialog(
|
||||
repeater: repeater,
|
||||
onLogin: (password, isAdmin) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => RepeaterHubScreen(
|
||||
repeater: repeater,
|
||||
password: password,
|
||||
isAdmin: isAdmin,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Room login, then the room chat (or the hub when [manage] is set).
|
||||
void showRoomLoginDialog(
|
||||
BuildContext context,
|
||||
Contact room, {
|
||||
bool manage = false,
|
||||
}) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => RoomLoginDialog(
|
||||
room: room,
|
||||
onLogin: (password, isAdmin) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final unread = connector.getUnreadCountForContactKey(room.publicKeyHex);
|
||||
connector.markContactRead(room.publicKeyHex);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => manage
|
||||
? RepeaterHubScreen(
|
||||
repeater: room,
|
||||
password: password,
|
||||
isAdmin: isAdmin,
|
||||
)
|
||||
: ChatScreen(contact: room, initialUnreadCount: unread),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Node details sheet (path, location, last seen, key) with the actions for
|
||||
/// its type: open chat, manage repeater, or join/manage room.
|
||||
void showNodeInfoSheet(
|
||||
BuildContext context,
|
||||
Contact contact, {
|
||||
LatLng? guessedPosition,
|
||||
}) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
showMeshSheet(
|
||||
context,
|
||||
builder: (sheetContext) {
|
||||
final l10n = context.l10n;
|
||||
void importIfNeeded() {
|
||||
if (!contact.isActive) {
|
||||
connector.importDiscoveredContact(contact);
|
||||
}
|
||||
}
|
||||
|
||||
final actions = <Widget>[];
|
||||
if (contact.type == advTypeChat) {
|
||||
actions.add(
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
importIfNeeded();
|
||||
final unread = connector.getUnreadCountForContactKey(
|
||||
contact.publicKeyHex,
|
||||
);
|
||||
Navigator.pop(sheetContext);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
ChatScreen(contact: contact, initialUnreadCount: unread),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Text(l10n.contacts_openChat),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (contact.type == advTypeRepeater) {
|
||||
actions.add(
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
importIfNeeded();
|
||||
Navigator.pop(sheetContext);
|
||||
showRepeaterLoginDialog(context, contact);
|
||||
},
|
||||
child: Text(l10n.map_manageRepeater),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (contact.type == advTypeRoom) {
|
||||
actions.add(
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
importIfNeeded();
|
||||
Navigator.pop(sheetContext);
|
||||
showRoomLoginDialog(context, contact);
|
||||
},
|
||||
child: Text(l10n.map_joinRoom),
|
||||
),
|
||||
);
|
||||
actions.add(
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
importIfNeeded();
|
||||
Navigator.pop(sheetContext);
|
||||
showRoomLoginDialog(context, contact, manage: true);
|
||||
},
|
||||
child: Text(l10n.map_manageServer),
|
||||
),
|
||||
);
|
||||
}
|
||||
return SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
BottomSheetHeader(
|
||||
title: contact.name,
|
||||
subtitle: contact.typeLabel(l10n),
|
||||
trailing: Icon(
|
||||
mapNodeTypeIcon(contact.type),
|
||||
color: mapNodeTypeColor(contact.type),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
NodeInfoRow(
|
||||
label: l10n.map_path,
|
||||
value: contact.pathLabel(
|
||||
l10n,
|
||||
pathHashByteWidth: connector.pathHashByteWidth,
|
||||
),
|
||||
),
|
||||
if (contact.hasLocation)
|
||||
NodeInfoRow(
|
||||
label: l10n.map_location,
|
||||
value:
|
||||
'${contact.latitude!.toStringAsFixed(6)}, ${contact.longitude!.toStringAsFixed(6)}',
|
||||
)
|
||||
else if (guessedPosition != null)
|
||||
NodeInfoRow(
|
||||
label: l10n.map_estLocation,
|
||||
value:
|
||||
'~${guessedPosition.latitude.toStringAsFixed(6)}, ${guessedPosition.longitude.toStringAsFixed(6)}',
|
||||
),
|
||||
NodeInfoRow(
|
||||
label: l10n.map_lastSeen,
|
||||
value: formatNodeLastSeen(l10n, contact.lastSeen),
|
||||
),
|
||||
NodeInfoRow(
|
||||
label: l10n.map_publicKey,
|
||||
value: contact.publicKeyHex,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
...actions,
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
|
||||
/// Asks the user to confirm, then sets the radio's advertised location to
|
||||
/// [position] and waits for SELF_INFO to report it. Shows a success or
|
||||
/// failure snackbar and returns whether the radio confirmed the new location.
|
||||
Future<bool> confirmAndSetMyLocation(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
LatLng position,
|
||||
) async {
|
||||
if (!connector.isConnected) return false;
|
||||
final l10n = context.l10n;
|
||||
final latText = position.latitude.toStringAsFixed(6);
|
||||
final lonText = position.longitude.toStringAsFixed(6);
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(l10n.map_setLocationConfirmTitle),
|
||||
content: Text(l10n.map_setLocationConfirmBody(latText, lonText)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, false),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, true),
|
||||
child: Text(l10n.map_setLocationAction),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmed != true || !context.mounted || !connector.isConnected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The firmware stores coordinates as int32 micro-degrees.
|
||||
bool matches() {
|
||||
final lat = connector.selfLatitude;
|
||||
final lon = connector.selfLongitude;
|
||||
return lat != null &&
|
||||
lon != null &&
|
||||
(lat - position.latitude).abs() < 2e-6 &&
|
||||
(lon - position.longitude).abs() < 2e-6;
|
||||
}
|
||||
|
||||
var ok = false;
|
||||
try {
|
||||
await connector.setNodeLocation(
|
||||
lat: position.latitude,
|
||||
lon: position.longitude,
|
||||
);
|
||||
await connector.refreshDeviceInfo();
|
||||
// Self info arrives asynchronously after the query; wait for it.
|
||||
final deadline = DateTime.now().add(const Duration(seconds: 6));
|
||||
while (context.mounted && connector.isConnected) {
|
||||
if (matches()) {
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
if (DateTime.now().isAfter(deadline)) break;
|
||||
await Future<void>.delayed(const Duration(milliseconds: 250));
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Set node location failed: $e');
|
||||
}
|
||||
if (!context.mounted) return ok;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
ok ? l10n.map_locationSetSuccess : l10n.map_locationSetFailed,
|
||||
),
|
||||
);
|
||||
return ok;
|
||||
}
|
||||
+126
-40
@@ -9,6 +9,7 @@ import '../l10n/l10n.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import 'mesh_ui.dart';
|
||||
import 'node_info_sheet.dart';
|
||||
import 'signal_ui.dart';
|
||||
|
||||
Contact? _getRepeaterPrefixMatchNearLocation(
|
||||
@@ -276,53 +277,77 @@ class _SNRIndicatorState extends State<SNRIndicator> {
|
||||
);
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 10,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
AvatarCircle(
|
||||
name: name ?? prefixLabel,
|
||||
size: 36,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
return Semantics(
|
||||
button: true,
|
||||
hint: l10n.map_details,
|
||||
child: InkWell(
|
||||
onTap: () => contact != null
|
||||
? showNodeInfoSheet(context, contact)
|
||||
: _showUnknownRepeaterSheet(
|
||||
context,
|
||||
repeater,
|
||||
prefixLabel,
|
||||
),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: 56),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 10,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
name ?? prefixLabel,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
AvatarCircle(
|
||||
name: name ?? prefixLabel,
|
||||
size: 36,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.circle,
|
||||
size: 8,
|
||||
color: snrColor,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'${repeater.snr.toStringAsFixed(1)} dB • ${_formatLastUpdated(repeater.lastUpdated)}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
name ?? prefixLabel,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.circle,
|
||||
size: 8,
|
||||
color: snrColor,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'${repeater.snr.toStringAsFixed(1)} dB • ${_formatLastUpdated(repeater.lastUpdated)}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12,
|
||||
color: colorScheme
|
||||
.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
size: 24,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -341,4 +366,65 @@ class _SNRIndicatorState extends State<SNRIndicator> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showUnknownRepeaterSheet(
|
||||
BuildContext context,
|
||||
DirectRepeater repeater,
|
||||
String prefixLabel,
|
||||
) {
|
||||
showMeshSheet<void>(
|
||||
context,
|
||||
builder: (sheetContext) {
|
||||
final l10n = sheetContext.l10n;
|
||||
final scheme = Theme.of(sheetContext).colorScheme;
|
||||
return SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
BottomSheetHeader(
|
||||
title: prefixLabel,
|
||||
subtitle: l10n.snrIndicator_unknownRepeater,
|
||||
trailing: Icon(
|
||||
mapNodeTypeIcon(advTypeRepeater),
|
||||
color: mapNodeTypeColor(advTypeRepeater),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
NodeInfoRow(
|
||||
label: l10n.map_publicKeyPrefix,
|
||||
value: repeater.pubkeyPrefixHex,
|
||||
),
|
||||
NodeInfoRow(
|
||||
label: l10n.repeater_lastSnr,
|
||||
value: '${repeater.snr.toStringAsFixed(1)} dB',
|
||||
),
|
||||
NodeInfoRow(
|
||||
label: l10n.map_lastSeen,
|
||||
value: formatNodeLastSeen(l10n, repeater.lastUpdated),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
l10n.snrIndicator_unknownRepeaterHint,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user