Merge upstream/dev (35 commits) into tth
Conflicts in lib/widgets/mesh_nav_tile.dart and lib/widgets/mesh_ui.dart: took upstream's iconSlot/ThemedIcon, busy spinner and SectionHeader description, and re-applied the terminal theme on top (18 dp icons, narrower gaps and padding, mono section labels). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
ceab62428a
103 files changed
+13328
-5463
No files matched your search
@@ -0,0 +1,204 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/mesh_nav_tile.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
|
||||
const String _sourceCodeHost = 'github.com/zjs81/meshcore-open';
|
||||
final Uri _sourceCodeUrl = Uri.https('github.com', '/zjs81/meshcore-open');
|
||||
final Uri _licenseUrl = Uri.https(
|
||||
'github.com',
|
||||
'/zjs81/meshcore-open/blob/HEAD/LICENSE',
|
||||
);
|
||||
final Uri _contributorsUrl = Uri.https(
|
||||
'github.com',
|
||||
'/zjs81/meshcore-open/graphs/contributors',
|
||||
);
|
||||
|
||||
/// Version label for Settings and About.
|
||||
Future<String> loadAppVersionLabel() async {
|
||||
final info = await PackageInfo.fromPlatform();
|
||||
return '${info.version} BETA';
|
||||
}
|
||||
|
||||
/// App name, version, description, source code, licenses and credits.
|
||||
class AboutScreen extends StatefulWidget {
|
||||
const AboutScreen({super.key});
|
||||
|
||||
@override
|
||||
State<AboutScreen> createState() => _AboutScreenState();
|
||||
}
|
||||
|
||||
class _AboutScreenState extends State<AboutScreen> {
|
||||
String? _version;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loadAppVersionLabel().then((version) {
|
||||
if (mounted) setState(() => _version = version);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _open(Uri url) async {
|
||||
final opened = await launchUrl(url, mode: LaunchMode.externalApplication);
|
||||
if (opened || !mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.chat_couldNotOpenLink(url.toString())),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final version = _version ?? l10n.common_loading;
|
||||
// The current year, so the notice doesn't go stale between releases.
|
||||
final legalese = l10n.settings_aboutLegalese('${DateTime.now().year}');
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: AdaptiveAppBarTitle(l10n.settings_about),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: MeshSettingsTileTheme(
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
|
||||
children: [
|
||||
MeshCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.sm),
|
||||
child: Image.asset(
|
||||
'assets/images/mesh-icon.png',
|
||||
width: 56,
|
||||
height: 56,
|
||||
excludeFromSemantics: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l10n.appTitle,
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
version,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 14,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
l10n.settings_aboutDescription,
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SectionHeader(l10n.about_project),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
MeshNavTile(
|
||||
icon: Icons.code,
|
||||
title: l10n.about_sourceCode,
|
||||
subtitle: _sourceCodeHost,
|
||||
trailing: Icon(
|
||||
Icons.open_in_new,
|
||||
size: 24,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
onTap: () => _open(_sourceCodeUrl),
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
icon: Icons.gavel_outlined,
|
||||
title: l10n.about_license,
|
||||
trailing: Icon(
|
||||
Icons.open_in_new,
|
||||
size: 24,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
onTap: () => _open(_licenseUrl),
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
icon: Icons.description_outlined,
|
||||
title: l10n.about_openSourceLicenses,
|
||||
onTap: () => showLicensePage(
|
||||
context: context,
|
||||
applicationName: l10n.appTitle,
|
||||
applicationVersion: version,
|
||||
applicationLegalese: legalese,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SectionHeader(l10n.about_credits),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
MeshNavTile(
|
||||
icon: Icons.people_outline,
|
||||
title: l10n.about_contributors,
|
||||
trailing: Icon(
|
||||
Icons.open_in_new,
|
||||
size: 24,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
onTap: () => _open(_contributorsUrl),
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
leading: const Icon(Icons.terrain_outlined, size: 24),
|
||||
title: Text(l10n.settings_aboutOpenMeteoAttribution),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 20, 16, 0),
|
||||
child: Text(
|
||||
legalese,
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -236,8 +236,6 @@ class _AddContactScreenState extends State<AddContactScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -264,31 +262,7 @@ class _AddContactScreenState extends State<AddContactScreen> {
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
MeshInfoCard(l10n.addContact_infoBanner),
|
||||
const SizedBox(height: 8),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
|
||||
+591
-135
@@ -1,17 +1,38 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../helpers/chat_jump.dart';
|
||||
import '../helpers/message_search.dart';
|
||||
import '../helpers/message_url_image_helper.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/bookmarked_message.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../services/chat_text_scale_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/chat_search_results.dart';
|
||||
import '../widgets/chat_send_pipeline.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/translated_message_content.dart';
|
||||
|
||||
class BookmarksScreen extends StatefulWidget {
|
||||
const BookmarksScreen({super.key});
|
||||
final BookmarkSourceType? initialSourceType;
|
||||
final String? initialSourceId;
|
||||
final List<String> sourceIdAliases;
|
||||
final String? initialSourceName;
|
||||
|
||||
const BookmarksScreen({
|
||||
super.key,
|
||||
this.initialSourceType,
|
||||
this.initialSourceId,
|
||||
this.sourceIdAliases = const [],
|
||||
this.initialSourceName,
|
||||
});
|
||||
|
||||
@override
|
||||
State<BookmarksScreen> createState() => _BookmarksScreenState();
|
||||
@@ -19,168 +40,603 @@ class BookmarksScreen extends StatefulWidget {
|
||||
|
||||
class _BookmarksScreenState extends State<BookmarksScreen> {
|
||||
late Future<List<BookmarkedMessage>> _bookmarks;
|
||||
List<BookmarkedMessage> _loadedBookmarks = const [];
|
||||
bool _hasLoadedBookmarks = false;
|
||||
late bool _filterToInitialSource;
|
||||
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
bool _searching = false;
|
||||
String _searchQuery = '';
|
||||
String? _highlightedStorageId;
|
||||
Timer? _highlightTimer;
|
||||
|
||||
final Set<String> _selectedIds = <String>{};
|
||||
|
||||
bool get _hasInitialSource => widget.initialSourceId != null;
|
||||
bool get _selecting => _selectedIds.isNotEmpty;
|
||||
bool get _showSearchResults => _searching && _searchQuery.trim().isNotEmpty;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_bookmarks = context.read<MeshCoreConnector>().loadBookmarkedMessages();
|
||||
_filterToInitialSource = widget.initialSourceId != null;
|
||||
_bookmarks = _fetchBookmarks();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_highlightTimer?.cancel();
|
||||
_searchController.dispose();
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<List<BookmarkedMessage>> _fetchBookmarks() async {
|
||||
final loaded = await context
|
||||
.read<MeshCoreConnector>()
|
||||
.loadBookmarkedMessages();
|
||||
if (mounted) {
|
||||
_loadedBookmarks = loaded;
|
||||
_hasLoadedBookmarks = true;
|
||||
}
|
||||
return loaded;
|
||||
}
|
||||
|
||||
void _reload() {
|
||||
setState(() {
|
||||
_bookmarks = context.read<MeshCoreConnector>().loadBookmarkedMessages();
|
||||
_bookmarks = _fetchBookmarks();
|
||||
});
|
||||
}
|
||||
|
||||
bool _matchesInitialSource(
|
||||
BookmarkedMessage bookmark,
|
||||
MeshCoreConnector connector,
|
||||
) {
|
||||
final sourceId = widget.initialSourceId;
|
||||
if (sourceId == null) return true;
|
||||
if (widget.initialSourceType != null &&
|
||||
bookmark.sourceType != widget.initialSourceType) {
|
||||
return false;
|
||||
}
|
||||
final validIds = <String>{sourceId, ...widget.sourceIdAliases};
|
||||
if (bookmark.sourceType == BookmarkSourceType.channel) {
|
||||
for (final channel in connector.channels) {
|
||||
final slotId = 'slot:${channel.index}';
|
||||
final storageId = channel.storageId;
|
||||
if (validIds.contains(slotId) ||
|
||||
(storageId != null && validIds.contains(storageId))) {
|
||||
validIds.add(slotId);
|
||||
if (storageId != null) validIds.add(storageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
return validIds.contains(bookmark.sourceId);
|
||||
}
|
||||
|
||||
List<BookmarkedMessage> _filteredBookmarks(
|
||||
List<BookmarkedMessage> all,
|
||||
MeshCoreConnector connector,
|
||||
) {
|
||||
final filtered = [
|
||||
for (final bookmark in all)
|
||||
if (!_hasInitialSource ||
|
||||
!_filterToInitialSource ||
|
||||
_matchesInitialSource(bookmark, connector))
|
||||
bookmark,
|
||||
];
|
||||
filtered.sort((a, b) => a.receivedAt.compareTo(b.receivedAt));
|
||||
return filtered;
|
||||
}
|
||||
|
||||
void _openSearch() => setState(() => _searching = true);
|
||||
|
||||
void _closeSearch() {
|
||||
_searchController.clear();
|
||||
setState(() {
|
||||
_searching = false;
|
||||
_searchQuery = '';
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildSearchField() {
|
||||
return CallbackShortcuts(
|
||||
bindings: {
|
||||
const SingleActivator(LogicalKeyboardKey.escape): _closeSearch,
|
||||
},
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
autofocus: true,
|
||||
textInputAction: TextInputAction.search,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
decoration: InputDecoration(
|
||||
hintText: context.l10n.chatSearch_hint,
|
||||
border: InputBorder.none,
|
||||
),
|
||||
onChanged: (value) => setState(() => _searchQuery = value),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<ChatSearchEntry>> _loadSearchEntries() async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final all = await connector.loadBookmarkedMessages();
|
||||
if (mounted) {
|
||||
_loadedBookmarks = all;
|
||||
_hasLoadedBookmarks = true;
|
||||
}
|
||||
final visible = _filteredBookmarks(all, connector);
|
||||
return [
|
||||
for (final bookmark in visible)
|
||||
ChatSearchEntry(
|
||||
id: bookmark.storageId,
|
||||
sender: '${bookmark.senderName} · ${bookmark.sourceName}',
|
||||
text: bookmark.text,
|
||||
translatedText: bookmark.translatedText,
|
||||
time: bookmark.receivedAt,
|
||||
matchSender: true,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
Future<void> _jumpToSearchResult(String storageId) async {
|
||||
FocusScope.of(context).unfocus();
|
||||
_closeSearch();
|
||||
await _bookmarks;
|
||||
if (!mounted) return;
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
for (var i = 0; i < 5 && mounted && !_scrollController.hasClients; i++) {
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
}
|
||||
if (!mounted) return;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final visible = _filteredBookmarks(_loadedBookmarks, connector);
|
||||
final index = visible.indexWhere((b) => b.storageId == storageId);
|
||||
if (index < 0) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.chatSearch_jumpFailed),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final targetIndex = visible.length - 1 - index;
|
||||
if (_scrollController.hasClients) {
|
||||
await scrollListToIndex(
|
||||
controller: _scrollController,
|
||||
targetIndex: targetIndex,
|
||||
itemCount: visible.length,
|
||||
isMounted: () => mounted,
|
||||
);
|
||||
}
|
||||
if (!mounted) return;
|
||||
_highlightTimer?.cancel();
|
||||
setState(() => _highlightedStorageId = storageId);
|
||||
_highlightTimer = Timer(const Duration(seconds: 2), () {
|
||||
if (mounted) setState(() => _highlightedStorageId = null);
|
||||
});
|
||||
}
|
||||
|
||||
void _toggleSelected(BookmarkedMessage bookmark) {
|
||||
HapticFeedback.selectionClick();
|
||||
setState(() {
|
||||
if (!_selectedIds.remove(bookmark.storageId)) {
|
||||
_selectedIds.add(bookmark.storageId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _clearSelection() => setState(_selectedIds.clear);
|
||||
|
||||
Future<void> _remove(BookmarkedMessage bookmark) async {
|
||||
final confirmed = await confirmRemoveBookmarks(context);
|
||||
if (!confirmed || !mounted) return;
|
||||
await context.read<MeshCoreConnector>().setBookmarkedMessage(
|
||||
bookmark,
|
||||
isBookmarked: false,
|
||||
);
|
||||
if (!mounted) return;
|
||||
_selectedIds.remove(bookmark.storageId);
|
||||
_reload();
|
||||
}
|
||||
|
||||
Future<void> _removeSelected() async {
|
||||
if (_selectedIds.isEmpty) return;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final visible = _filteredBookmarks(_loadedBookmarks, connector);
|
||||
final toRemove = [
|
||||
for (final bookmark in visible)
|
||||
if (_selectedIds.contains(bookmark.storageId)) bookmark,
|
||||
];
|
||||
final count = toRemove.isNotEmpty ? toRemove.length : _selectedIds.length;
|
||||
final confirmed = await confirmRemoveBookmarks(context, count: count);
|
||||
if (!confirmed || !mounted) return;
|
||||
final targets = toRemove.isNotEmpty
|
||||
? toRemove
|
||||
: [
|
||||
for (final bookmark in _loadedBookmarks)
|
||||
if (_selectedIds.contains(bookmark.storageId)) bookmark,
|
||||
];
|
||||
_clearSelection();
|
||||
for (final bookmark in targets) {
|
||||
await connector.setBookmarkedMessage(bookmark, isBookmarked: false);
|
||||
}
|
||||
if (mounted) _reload();
|
||||
}
|
||||
|
||||
PreferredSizeWidget _buildSelectionAppBar(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return AppBar(
|
||||
leading: IconButton(
|
||||
tooltip: l10n.chat_clearSelection,
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: _clearSelection,
|
||||
),
|
||||
title: Text(l10n.chat_selectedCount(_selectedIds.length)),
|
||||
centerTitle: false,
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: l10n.bookmarks_remove,
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
onPressed: _selectedIds.isEmpty ? null : _removeSelected,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildScopePill(BuildContext context) {
|
||||
final sourceLabel =
|
||||
(widget.initialSourceName != null &&
|
||||
widget.initialSourceName!.trim().isNotEmpty)
|
||||
? widget.initialSourceName!
|
||||
: widget.initialSourceId!;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: SegmentedButton<bool>(
|
||||
showSelectedIcon: false,
|
||||
style: SegmentedButton.styleFrom(
|
||||
minimumSize: const Size(48, 48),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.pill),
|
||||
),
|
||||
),
|
||||
segments: [
|
||||
ButtonSegment<bool>(
|
||||
value: false,
|
||||
label: MeshSegmentLabel(context.l10n.listFilter_all),
|
||||
),
|
||||
ButtonSegment<bool>(
|
||||
value: true,
|
||||
label: MeshSegmentLabel(sourceLabel),
|
||||
),
|
||||
],
|
||||
selected: {_filterToInitialSource},
|
||||
onSelectionChanged: (selection) {
|
||||
setState(() {
|
||||
_filterToInitialSource = selection.first;
|
||||
_selectedIds.clear();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSelectableRow(BookmarkedMessage bookmark, Widget cardBody) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final selected = _selectedIds.contains(bookmark.storageId);
|
||||
return Semantics(
|
||||
selected: selected,
|
||||
button: true,
|
||||
child: Material(
|
||||
color: selected
|
||||
? scheme.primary.withValues(alpha: 0.16)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
onTap: () => _toggleSelected(bookmark),
|
||||
onLongPress: () => _toggleSelected(bookmark),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
selected ? Icons.check_circle : Icons.radio_button_unchecked,
|
||||
size: 28,
|
||||
color: selected ? scheme.primary : scheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: AbsorbPointer(child: cardBody)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final publicIpfsGateway = context
|
||||
.watch<AppSettingsService>()
|
||||
.settings
|
||||
.publicIpfsGateway;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(l10n.bookmarks_title), centerTitle: true),
|
||||
body: FutureBuilder<List<BookmarkedMessage>>(
|
||||
future: _bookmarks,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final bookmarks = snapshot.data ?? const <BookmarkedMessage>[];
|
||||
if (bookmarks.isEmpty) {
|
||||
return EmptyState(
|
||||
icon: Icons.bookmark_border,
|
||||
title: l10n.bookmarks_empty,
|
||||
);
|
||||
}
|
||||
bookmarks.sort((a, b) => a.receivedAt.compareTo(b.receivedAt));
|
||||
return ListView.builder(
|
||||
reverse: true,
|
||||
padding: const EdgeInsets.all(12),
|
||||
itemCount: bookmarks.length,
|
||||
itemBuilder: (context, index) {
|
||||
final bookmark = bookmarks[bookmarks.length - 1 - index];
|
||||
final sourceType =
|
||||
bookmark.sourceType == BookmarkSourceType.channel
|
||||
? l10n.bookmarks_channel
|
||||
: l10n.bookmarks_contact;
|
||||
final receivedAt = bookmark.receivedAt.toLocal();
|
||||
final localizations = MaterialLocalizations.of(context);
|
||||
final time = localizations.formatTimeOfDay(
|
||||
TimeOfDay.fromDateTime(receivedAt),
|
||||
alwaysUse24HourFormat: MediaQuery.alwaysUse24HourFormatOf(
|
||||
context,
|
||||
),
|
||||
);
|
||||
final dateTime =
|
||||
'${localizations.formatShortDate(receivedAt)} $time';
|
||||
final translation = bookmark.translatedText?.trim();
|
||||
final displayText = translation?.isNotEmpty == true
|
||||
? translation!
|
||||
: bookmark.text;
|
||||
final textStyle =
|
||||
Theme.of(context).textTheme.bodyMedium ?? const TextStyle();
|
||||
final textContent = TranslatedMessageContent(
|
||||
displayText: displayText,
|
||||
originalText: displayText == bookmark.text
|
||||
final publicIpfsGateway =
|
||||
context.watch<AppSettingsService?>()?.settings.publicIpfsGateway ?? '';
|
||||
final textScale = context.watch<ChatTextScaleService?>()?.scale ?? 1.0;
|
||||
|
||||
return PopScope(
|
||||
canPop: !_searching && !_selecting,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (didPop) return;
|
||||
if (_selecting) {
|
||||
_clearSelection();
|
||||
} else if (_searching) {
|
||||
_closeSearch();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: _selecting
|
||||
? _buildSelectionAppBar(context)
|
||||
: AppBar(
|
||||
leading: _searching
|
||||
? IconButton(
|
||||
tooltip: l10n.chatSearch_close,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: _closeSearch,
|
||||
)
|
||||
: null,
|
||||
title: _searching
|
||||
? _buildSearchField()
|
||||
: Text(l10n.bookmarks_title),
|
||||
centerTitle: !_searching,
|
||||
actions: _searching
|
||||
? null
|
||||
: 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),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 8, 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(top: 2, right: 8),
|
||||
child: Icon(
|
||||
Icons.bookmark,
|
||||
size: 20,
|
||||
color: Color(0xFFFFE54A),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'$sourceType · ${bookmark.sourceName}',
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
: [
|
||||
IconButton(
|
||||
tooltip: l10n.chatSearch_tooltip,
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: _openSearch,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
if (_hasInitialSource) _buildScopePill(context),
|
||||
Expanded(
|
||||
child: _showSearchResults
|
||||
? ChatSearchResults(
|
||||
key: ValueKey<bool>(_filterToInitialSource),
|
||||
query: _searchQuery.trim(),
|
||||
loadEntries: _loadSearchEntries,
|
||||
textScale: textScale,
|
||||
onSelect: (entry) =>
|
||||
unawaited(_jumpToSearchResult(entry.id)),
|
||||
)
|
||||
: FutureBuilder<List<BookmarkedMessage>>(
|
||||
future: _bookmarks,
|
||||
initialData: _hasLoadedBookmarks
|
||||
? _loadedBookmarks
|
||||
: null,
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData &&
|
||||
snapshot.connectionState != ConnectionState.done) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final allBookmarks =
|
||||
snapshot.data ?? const <BookmarkedMessage>[];
|
||||
_loadedBookmarks = allBookmarks;
|
||||
_hasLoadedBookmarks = true;
|
||||
final bookmarks = _filteredBookmarks(
|
||||
allBookmarks,
|
||||
connector,
|
||||
);
|
||||
if (bookmarks.isEmpty) {
|
||||
return EmptyState(
|
||||
icon: Icons.bookmark_border,
|
||||
title: l10n.bookmarks_empty,
|
||||
);
|
||||
}
|
||||
return ListView.builder(
|
||||
controller: _scrollController,
|
||||
reverse: true,
|
||||
padding: const EdgeInsets.all(12),
|
||||
itemCount: bookmarks.length,
|
||||
itemBuilder: (context, index) {
|
||||
final bookmark =
|
||||
bookmarks[bookmarks.length - 1 - index];
|
||||
final sourceType =
|
||||
bookmark.sourceType ==
|
||||
BookmarkSourceType.channel
|
||||
? l10n.bookmarks_channel
|
||||
: l10n.bookmarks_contact;
|
||||
final receivedAt = bookmark.receivedAt.toLocal();
|
||||
final localizations = MaterialLocalizations.of(
|
||||
context,
|
||||
);
|
||||
final time = localizations.formatTimeOfDay(
|
||||
TimeOfDay.fromDateTime(receivedAt),
|
||||
alwaysUse24HourFormat:
|
||||
MediaQuery.alwaysUse24HourFormatOf(context),
|
||||
);
|
||||
final dateTime =
|
||||
'${localizations.formatShortDate(receivedAt)} $time';
|
||||
final translation = bookmark.translatedText?.trim();
|
||||
final displayText = translation?.isNotEmpty == true
|
||||
? translation!
|
||||
: bookmark.text;
|
||||
final textStyle =
|
||||
Theme.of(context).textTheme.bodyMedium ??
|
||||
const TextStyle();
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final baseCardColor =
|
||||
Theme.of(context).cardTheme.color ??
|
||||
scheme.surfaceContainerLow;
|
||||
final highlighted =
|
||||
bookmark.storageId == _highlightedStorageId;
|
||||
final cardColor = highlighted
|
||||
? Color.alphaBlend(
|
||||
scheme.primary.withValues(alpha: 0.18),
|
||||
baseCardColor,
|
||||
)
|
||||
: baseCardColor;
|
||||
final textContent = TranslatedMessageContent(
|
||||
displayText: displayText,
|
||||
originalText: displayText == bookmark.text
|
||||
? null
|
||||
: bookmark.text,
|
||||
style: textStyle,
|
||||
originalStyle: textStyle.copyWith(
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
backgroundColor: cardColor,
|
||||
selectable: false,
|
||||
);
|
||||
final card = Card(
|
||||
margin: EdgeInsets.zero,
|
||||
color: cardColor,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(
|
||||
MeshRadii.md,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'${bookmark.senderName} · $dateTime',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.common_copy,
|
||||
onPressed: () =>
|
||||
copyChatMessageText(context, bookmark.text),
|
||||
icon: const Icon(Icons.copy),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.bookmarks_remove,
|
||||
onPressed: () => _remove(bookmark),
|
||||
icon: const Icon(Icons.bookmark_remove_outlined),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (MessageUrlImageHelper.hasPotentialImageUrl(
|
||||
bookmark.text,
|
||||
))
|
||||
MessageUrlImageFutureBuilder(
|
||||
messageId: bookmark.messageId,
|
||||
text: bookmark.text,
|
||||
publicGateway: publicIpfsGateway,
|
||||
builder: (context, snapshot) {
|
||||
final imageUrl = snapshot.data;
|
||||
if (imageUrl == null) return textContent;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: MessageUrlImagePreview(
|
||||
imageUrl: imageUrl,
|
||||
onLongPress: _selecting
|
||||
? null
|
||||
: () => _toggleSelected(bookmark),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
16,
|
||||
12,
|
||||
8,
|
||||
12,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: 2,
|
||||
right: 8,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.bookmark,
|
||||
size: 20,
|
||||
color: Color(0xFFFFE54A),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'$sourceType · ${bookmark.sourceName}',
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleSmall,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'${bookmark.senderName} · $dateTime',
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.common_copy,
|
||||
onPressed: () =>
|
||||
copyChatMessageText(
|
||||
context,
|
||||
bookmark.text,
|
||||
),
|
||||
icon: const Icon(Icons.copy),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.bookmarks_remove,
|
||||
onPressed: () => _remove(bookmark),
|
||||
icon: const Icon(
|
||||
Icons.bookmark_remove_outlined,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (MessageUrlImageHelper.hasPotentialImageUrl(
|
||||
bookmark.text,
|
||||
))
|
||||
MessageUrlImageFutureBuilder(
|
||||
messageId: bookmark.messageId,
|
||||
text: bookmark.text,
|
||||
publicGateway: publicIpfsGateway,
|
||||
builder: (context, snapshot) {
|
||||
final imageUrl = snapshot.data;
|
||||
if (imageUrl == null) {
|
||||
return textContent;
|
||||
}
|
||||
return Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(
|
||||
bottom: 8,
|
||||
),
|
||||
child: MessageUrlImagePreview(
|
||||
imageUrl: imageUrl,
|
||||
),
|
||||
),
|
||||
textContent,
|
||||
],
|
||||
);
|
||||
},
|
||||
)
|
||||
else
|
||||
textContent,
|
||||
],
|
||||
),
|
||||
),
|
||||
textContent,
|
||||
],
|
||||
),
|
||||
);
|
||||
final highlightedCard = highlighted
|
||||
? AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.primary.withValues(
|
||||
alpha: 0.18,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(
|
||||
MeshRadii.md,
|
||||
),
|
||||
),
|
||||
child: card,
|
||||
)
|
||||
: card;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: _selecting
|
||||
? _buildSelectableRow(
|
||||
bookmark,
|
||||
highlightedCard,
|
||||
)
|
||||
: highlightedCard,
|
||||
);
|
||||
},
|
||||
)
|
||||
else
|
||||
textContent,
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ 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';
|
||||
@@ -77,7 +76,9 @@ import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/share_contact_sheet.dart';
|
||||
import '../widgets/shared_contact_card.dart';
|
||||
import 'app_settings_screen.dart';
|
||||
import 'bookmarks_screen.dart';
|
||||
import 'channel_chat_transcript_grouping.dart';
|
||||
import 'chat_compression_screen.dart';
|
||||
import 'channels_screen.dart' show confirmDeleteChannel, showEditChannelSheet;
|
||||
import 'channel_message_path_screen.dart';
|
||||
import 'map_screen.dart';
|
||||
@@ -180,7 +181,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
/// Message ids picked for a bulk action. Non-empty means selection mode:
|
||||
/// taps toggle messages and the app bar shows the bulk actions.
|
||||
final Set<String> _selectedIds = <String>{};
|
||||
bool _showBookmarkedOnly = false;
|
||||
bool get _selecting => _selectedIds.isNotEmpty;
|
||||
|
||||
@override
|
||||
@@ -601,6 +601,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
_toggleChannelFiltering();
|
||||
case 'notifications':
|
||||
showChannelNotificationModeSheet(context, muteKey);
|
||||
case 'compression':
|
||||
_openCompressionScreen();
|
||||
case 'region':
|
||||
openRegionSelectDialog(widget.channel);
|
||||
case 'editChannel':
|
||||
@@ -611,10 +613,27 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
onSaved: _onChannelEdited,
|
||||
);
|
||||
case 'showBookmarks':
|
||||
setState(() {
|
||||
_showBookmarkedOnly = !_showBookmarkedOnly;
|
||||
_selectedIds.clear();
|
||||
});
|
||||
final channelLabel = widget.channel.name.isEmpty
|
||||
? '#${context.l10n.channels_channelIndex(widget.channel.index)}'
|
||||
: (widget.channel.name.startsWith('#')
|
||||
? widget.channel.name
|
||||
: '#${widget.channel.name}');
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => BookmarksScreen(
|
||||
initialSourceType: BookmarkSourceType.channel,
|
||||
initialSourceId:
|
||||
widget.channel.storageId ??
|
||||
'slot:${widget.channel.index}',
|
||||
sourceIdAliases: [
|
||||
?widget.channel.storageId,
|
||||
'slot:${widget.channel.index}',
|
||||
],
|
||||
initialSourceName: channelLabel,
|
||||
),
|
||||
),
|
||||
);
|
||||
case 'background':
|
||||
showChatBackgroundSheet(
|
||||
context,
|
||||
@@ -658,6 +677,20 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'compression',
|
||||
child: _menuRow(
|
||||
Icons.compress,
|
||||
context.l10n.chatCompression_label(
|
||||
chatCompressionModeLabel(
|
||||
context,
|
||||
context.read<MeshCoreConnector>().channelCompressionMode(
|
||||
widget.channel.index,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'region',
|
||||
child: _menuRow(
|
||||
@@ -673,9 +706,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
PopupMenuItem(
|
||||
value: 'showBookmarks',
|
||||
child: _menuRow(
|
||||
_showBookmarkedOnly ? Icons.bookmark : Icons.bookmark_border,
|
||||
context.l10n.chat_showBookmarks,
|
||||
color: _showBookmarkedOnly ? const Color(0xFFFFE54A) : null,
|
||||
Icons.bookmark_border,
|
||||
context.l10n.bookmarks_title,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
@@ -882,7 +914,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
bottom: false,
|
||||
child: Column(
|
||||
children: [
|
||||
_buildCompressionSelector(),
|
||||
Expanded(
|
||||
child: ChatBackdrop(
|
||||
contentKey: _messageAreaKey,
|
||||
@@ -910,22 +941,13 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
final layout = _transcriptLayoutFor(
|
||||
context,
|
||||
messages,
|
||||
showBookmarkedOnly: _showBookmarkedOnly,
|
||||
);
|
||||
// Fewer entries than messages means the message filter
|
||||
// hid or collapsed some; bookmark filtering is deliberate.
|
||||
final hidesMessages =
|
||||
!_showBookmarkedOnly &&
|
||||
layout.length < messages.length;
|
||||
// hid or collapsed some.
|
||||
final hidesMessages = layout.length < messages.length;
|
||||
if (hidesMessages) _scheduleHiddenHistoryBackfill();
|
||||
|
||||
if (layout.length == 0) {
|
||||
if (_showBookmarkedOnly) {
|
||||
return EmptyState(
|
||||
icon: Icons.bookmark_border,
|
||||
title: context.l10n.bookmarks_empty,
|
||||
);
|
||||
}
|
||||
final canLoadOlder =
|
||||
hidesMessages && !_olderHistoryExhausted;
|
||||
return EmptyState(
|
||||
@@ -987,6 +1009,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
return Stack(
|
||||
children: [
|
||||
ChatZoomWrapper(
|
||||
enabled: !_selecting,
|
||||
child: ListView.builder(
|
||||
reverse: true, // List grows from bottom up
|
||||
controller: _scrollController,
|
||||
@@ -1016,14 +1039,19 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
);
|
||||
}
|
||||
final row = layout.rowAt(index, messages);
|
||||
final GlobalKey messageKey;
|
||||
// Duplicate-id rows use a stable value key
|
||||
// (not a fresh GlobalKey) so toggling one
|
||||
// row does not remount every visible row.
|
||||
final Key messageKey;
|
||||
if (layout.keyedIndices.contains(index)) {
|
||||
messageKey = _messageKeys.putIfAbsent(
|
||||
row.id,
|
||||
GlobalKey.new,
|
||||
);
|
||||
} else {
|
||||
messageKey = GlobalKey();
|
||||
messageKey = ValueKey<String>(
|
||||
'${row.id}#dup$index',
|
||||
);
|
||||
}
|
||||
final dividerId = _unreadDividerMessageId;
|
||||
final isUnreadAnchor =
|
||||
@@ -1271,7 +1299,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
: null,
|
||||
child: MessageBubbleFrame(
|
||||
isOutgoing: isOutgoing,
|
||||
isBookmarked: message.isBookmarked || _showBookmarkedOnly,
|
||||
isBookmarked: message.isBookmarked,
|
||||
compact: gifId != null,
|
||||
maxWidth: constraints.maxWidth,
|
||||
child: Column(
|
||||
@@ -2317,9 +2345,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
/// `State`'s) — `watch` asserts on that.
|
||||
_TranscriptLayout _transcriptLayoutFor(
|
||||
BuildContext context,
|
||||
List<ChannelMessage> messages, {
|
||||
bool showBookmarkedOnly = false,
|
||||
}) {
|
||||
List<ChannelMessage> messages,
|
||||
) {
|
||||
ReceivedImageStore? store;
|
||||
try {
|
||||
store = context.watch<ReceivedImageStore>();
|
||||
@@ -2348,7 +2375,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
displayMode,
|
||||
filterActive,
|
||||
_revealVersion,
|
||||
showBookmarkedOnly,
|
||||
_filteredMessagesSignature(messages),
|
||||
Object.hashAll(
|
||||
messages
|
||||
@@ -2357,8 +2383,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
),
|
||||
);
|
||||
final cached = _transcriptLayout;
|
||||
if (!showBookmarkedOnly &&
|
||||
cached != null &&
|
||||
if (cached != null &&
|
||||
cached.matches(
|
||||
messages,
|
||||
_imageStoreVersion,
|
||||
@@ -2367,14 +2392,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
)) {
|
||||
return cached;
|
||||
}
|
||||
final displayedMessages = showBookmarkedOnly
|
||||
? messages.where((message) => message.isBookmarked).toList()
|
||||
: messages;
|
||||
final images = store == null || showBookmarkedOnly
|
||||
final images = store == null
|
||||
? const <ReceivedImageEntry>[]
|
||||
: store.entriesForChannel(widget.channel.storageId);
|
||||
final layout = _TranscriptLayout.build(
|
||||
messages: displayedMessages,
|
||||
messages: messages,
|
||||
images: images,
|
||||
imageVersion: _imageStoreVersion,
|
||||
channelIndex: widget.channel.index,
|
||||
@@ -2836,26 +2858,35 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
/// 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() {
|
||||
void _openCompressionScreen() {
|
||||
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,
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final settingsService = context.read<AppSettingsService>();
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChatCompressionScreen(
|
||||
listenable: Listenable.merge([connector, settingsService]),
|
||||
read: () {
|
||||
final hasStorageId = connector.channelIdForSlot(slot) != null;
|
||||
return ChatCompressionState(
|
||||
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),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3220,8 +3251,14 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
? context.l10n.chat_removeBookmark
|
||||
: context.l10n.chat_bookmark,
|
||||
),
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final selfLabel = connector.selfName ?? context.l10n.chat_me;
|
||||
Navigator.pop(sheetContext);
|
||||
if (message.isBookmarked) {
|
||||
final confirmed = await confirmRemoveBookmarks(context);
|
||||
if (!confirmed || !mounted) return;
|
||||
}
|
||||
final bookmark = BookmarkedMessage.fromChannel(
|
||||
message: message,
|
||||
channelId:
|
||||
@@ -3229,15 +3266,12 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
'slot:${widget.channel.index}',
|
||||
channelName: widget.channel.name,
|
||||
senderName: message.isOutgoing
|
||||
? (context.read<MeshCoreConnector>().selfName ??
|
||||
context.l10n.chat_me)
|
||||
? selfLabel
|
||||
: message.senderName,
|
||||
);
|
||||
unawaited(
|
||||
context.read<MeshCoreConnector>().setBookmarkedMessage(
|
||||
bookmark,
|
||||
isBookmarked: !message.isBookmarked,
|
||||
),
|
||||
await connector.setBookmarkedMessage(
|
||||
bookmark,
|
||||
isBookmarked: !message.isBookmarked,
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -3341,10 +3375,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
final filterActive = _transcriptLayout?.filterActive ?? true;
|
||||
return [
|
||||
for (final m in messages)
|
||||
if ((!_showBookmarkedOnly || m.isBookmarked) &&
|
||||
!(filterActive &&
|
||||
m.isFiltered &&
|
||||
!_revealedFilteredIds.contains(m.messageId)))
|
||||
if (!(filterActive &&
|
||||
m.isFiltered &&
|
||||
!_revealedFilteredIds.contains(m.messageId)))
|
||||
m,
|
||||
];
|
||||
}
|
||||
@@ -3423,6 +3456,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
icon: const Icon(Icons.visibility_outlined),
|
||||
onPressed: () => _bulkMarkNotSpam(notSpamCandidates),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.chat_bookmark,
|
||||
icon: const Icon(Icons.bookmark_add_outlined),
|
||||
onPressed: selected.isEmpty ? null : () => _bulkBookmark(selected),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.common_delete,
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
@@ -3497,6 +3535,25 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
showDismissibleSnackBar(context, content: Text(text));
|
||||
}
|
||||
|
||||
Future<void> _bulkBookmark(List<ChannelMessage> messages) async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final selfLabel = connector.selfName ?? context.l10n.chat_me;
|
||||
final channelId =
|
||||
widget.channel.storageId ?? 'slot:${widget.channel.index}';
|
||||
final channelName = widget.channel.name;
|
||||
final toBookmark = messages.where((m) => !m.isBookmarked).toList();
|
||||
_clearSelection();
|
||||
for (final message in toBookmark) {
|
||||
final bookmark = BookmarkedMessage.fromChannel(
|
||||
message: message,
|
||||
channelId: channelId,
|
||||
channelName: channelName,
|
||||
senderName: message.isOutgoing ? selfLabel : message.senderName,
|
||||
);
|
||||
await connector.setBookmarkedMessage(bookmark, isBookmarked: true);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _bulkDelete(List<ChannelMessage> messages) async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final confirmed = await confirmBulkDelete(context, messages.length);
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/app_settings.dart';
|
||||
import '../models/chat_compression_mode.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/mesh_nav_tile.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
|
||||
export '../models/chat_compression_mode.dart';
|
||||
|
||||
String chatCompressionModeLabel(BuildContext context, ChatCompressionMode m) {
|
||||
final l10n = context.l10n;
|
||||
return switch (m) {
|
||||
ChatCompressionMode.off => l10n.chatCompression_off,
|
||||
ChatCompressionMode.smaz => l10n.chatCompression_smaz,
|
||||
ChatCompressionMode.cyr2lat => l10n.chatCompression_cyr2lat,
|
||||
};
|
||||
}
|
||||
|
||||
/// What the page shows for one chat, read fresh each time [listenable] fires.
|
||||
class ChatCompressionState {
|
||||
final ChatCompressionMode mode;
|
||||
|
||||
/// False locks the choices; [disabledReason] says why.
|
||||
final bool enabled;
|
||||
final String? disabledReason;
|
||||
|
||||
final List<Cyr2LatProfile> profiles;
|
||||
|
||||
/// The Cyr2Lat profile saved for this chat, if any.
|
||||
final String? profileId;
|
||||
|
||||
/// The app-wide profile, which sending uses when [profileId] is unset or
|
||||
/// no longer exists.
|
||||
final String? defaultProfileId;
|
||||
|
||||
const ChatCompressionState({
|
||||
required this.mode,
|
||||
required this.enabled,
|
||||
this.disabledReason,
|
||||
required this.profiles,
|
||||
required this.profileId,
|
||||
this.defaultProfileId,
|
||||
});
|
||||
|
||||
/// The profile sending actually uses, matching the connector's fallback.
|
||||
String? get effectiveProfileId {
|
||||
bool known(String? id) => profiles.any((p) => p.id == id);
|
||||
if (known(profileId)) return profileId;
|
||||
if (known(defaultProfileId)) return defaultProfileId;
|
||||
return profiles.isEmpty ? null : profiles.first.id;
|
||||
}
|
||||
}
|
||||
|
||||
/// The page behind the chat menu's "Compression: ..." item. Shows the three
|
||||
/// choices with a short note each, plus the Cyr2Lat profile picker.
|
||||
///
|
||||
/// The caller supplies the saved state through [read] (re-read whenever
|
||||
/// [listenable] notifies) and persists changes through the callbacks. A new
|
||||
/// choice shows only once the saved state changes; a callback that throws
|
||||
/// leaves the saved choice in place and shows an error.
|
||||
class ChatCompressionScreen extends StatefulWidget {
|
||||
final Listenable listenable;
|
||||
final ChatCompressionState Function() read;
|
||||
final Future<void> Function(ChatCompressionMode mode) onModeChanged;
|
||||
final Future<void> Function(String profileId) onProfileChanged;
|
||||
|
||||
const ChatCompressionScreen({
|
||||
super.key,
|
||||
required this.listenable,
|
||||
required this.read,
|
||||
required this.onModeChanged,
|
||||
required this.onProfileChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ChatCompressionScreen> createState() => _ChatCompressionScreenState();
|
||||
}
|
||||
|
||||
class _ChatCompressionScreenState extends State<ChatCompressionScreen> {
|
||||
bool _busy = false;
|
||||
bool _failed = false;
|
||||
|
||||
/// Counts failed saves, so the profile picker drops an unsaved choice.
|
||||
int _failures = 0;
|
||||
|
||||
/// Runs one save; a failure keeps the saved state and shows an error.
|
||||
Future<void> _save(Future<void> Function() write) async {
|
||||
if (_busy || !widget.read().enabled) return;
|
||||
setState(() {
|
||||
_busy = true;
|
||||
_failed = false;
|
||||
});
|
||||
var ok = false;
|
||||
try {
|
||||
await write();
|
||||
ok = true;
|
||||
} catch (e) {
|
||||
debugPrint('[ChatCompressionScreen] save failed: $e');
|
||||
}
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_busy = false;
|
||||
_failed = !ok;
|
||||
if (!ok) _failures++;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: AdaptiveAppBarTitle(l10n.chatCompression_title),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
if (_busy)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(14),
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: ListenableBuilder(
|
||||
listenable: widget.listenable,
|
||||
builder: (context, _) => _buildBody(context, widget.read()),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(BuildContext context, ChatCompressionState view) {
|
||||
final l10n = context.l10n;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final canChange = view.enabled && !_busy;
|
||||
|
||||
Widget option(ChatCompressionMode mode, String description) {
|
||||
return MeshSheetOption(
|
||||
label: chatCompressionModeLabel(context, mode),
|
||||
subtitle: description,
|
||||
selected: view.mode == mode,
|
||||
onTap: canChange ? () => _save(() => widget.onModeChanged(mode)) : null,
|
||||
);
|
||||
}
|
||||
|
||||
final profileValue = view.effectiveProfileId;
|
||||
|
||||
return ListView(
|
||||
padding: const EdgeInsets.only(bottom: 24),
|
||||
children: [
|
||||
if (_failed)
|
||||
MeshCard(
|
||||
color: scheme.errorContainer,
|
||||
borderColor: scheme.errorContainer,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.error_outline, color: scheme.onErrorContainer),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.chatCompression_saveFailed,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onErrorContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (!view.enabled && view.disabledReason != null)
|
||||
MeshInfoCard(view.disabledReason!),
|
||||
SectionHeader(
|
||||
l10n.chatCompression_title,
|
||||
description: l10n.chatCompression_sheetSubtitle,
|
||||
),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
option(
|
||||
ChatCompressionMode.off,
|
||||
l10n.chatCompression_offDescription,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
option(
|
||||
ChatCompressionMode.smaz,
|
||||
l10n.chatCompression_smazDescription,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
option(
|
||||
ChatCompressionMode.cyr2lat,
|
||||
l10n.chatCompression_cyr2latDescription,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (view.mode == ChatCompressionMode.cyr2lat &&
|
||||
view.profiles.isNotEmpty) ...[
|
||||
SectionHeader(l10n.chatCompression_profile),
|
||||
MeshCard(
|
||||
child: DropdownButtonFormField<String>(
|
||||
// The field keeps a picked value internally, so rebuild it
|
||||
// with the saved value after a change or a failure.
|
||||
key: ValueKey('$profileValue#$_failures'),
|
||||
isExpanded: true,
|
||||
initialValue: profileValue,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.chatCompression_profile,
|
||||
),
|
||||
items: [
|
||||
for (final profile in view.profiles)
|
||||
DropdownMenuItem(
|
||||
value: profile.id,
|
||||
child: Text(profile.name, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
],
|
||||
onChanged: canChange
|
||||
? (id) {
|
||||
if (id == null || id == profileValue) return;
|
||||
_save(() => widget.onProfileChanged(id));
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
+484
-258
@@ -38,13 +38,14 @@ 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';
|
||||
import '../widgets/reaction_chips.dart';
|
||||
import '../widgets/chat_day_separator.dart';
|
||||
import 'bookmarks_screen.dart';
|
||||
import 'channel_message_path_screen.dart';
|
||||
import 'chat_compression_screen.dart';
|
||||
import 'contacts_screen.dart' show confirmRemoveContact;
|
||||
import 'map_screen.dart';
|
||||
import 'repeater_hub_screen.dart';
|
||||
@@ -99,13 +100,14 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
final _textController = TextEditingController();
|
||||
final _scrollController = ChatScrollController();
|
||||
final _scrollAnchor = ChatScrollAnchor();
|
||||
({String id, bool bookmarksOnly})? _newestRow;
|
||||
String? _newestRowId;
|
||||
final _textFieldFocusNode = FocusNode();
|
||||
bool _focusLostWhileAway = false;
|
||||
bool _focusLostToRoute = false;
|
||||
final GlobalKey _unreadScrollKey = GlobalKey();
|
||||
bool _isLoadingOlder = false;
|
||||
bool _showBookmarkedOnly = false;
|
||||
final Set<String> _selectedIds = <String>{};
|
||||
bool get _selecting => _selectedIds.isNotEmpty;
|
||||
MeshCoreConnector? _connector;
|
||||
Message? _pendingUnreadScrollTarget;
|
||||
String? _unreadDividerMessageId;
|
||||
@@ -417,9 +419,14 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
canPop: !_searching,
|
||||
canPop: !_searching && !_selecting,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop && _searching) _closeSearch();
|
||||
if (didPop) return;
|
||||
if (_selecting) {
|
||||
_clearSelection();
|
||||
} else if (_searching) {
|
||||
_closeSearch();
|
||||
}
|
||||
},
|
||||
child: _buildScaffold(context),
|
||||
);
|
||||
@@ -427,211 +434,243 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
|
||||
Widget _buildScaffold(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: _searching
|
||||
? IconButton(
|
||||
tooltip: context.l10n.chatSearch_close,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: _closeSearch,
|
||||
)
|
||||
: null,
|
||||
title: _searching
|
||||
? _buildSearchField()
|
||||
: Consumer2<PathHistoryService, MeshCoreConnector>(
|
||||
builder: (context, pathService, connector, _) {
|
||||
final contact = _resolveContact(connector);
|
||||
final pathLabel = _currentPathLabel(contact);
|
||||
appBar: _selecting
|
||||
? _buildSelectionAppBar(context)
|
||||
: AppBar(
|
||||
leading: _searching
|
||||
? IconButton(
|
||||
tooltip: context.l10n.chatSearch_close,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: _closeSearch,
|
||||
)
|
||||
: null,
|
||||
title: _searching
|
||||
? _buildSearchField()
|
||||
: Consumer2<PathHistoryService, MeshCoreConnector>(
|
||||
builder: (context, pathService, connector, _) {
|
||||
final contact = _resolveContact(connector);
|
||||
final pathLabel = _currentPathLabel(contact);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
contact.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () =>
|
||||
ContactRoutingSheet.show(context, contact: contact),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
// Follows the chat text size, capped so the two-line
|
||||
// title still fits the app bar.
|
||||
final textScale = context
|
||||
.select<ChatTextScaleService, double>(
|
||||
(service) => service.scale,
|
||||
)
|
||||
.clamp(1.0, 1.3);
|
||||
return Text(
|
||||
pathLabel,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12 * textScale,
|
||||
fontWeight: FontWeight.normal,
|
||||
decoration: TextDecoration.underline,
|
||||
decorationStyle: TextDecorationStyle.dotted,
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
contact.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => ContactRoutingSheet.show(
|
||||
context,
|
||||
contact: contact,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 6,
|
||||
),
|
||||
);
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
// Follows the chat text size, capped so the two-line
|
||||
// title still fits the app bar.
|
||||
final textScale = context
|
||||
.select<ChatTextScaleService, double>(
|
||||
(service) => service.scale,
|
||||
)
|
||||
.clamp(1.0, 1.3);
|
||||
return Text(
|
||||
pathLabel,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12 * textScale,
|
||||
fontWeight: FontWeight.normal,
|
||||
decoration: TextDecoration.underline,
|
||||
decorationStyle:
|
||||
TextDecorationStyle.dotted,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
centerTitle: false,
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
actionsPadding: const EdgeInsetsDirectional.only(end: 4),
|
||||
// While searching the field gets the whole bar; the leading arrow
|
||||
// closes the search.
|
||||
actions: _searching
|
||||
? null
|
||||
: [
|
||||
const RadioStatsIconButton(),
|
||||
IconButton(
|
||||
tooltip: context.l10n.chatSearch_tooltip,
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: _openSearch,
|
||||
),
|
||||
Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, _) {
|
||||
final contact = _resolveContact(connector);
|
||||
final isRoom = contact.type == advTypeRoom;
|
||||
final readOnly = isRadioReadOnly(connector);
|
||||
|
||||
return PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
onSelected: (value) {
|
||||
switch (value) {
|
||||
case 'routing':
|
||||
ContactRoutingSheet.show(
|
||||
context,
|
||||
contact: contact,
|
||||
);
|
||||
case 'info':
|
||||
_showContactInfo(context);
|
||||
case 'compression':
|
||||
_openCompressionScreen();
|
||||
case 'settings':
|
||||
_showContactSettings(context);
|
||||
case 'showBookmarks':
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => BookmarksScreen(
|
||||
initialSourceType:
|
||||
BookmarkSourceType.contact,
|
||||
initialSourceId:
|
||||
widget.contact.publicKeyHex,
|
||||
initialSourceName: contact.name,
|
||||
),
|
||||
),
|
||||
);
|
||||
case 'background':
|
||||
showChatBackgroundSheet(
|
||||
context,
|
||||
ChatBackgroundService.contactKey(contact),
|
||||
);
|
||||
case 'telemetry':
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TelemetryScreen(
|
||||
contact: widget.contact,
|
||||
),
|
||||
),
|
||||
);
|
||||
case 'roomManagement':
|
||||
_showRoomManagementLogin(contact);
|
||||
case 'clearChat':
|
||||
_confirmClearChat(context, connector);
|
||||
case 'removeContact':
|
||||
confirmRemoveContact(
|
||||
context,
|
||||
connector,
|
||||
contact,
|
||||
onRemoved: () {
|
||||
if (mounted) Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
value: 'routing',
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.route,
|
||||
label: context.l10n.routing_title,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'info',
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.info_outline,
|
||||
label: context.l10n.contact_info,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'telemetry',
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.bar_chart,
|
||||
label: context.l10n.contact_telemetry,
|
||||
),
|
||||
),
|
||||
if (isRoom)
|
||||
PopupMenuItem(
|
||||
value: 'roomManagement',
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.room_preferences,
|
||||
label: context.l10n.room_management,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'compression',
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.compress,
|
||||
label: context.l10n.chatCompression_label(
|
||||
chatCompressionModeLabel(
|
||||
context,
|
||||
connector.contactCompressionMode(
|
||||
widget.contact.publicKeyHex,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'settings',
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.settings,
|
||||
label: context.l10n.contact_settings,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'showBookmarks',
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.bookmark_border,
|
||||
label: context.l10n.bookmarks_title,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'background',
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.wallpaper,
|
||||
label: context.l10n.chatBackground_title,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'clearChat',
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.delete,
|
||||
label: context.l10n.contact_clearChat,
|
||||
color: readOnly
|
||||
? null
|
||||
: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'removeContact',
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.person_remove,
|
||||
label:
|
||||
context.l10n.contacts_removeFromContacts,
|
||||
color: readOnly
|
||||
? null
|
||||
: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
centerTitle: false,
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
actionsPadding: const EdgeInsetsDirectional.only(end: 4),
|
||||
// While searching the field gets the whole bar; the leading arrow
|
||||
// closes the search.
|
||||
actions: _searching
|
||||
? null
|
||||
: [
|
||||
const RadioStatsIconButton(),
|
||||
IconButton(
|
||||
tooltip: context.l10n.chatSearch_tooltip,
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: _openSearch,
|
||||
),
|
||||
Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, _) {
|
||||
final contact = _resolveContact(connector);
|
||||
final isRoom = contact.type == advTypeRoom;
|
||||
final readOnly = isRadioReadOnly(connector);
|
||||
|
||||
return PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
onSelected: (value) {
|
||||
switch (value) {
|
||||
case 'routing':
|
||||
ContactRoutingSheet.show(context, contact: contact);
|
||||
case 'info':
|
||||
_showContactInfo(context);
|
||||
case 'settings':
|
||||
_showContactSettings(context);
|
||||
case 'showBookmarks':
|
||||
setState(
|
||||
() => _showBookmarkedOnly = !_showBookmarkedOnly,
|
||||
);
|
||||
case 'background':
|
||||
showChatBackgroundSheet(
|
||||
context,
|
||||
ChatBackgroundService.contactKey(contact),
|
||||
);
|
||||
case 'telemetry':
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
TelemetryScreen(contact: widget.contact),
|
||||
),
|
||||
);
|
||||
case 'roomManagement':
|
||||
_showRoomManagementLogin(contact);
|
||||
case 'clearChat':
|
||||
_confirmClearChat(context, connector);
|
||||
case 'removeContact':
|
||||
confirmRemoveContact(
|
||||
context,
|
||||
connector,
|
||||
contact,
|
||||
onRemoved: () {
|
||||
if (mounted) Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
value: 'routing',
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.route,
|
||||
label: context.l10n.routing_title,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'info',
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.info_outline,
|
||||
label: context.l10n.contact_info,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'telemetry',
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.bar_chart,
|
||||
label: context.l10n.contact_telemetry,
|
||||
),
|
||||
),
|
||||
if (isRoom)
|
||||
PopupMenuItem(
|
||||
value: 'roomManagement',
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.room_preferences,
|
||||
label: context.l10n.room_management,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'settings',
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.settings,
|
||||
label: context.l10n.contact_settings,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'showBookmarks',
|
||||
child: MeshMenuItemRow(
|
||||
icon: _showBookmarkedOnly
|
||||
? Icons.bookmark
|
||||
: Icons.bookmark_border,
|
||||
label: context.l10n.chat_showBookmarks,
|
||||
color: _showBookmarkedOnly
|
||||
? const Color(0xFFFFE54A)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'background',
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.wallpaper,
|
||||
label: context.l10n.chatBackground_title,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'clearChat',
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.delete,
|
||||
label: context.l10n.contact_clearChat,
|
||||
color: readOnly
|
||||
? null
|
||||
: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'removeContact',
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.person_remove,
|
||||
label: context.l10n.contacts_removeFromContacts,
|
||||
color: readOnly
|
||||
? null
|
||||
: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: _showSearchResults
|
||||
? _buildSearchResults(_loadSearchEntries)
|
||||
: Consumer<MeshCoreConnector>(
|
||||
@@ -650,7 +689,6 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
);
|
||||
return Column(
|
||||
children: [
|
||||
_buildCompressionSelector(connector),
|
||||
Expanded(
|
||||
child: ChatBackdrop(
|
||||
contentKey: _messageAreaKey,
|
||||
@@ -679,27 +717,32 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
|
||||
/// Compression is stored on this phone per contact, so it can change
|
||||
/// while the radio is offline.
|
||||
Widget _buildCompressionSelector(MeshCoreConnector connector) {
|
||||
void _openCompressionScreen() {
|
||||
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,
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final settingsService = context.read<AppSettingsService>();
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChatCompressionScreen(
|
||||
listenable: Listenable.merge([connector, settingsService]),
|
||||
read: () => ChatCompressionState(
|
||||
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(
|
||||
icon: Icons.chat_bubble_outline,
|
||||
title: context.l10n.chat_noMessages,
|
||||
@@ -709,40 +752,25 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBookmarkEmptyState() => EmptyState(
|
||||
icon: Icons.bookmark_border,
|
||||
title: context.l10n.bookmarks_empty,
|
||||
);
|
||||
|
||||
Widget _buildMessageList(
|
||||
List<Message> messages,
|
||||
MeshCoreConnector connector,
|
||||
) {
|
||||
final visibleMessages = _showBookmarkedOnly
|
||||
? messages.where((message) => message.isBookmarked).toList()
|
||||
: messages;
|
||||
if (_showBookmarkedOnly && visibleMessages.isEmpty) {
|
||||
return _buildBookmarkEmptyState();
|
||||
}
|
||||
// Reverse messages so newest appear at bottom with reverse: true
|
||||
final reversedMessages = visibleMessages.reversed.toList();
|
||||
final reversedMessages = messages.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 &&
|
||||
final previousId = _newestRowId;
|
||||
final newestId = reversedMessages.first.messageId;
|
||||
_newestRowId = newestId;
|
||||
if (previousId != null &&
|
||||
previousId != newestId &&
|
||||
_pendingUnreadScrollTarget == null &&
|
||||
_scrollController.showJumpToBottom.value) {
|
||||
final inserted = reversedMessages.indexWhere(
|
||||
(m) => m.messageId == previous.id,
|
||||
(m) => m.messageId == previousId,
|
||||
);
|
||||
if (inserted > 0) _scrollAnchor.rowsInsertedBelow(inserted);
|
||||
}
|
||||
@@ -761,6 +789,7 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
});
|
||||
|
||||
return ChatZoomWrapper(
|
||||
enabled: !_selecting,
|
||||
child: AnchoredChatListView.builder(
|
||||
scrollAnchor: _scrollAnchor,
|
||||
reverse: true, // List grows from bottom up
|
||||
@@ -799,12 +828,7 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
if (isRoom) {
|
||||
// Room-server messages carry the original author's 4-byte prefix
|
||||
// separately from message.text; use it only for resolving the name.
|
||||
roomAuthor = _resolveContactFrom4Bytes(
|
||||
connector,
|
||||
message.fourByteRoomContactKey.isEmpty
|
||||
? Uint8List.fromList([0, 0, 0, 0])
|
||||
: message.fourByteRoomContactKey,
|
||||
);
|
||||
roomAuthor = _roomAuthorOf(connector, message);
|
||||
fourByteHex = message.fourByteRoomContactKey
|
||||
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||
.join()
|
||||
@@ -829,7 +853,7 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
: contact.name,
|
||||
sourceId: widget.contact.publicKeyHex,
|
||||
textScale: textScale,
|
||||
isBookmarked: message.isBookmarked || _showBookmarkedOnly,
|
||||
isBookmarked: message.isBookmarked,
|
||||
onLongPress: () => _showMessageActions(message, contact),
|
||||
onRetryReaction: (msg, emoji) =>
|
||||
_sendReaction(msg, contact, emoji),
|
||||
@@ -844,7 +868,7 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
message.receivedAt,
|
||||
);
|
||||
final highlighted = message.messageId == _highlightedMessageId;
|
||||
final shown = highlighted
|
||||
final styled = highlighted
|
||||
? AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
decoration: BoxDecoration(
|
||||
@@ -856,6 +880,9 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
child: bubble,
|
||||
)
|
||||
: bubble;
|
||||
final shown = _selecting
|
||||
? _buildSelectableRow(message, styled)
|
||||
: styled;
|
||||
final child = isUnreadAnchor || startsDay
|
||||
? Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -1077,6 +1104,15 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
return connector.contacts[_resolveContactIndex];
|
||||
}
|
||||
|
||||
/// The known author of a room-server post, or null when unknown.
|
||||
Contact? _roomAuthorOf(MeshCoreConnector connector, Message message) =>
|
||||
_resolveContactFrom4Bytes(
|
||||
connector,
|
||||
message.fourByteRoomContactKey.isEmpty
|
||||
? Uint8List.fromList([0, 0, 0, 0])
|
||||
: message.fourByteRoomContactKey,
|
||||
);
|
||||
|
||||
Contact? _resolveContactFrom4Bytes(
|
||||
MeshCoreConnector connector,
|
||||
Uint8List key4Bytes,
|
||||
@@ -1432,6 +1468,14 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
_showEmojiPicker(message, contact);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.checklist),
|
||||
title: Text(context.l10n.chat_selectMessages),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_toggleSelected(message);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.route),
|
||||
title: Text(context.l10n.chat_path),
|
||||
@@ -1492,22 +1536,23 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
? context.l10n.chat_removeBookmark
|
||||
: context.l10n.chat_bookmark,
|
||||
),
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final selfLabel = connector.selfName ?? context.l10n.chat_me;
|
||||
Navigator.pop(sheetContext);
|
||||
if (message.isBookmarked) {
|
||||
final confirmed = await confirmRemoveBookmarks(context);
|
||||
if (!confirmed || !mounted) return;
|
||||
}
|
||||
final bookmark = BookmarkedMessage.fromContact(
|
||||
message: message,
|
||||
contactKey: widget.contact.publicKeyHex,
|
||||
contactName: widget.contact.name,
|
||||
senderName: message.isOutgoing
|
||||
? (context.read<MeshCoreConnector>().selfName ??
|
||||
context.l10n.chat_me)
|
||||
: contact.name,
|
||||
senderName: message.isOutgoing ? selfLabel : contact.name,
|
||||
);
|
||||
unawaited(
|
||||
context.read<MeshCoreConnector>().setBookmarkedMessage(
|
||||
bookmark,
|
||||
isBookmarked: !message.isBookmarked,
|
||||
),
|
||||
await connector.setBookmarkedMessage(
|
||||
bookmark,
|
||||
isBookmarked: !message.isBookmarked,
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -1559,6 +1604,187 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
);
|
||||
}
|
||||
|
||||
// ---- bulk selection -------------------------------------------------------
|
||||
|
||||
void _toggleSelected(Message message) {
|
||||
HapticFeedback.selectionClick();
|
||||
setState(() {
|
||||
if (!_selectedIds.remove(message.messageId)) {
|
||||
_selectedIds.add(message.messageId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _clearSelection() => setState(_selectedIds.clear);
|
||||
|
||||
/// Selected messages still in the transcript, oldest first.
|
||||
List<Message> _selectedMessages() {
|
||||
final messages = context.read<MeshCoreConnector>().getMessages(
|
||||
widget.contact,
|
||||
);
|
||||
return [
|
||||
for (final m in messages)
|
||||
if (_selectedIds.contains(m.messageId)) m,
|
||||
];
|
||||
}
|
||||
|
||||
Widget _buildSelectableRow(Message message, Widget messageBody) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final selected = _selectedIds.contains(message.messageId);
|
||||
return Semantics(
|
||||
selected: selected,
|
||||
button: true,
|
||||
child: Material(
|
||||
color: selected
|
||||
? scheme.primary.withValues(alpha: 0.16)
|
||||
: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => _toggleSelected(message),
|
||||
onLongPress: () => _toggleSelected(message),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
selected ? Icons.check_circle : Icons.radio_button_unchecked,
|
||||
size: 28,
|
||||
color: selected ? scheme.primary : scheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// Links, images and reactions inside the bubble must not
|
||||
// react while picking messages.
|
||||
Expanded(child: AbsorbPointer(child: messageBody)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
PreferredSizeWidget _buildSelectionAppBar(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final selected = _selectedMessages();
|
||||
final readOnly = context.radioReadOnly;
|
||||
final canResend =
|
||||
!readOnly && selected.any((m) => m.isOutgoing && !m.isCli);
|
||||
return AppBar(
|
||||
leading: IconButton(
|
||||
tooltip: l10n.chat_clearSelection,
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: _clearSelection,
|
||||
),
|
||||
title: Text(l10n.chat_selectedCount(selected.length)),
|
||||
actions: [
|
||||
if (canResend)
|
||||
IconButton(
|
||||
tooltip: l10n.chat_resend,
|
||||
icon: const Icon(Icons.replay),
|
||||
onPressed: () => _bulkResend(selected),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.chat_bookmark,
|
||||
icon: const Icon(Icons.bookmark_border),
|
||||
onPressed: selected.isEmpty ? null : () => _bulkBookmark(selected),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.common_copy,
|
||||
icon: const Icon(Icons.copy),
|
||||
onPressed: selected.isEmpty ? null : () => _bulkCopy(selected),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.common_delete,
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
onPressed: selected.isEmpty || readOnly
|
||||
? null
|
||||
: () => _bulkDelete(selected),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _bulkCopy(List<Message> messages) {
|
||||
final text = messages.map((m) => m.text).join('\n');
|
||||
setState(_selectedIds.clear);
|
||||
copyChatMessageText(context, text);
|
||||
}
|
||||
|
||||
void _bulkBookmark(List<Message> messages) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final contact = _resolveContact(connector);
|
||||
final isRoom = contact.type == advTypeRoom;
|
||||
final me = connector.selfName ?? context.l10n.chat_me;
|
||||
setState(_selectedIds.clear);
|
||||
for (final m in messages) {
|
||||
unawaited(
|
||||
connector.setBookmarkedMessage(
|
||||
BookmarkedMessage.fromContact(
|
||||
message: m,
|
||||
contactKey: widget.contact.publicKeyHex,
|
||||
contactName: widget.contact.name,
|
||||
senderName: m.isOutgoing
|
||||
? me
|
||||
: (isRoom ? _roomAuthorOf(connector, m) : null)?.name ??
|
||||
contact.name,
|
||||
),
|
||||
isBookmarked: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _bulkDelete(List<Message> messages) async {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final confirmed = await confirmBulkDelete(context, messages.length);
|
||||
if (!confirmed || !mounted) return;
|
||||
setState(_selectedIds.clear);
|
||||
for (final m in messages) {
|
||||
await connector.deleteMessage(m);
|
||||
}
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.chat_messagesDeleted(messages.length)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _bulkResend(List<Message> messages) async {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final outgoing = [
|
||||
for (final m in messages)
|
||||
if (m.isOutgoing && !m.isCli) m,
|
||||
];
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
final l10n = dialogContext.l10n;
|
||||
return AlertDialog(
|
||||
title: Text(l10n.chat_resendSelectedTitle),
|
||||
content: Text(l10n.chat_resendSelectedConfirm(outgoing.length)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, false),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, true),
|
||||
child: Text(l10n.chat_resend),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
if (confirmed != true || !mounted) return;
|
||||
final contact = _resolveContact(connector);
|
||||
setState(_selectedIds.clear);
|
||||
// Oldest first so the resent messages keep their order.
|
||||
for (final m in outgoing) {
|
||||
await connector.resendMessage(contact, m);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _deleteMessage(Message message) async {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
await context.read<MeshCoreConnector>().deleteMessage(message);
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/unsaved_changes_guard.dart';
|
||||
|
||||
typedef _ContactForm = ({
|
||||
bool autoAddUsers,
|
||||
bool autoAddRepeaters,
|
||||
bool autoAddRoomServers,
|
||||
bool autoAddSensors,
|
||||
bool overwriteOldest,
|
||||
int? maxHops,
|
||||
bool evictDiscovered,
|
||||
});
|
||||
|
||||
/// Contact auto-add and overflow options. Sent on Save.
|
||||
class ContactSettingsScreen extends StatefulWidget {
|
||||
const ContactSettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
State<ContactSettingsScreen> createState() => _ContactSettingsScreenState();
|
||||
}
|
||||
|
||||
class _ContactSettingsScreenState extends State<ContactSettingsScreen> {
|
||||
late bool _autoAddUsers;
|
||||
late bool _autoAddRepeaters;
|
||||
late bool _autoAddRoomServers;
|
||||
late bool _autoAddSensors;
|
||||
late bool _overwriteOldest;
|
||||
// Null when the firmware doesn't report a hop limit.
|
||||
int? _maxHops;
|
||||
late bool _evictDiscovered;
|
||||
late _ContactForm _savedForm;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
_autoAddUsers = connector.autoAddUsers ?? false;
|
||||
_autoAddRepeaters = connector.autoAddRepeaters ?? false;
|
||||
_autoAddRoomServers = connector.autoAddRoomServers ?? false;
|
||||
_autoAddSensors = connector.autoAddSensors ?? false;
|
||||
_overwriteOldest = connector.autoAddOverwriteOldest ?? false;
|
||||
_maxHops = connector.autoAddMaxHops;
|
||||
_evictDiscovered = context
|
||||
.read<AppSettingsService>()
|
||||
.settings
|
||||
.evictDiscoveredContactsEnabled;
|
||||
_savedForm = _form;
|
||||
}
|
||||
|
||||
_ContactForm get _form => (
|
||||
autoAddUsers: _autoAddUsers,
|
||||
autoAddRepeaters: _autoAddRepeaters,
|
||||
autoAddRoomServers: _autoAddRoomServers,
|
||||
autoAddSensors: _autoAddSensors,
|
||||
overwriteOldest: _overwriteOldest,
|
||||
maxHops: _maxHops,
|
||||
evictDiscovered: _evictDiscovered,
|
||||
);
|
||||
|
||||
Future<bool> _save() async {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final settingsService = context.read<AppSettingsService>();
|
||||
final form = _form;
|
||||
await connector.sendFrame(
|
||||
buildSetAutoAddConfigFrame(
|
||||
autoAddChat: form.autoAddUsers,
|
||||
autoAddRepeater: form.autoAddRepeaters,
|
||||
autoAddRoomServer: form.autoAddRoomServers,
|
||||
autoAddSensor: form.autoAddSensors,
|
||||
overwriteOldest: form.overwriteOldest,
|
||||
// Sent only when changed, so the frame is otherwise unchanged.
|
||||
maxHops: form.maxHops != _savedForm.maxHops ? form.maxHops : null,
|
||||
),
|
||||
);
|
||||
await connector.sendFrame(buildGetAutoAddFlagsFrame());
|
||||
await settingsService.setEvictDiscoveredContactsEnabled(
|
||||
form.evictDiscovered,
|
||||
);
|
||||
if (form.evictDiscovered) {
|
||||
await connector.trimDiscoveredContactsToLimit();
|
||||
}
|
||||
if (!mounted) return true;
|
||||
setState(() => _savedForm = form);
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_contactSettingsSaved),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
Widget _switch({
|
||||
required Widget icon,
|
||||
required String title,
|
||||
String? subtitle,
|
||||
required bool value,
|
||||
required ValueChanged<bool> onChanged,
|
||||
}) {
|
||||
return SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
secondary: icon,
|
||||
title: Text(title),
|
||||
subtitle: subtitle == null ? null : Text(subtitle),
|
||||
value: value,
|
||||
onChanged: (value) => setState(() => onChanged(value)),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
const divider = Divider(height: 1, indent: 16);
|
||||
return SaveToRadioPage(
|
||||
title: l10n.settings_contactSettings,
|
||||
hasChanges: _form != _savedForm,
|
||||
onSave: _save,
|
||||
children: [
|
||||
SectionHeader(
|
||||
l10n.contactsSettings_autoAddTitle,
|
||||
description: l10n.contactsSettings_autoAddDescription,
|
||||
),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
// Same icons as the contact list and map.
|
||||
_switch(
|
||||
icon: const Icon(Icons.person, size: 24),
|
||||
title: l10n.contactsSettings_autoAddUsersTitle,
|
||||
value: _autoAddUsers,
|
||||
onChanged: (v) => _autoAddUsers = v,
|
||||
),
|
||||
divider,
|
||||
_switch(
|
||||
icon: const ThemedIcon(ThemeIconSlot.repeater, size: 24),
|
||||
title: l10n.contactsSettings_autoAddRepeatersTitle,
|
||||
value: _autoAddRepeaters,
|
||||
onChanged: (v) => _autoAddRepeaters = v,
|
||||
),
|
||||
divider,
|
||||
_switch(
|
||||
icon: const ThemedIcon(ThemeIconSlot.room, size: 24),
|
||||
title: l10n.contactsSettings_autoAddRoomServersTitle,
|
||||
value: _autoAddRoomServers,
|
||||
onChanged: (v) => _autoAddRoomServers = v,
|
||||
),
|
||||
divider,
|
||||
_switch(
|
||||
icon: const ThemedIcon(ThemeIconSlot.sensor, size: 24),
|
||||
title: l10n.contactsSettings_autoAddSensorsTitle,
|
||||
value: _autoAddSensors,
|
||||
onChanged: (v) => _autoAddSensors = v,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SectionHeader(l10n.contactsSettings_otherTitle),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
_switch(
|
||||
icon: const ThemedIcon(ThemeIconSlot.contacts, size: 24),
|
||||
title: l10n.contactsSettings_overwriteOldestTitle,
|
||||
subtitle: l10n.contactsSettings_overwriteOldestSubtitle,
|
||||
value: _overwriteOldest,
|
||||
onChanged: (v) => _overwriteOldest = v,
|
||||
),
|
||||
if (_maxHops != null) ...[
|
||||
divider,
|
||||
// Same row shape as SettingsValueSlider: icon, title and
|
||||
// description, with the dropdown under the description.
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
leading: const Icon(Icons.linear_scale, size: 24),
|
||||
title: Text(l10n.contactsSettings_hopLimit),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(l10n.contactsSettings_hopLimitSubtitle),
|
||||
const SizedBox(height: 8),
|
||||
DropdownButtonFormField<int>(
|
||||
initialValue: _maxHops,
|
||||
isExpanded: true,
|
||||
// Firmware: 0 = no limit, N = under N hops (max 64).
|
||||
items: [
|
||||
for (var hops = 0; hops <= 64; hops++)
|
||||
DropdownMenuItem(
|
||||
value: hops,
|
||||
child: Text(
|
||||
l10n.contactsSettings_hopLimitOption(hops),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (v) {
|
||||
if (v != null) setState(() => _maxHops = v);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
divider,
|
||||
_switch(
|
||||
// The Discovered Contacts icon.
|
||||
icon: const Icon(Icons.person_add_rounded, size: 24),
|
||||
title: l10n.contactsSettings_evictDiscoveredContactsTitle,
|
||||
subtitle: l10n.contactsSettings_evictDiscoveredContactsSubtitle(
|
||||
MeshCoreConnector.maxDiscoveredContacts,
|
||||
),
|
||||
value: _evictDiscovered,
|
||||
onChanged: (v) => _evictDiscovered = v,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ import '../widgets/sync_progress_overlay.dart';
|
||||
import '../widgets/unread_badge.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import 'add_contact_screen.dart';
|
||||
import 'bookmarks_screen.dart';
|
||||
import 'channels_screen.dart';
|
||||
import 'chat_screen.dart';
|
||||
import 'discovery_screen.dart';
|
||||
@@ -385,6 +386,16 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
MaterialPageRoute(builder: (_) => const DiscoveryScreen()),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.bookmark_border,
|
||||
label: menuContext.l10n.bookmarks_title,
|
||||
),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const BookmarksScreen()),
|
||||
),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
PopupMenuItem(
|
||||
enabled: !readOnly,
|
||||
|
||||
@@ -159,19 +159,19 @@ class _CoordinateMapScreenState extends State<CoordinateMapScreen> {
|
||||
right: 12,
|
||||
child: Column(
|
||||
children: [
|
||||
_CoordinateMapControlButton(
|
||||
CoordinateMapControlButton(
|
||||
icon: Icons.add,
|
||||
tooltip: l10n.map_zoomIn,
|
||||
onPressed: () => _zoomBy(1),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_CoordinateMapControlButton(
|
||||
CoordinateMapControlButton(
|
||||
icon: Icons.remove,
|
||||
tooltip: l10n.map_zoomOut,
|
||||
onPressed: () => _zoomBy(-1),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_CoordinateMapControlButton(
|
||||
CoordinateMapControlButton(
|
||||
icon: Icons.my_location,
|
||||
tooltip: l10n.map_centerMap,
|
||||
onPressed: () => _mapController.move(_position, _initialZoom),
|
||||
@@ -227,12 +227,14 @@ class _CoordinateMapScreenState extends State<CoordinateMapScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
class _CoordinateMapControlButton extends StatelessWidget {
|
||||
/// Zoom and recenter button floating over a full-screen map.
|
||||
class CoordinateMapControlButton extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String tooltip;
|
||||
final VoidCallback onPressed;
|
||||
|
||||
const _CoordinateMapControlButton({
|
||||
const CoordinateMapControlButton({
|
||||
super.key,
|
||||
required this.icon,
|
||||
required this.tooltip,
|
||||
required this.onPressed,
|
||||
|
||||
@@ -11,10 +11,11 @@ import '../connector/meshcore_connector.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
import '../utils/bookmark_markdown_export.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
import '../utils/share_origin.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/mesh_nav_tile.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
@@ -34,11 +35,7 @@ class ExportScreen extends StatelessWidget {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: AppBarTitle(
|
||||
l10n.settings_export,
|
||||
indicators: false,
|
||||
subtitle: false,
|
||||
),
|
||||
title: AdaptiveAppBarTitle(l10n.settings_exportData),
|
||||
centerTitle: true,
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
),
|
||||
@@ -47,25 +44,32 @@ class ExportScreen extends StatelessWidget {
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
|
||||
children: [
|
||||
SectionHeader(l10n.settings_export),
|
||||
SectionHeader(
|
||||
l10n.export_messagesTitle,
|
||||
description: l10n.export_messagesDescription,
|
||||
),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: MeshNavTile(
|
||||
// The bookmark icon used in chats.
|
||||
icon: Icons.bookmark_border,
|
||||
title: l10n.settings_exportBookmarks,
|
||||
subtitle: l10n.settings_exportBookmarksSubtitle,
|
||||
onTap: () => _exportBookmarks(context),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SectionHeader(
|
||||
l10n.export_locationsTitle,
|
||||
description: l10n.export_locationsDescription,
|
||||
),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
// Same icons as the contact list and Contact Settings.
|
||||
MeshNavTile(
|
||||
icon: Icons.download_outlined,
|
||||
icon: Icons.cell_tower,
|
||||
iconSlot: ThemeIconSlot.repeater,
|
||||
title: l10n.settings_gpxExportRepeaters,
|
||||
subtitle: l10n.settings_gpxExportRepeatersSubtitle,
|
||||
onTap: () {
|
||||
final exporter = GpxExport(connector)..addRepeaters();
|
||||
_gpxExport(
|
||||
@@ -79,9 +83,8 @@ class ExportScreen extends StatelessWidget {
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
icon: Icons.download_outlined,
|
||||
icon: Icons.person,
|
||||
title: l10n.settings_gpxExportContacts,
|
||||
subtitle: l10n.settings_gpxExportContactsSubtitle,
|
||||
onTap: () {
|
||||
final exporter = GpxExport(connector)..addContacts();
|
||||
_gpxExport(
|
||||
@@ -95,9 +98,9 @@ class ExportScreen extends StatelessWidget {
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
icon: Icons.download_outlined,
|
||||
icon: Icons.people_outline,
|
||||
iconSlot: ThemeIconSlot.contacts,
|
||||
title: l10n.settings_gpxExportAll,
|
||||
subtitle: l10n.settings_gpxExportAllSubtitle,
|
||||
onTap: () {
|
||||
final exporter = GpxExport(connector)..addAll();
|
||||
_gpxExport(
|
||||
|
||||
@@ -21,6 +21,7 @@ import '../widgets/app_bar.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/path_map_scaffold.dart';
|
||||
import '../widgets/quick_switch_bar.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
import '../icons/los_icon.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
|
||||
@@ -440,10 +441,7 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: 0,
|
||||
child: LinearProgressIndicator(
|
||||
color: LosPalette.selected,
|
||||
backgroundColor: LosPalette.chartBackground,
|
||||
),
|
||||
child: const MeshProgressBar(),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:provider/provider.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 'coordinate_map_screen.dart';
|
||||
import 'map_screen.dart';
|
||||
|
||||
/// Map with a fixed centre pin. Pops the chosen [LatLng], or null on back.
|
||||
class LocationPickerScreen extends StatefulWidget {
|
||||
/// Start position; defaults to the Map tab's last camera.
|
||||
final LatLng? initial;
|
||||
|
||||
const LocationPickerScreen({super.key, this.initial});
|
||||
|
||||
@override
|
||||
State<LocationPickerScreen> createState() => _LocationPickerScreenState();
|
||||
}
|
||||
|
||||
class _LocationPickerScreenState extends State<LocationPickerScreen> {
|
||||
static const double _minZoom = 2.0;
|
||||
static const double _maxZoom = 18.0;
|
||||
static const double _pinnedZoom = 15.0;
|
||||
static const double _pinSize = 48.0;
|
||||
|
||||
final MapController _mapController = MapController();
|
||||
late final ({LatLng center, double zoom}) _initialCamera;
|
||||
late LatLng _center;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final initial = widget.initial;
|
||||
_initialCamera = initial != null
|
||||
? (center: initial, zoom: _pinnedZoom)
|
||||
: savedMapCamera() ?? (center: const LatLng(20, 0), zoom: _minZoom);
|
||||
_center = _initialCamera.center;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
/// Wraps longitude to ±180 (the camera can go past it) and clamps latitude.
|
||||
LatLng get _normalizedCenter {
|
||||
final lon = ((_center.longitude + 180) % 360 + 360) % 360 - 180;
|
||||
return LatLng(_center.latitude.clamp(-90.0, 90.0), lon);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final mapTheme = MeshMapTheme.of(context);
|
||||
final tileCache = context.read<MapTileCacheService>();
|
||||
final center = _normalizedCenter;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
title: AdaptiveAppBarTitle(l10n.location_pickOnMap),
|
||||
),
|
||||
// Scrolls at large text sizes instead of covering the map.
|
||||
body: LayoutBuilder(
|
||||
builder: (context, constraints) => Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Stack(
|
||||
children: [
|
||||
FlutterMap(
|
||||
mapController: _mapController,
|
||||
options: MapOptions(
|
||||
initialCenter: _initialCamera.center,
|
||||
initialZoom: _initialCamera.zoom,
|
||||
minZoom: _minZoom,
|
||||
maxZoom: _maxZoom,
|
||||
interactionOptions: const InteractionOptions(
|
||||
flags: ~InteractiveFlag.rotate,
|
||||
),
|
||||
onPositionChanged: (camera, _) =>
|
||||
setState(() => _center = camera.center),
|
||||
onTap: (_, point) => _mapController.move(
|
||||
point,
|
||||
_mapController.camera.zoom,
|
||||
),
|
||||
),
|
||||
children: [tileCache.buildTileLayer(context)],
|
||||
),
|
||||
// Pin tip at the map centre.
|
||||
Center(
|
||||
child: IgnorePointer(
|
||||
child: Transform.translate(
|
||||
offset: const Offset(0, -_pinSize / 2),
|
||||
child: Icon(
|
||||
Icons.location_on,
|
||||
size: _pinSize,
|
||||
color: mapTheme.followsTheme
|
||||
? mapTheme.accent
|
||||
: MapPalette.batteryLow,
|
||||
shadows: const [
|
||||
Shadow(
|
||||
color: MapPalette.markerShadow,
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: constraints.maxHeight * 0.6,
|
||||
),
|
||||
child: Material(
|
||||
color: scheme.surfaceContainerLow,
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
l10n.locationPicker_hint,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${center.latitude.toStringAsFixed(6)}, '
|
||||
'${center.longitude.toStringAsFixed(6)}',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
FilledButton.icon(
|
||||
onPressed: () => Navigator.pop(context, center),
|
||||
icon: const Icon(Icons.check),
|
||||
label: Text(l10n.locationPicker_useLocation),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,329 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../helpers/guessed_location_estimator.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../widgets/mesh_nav_tile.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/unsaved_changes_guard.dart';
|
||||
import 'location_picker_screen.dart';
|
||||
|
||||
/// Form values compared to detect unsaved edits.
|
||||
typedef _LocationForm = ({
|
||||
String latitude,
|
||||
String longitude,
|
||||
String interval,
|
||||
bool gpsEnabled,
|
||||
});
|
||||
|
||||
/// Advertised location and, with GPS hardware, GPS settings. Sent on Save.
|
||||
class LocationSettingsScreen extends StatefulWidget {
|
||||
const LocationSettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
State<LocationSettingsScreen> createState() => _LocationSettingsScreenState();
|
||||
}
|
||||
|
||||
class _LocationSettingsScreenState extends State<LocationSettingsScreen> {
|
||||
final _latController = TextEditingController();
|
||||
final _lonController = TextEditingController();
|
||||
final _intervalController = TextEditingController();
|
||||
late final bool _hasGps;
|
||||
bool _gpsEnabled = false;
|
||||
double? _deviceLatitude;
|
||||
double? _deviceLongitude;
|
||||
late _LocationForm _savedForm;
|
||||
String? _latError;
|
||||
String? _lonError;
|
||||
String? _intervalError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final settingsService = context.read<AppSettingsService>();
|
||||
// Null until the device answers.
|
||||
final customVars = connector.currentCustomVars ?? {};
|
||||
_hasGps = customVars.containsKey('gps');
|
||||
_gpsEnabled = customVars['gps'] == '1';
|
||||
_deviceLatitude = connector.selfLatitude;
|
||||
_deviceLongitude = connector.selfLongitude;
|
||||
if (_hasLocation) {
|
||||
_latController.text = _deviceLatitude!.toStringAsFixed(6);
|
||||
_lonController.text = _deviceLongitude!.toStringAsFixed(6);
|
||||
}
|
||||
_intervalController.text = settingsService
|
||||
.resolvedGpsIntervalSeconds(customVars)
|
||||
.toString();
|
||||
_savedForm = _currentForm();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_latController.dispose();
|
||||
_lonController.dispose();
|
||||
_intervalController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Firmware stores "no location" as 0,0 (the default for a fresh node), so
|
||||
/// that pair is shown as empty fields rather than a real coordinate.
|
||||
bool get _hasLocation {
|
||||
final lat = _deviceLatitude;
|
||||
final lon = _deviceLongitude;
|
||||
return lat != null && lon != null && !(lat == 0 && lon == 0);
|
||||
}
|
||||
|
||||
_LocationForm _currentForm() => (
|
||||
latitude: _latController.text.trim(),
|
||||
longitude: _lonController.text.trim(),
|
||||
interval: _hasGps ? _intervalController.text.trim() : '',
|
||||
gpsEnabled: _hasGps && _gpsEnabled,
|
||||
);
|
||||
|
||||
/// Valid field coordinates, else the radio's location.
|
||||
LatLng? get _pickerStart {
|
||||
final lat = double.tryParse(_latController.text.trim());
|
||||
final lon = double.tryParse(_lonController.text.trim());
|
||||
if (lat != null && lon != null && isPlausibleLocation(lat, lon)) {
|
||||
return LatLng(lat, lon);
|
||||
}
|
||||
return _hasLocation ? LatLng(_deviceLatitude!, _deviceLongitude!) : null;
|
||||
}
|
||||
|
||||
Future<void> _pickOnMap() async {
|
||||
final picked = await Navigator.push<LatLng>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => LocationPickerScreen(initial: _pickerStart),
|
||||
),
|
||||
);
|
||||
if (picked == null || !mounted) return;
|
||||
setState(() {
|
||||
_latController.text = picked.latitude.toStringAsFixed(6);
|
||||
_lonController.text = picked.longitude.toStringAsFixed(6);
|
||||
_latError = null;
|
||||
_lonError = null;
|
||||
});
|
||||
}
|
||||
|
||||
/// Validates all fields, then sends GPS (if changed), interval and location.
|
||||
Future<bool> _save() async {
|
||||
final l10n = context.l10n;
|
||||
// Validate first so a typo doesn't leave half the changes applied.
|
||||
int? interval;
|
||||
String? intervalError;
|
||||
if (_hasGps) {
|
||||
final intervalText = _intervalController.text.trim();
|
||||
if (intervalText.isNotEmpty) {
|
||||
interval = int.tryParse(intervalText);
|
||||
if (interval == null || interval < 60 || interval >= 86400) {
|
||||
intervalError = l10n.settings_locationIntervalInvalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final latText = _latController.text.trim();
|
||||
final lonText = _lonController.text.trim();
|
||||
double? lat;
|
||||
double? lon;
|
||||
String? latError;
|
||||
String? lonError;
|
||||
var clearsLocation = false;
|
||||
if (latText.isEmpty && lonText.isEmpty) {
|
||||
// Clearing both fields removes the location. Companion firmware has no
|
||||
// dedicated "clear" command: CMD_SET_ADVERT_LATLON with 0,0 restores
|
||||
// the factory default, which firmware and this app treat as unset.
|
||||
if (_hasLocation) {
|
||||
lat = 0;
|
||||
lon = 0;
|
||||
clearsLocation = true;
|
||||
}
|
||||
} else {
|
||||
// One empty field keeps the device's current value for that axis.
|
||||
lat = latText.isNotEmpty
|
||||
? double.tryParse(latText)
|
||||
: (_hasLocation ? _deviceLatitude : null);
|
||||
lon = lonText.isNotEmpty
|
||||
? double.tryParse(lonText)
|
||||
: (_hasLocation ? _deviceLongitude : null);
|
||||
if (lat == null) {
|
||||
latError = latText.isEmpty
|
||||
? l10n.settings_locationBothRequired
|
||||
: l10n.settings_locationInvalid;
|
||||
} else if (lat < -90 || lat > 90) {
|
||||
latError = l10n.settings_locationInvalid;
|
||||
}
|
||||
if (lon == null) {
|
||||
lonError = lonText.isEmpty
|
||||
? l10n.settings_locationBothRequired
|
||||
: l10n.settings_locationInvalid;
|
||||
} else if (lon < -180 || lon > 180) {
|
||||
lonError = l10n.settings_locationInvalid;
|
||||
}
|
||||
}
|
||||
|
||||
if (intervalError != null || latError != null || lonError != null) {
|
||||
setState(() {
|
||||
_intervalError = intervalError;
|
||||
_latError = latError;
|
||||
_lonError = lonError;
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
// An empty interval leaves the stored one; show it again.
|
||||
if (_hasGps && _intervalController.text.trim().isEmpty) {
|
||||
_intervalController.text = _savedForm.interval;
|
||||
}
|
||||
final gpsChanged = _hasGps && _gpsEnabled != _savedForm.gpsEnabled;
|
||||
if (!gpsChanged && interval == null && (lat == null || lon == null)) {
|
||||
// Nothing to send, like the old dialog.
|
||||
setState(() => _savedForm = _currentForm());
|
||||
return true;
|
||||
}
|
||||
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final settingsService = context.read<AppSettingsService>();
|
||||
if (gpsChanged) {
|
||||
await connector.setCustomVar(_gpsEnabled ? "gps:1" : "gps:0");
|
||||
}
|
||||
if (interval != null) {
|
||||
await settingsService.setGpsIntervalSeconds(
|
||||
interval,
|
||||
writeToDevice: (value) => connector.setCustomVar("gps_interval:$value"),
|
||||
);
|
||||
}
|
||||
if (lat != null && lon != null) {
|
||||
await connector.setNodeLocation(lat: lat, lon: lon);
|
||||
}
|
||||
await connector.refreshDeviceInfo();
|
||||
if (!mounted) return true;
|
||||
setState(() {
|
||||
if (lat != null && lon != null) {
|
||||
_deviceLatitude = lat;
|
||||
_deviceLongitude = lon;
|
||||
}
|
||||
_savedForm = _currentForm();
|
||||
});
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
clearsLocation
|
||||
? l10n.settings_locationCleared
|
||||
: l10n.settings_locationUpdated,
|
||||
),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
const coordinateKeyboard = TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
signed: true,
|
||||
);
|
||||
return SaveToRadioPage(
|
||||
title: l10n.settings_location,
|
||||
hasChanges: _currentForm() != _savedForm,
|
||||
onSave: _save,
|
||||
children: [
|
||||
SectionHeader(
|
||||
l10n.location_coordinates,
|
||||
description: l10n.location_coordinatesDescription,
|
||||
),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(
|
||||
controller: _latController,
|
||||
onTapOutside: (_) => FocusScope.of(context).unfocus(),
|
||||
onChanged: (_) => setState(() => _latError = null),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_latitude,
|
||||
errorText: _latError,
|
||||
errorMaxLines: 2,
|
||||
),
|
||||
keyboardType: coordinateKeyboard,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _lonController,
|
||||
onTapOutside: (_) => FocusScope.of(context).unfocus(),
|
||||
onChanged: (_) => setState(() => _lonError = null),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_longitude,
|
||||
helperText: l10n.settings_locationClearHelper,
|
||||
helperMaxLines: 2,
|
||||
errorText: _lonError,
|
||||
errorMaxLines: 2,
|
||||
),
|
||||
keyboardType: coordinateKeyboard,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
icon: Icons.map_outlined,
|
||||
title: l10n.location_pickOnMap,
|
||||
onTap: _pickOnMap,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_hasGps) ...[
|
||||
SectionHeader(l10n.telemetry_gpsLabel),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
secondary: const Icon(Icons.gps_fixed, size: 24),
|
||||
title: Text(l10n.settings_locationGPSEnable),
|
||||
subtitle: Text(l10n.settings_locationGPSEnableSubtitle),
|
||||
value: _gpsEnabled,
|
||||
// Sent on Save.
|
||||
onChanged: (value) => setState(() => _gpsEnabled = value),
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: TextField(
|
||||
controller: _intervalController,
|
||||
onTapOutside: (_) => FocusScope.of(context).unfocus(),
|
||||
onChanged: (_) => setState(() => _intervalError = null),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_locationIntervalSec,
|
||||
helperText: l10n.settings_locationIntervalHelper,
|
||||
errorText: _intervalError,
|
||||
errorMaxLines: 2,
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: false,
|
||||
signed: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,17 @@ import '../helpers/utf8_length_limiter.dart';
|
||||
import 'line_of_sight_map_screen.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
|
||||
const String _lastCameraKey = 'map_last_camera';
|
||||
|
||||
/// The Map tab's last camera, or null if never saved.
|
||||
({LatLng center, double zoom})? savedMapCamera() {
|
||||
final saved = PrefsManager.instance.getStringList(_lastCameraKey);
|
||||
if (saved == null || saved.length != 3) return null;
|
||||
final values = saved.map(double.tryParse).toList();
|
||||
if (values.contains(null)) return null;
|
||||
return (center: LatLng(values[0]!, values[1]!), zoom: values[2]!);
|
||||
}
|
||||
|
||||
class MapScreen extends StatefulWidget {
|
||||
final LatLng? highlightPosition;
|
||||
final String? highlightLabel;
|
||||
@@ -134,7 +145,6 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
// been positioned once.
|
||||
({LatLng center, double zoom})? _initialCamera;
|
||||
|
||||
static const String _lastCameraKey = 'map_last_camera';
|
||||
static const Duration _cameraSaveDelay = Duration(milliseconds: 500);
|
||||
Timer? _cameraSaveTimer;
|
||||
List<String>? _pendingCamera;
|
||||
@@ -145,14 +155,7 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
if (lat != null && lon != null && isPlausibleLocation(lat, lon)) {
|
||||
return (center: LatLng(lat, lon), zoom: 12.0);
|
||||
}
|
||||
final saved = PrefsManager.instance.getStringList(_lastCameraKey);
|
||||
if (saved != null && saved.length == 3) {
|
||||
final values = saved.map(double.tryParse).toList();
|
||||
if (!values.contains(null)) {
|
||||
return (center: LatLng(values[0]!, values[1]!), zoom: values[2]!);
|
||||
}
|
||||
}
|
||||
return (center: const LatLng(20, 0), zoom: _mapMinZoom);
|
||||
return savedMapCamera() ?? (center: const LatLng(20, 0), zoom: _mapMinZoom);
|
||||
}
|
||||
|
||||
void _scheduleCameraSave() {
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/mesh_nav_tile.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/unsaved_changes_guard.dart';
|
||||
|
||||
/// Node name editor showing the bytes left for messages.
|
||||
class NodeNameScreen extends StatefulWidget {
|
||||
const NodeNameScreen({super.key});
|
||||
|
||||
@override
|
||||
State<NodeNameScreen> createState() => _NodeNameScreenState();
|
||||
}
|
||||
|
||||
class _NodeNameScreenState extends State<NodeNameScreen> {
|
||||
final _page = GlobalKey<SaveToRadioPageState>();
|
||||
late final TextEditingController _controller;
|
||||
late String _savedName;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final name = context.read<MeshCoreConnector>().selfName ?? '';
|
||||
// Compared trimmed, like the field.
|
||||
_savedName = name.trim();
|
||||
_controller = TextEditingController(text: name)
|
||||
..addListener(() => setState(() {}));
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String get _name => _controller.text.trim();
|
||||
|
||||
Future<bool> _save() async {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final name = _name;
|
||||
await connector.setNodeName(name);
|
||||
await connector.refreshDeviceInfo();
|
||||
if (!mounted) return true;
|
||||
setState(() => _savedName = name);
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_nodeNameUpdated),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final bytes = utf8ByteLength(_name);
|
||||
final over = bytes - maxRadioNameBytes;
|
||||
return SaveToRadioPage(
|
||||
key: _page,
|
||||
title: l10n.settings_nodeName,
|
||||
hasChanges: _name != _savedName,
|
||||
canSave: _name.isNotEmpty && over <= 0,
|
||||
onSave: _save,
|
||||
children: [
|
||||
SectionHeader(l10n.settings_nodeName),
|
||||
MeshCard(
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
autofocus: _savedName.isEmpty,
|
||||
textInputAction: TextInputAction.done,
|
||||
onSubmitted: (_) => _page.currentState?.save(),
|
||||
onTapOutside: (_) => FocusScope.of(context).unfocus(),
|
||||
// No length limit: an over-long name shows how far over it is
|
||||
// instead of silently refusing input.
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_infoName,
|
||||
hintText: l10n.settings_nodeNameHint,
|
||||
errorText: over > 0 ? l10n.nodeName_bytesOver(over) : null,
|
||||
suffixIcon: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 8, end: 12),
|
||||
child: Text(
|
||||
'$bytes / $maxRadioNameBytes',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: over > 0 ? scheme.error : scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
suffixIconConstraints: const BoxConstraints(),
|
||||
),
|
||||
),
|
||||
),
|
||||
SectionHeader(
|
||||
l10n.nodeName_messageLength,
|
||||
description: l10n.nodeName_info,
|
||||
),
|
||||
_buildMessageLimits(context),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMessageLimits(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final name = _name;
|
||||
// Empty or over-long names can't be saved.
|
||||
final channelValue =
|
||||
name.isEmpty || utf8ByteLength(name) > maxRadioNameBytes
|
||||
? l10n.common_notAvailable
|
||||
: l10n.nodeName_bytesAvailable(maxChannelMessageBytes(name));
|
||||
return MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
_LimitRow(
|
||||
icon: Icons.forum_outlined,
|
||||
title: l10n.nodeName_channelMessages,
|
||||
value: channelValue,
|
||||
subtitle: l10n.nodeName_channelMessagesSubtitle,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
_LimitRow(
|
||||
icon: Icons.chat_bubble_outline,
|
||||
title: l10n.nodeName_directMessages,
|
||||
value: l10n.nodeName_bytesAvailable(maxContactMessageBytes()),
|
||||
subtitle: l10n.nodeName_directMessagesSubtitle,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Settings row with a read-only value: icon, title, the value in mono 15
|
||||
/// (like the Settings device info values) and a subtitle.
|
||||
class _LimitRow extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String value;
|
||||
final String subtitle;
|
||||
|
||||
const _LimitRow({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.value,
|
||||
required this.subtitle,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
return MergeSemantics(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: 24, color: scheme.onSurfaceVariant),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: meshTileTitleStyle(theme)),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
value,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
subtitle,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/settings_reveal.dart';
|
||||
import '../widgets/unsaved_changes_guard.dart';
|
||||
|
||||
typedef _PrivacyForm = ({
|
||||
bool advertLocation,
|
||||
bool autoZeroHopAdvert,
|
||||
int multiAcks,
|
||||
int telemetryBase,
|
||||
int telemetryLocation,
|
||||
int telemetryEnvironment,
|
||||
});
|
||||
|
||||
/// Location sharing, ACKs and telemetry permissions. Sent on Save.
|
||||
class PrivacySettingsScreen extends StatefulWidget {
|
||||
const PrivacySettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
State<PrivacySettingsScreen> createState() => _PrivacySettingsScreenState();
|
||||
}
|
||||
|
||||
class _PrivacySettingsScreenState extends State<PrivacySettingsScreen> {
|
||||
late bool _advertLocation;
|
||||
late bool _autoZeroHopAdvert;
|
||||
// Raw value: firmware also accepts 2, kept unless the switch is changed.
|
||||
late int _multiAcks;
|
||||
late int _telemetryBase;
|
||||
late int _telemetryLocation;
|
||||
late int _telemetryEnvironment;
|
||||
late _PrivacyForm _savedForm;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
_advertLocation = connector.advertLocationPolicy != 0;
|
||||
_autoZeroHopAdvert = context
|
||||
.read<AppSettingsService>()
|
||||
.settings
|
||||
.autoSendZeroHopAdvertOnGpsUpdate;
|
||||
_multiAcks = connector.multiAcks;
|
||||
_telemetryBase = connector.telemetryModeBase;
|
||||
_telemetryLocation = connector.telemetryModeLoc;
|
||||
_telemetryEnvironment = connector.telemetryModeEnv;
|
||||
_savedForm = _form;
|
||||
}
|
||||
|
||||
_PrivacyForm get _form => (
|
||||
advertLocation: _advertLocation,
|
||||
autoZeroHopAdvert: _autoZeroHopAdvert,
|
||||
multiAcks: _multiAcks,
|
||||
telemetryBase: _telemetryBase,
|
||||
telemetryLocation: _telemetryLocation,
|
||||
telemetryEnvironment: _telemetryEnvironment,
|
||||
);
|
||||
|
||||
Future<bool> _save() async {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final settingsService = context.read<AppSettingsService>();
|
||||
final form = _form;
|
||||
await connector.setTelemetryModeBase(
|
||||
form.telemetryBase,
|
||||
form.telemetryLocation,
|
||||
form.telemetryEnvironment,
|
||||
form.advertLocation ? 1 : 0,
|
||||
form.multiAcks,
|
||||
);
|
||||
await settingsService.setAutoSendZeroHopAdvertOnGpsUpdate(
|
||||
form.autoZeroHopAdvert,
|
||||
);
|
||||
await connector.refreshDeviceInfo();
|
||||
if (!mounted) return true;
|
||||
setState(() => _savedForm = form);
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_telemetryModeUpdated),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
const switchPadding = EdgeInsets.symmetric(horizontal: 16, vertical: 4);
|
||||
return SaveToRadioPage(
|
||||
title: l10n.settings_privacy,
|
||||
hasChanges: _form != _savedForm,
|
||||
onSave: _save,
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
MeshInfoCard(l10n.settings_privacySettingsDescription),
|
||||
SectionHeader(l10n.settings_location),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
SwitchListTile(
|
||||
contentPadding: switchPadding,
|
||||
// Same icon as the Location row in Settings.
|
||||
secondary: const Icon(Icons.location_on_outlined, size: 24),
|
||||
title: Text(l10n.settings_advertLocation),
|
||||
subtitle: Text(l10n.settings_advertLocationSubtitle),
|
||||
value: _advertLocation,
|
||||
onChanged: (value) => setState(() => _advertLocation = value),
|
||||
),
|
||||
SettingsReveal(
|
||||
visible: _advertLocation,
|
||||
children: [
|
||||
SwitchListTile(
|
||||
contentPadding: switchPadding,
|
||||
// Same icon as the zero-hop advert action in Contacts.
|
||||
secondary: const Icon(
|
||||
Icons.connect_without_contact,
|
||||
size: 24,
|
||||
),
|
||||
title: Text(l10n.settings_autoZeroHopAdvertOnGpsUpdate),
|
||||
subtitle: Text(
|
||||
l10n.settings_autoZeroHopAdvertOnGpsUpdateSubtitle,
|
||||
),
|
||||
value: _autoZeroHopAdvert,
|
||||
onChanged: (value) =>
|
||||
setState(() => _autoZeroHopAdvert = value),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SectionHeader(l10n.appSettings_messaging),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: SwitchListTile(
|
||||
contentPadding: switchPadding,
|
||||
// Double form of the delivered tick used in chats.
|
||||
secondary: const Icon(Icons.done_all, size: 24),
|
||||
title: Text(l10n.settings_multiAck),
|
||||
subtitle: Text(l10n.settings_multiAckSubtitle),
|
||||
value: _multiAcks == 1,
|
||||
onChanged: (value) => setState(() => _multiAcks = value ? 1 : 0),
|
||||
),
|
||||
),
|
||||
SectionHeader(l10n.contact_telemetry),
|
||||
MeshInfoCard(l10n.settings_telemetryPerContactHint),
|
||||
MeshCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_telemetryField(
|
||||
label: l10n.settings_telemetryBaseMode,
|
||||
value: _telemetryBase,
|
||||
onChanged: (value) => _telemetryBase = value,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_telemetryField(
|
||||
label: l10n.settings_telemetryLocationMode,
|
||||
value: _telemetryLocation,
|
||||
onChanged: (value) => _telemetryLocation = value,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_telemetryField(
|
||||
label: l10n.settings_telemetryEnvironmentMode,
|
||||
value: _telemetryEnvironment,
|
||||
onChanged: (value) => _telemetryEnvironment = value,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _telemetryField({
|
||||
required String label,
|
||||
required int value,
|
||||
required ValueChanged<int> onChanged,
|
||||
}) {
|
||||
final l10n = context.l10n;
|
||||
DropdownMenuItem<int> item(int mode, String text) => DropdownMenuItem(
|
||||
value: mode,
|
||||
child: Text(text, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
);
|
||||
return DropdownButtonFormField<int>(
|
||||
initialValue: value,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(labelText: label),
|
||||
items: [
|
||||
item(teleModeDeny, l10n.settings_denyAll),
|
||||
item(teleModeAllowFlags, l10n.settings_allowByContact),
|
||||
item(teleModeAllowAll, l10n.settings_allowAll),
|
||||
],
|
||||
onChanged: (mode) {
|
||||
if (mode != null) setState(() => onChanged(mode));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,958 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/radio_settings.dart';
|
||||
import '../services/app_debug_log_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/unsaved_changes_guard.dart';
|
||||
|
||||
/// Convert device coding-rate value (1-4 on some firmware, 5-8 on others)
|
||||
/// to the UI enum range (always 5-8).
|
||||
int _toUiCodingRate(int deviceCr) {
|
||||
return deviceCr <= 4 ? deviceCr + 4 : deviceCr;
|
||||
}
|
||||
|
||||
const Set<int> _defaultRepeatFreqsKHz = {433000, 869495, 918000};
|
||||
|
||||
/// Whether the firmware accepts [freqKHz] for off-grid client repeat, using
|
||||
/// the ranges from CMD_GET_ALLOWED_REPEAT_FREQ when known.
|
||||
bool _isAllowedRepeatFreqKHz(MeshCoreConnector connector, int freqKHz) {
|
||||
final ranges = connector.allowedRepeatFreqRanges;
|
||||
if (ranges == null || ranges.isEmpty) {
|
||||
return _defaultRepeatFreqsKHz.contains(freqKHz);
|
||||
}
|
||||
return ranges.any((r) => freqKHz >= r.lowKHz && freqKHz <= r.highKHz);
|
||||
}
|
||||
|
||||
/// Lowest TX power companion firmware accepts (CMD_SET_RADIO_TX_POWER).
|
||||
const int _minTxPowerDbm = -9;
|
||||
|
||||
/// Form values compared to detect unsaved edits. Numbers are compared parsed
|
||||
/// ("869.6" equals "869.600").
|
||||
typedef _RadioForm = ({
|
||||
Object frequency,
|
||||
LoRaBandwidth bandwidth,
|
||||
LoRaSpreadingFactor spreadingFactor,
|
||||
LoRaCodingRate codingRate,
|
||||
Object txPower,
|
||||
bool clientRepeat,
|
||||
int pathHashByteWidth,
|
||||
});
|
||||
|
||||
/// Radio parameters, sent on Save. Edits stay if the radio rejects them.
|
||||
class RadioSettingsScreen extends StatefulWidget {
|
||||
final MeshCoreConnector connector;
|
||||
|
||||
const RadioSettingsScreen({super.key, required this.connector});
|
||||
|
||||
@override
|
||||
State<RadioSettingsScreen> createState() => _RadioSettingsScreenState();
|
||||
}
|
||||
|
||||
class _RadioSettingsScreenState extends State<RadioSettingsScreen> {
|
||||
final _frequencyController = TextEditingController();
|
||||
LoRaBandwidth _bandwidth = LoRaBandwidth.bw125;
|
||||
LoRaSpreadingFactor _spreadingFactor = LoRaSpreadingFactor.sf7;
|
||||
LoRaCodingRate _codingRate = LoRaCodingRate.cr4_5;
|
||||
final _txPowerController = TextEditingController(text: '20');
|
||||
bool _clientRepeat = false;
|
||||
int _pathHashByteWidth = 1;
|
||||
int? _selectedPresetIndex;
|
||||
_RadioSettingsSnapshot? _lastNonRepeatSnapshot;
|
||||
String? _frequencyError;
|
||||
String? _txPowerError;
|
||||
late _RadioForm _savedForm;
|
||||
|
||||
bool get _supportsPathHashMode => widget.connector.supportsPathHashMode;
|
||||
|
||||
AppDebugLogService get _appLog =>
|
||||
Provider.of<AppDebugLogService>(context, listen: false);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// Populate with current settings if available
|
||||
if (widget.connector.currentFreqHz != null) {
|
||||
_frequencyController.text = (widget.connector.currentFreqHz! / 1000.0)
|
||||
.toStringAsFixed(3);
|
||||
} else {
|
||||
_frequencyController.text = '915.0';
|
||||
}
|
||||
|
||||
if (widget.connector.currentBwHz != null) {
|
||||
// Find matching bandwidth enum
|
||||
final bwValue = widget.connector.currentBwHz!;
|
||||
for (var bw in LoRaBandwidth.values) {
|
||||
if (bw.hz == bwValue) {
|
||||
_bandwidth = bw;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (widget.connector.currentSf != null) {
|
||||
// Find matching spreading factor enum
|
||||
final sfValue = widget.connector.currentSf!;
|
||||
for (var sf in LoRaSpreadingFactor.values) {
|
||||
if (sf.value == sfValue) {
|
||||
_spreadingFactor = sf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (widget.connector.currentCr != null) {
|
||||
// Find matching coding rate enum
|
||||
final crValue = _toUiCodingRate(widget.connector.currentCr!);
|
||||
for (var cr in LoRaCodingRate.values) {
|
||||
if (cr.value == crValue) {
|
||||
_codingRate = cr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (widget.connector.currentTxPower != null) {
|
||||
_txPowerController.text = widget.connector.currentTxPower.toString();
|
||||
}
|
||||
|
||||
_pathHashByteWidth = widget.connector.pathHashByteWidth;
|
||||
_clientRepeat = widget.connector.clientRepeat ?? false;
|
||||
_selectedPresetIndex = _findMatchingPresetIndex();
|
||||
if (_clientRepeat) {
|
||||
_lastNonRepeatSnapshot =
|
||||
_sessionRememberedNonRepeatSnapshot() ??
|
||||
_inferNonRepeatSnapshotForRepeatEnabled();
|
||||
_selectedPresetIndex = _findMatchingPresetIndexForSnapshot(
|
||||
_lastNonRepeatSnapshot!,
|
||||
);
|
||||
} else {
|
||||
_lastNonRepeatSnapshot = _nonRepeatSnapshotForCurrentSelection();
|
||||
}
|
||||
_savedForm = _currentForm();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
_logRadioSettingsState('Page initialized');
|
||||
});
|
||||
}
|
||||
|
||||
_RadioForm _currentForm() {
|
||||
final frequencyText = _frequencyController.text.trim();
|
||||
final frequencyMHz = double.tryParse(frequencyText);
|
||||
final txPowerText = _txPowerController.text.trim();
|
||||
return (
|
||||
frequency: frequencyMHz == null
|
||||
? frequencyText
|
||||
: (frequencyMHz * 1000).round(),
|
||||
bandwidth: _bandwidth,
|
||||
spreadingFactor: _spreadingFactor,
|
||||
codingRate: _codingRate,
|
||||
txPower: int.tryParse(txPowerText) ?? txPowerText,
|
||||
clientRepeat: _clientRepeat,
|
||||
pathHashByteWidth: _pathHashByteWidth,
|
||||
);
|
||||
}
|
||||
|
||||
bool get _hasChanges => _currentForm() != _savedForm;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_frequencyController.dispose();
|
||||
_txPowerController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _applyPreset(int index) {
|
||||
setState(() {
|
||||
_applyPresetState(index);
|
||||
});
|
||||
_logRadioSettingsState(
|
||||
'Applied preset ${RadioSettings.presets[index].$1} (#$index)',
|
||||
);
|
||||
}
|
||||
|
||||
int? _findMatchingPresetIndex() {
|
||||
return _findMatchingPresetIndexForSnapshot(_currentSnapshot());
|
||||
}
|
||||
|
||||
int? _findMatchingPresetIndexForSnapshot(_RadioSettingsSnapshot snapshot) {
|
||||
for (final i in _visiblePresetIndexes()) {
|
||||
final preset = RadioSettings.presets[i].$2;
|
||||
if (preset.frequencyHz == snapshot.frequencyHz &&
|
||||
preset.bandwidth == snapshot.bandwidth &&
|
||||
preset.spreadingFactor == snapshot.spreadingFactor &&
|
||||
preset.codingRate == snapshot.codingRate) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Iterable<int> _visiblePresetIndexes() sync* {
|
||||
for (var i = 0; i < RadioSettings.presets.length; i++) {
|
||||
if (_isOffGridPresetIndex(i)) {
|
||||
continue;
|
||||
}
|
||||
yield i;
|
||||
}
|
||||
}
|
||||
|
||||
_RadioSettingsSnapshot _currentSnapshot() {
|
||||
final frequencyMHz = double.tryParse(_frequencyController.text) ?? 915.0;
|
||||
final txPowerDbm = int.tryParse(_txPowerController.text) ?? 20;
|
||||
return _RadioSettingsSnapshot(
|
||||
frequencyMHz: frequencyMHz,
|
||||
bandwidth: _bandwidth,
|
||||
spreadingFactor: _spreadingFactor,
|
||||
codingRate: _codingRate,
|
||||
txPowerDbm: txPowerDbm,
|
||||
);
|
||||
}
|
||||
|
||||
bool _isOffGridPresetIndex(int? index) {
|
||||
if (index == null) return false;
|
||||
return RadioSettings.presets[index].$1.startsWith('Off-Grid ');
|
||||
}
|
||||
|
||||
double _offGridFrequencyForBaseFrequency(double baseFrequencyMHz) {
|
||||
final baseKHz = (baseFrequencyMHz * 1000).round();
|
||||
final ranges = widget.connector.allowedRepeatFreqRanges;
|
||||
final candidates = ranges == null || ranges.isEmpty
|
||||
? _defaultRepeatFreqsKHz
|
||||
: {for (final r in ranges) baseKHz.clamp(r.lowKHz, r.highKHz)};
|
||||
final closestKHz = candidates.reduce(
|
||||
(a, b) => (a - baseKHz).abs() <= (b - baseKHz).abs() ? a : b,
|
||||
);
|
||||
return closestKHz / 1000.0;
|
||||
}
|
||||
|
||||
double _normalFrequencyForBand(double frequencyMHz) {
|
||||
if (frequencyMHz < 500) return 433.650;
|
||||
if (frequencyMHz < 900) return 869.432;
|
||||
return 915.8;
|
||||
}
|
||||
|
||||
_RadioSettingsSnapshot _fallbackNonRepeatSnapshot(
|
||||
double currentFrequencyMHz,
|
||||
) {
|
||||
return _RadioSettingsSnapshot(
|
||||
frequencyMHz: _normalFrequencyForBand(currentFrequencyMHz),
|
||||
bandwidth: _bandwidth,
|
||||
spreadingFactor: _spreadingFactor,
|
||||
codingRate: _codingRate,
|
||||
txPowerDbm: int.tryParse(_txPowerController.text) ?? 20,
|
||||
);
|
||||
}
|
||||
|
||||
_RadioSettingsSnapshot _nonRepeatSnapshotForCurrentSelection() {
|
||||
final current = _currentSnapshot();
|
||||
if (!_isOffGridPresetIndex(_selectedPresetIndex)) {
|
||||
return current;
|
||||
}
|
||||
return _fallbackNonRepeatSnapshot(current.frequencyMHz);
|
||||
}
|
||||
|
||||
_RadioSettingsSnapshot? _sessionRememberedNonRepeatSnapshot() {
|
||||
final snapshot = widget.connector.rememberedNonRepeatRadioState;
|
||||
if (snapshot == null) return null;
|
||||
return _RadioSettingsSnapshot.fromMeshCoreSnapshot(snapshot);
|
||||
}
|
||||
|
||||
_RadioSettingsSnapshot _inferNonRepeatSnapshotForRepeatEnabled() {
|
||||
final current = _currentSnapshot();
|
||||
for (final i in _visiblePresetIndexes()) {
|
||||
final preset = RadioSettings.presets[i].$2;
|
||||
final offGridFreqHz =
|
||||
(_offGridFrequencyForBaseFrequency(preset.frequencyMHz) * 1000)
|
||||
.round();
|
||||
if (offGridFreqHz == current.frequencyHz &&
|
||||
preset.bandwidth == current.bandwidth &&
|
||||
preset.spreadingFactor == current.spreadingFactor &&
|
||||
preset.codingRate == current.codingRate) {
|
||||
return _RadioSettingsSnapshot(
|
||||
frequencyMHz: preset.frequencyMHz,
|
||||
bandwidth: preset.bandwidth,
|
||||
spreadingFactor: preset.spreadingFactor,
|
||||
codingRate: preset.codingRate,
|
||||
txPowerDbm: current.txPowerDbm,
|
||||
);
|
||||
}
|
||||
}
|
||||
return _fallbackNonRepeatSnapshot(current.frequencyMHz);
|
||||
}
|
||||
|
||||
void _applySnapshot(_RadioSettingsSnapshot snapshot) {
|
||||
_frequencyController.text = snapshot.frequencyMHz.toStringAsFixed(3);
|
||||
_bandwidth = snapshot.bandwidth;
|
||||
_spreadingFactor = snapshot.spreadingFactor;
|
||||
_codingRate = snapshot.codingRate;
|
||||
_txPowerController.text = snapshot.txPowerDbm.toString();
|
||||
}
|
||||
|
||||
void _applyPresetState(int index) {
|
||||
final preset = RadioSettings.presets[index].$2;
|
||||
final baseSnapshot = _RadioSettingsSnapshot(
|
||||
frequencyMHz: preset.frequencyMHz,
|
||||
bandwidth: preset.bandwidth,
|
||||
spreadingFactor: preset.spreadingFactor,
|
||||
codingRate: preset.codingRate,
|
||||
txPowerDbm: preset.txPowerDbm,
|
||||
);
|
||||
final frequencyMHz = _clientRepeat
|
||||
? _offGridFrequencyForBaseFrequency(baseSnapshot.frequencyMHz)
|
||||
: baseSnapshot.frequencyMHz;
|
||||
_frequencyController.text = frequencyMHz.toString();
|
||||
_bandwidth = preset.bandwidth;
|
||||
_spreadingFactor = preset.spreadingFactor;
|
||||
_codingRate = preset.codingRate;
|
||||
_txPowerController.text = preset.txPowerDbm.toString();
|
||||
_selectedPresetIndex = index;
|
||||
_lastNonRepeatSnapshot = baseSnapshot;
|
||||
// Programmatic writes skip TextField.onChanged, so clear any stale
|
||||
// frequency/TX errors here or Save stays disabled.
|
||||
_validateFields();
|
||||
}
|
||||
|
||||
void _syncPresetSelection() {
|
||||
final previousPresetIndex = _selectedPresetIndex;
|
||||
final previousLastNonRepeat = _lastNonRepeatSnapshot;
|
||||
if (_clientRepeat) {
|
||||
final baseSnapshot =
|
||||
previousLastNonRepeat ?? _inferNonRepeatSnapshotForRepeatEnabled();
|
||||
if (_bandwidth != baseSnapshot.bandwidth ||
|
||||
_spreadingFactor != baseSnapshot.spreadingFactor ||
|
||||
_codingRate != baseSnapshot.codingRate ||
|
||||
(int.tryParse(_txPowerController.text) ?? 20) !=
|
||||
baseSnapshot.txPowerDbm) {
|
||||
_lastNonRepeatSnapshot = _RadioSettingsSnapshot(
|
||||
frequencyMHz: baseSnapshot.frequencyMHz,
|
||||
bandwidth: _bandwidth,
|
||||
spreadingFactor: _spreadingFactor,
|
||||
codingRate: _codingRate,
|
||||
txPowerDbm: int.tryParse(_txPowerController.text) ?? 20,
|
||||
);
|
||||
}
|
||||
_selectedPresetIndex = _findMatchingPresetIndexForSnapshot(
|
||||
_lastNonRepeatSnapshot ?? baseSnapshot,
|
||||
);
|
||||
if (previousPresetIndex != _selectedPresetIndex ||
|
||||
previousLastNonRepeat != _lastNonRepeatSnapshot) {
|
||||
_logRadioSettingsState(
|
||||
'Preset match updated while repeat enabled: ${_presetLabel(previousPresetIndex)} -> ${_presetLabel(_selectedPresetIndex)}',
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
_lastNonRepeatSnapshot = _nonRepeatSnapshotForCurrentSelection();
|
||||
_selectedPresetIndex = _findMatchingPresetIndexForSnapshot(
|
||||
_lastNonRepeatSnapshot!,
|
||||
);
|
||||
if (previousPresetIndex != _selectedPresetIndex ||
|
||||
previousLastNonRepeat != _lastNonRepeatSnapshot) {
|
||||
_logRadioSettingsState(
|
||||
'Preset sync updated state from ${_presetLabel(previousPresetIndex)} to ${_presetLabel(_selectedPresetIndex)}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _handleManualSettingsChanged(String source) {
|
||||
_logRadioSettingsState('Manual settings edit: $source');
|
||||
setState(() {
|
||||
_validateFields();
|
||||
_syncPresetSelection();
|
||||
});
|
||||
}
|
||||
|
||||
void _validateFields() {
|
||||
final l10n = context.l10n;
|
||||
final freqMHz = double.tryParse(_frequencyController.text);
|
||||
_frequencyError = (freqMHz == null || freqMHz < 150 || freqMHz > 2500)
|
||||
? l10n.settings_frequencyInvalid
|
||||
: null;
|
||||
|
||||
final maxTxPower = widget.connector.maxTxPower ?? 22;
|
||||
final txPower = int.tryParse(_txPowerController.text);
|
||||
_txPowerError =
|
||||
(txPower == null || txPower < _minTxPowerDbm || txPower > maxTxPower)
|
||||
? l10n.settings_txPowerInvalidRange(_minTxPowerDbm, maxTxPower)
|
||||
: null;
|
||||
}
|
||||
|
||||
void _handleClientRepeatChanged(bool enabled) {
|
||||
_logRadioSettingsState(
|
||||
'Off-grid repeat toggle requested: $_clientRepeat -> $enabled',
|
||||
);
|
||||
setState(() {
|
||||
final currentSnapshot = _currentSnapshot();
|
||||
if (enabled) {
|
||||
if (!_clientRepeat) {
|
||||
_syncPresetSelection();
|
||||
}
|
||||
final baseSnapshot = _lastNonRepeatSnapshot ?? currentSnapshot;
|
||||
_clientRepeat = true;
|
||||
_frequencyController.text = _offGridFrequencyForBaseFrequency(
|
||||
baseSnapshot.frequencyMHz,
|
||||
).toStringAsFixed(3);
|
||||
_validateFields();
|
||||
return;
|
||||
}
|
||||
|
||||
_clientRepeat = false;
|
||||
_applySnapshot(
|
||||
_lastNonRepeatSnapshot ??
|
||||
_fallbackNonRepeatSnapshot(currentSnapshot.frequencyMHz),
|
||||
);
|
||||
_validateFields();
|
||||
_syncPresetSelection();
|
||||
});
|
||||
_logRadioSettingsState('Off-grid repeat toggle applied');
|
||||
}
|
||||
|
||||
/// Returns whether the radio applied every change.
|
||||
Future<bool> _saveSettings() async {
|
||||
final l10n = context.l10n;
|
||||
final freqMHz = double.tryParse(_frequencyController.text);
|
||||
final txPower = int.tryParse(_txPowerController.text);
|
||||
|
||||
if (freqMHz == null || freqMHz < 150 || freqMHz > 2500) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_frequencyInvalid),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
final maxTxPower = widget.connector.maxTxPower ?? 22;
|
||||
if (txPower == null || txPower < _minTxPowerDbm || txPower > maxTxPower) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
l10n.settings_txPowerInvalidRange(_minTxPowerDbm, maxTxPower),
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
final freqHz = (freqMHz * 1000).round();
|
||||
final bwHz = _bandwidth.hz;
|
||||
final sf = _spreadingFactor.value;
|
||||
final cr = _codingRate.value;
|
||||
|
||||
// if the client repeat isnt null then we know its supported
|
||||
//otherwise we leave it out of the frame to avoid accidentally enabling
|
||||
final knownRepeat = widget.connector.clientRepeat != null;
|
||||
|
||||
if (knownRepeat) {
|
||||
if (_clientRepeat && !_isAllowedRepeatFreqKHz(widget.connector, freqHz)) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_clientRepeatFreqWarning),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
_logRadioSettingsState('Saving radio settings');
|
||||
final accepted = await widget.connector.setRadioParams(
|
||||
freqHz,
|
||||
bwHz,
|
||||
sf,
|
||||
cr,
|
||||
clientRepeat: knownRepeat ? _clientRepeat : null,
|
||||
);
|
||||
if (!accepted) {
|
||||
_logRadioSettingsState('Radio rejected requested settings');
|
||||
if (!mounted) return false;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_radioSettingsNotApplied),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
await widget.connector.sendFrame(buildSetRadioTxPowerFrame(txPower));
|
||||
// setPathHashMode updates the local width optimistically; the refreshed
|
||||
// DEVICE_INFO below overwrites it with what the radio actually stored.
|
||||
final requestedPathHashWidth =
|
||||
_supportsPathHashMode &&
|
||||
_pathHashByteWidth != widget.connector.pathHashByteWidth
|
||||
? _pathHashByteWidth
|
||||
: null;
|
||||
if (requestedPathHashWidth != null) {
|
||||
await widget.connector.setPathHashMode(requestedPathHashWidth - 1);
|
||||
}
|
||||
final selfInfo = widget.connector.receivedFrames
|
||||
.firstWhere((f) => f.isNotEmpty && f[0] == respCodeSelfInfo)
|
||||
.timeout(const Duration(seconds: 5));
|
||||
final deviceInfo = requestedPathHashWidth == null
|
||||
? null
|
||||
: widget.connector.receivedFrames
|
||||
.firstWhere((f) => f.isNotEmpty && f[0] == respCodeDeviceInfo)
|
||||
.timeout(const Duration(seconds: 5));
|
||||
await widget.connector.refreshDeviceInfo();
|
||||
// Without a refreshed DEVICE_INFO the path hash change is unconfirmed
|
||||
// (this also covers setPathHashMode skipping a disconnected radio).
|
||||
final pathHashApplied =
|
||||
deviceInfo == null ||
|
||||
await deviceInfo.then(
|
||||
(_) => widget.connector.pathHashByteWidth == requestedPathHashWidth,
|
||||
onError: (_) => false,
|
||||
);
|
||||
final radioApplied = await selfInfo.then(
|
||||
(_) => _deviceMatches(
|
||||
freqHz: freqHz,
|
||||
bwHz: bwHz,
|
||||
sf: sf,
|
||||
cr: cr,
|
||||
txPower: txPower,
|
||||
clientRepeat: knownRepeat ? _clientRepeat : null,
|
||||
),
|
||||
onError: (_) => true,
|
||||
);
|
||||
if (!radioApplied) {
|
||||
_logRadioSettingsState('Radio did not apply requested settings');
|
||||
if (!mounted) return false;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_radioSettingsNotApplied),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (!pathHashApplied) {
|
||||
// Radio params and TX power were already applied; only the path
|
||||
// hash size is outstanding, so say that rather than a generic error.
|
||||
_logRadioSettingsState('Radio did not apply requested path hash size');
|
||||
if (!mounted) return false;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_pathHashModeNotApplied),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
final rememberedSnapshot = _clientRepeat
|
||||
? _lastNonRepeatSnapshot
|
||||
: _currentSnapshot();
|
||||
if (rememberedSnapshot != null) {
|
||||
widget.connector.rememberNonRepeatRadioState(
|
||||
rememberedSnapshot.toMeshCoreSnapshot(),
|
||||
);
|
||||
}
|
||||
|
||||
if (!mounted) return true;
|
||||
_logRadioSettingsState('Radio settings saved successfully');
|
||||
setState(() => _savedForm = _currentForm());
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_radioSettingsUpdated),
|
||||
);
|
||||
return true;
|
||||
} catch (e) {
|
||||
_appLog.warn('Radio settings save failed: $e', tag: 'RadioSettings');
|
||||
if (!mounted) return false;
|
||||
// Keep the edits so the user can retry.
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_error(e.toString())),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool _deviceMatches({
|
||||
required int freqHz,
|
||||
required int bwHz,
|
||||
required int sf,
|
||||
required int cr,
|
||||
required int txPower,
|
||||
required bool? clientRepeat,
|
||||
}) {
|
||||
final c = widget.connector;
|
||||
// Firmware stores freq/bw as float MHz/kHz, so allow 1 unit of rounding.
|
||||
return c.currentFreqHz != null &&
|
||||
(c.currentFreqHz! - freqHz).abs() <= 1 &&
|
||||
c.currentBwHz != null &&
|
||||
(c.currentBwHz! - bwHz).abs() <= 1 &&
|
||||
c.currentSf == sf &&
|
||||
c.currentCr != null &&
|
||||
_toUiCodingRate(c.currentCr!) == cr &&
|
||||
c.currentTxPower == txPower &&
|
||||
(clientRepeat == null || c.clientRepeat == clientRepeat);
|
||||
}
|
||||
|
||||
String _presetLabel(int? index) {
|
||||
if (index == null) {
|
||||
return 'custom';
|
||||
}
|
||||
return '${RadioSettings.presets[index].$1} (#$index)';
|
||||
}
|
||||
|
||||
String _formatSnapshot(_RadioSettingsSnapshot? snapshot) {
|
||||
if (snapshot == null) {
|
||||
return 'null';
|
||||
}
|
||||
return '${snapshot.frequencyMHz.toStringAsFixed(3)}MHz/'
|
||||
'${snapshot.bandwidth.label}/'
|
||||
'${snapshot.spreadingFactor.label}/'
|
||||
'${snapshot.codingRate.label}/'
|
||||
'${snapshot.txPowerDbm}dBm';
|
||||
}
|
||||
|
||||
void _logRadioSettingsState(String message) {
|
||||
if (!kDebugMode) return;
|
||||
_appLog.info(
|
||||
'$message | '
|
||||
'freq=${_frequencyController.text}MHz '
|
||||
'bw=${_bandwidth.label} '
|
||||
'sf=${_spreadingFactor.label} '
|
||||
'cr=${_codingRate.label} '
|
||||
'tx=${_txPowerController.text}dBm '
|
||||
'pathHash=${_pathHashByteWidth}B '
|
||||
'repeat=$_clientRepeat '
|
||||
'preset=${_presetLabel(_selectedPresetIndex)} '
|
||||
'lastNonRepeat=${_formatSnapshot(_lastNonRepeatSnapshot)}',
|
||||
tag: 'RadioSettings',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return SaveToRadioPage(
|
||||
title: l10n.settings_radioSettings,
|
||||
hasChanges: _hasChanges,
|
||||
canSave: _frequencyError == null && _txPowerError == null,
|
||||
onSave: _saveSettings,
|
||||
children: [
|
||||
SectionHeader(l10n.settings_radioParameters),
|
||||
MeshCard(child: _buildPresetField(context)),
|
||||
MeshCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: _buildParameterFields(context),
|
||||
),
|
||||
),
|
||||
if (widget.connector.clientRepeat != null) ...[
|
||||
SectionHeader(l10n.settings_clientRepeat),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_offGridText(context, l10n.settings_clientRepeatDescription),
|
||||
const Divider(height: 1, indent: 16, endIndent: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
secondary: const ThemedIcon(ThemeIconSlot.repeater, size: 24),
|
||||
title: Text(l10n.settings_clientRepeatSwitch),
|
||||
value: _clientRepeat,
|
||||
onChanged: _handleClientRepeatChanged,
|
||||
),
|
||||
const Divider(height: 1, indent: 16, endIndent: 16),
|
||||
_offGridText(context, l10n.settings_clientRepeatNote),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Explanation text in the Off-Grid card, styled like tile subtitles.
|
||||
Widget _offGridText(BuildContext context, String text) {
|
||||
final theme = Theme.of(context);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
child: Text(
|
||||
text,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPresetField(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return DropdownButtonFormField<int>(
|
||||
key: ValueKey<int?>(_selectedPresetIndex),
|
||||
initialValue: _selectedPresetIndex ?? -1,
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(labelText: l10n.settings_presets),
|
||||
items: [
|
||||
if (_selectedPresetIndex == null)
|
||||
DropdownMenuItem(value: -1, child: Text(l10n.settings_presetCustom)),
|
||||
for (final i in _visiblePresetIndexes())
|
||||
DropdownMenuItem(
|
||||
value: i,
|
||||
child: Text(
|
||||
RadioSettings.presets[i].$1,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (index) {
|
||||
if (index != null && index >= 0) {
|
||||
_applyPreset(index);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildParameterFields(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return [
|
||||
TextField(
|
||||
controller: _frequencyController,
|
||||
onTapOutside: (_) => FocusScope.of(context).unfocus(),
|
||||
onChanged: (_) => _handleManualSettingsChanged('frequency'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_frequency,
|
||||
helperText: _clientRepeat
|
||||
? l10n.settings_clientRepeatFrequencyNote(
|
||||
_frequencyController.text,
|
||||
)
|
||||
: l10n.settings_frequencyHelper,
|
||||
helperMaxLines: 3,
|
||||
errorText: _frequencyError,
|
||||
errorMaxLines: 3,
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<LoRaBandwidth>(
|
||||
isExpanded: true,
|
||||
initialValue: _bandwidth,
|
||||
decoration: InputDecoration(labelText: l10n.settings_bandwidth),
|
||||
items: LoRaBandwidth.values
|
||||
.map(
|
||||
(bw) => DropdownMenuItem(
|
||||
value: bw,
|
||||
child: Text(bw.label, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_bandwidth = value;
|
||||
_syncPresetSelection();
|
||||
});
|
||||
_logRadioSettingsState('Manual settings edit: bandwidth');
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<LoRaSpreadingFactor>(
|
||||
isExpanded: true,
|
||||
initialValue: _spreadingFactor,
|
||||
decoration: InputDecoration(labelText: l10n.settings_spreadingFactor),
|
||||
items: LoRaSpreadingFactor.values
|
||||
.map(
|
||||
(sf) => DropdownMenuItem(
|
||||
value: sf,
|
||||
child: Text(sf.label, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_spreadingFactor = value;
|
||||
_syncPresetSelection();
|
||||
});
|
||||
_logRadioSettingsState('Manual settings edit: spreading factor');
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<LoRaCodingRate>(
|
||||
isExpanded: true,
|
||||
initialValue: _codingRate,
|
||||
decoration: InputDecoration(labelText: l10n.settings_codingRate),
|
||||
items: LoRaCodingRate.values
|
||||
.map(
|
||||
(cr) => DropdownMenuItem(
|
||||
value: cr,
|
||||
child: Text(cr.label, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_codingRate = value;
|
||||
_syncPresetSelection();
|
||||
});
|
||||
_logRadioSettingsState('Manual settings edit: coding rate');
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _txPowerController,
|
||||
onTapOutside: (_) => FocusScope.of(context).unfocus(),
|
||||
onChanged: (_) => _handleManualSettingsChanged('tx power'),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_txPower,
|
||||
helperText: l10n.settings_txPowerRangeHelper(
|
||||
_minTxPowerDbm,
|
||||
widget.connector.maxTxPower ?? 22,
|
||||
),
|
||||
helperMaxLines: 3,
|
||||
errorText: _txPowerError,
|
||||
errorMaxLines: 3,
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
if (_supportsPathHashMode) ...[
|
||||
const SizedBox(height: 16),
|
||||
_buildPathHashField(context),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/// The helper text, with the quoted example IDs ("ab12") in monospace like
|
||||
/// other hashes. A widget helper has no line limit.
|
||||
Widget _pathHashHelper(BuildContext context, String text) {
|
||||
final theme = Theme.of(context);
|
||||
final style = theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
);
|
||||
final mono = MeshTheme.mono(fontSize: style?.fontSize, color: style?.color);
|
||||
final spans = <TextSpan>[];
|
||||
var last = 0;
|
||||
for (final m in RegExp(r'"[^"\n]+"').allMatches(text)) {
|
||||
spans.add(TextSpan(text: text.substring(last, m.start)));
|
||||
spans.add(TextSpan(text: m[0], style: mono));
|
||||
last = m.end;
|
||||
}
|
||||
spans.add(TextSpan(text: text.substring(last)));
|
||||
return Text.rich(TextSpan(style: style, children: spans));
|
||||
}
|
||||
|
||||
Widget _buildPathHashField(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
// Values are path hash modes (0-2, byte width - 1), matching the
|
||||
// selector in repeater_settings_screen.
|
||||
return DropdownButtonFormField<int>(
|
||||
isExpanded: true,
|
||||
initialValue: (_pathHashByteWidth - 1).clamp(0, 2).toInt(),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_pathHashMode,
|
||||
helper: _pathHashHelper(context, l10n.settings_pathHashModeHelper),
|
||||
),
|
||||
items: [
|
||||
DropdownMenuItem(
|
||||
value: 0,
|
||||
child: Text(
|
||||
l10n.repeater_pathHashModeOption0,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 1,
|
||||
child: Text(
|
||||
l10n.repeater_pathHashModeOption1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 2,
|
||||
child: Text(
|
||||
l10n.repeater_pathHashModeOption2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (value) {
|
||||
if (value == null) return;
|
||||
setState(() => _pathHashByteWidth = value + 1);
|
||||
_logRadioSettingsState('Manual settings edit: path hash size');
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RadioSettingsSnapshot {
|
||||
final double frequencyMHz;
|
||||
final LoRaBandwidth bandwidth;
|
||||
final LoRaSpreadingFactor spreadingFactor;
|
||||
final LoRaCodingRate codingRate;
|
||||
final int txPowerDbm;
|
||||
|
||||
const _RadioSettingsSnapshot({
|
||||
required this.frequencyMHz,
|
||||
required this.bandwidth,
|
||||
required this.spreadingFactor,
|
||||
required this.codingRate,
|
||||
required this.txPowerDbm,
|
||||
});
|
||||
|
||||
/// Frequency in integer Hz — avoids floating-point comparison issues.
|
||||
int get frequencyHz => (frequencyMHz * 1000).round();
|
||||
|
||||
/// Convert from the connector's raw-int snapshot to UI-enum snapshot.
|
||||
static _RadioSettingsSnapshot? fromMeshCoreSnapshot(
|
||||
MeshCoreRadioStateSnapshot snapshot,
|
||||
) {
|
||||
final bw = LoRaBandwidth.values
|
||||
.where((b) => b.hz == snapshot.bwHz)
|
||||
.firstOrNull;
|
||||
final sf = LoRaSpreadingFactor.values
|
||||
.where((s) => s.value == snapshot.sf)
|
||||
.firstOrNull;
|
||||
final cr = LoRaCodingRate.values
|
||||
.where((c) => c.value == _toUiCodingRate(snapshot.cr))
|
||||
.firstOrNull;
|
||||
if (bw == null || sf == null || cr == null) return null;
|
||||
return _RadioSettingsSnapshot(
|
||||
frequencyMHz: snapshot.freqHz / 1000.0,
|
||||
bandwidth: bw,
|
||||
spreadingFactor: sf,
|
||||
codingRate: cr,
|
||||
txPowerDbm: snapshot.txPowerDbm,
|
||||
);
|
||||
}
|
||||
|
||||
/// Convert back to the connector's raw-int snapshot.
|
||||
MeshCoreRadioStateSnapshot toMeshCoreSnapshot() {
|
||||
return MeshCoreRadioStateSnapshot(
|
||||
freqHz: frequencyHz,
|
||||
bwHz: bandwidth.hz,
|
||||
sf: spreadingFactor.value,
|
||||
cr: codingRate.value,
|
||||
txPowerDbm: txPowerDbm,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is _RadioSettingsSnapshot &&
|
||||
frequencyHz == other.frequencyHz &&
|
||||
bandwidth == other.bandwidth &&
|
||||
spreadingFactor == other.spreadingFactor &&
|
||||
codingRate == other.codingRate &&
|
||||
txPowerDbm == other.txPowerDbm;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
frequencyHz,
|
||||
bandwidth,
|
||||
spreadingFactor,
|
||||
codingRate,
|
||||
txPowerDbm,
|
||||
);
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import '../widgets/mesh_nav_tile.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/radio_disconnected_banner.dart';
|
||||
import '../widgets/routing_sheet.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
import '../utils/keys.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
|
||||
@@ -889,12 +890,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
label: Text(l10n.common_save),
|
||||
),
|
||||
],
|
||||
bottom: _loadingAll
|
||||
? PreferredSize(
|
||||
preferredSize: const Size.fromHeight(4),
|
||||
child: LinearProgressIndicator(value: _loadAllProgress),
|
||||
)
|
||||
: null,
|
||||
bottom: MeshProgressAppBarBottom(
|
||||
active: _loadingAll,
|
||||
value: _loadAllProgress,
|
||||
),
|
||||
),
|
||||
body: MeshSettingsTileTheme(
|
||||
child: SafeArea(
|
||||
|
||||
+135
-854
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user