Open repeater details from the nearby repeaters list
Each nearby repeater is now a tappable row that opens the same node details sheet as the map, or a short sheet with the key prefix and signal when the repeater isn't a known contact. The map's node info sheet and login dialogs move to widgets/node_info_sheet.dart so both places share them.
This commit is contained in:
1 parent
caf20b4415
commit
c131f56dae
24 files changed
+616
-331
No files matched your search
@@ -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,
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
+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