Merge upstream/dev (22 commits) [upstream-sync]
Conflicts resolved by hand, our fork changes carried over: - MainActivity.kt: keep the unread widget hooks next to upstream's scroll capture (attach and detach both). - app_settings_screen.dart: upstream wrapped the list in MeshSettingsTileTheme; image-message and translation sections stay gated on kOnDeviceMl (ML-free build). - channel_chat_screen.dart: upstream split build() into methods; took theirs and re-applied the terminal-theme list padding. - chat_composer.dart: both imports (terminal_theme, radio_guard). - mesh_nav_tile.dart: upstream's meshTileTitleStyle, with the smaller terminal-theme title kept. flutter analyze clean, flutter test 1522 passed (CI image, local). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
185d2aca53
210 files changed
+52066
-5541
No files matched your search
@@ -46,94 +46,96 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
centerTitle: true,
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
// Each card subscribes to only what it shows, so connector traffic
|
||||
// and translation download ticks do not rebuild the whole list.
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
|
||||
children: [
|
||||
// APPEARANCE
|
||||
SectionHeader(context.l10n.appSettings_appearance),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildAppearanceContent),
|
||||
),
|
||||
|
||||
// NOTIFICATIONS
|
||||
SectionHeader(context.l10n.appSettings_notifications),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildNotificationsContent),
|
||||
),
|
||||
|
||||
// MESSAGING
|
||||
SectionHeader(context.l10n.appSettings_messaging),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildMessagingContent),
|
||||
),
|
||||
|
||||
// ROUTING
|
||||
SectionHeader(context.l10n.appSettings_routingSection),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildRoutingContent),
|
||||
),
|
||||
|
||||
// IMAGE MESSAGES
|
||||
if (kOnDeviceMl) ...[
|
||||
SectionHeader(context.l10n.appSettings_imageMessagesSection),
|
||||
body: MeshSettingsTileTheme(
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
// Each card subscribes to only what it shows, so connector traffic
|
||||
// and translation download ticks do not rebuild the whole list.
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
|
||||
children: [
|
||||
// APPEARANCE
|
||||
SectionHeader(context.l10n.appSettings_appearance),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildImageMessagesContent),
|
||||
child: _settingsCard(_buildAppearanceContent),
|
||||
),
|
||||
],
|
||||
|
||||
// BATTERY
|
||||
SectionHeader(context.l10n.appSettings_battery),
|
||||
MeshCard(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 16),
|
||||
child: _settingsCard(_buildBatteryContent),
|
||||
),
|
||||
// NOTIFICATIONS
|
||||
SectionHeader(context.l10n.appSettings_notifications),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildNotificationsContent),
|
||||
),
|
||||
|
||||
// MAP
|
||||
SectionHeader(context.l10n.appSettings_mapDisplay),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildMapContent),
|
||||
),
|
||||
// MESSAGING
|
||||
SectionHeader(context.l10n.appSettings_messaging),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildMessagingContent),
|
||||
),
|
||||
|
||||
// NETWORK MAP
|
||||
SectionHeader(context.l10n.networkMap_settingsSection),
|
||||
const MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: NetworkMapSettingsSection(),
|
||||
),
|
||||
// ROUTING
|
||||
SectionHeader(context.l10n.appSettings_routingSection),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildRoutingContent),
|
||||
),
|
||||
|
||||
// TRANSLATION (non-web only)
|
||||
if (!kIsWeb && kOnDeviceMl) ...[
|
||||
SectionHeader(context.l10n.translation_title),
|
||||
// IMAGE MESSAGES
|
||||
if (kOnDeviceMl) ...[
|
||||
SectionHeader(context.l10n.appSettings_imageMessagesSection),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildImageMessagesContent),
|
||||
),
|
||||
],
|
||||
|
||||
// BATTERY
|
||||
SectionHeader(context.l10n.appSettings_battery),
|
||||
MeshCard(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 16),
|
||||
child: _settingsCard(_buildBatteryContent),
|
||||
),
|
||||
|
||||
// MAP
|
||||
SectionHeader(context.l10n.appSettings_mapDisplay),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildMapContent),
|
||||
),
|
||||
|
||||
// NETWORK MAP
|
||||
SectionHeader(context.l10n.networkMap_settingsSection),
|
||||
const MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: TranslationSettingsSection(),
|
||||
child: NetworkMapSettingsSection(),
|
||||
),
|
||||
|
||||
// TRANSLATION (non-web only)
|
||||
if (!kIsWeb && kOnDeviceMl) ...[
|
||||
SectionHeader(context.l10n.translation_title),
|
||||
const MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: TranslationSettingsSection(),
|
||||
),
|
||||
],
|
||||
|
||||
// CYR2LAT
|
||||
SectionHeader(context.l10n.channels_cyr2latSettingsHeading),
|
||||
MeshCard(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 16),
|
||||
child: _settingsCard(_buildCyr2LatContent),
|
||||
),
|
||||
|
||||
// DEBUG
|
||||
SectionHeader(context.l10n.appSettings_debugCard),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildDebugContent),
|
||||
),
|
||||
],
|
||||
|
||||
// CYR2LAT
|
||||
SectionHeader(context.l10n.channels_cyr2latSettingsHeading),
|
||||
MeshCard(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 16),
|
||||
child: _settingsCard(_buildCyr2LatContent),
|
||||
),
|
||||
|
||||
// DEBUG
|
||||
SectionHeader(context.l10n.appSettings_debugCard),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildDebugContent),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -185,15 +187,19 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
segments: [
|
||||
ButtonSegment(
|
||||
value: 'system',
|
||||
label: Text(context.l10n.appSettings_themeSystem),
|
||||
label: MeshSegmentLabel(
|
||||
context.l10n.appSettings_themeSystem,
|
||||
),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: 'light',
|
||||
label: Text(context.l10n.appSettings_themeLight),
|
||||
label: MeshSegmentLabel(
|
||||
context.l10n.appSettings_themeLight,
|
||||
),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: 'dark',
|
||||
label: Text(context.l10n.appSettings_themeDark),
|
||||
label: MeshSegmentLabel(context.l10n.appSettings_themeDark),
|
||||
),
|
||||
// tth fork: untranslated on purpose, it is a name.
|
||||
const ButtonSegment(value: 'terminal', label: Text('Term')),
|
||||
@@ -531,116 +537,6 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
title: Text(context.l10n.appSettings_maxRouteWeight),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context.l10n.appSettings_maxRouteWeightSubtitle,
|
||||
),
|
||||
Slider(
|
||||
value: settingsService.settings.maxRouteWeight,
|
||||
min: 1,
|
||||
max: 10,
|
||||
divisions: 9,
|
||||
label: settingsService.settings.maxRouteWeight
|
||||
.round()
|
||||
.toString(),
|
||||
onChanged: (value) =>
|
||||
settingsService.setMaxRouteWeight(value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
title: Text(
|
||||
context.l10n.appSettings_initialRouteWeight,
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context
|
||||
.l10n
|
||||
.appSettings_initialRouteWeightSubtitle,
|
||||
),
|
||||
Slider(
|
||||
value:
|
||||
settingsService.settings.initialRouteWeight,
|
||||
min: 0.5,
|
||||
max: 5.0,
|
||||
divisions: 9,
|
||||
label: settingsService.settings.initialRouteWeight
|
||||
.toStringAsFixed(1),
|
||||
onChanged: (value) =>
|
||||
settingsService.setInitialRouteWeight(value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
title: Text(
|
||||
context.l10n.appSettings_routeWeightSuccessIncrement,
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context
|
||||
.l10n
|
||||
.appSettings_routeWeightSuccessIncrementSubtitle,
|
||||
),
|
||||
Slider(
|
||||
value: settingsService
|
||||
.settings
|
||||
.routeWeightSuccessIncrement,
|
||||
min: 0.1,
|
||||
max: 2.0,
|
||||
divisions: 19,
|
||||
label: settingsService
|
||||
.settings
|
||||
.routeWeightSuccessIncrement
|
||||
.toStringAsFixed(1),
|
||||
onChanged: (value) => settingsService
|
||||
.setRouteWeightSuccessIncrement(value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
title: Text(
|
||||
context.l10n.appSettings_routeWeightFailureDecrement,
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context
|
||||
.l10n
|
||||
.appSettings_routeWeightFailureDecrementSubtitle,
|
||||
),
|
||||
Slider(
|
||||
value: settingsService
|
||||
.settings
|
||||
.routeWeightFailureDecrement,
|
||||
min: 0.1,
|
||||
max: 2.0,
|
||||
divisions: 19,
|
||||
label: settingsService
|
||||
.settings
|
||||
.routeWeightFailureDecrement
|
||||
.toStringAsFixed(1),
|
||||
onChanged: (value) => settingsService
|
||||
.setRouteWeightFailureDecrement(value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
title: Text(context.l10n.appSettings_maxMessageRetries),
|
||||
@@ -947,7 +843,7 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
) {
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final alreadyHave = codec.availableModels.any((m) => m.id == spec.id);
|
||||
final alreadyHave = spec.hasCompleteInstalledRecord(codec.availableModels);
|
||||
// downloadPresetModel throws StateError on a placeholder URL, deliberately,
|
||||
// so the button must not be offerable until the weights are published.
|
||||
final blocked = spec.urlsArePlaceholders;
|
||||
@@ -1006,7 +902,7 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
final l10n = context.l10n;
|
||||
try {
|
||||
await codec.downloadPresetModel(spec);
|
||||
} on Exception catch (error) {
|
||||
} catch (error) {
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(l10n.imageMessages_downloadFailedWithError('$error')),
|
||||
|
||||
@@ -0,0 +1,824 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/image_codec_support.dart';
|
||||
import '../models/translation_support.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../services/backup_service.dart';
|
||||
import '../services/image_codec_service.dart';
|
||||
import '../services/translation_service.dart';
|
||||
import '../services/message_filter/message_filter_service.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
import '../utils/share_origin.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
|
||||
class BackupRestoreScreen extends StatefulWidget {
|
||||
const BackupRestoreScreen({super.key});
|
||||
|
||||
@override
|
||||
State<BackupRestoreScreen> createState() => _BackupRestoreScreenState();
|
||||
}
|
||||
|
||||
class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
static const int _maxImportBytes = 100 * 1024 * 1024;
|
||||
static const _backupService = BackupService();
|
||||
static const _fileType = XTypeGroup(
|
||||
label: 'MeshCore backup',
|
||||
extensions: ['json'],
|
||||
mimeTypes: ['application/json'],
|
||||
);
|
||||
static const Set<BackupItem> _defaultUncheckedItems = {
|
||||
BackupItem.privateKey,
|
||||
BackupItem.ipfsKey,
|
||||
BackupItem.stadiaMapKey,
|
||||
};
|
||||
static const Set<BackupItem> _deviceStoredItems = {
|
||||
BackupItem.deviceName,
|
||||
BackupItem.publicKey,
|
||||
BackupItem.radioSettings,
|
||||
BackupItem.location,
|
||||
BackupItem.contactSettings,
|
||||
BackupItem.privacySettings,
|
||||
BackupItem.contacts,
|
||||
BackupItem.channels,
|
||||
};
|
||||
static const Set<BackupItem> _defaultUncheckedOnRestore = {
|
||||
..._defaultUncheckedItems,
|
||||
..._deviceStoredItems,
|
||||
};
|
||||
final _passwordController = TextEditingController();
|
||||
final Set<BackupItem> _selectedItems = BackupItem.values
|
||||
.where((item) => !_defaultUncheckedItems.contains(item))
|
||||
.toSet();
|
||||
Set<BackupItem>? _availableItems;
|
||||
String? _importContents;
|
||||
String? _importFileName;
|
||||
Timer? _inspectionTimer;
|
||||
int _inspectionGeneration = 0;
|
||||
bool _hasInitializedImportSelection = false;
|
||||
bool _busy = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_inspectionTimer?.cancel();
|
||||
_passwordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: AppBarTitle(
|
||||
l10n.backupRestore_title,
|
||||
indicators: false,
|
||||
subtitle: false,
|
||||
),
|
||||
centerTitle: true,
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
|
||||
children: [
|
||||
SectionHeader(l10n.backupRestore_import),
|
||||
MeshCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
OutlinedButton.icon(
|
||||
onPressed: _busy ? null : _selectImportFile,
|
||||
icon: const Icon(Icons.upload_file_outlined),
|
||||
label: Text(
|
||||
_importFileName ?? l10n.backupRestore_selectImportFile,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _passwordController,
|
||||
obscureText: true,
|
||||
autocorrect: false,
|
||||
enableSuggestions: false,
|
||||
onChanged: (_) => _scheduleImportInspection(),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.backupRestore_password,
|
||||
helperText:
|
||||
_importContents != null &&
|
||||
_availableItems?.isEmpty == true
|
||||
? l10n.backupRestore_importUnavailable
|
||||
: l10n.backupRestore_passwordHelp,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SectionHeader(l10n.backupRestore_items),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
_groupTile(
|
||||
title: l10n.backupRestore_nodeSettings,
|
||||
icon: Icons.router_outlined,
|
||||
items: [
|
||||
(BackupItem.deviceName, l10n.backupRestore_deviceName),
|
||||
(BackupItem.privateKey, l10n.backupRestore_privateKey),
|
||||
(BackupItem.publicKey, l10n.backupRestore_publicKey),
|
||||
(
|
||||
BackupItem.radioSettings,
|
||||
l10n.backupRestore_radioSettings,
|
||||
),
|
||||
(BackupItem.regions, l10n.backupRestore_regions),
|
||||
],
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
_groupTile(
|
||||
title: l10n.backupRestore_locationSettings,
|
||||
icon: Icons.location_on_outlined,
|
||||
items: [
|
||||
(BackupItem.location, l10n.backupRestore_location),
|
||||
(
|
||||
BackupItem.contactSettings,
|
||||
l10n.backupRestore_contactSettings,
|
||||
),
|
||||
(
|
||||
BackupItem.privacySettings,
|
||||
l10n.backupRestore_privacySettings,
|
||||
),
|
||||
],
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
_groupTile(
|
||||
title: l10n.backupRestore_appSettings,
|
||||
icon: Icons.settings_outlined,
|
||||
items: [
|
||||
(BackupItem.appSettings, l10n.backupRestore_appSettings),
|
||||
(BackupItem.ipfsKey, l10n.backupRestore_ipfsKey),
|
||||
(
|
||||
BackupItem.stadiaMapKey,
|
||||
l10n.backupRestore_stadiaMapKey,
|
||||
),
|
||||
],
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
_groupTile(
|
||||
title: l10n.backupRestore_contacts,
|
||||
icon: Icons.contacts_outlined,
|
||||
items: [
|
||||
(BackupItem.contacts, l10n.backupRestore_contactsData),
|
||||
(
|
||||
BackupItem.perContactSettings,
|
||||
l10n.backupRestore_perContactSettings,
|
||||
),
|
||||
(
|
||||
BackupItem.contactGroups,
|
||||
l10n.backupRestore_contactGroups,
|
||||
),
|
||||
(
|
||||
BackupItem.contactHistory,
|
||||
l10n.backupRestore_contactHistory,
|
||||
),
|
||||
],
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
_itemTile(
|
||||
BackupItem.discoveredContacts,
|
||||
l10n.backupRestore_discoveredContacts,
|
||||
Icons.person_search_outlined,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
_groupTile(
|
||||
title: l10n.backupRestore_channels,
|
||||
icon: Icons.forum_outlined,
|
||||
items: [
|
||||
(BackupItem.channels, l10n.backupRestore_channelsData),
|
||||
(
|
||||
BackupItem.channelFilters,
|
||||
l10n.backupRestore_channelFilters,
|
||||
),
|
||||
(
|
||||
BackupItem.channelSettings,
|
||||
l10n.backupRestore_channelSettings,
|
||||
),
|
||||
(BackupItem.communities, l10n.backupRestore_communities),
|
||||
(
|
||||
BackupItem.channelHistory,
|
||||
l10n.backupRestore_channelHistory,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 0),
|
||||
child: FilledButton.icon(
|
||||
onPressed:
|
||||
_busy ||
|
||||
_selectedItems.isEmpty ||
|
||||
(_importContents != null && _availableItems == null)
|
||||
? null
|
||||
: _runAction,
|
||||
icon: _busy
|
||||
? const SizedBox.square(
|
||||
dimension: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Icon(
|
||||
_importContents == null
|
||||
? Icons.backup_outlined
|
||||
: Icons.restore_outlined,
|
||||
),
|
||||
label: Text(
|
||||
_importContents == null
|
||||
? l10n.backupRestore_backup
|
||||
: l10n.backupRestore_restore,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _groupTile({
|
||||
required String title,
|
||||
required IconData icon,
|
||||
required List<(BackupItem, String)> items,
|
||||
}) {
|
||||
return ExpansionTile(
|
||||
leading: Icon(icon),
|
||||
title: Text(title),
|
||||
tilePadding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
childrenPadding: EdgeInsets.zero,
|
||||
initiallyExpanded: true,
|
||||
visualDensity: VisualDensity.compact,
|
||||
children: [for (final item in items) _itemTile(item.$1, item.$2)],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _itemTile(BackupItem item, String title, [IconData? icon]) {
|
||||
final available =
|
||||
_availableItems == null || _availableItems!.contains(item);
|
||||
return CheckboxListTile(
|
||||
value: _selectedItems.contains(item),
|
||||
dense: true,
|
||||
visualDensity: VisualDensity.compact,
|
||||
onChanged: _busy || !available
|
||||
? null
|
||||
: (selected) => setState(() {
|
||||
if (selected == true) {
|
||||
_selectedItems.add(item);
|
||||
} else {
|
||||
_selectedItems.remove(item);
|
||||
}
|
||||
}),
|
||||
secondary: icon == null ? null : Icon(icon),
|
||||
title: Text(title),
|
||||
controlAffinity: ListTileControlAffinity.trailing,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _selectImportFile() async {
|
||||
final l10n = context.l10n;
|
||||
try {
|
||||
final file = await openFile(acceptedTypeGroups: const [_fileType]);
|
||||
if (file == null) return;
|
||||
if (await file.length() > _maxImportBytes) {
|
||||
_showMessage(l10n.backupRestore_fileTooLarge);
|
||||
return;
|
||||
}
|
||||
final contents = utf8.decode(await file.readAsBytes());
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_importContents = contents;
|
||||
_importFileName = file.name;
|
||||
_availableItems = null;
|
||||
_selectedItems.clear();
|
||||
_hasInitializedImportSelection = false;
|
||||
});
|
||||
await _inspectImport();
|
||||
} catch (error) {
|
||||
if (mounted) {
|
||||
_showMessage(l10n.backupRestore_failed(error.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _scheduleImportInspection() {
|
||||
_inspectionTimer?.cancel();
|
||||
_inspectionTimer = Timer(const Duration(milliseconds: 350), _inspectImport);
|
||||
}
|
||||
|
||||
Future<void> _inspectImport() async {
|
||||
final contents = _importContents;
|
||||
if (contents == null) return;
|
||||
final generation = ++_inspectionGeneration;
|
||||
try {
|
||||
final info = await _backupService.inspectImport(
|
||||
contents: contents,
|
||||
password: _passwordController.text,
|
||||
);
|
||||
if (!mounted || generation != _inspectionGeneration) return;
|
||||
setState(() {
|
||||
_availableItems = info.availableItems;
|
||||
if (!_hasInitializedImportSelection) {
|
||||
_selectedItems
|
||||
..clear()
|
||||
..addAll(
|
||||
info.availableItems.where(
|
||||
(item) => !_defaultUncheckedOnRestore.contains(item),
|
||||
),
|
||||
);
|
||||
_hasInitializedImportSelection = true;
|
||||
} else {
|
||||
_selectedItems.retainAll(info.availableItems);
|
||||
}
|
||||
});
|
||||
} catch (_) {
|
||||
if (!mounted || generation != _inspectionGeneration) return;
|
||||
setState(() {
|
||||
_availableItems = <BackupItem>{};
|
||||
_selectedItems.clear();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _runAction() async {
|
||||
if (_selectedItems.isEmpty) {
|
||||
_showMessage(context.l10n.backupRestore_selectAtLeastOne);
|
||||
return;
|
||||
}
|
||||
if (_importContents != null) {
|
||||
await _restore();
|
||||
} else {
|
||||
await _createBackup();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _createBackup() async {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final shareOrigin = shareOriginOf(context);
|
||||
setState(() => _busy = true);
|
||||
try {
|
||||
final contents = await _backupService.createBackup(
|
||||
items: Set<BackupItem>.of(_selectedItems),
|
||||
connector: connector,
|
||||
settings: context.read<AppSettingsService>().settings,
|
||||
password: _passwordController.text,
|
||||
);
|
||||
if (!mounted) return;
|
||||
final deviceName = (connector.selfName ?? '')
|
||||
.trim()
|
||||
.replaceAll(RegExp(r'[<>:"/\\|?*\x00-\x1f]'), '_')
|
||||
.replaceAll(RegExp(r'\s+'), '_')
|
||||
.replaceAll(RegExp(r'^\.+'), '')
|
||||
.replaceAll(RegExp(r'[. ]+$'), '');
|
||||
final filename =
|
||||
'meshcore-open_${deviceName.isEmpty ? 'radio' : deviceName}_backup_${DateTime.now().millisecondsSinceEpoch}.json';
|
||||
final file = XFile.fromData(
|
||||
Uint8List.fromList(utf8.encode(contents)),
|
||||
name: filename,
|
||||
mimeType: 'application/json',
|
||||
);
|
||||
if (PlatformInfo.isWeb) {
|
||||
await file.saveTo(filename);
|
||||
} else if (PlatformInfo.isDesktop) {
|
||||
final location = await getSaveLocation(
|
||||
suggestedName: filename,
|
||||
acceptedTypeGroups: const [_fileType],
|
||||
);
|
||||
if (location == null) return;
|
||||
await file.saveTo(location.path);
|
||||
} else {
|
||||
final result = await SharePlus.instance.share(
|
||||
ShareParams(
|
||||
files: [file],
|
||||
fileNameOverrides: [filename],
|
||||
sharePositionOrigin: shareOrigin,
|
||||
),
|
||||
);
|
||||
if (result.status == ShareResultStatus.dismissed) return;
|
||||
}
|
||||
if (mounted) _showMessage(l10n.backupRestore_backupComplete);
|
||||
} catch (error) {
|
||||
if (mounted) {
|
||||
_showMessage(l10n.backupRestore_failed(error.toString()));
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _busy = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restore() async {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final appSettingsService = context.read<AppSettingsService>();
|
||||
final messageFilterService = context.read<MessageFilterService>();
|
||||
final translationService = context.read<TranslationService>();
|
||||
final imageCodecService = context.read<ImageCodecService>();
|
||||
final needsKeyConfirmation = _selectedItems.contains(BackupItem.privateKey);
|
||||
if (needsKeyConfirmation && !await _confirmIdentityReplacement()) return;
|
||||
setState(() => _busy = true);
|
||||
try {
|
||||
await _backupService.restoreBackup(
|
||||
contents: _importContents!,
|
||||
password: _passwordController.text,
|
||||
items: Set<BackupItem>.of(_selectedItems),
|
||||
connector: connector,
|
||||
appSettingsService: appSettingsService,
|
||||
);
|
||||
if (_selectedItems.any(
|
||||
(item) =>
|
||||
item == BackupItem.appSettings ||
|
||||
item == BackupItem.ipfsKey ||
|
||||
item == BackupItem.stadiaMapKey,
|
||||
)) {
|
||||
await appSettingsService.loadSettings();
|
||||
if (_selectedItems.contains(BackupItem.appSettings)) {
|
||||
await _offerMissingModels(
|
||||
appSettingsService,
|
||||
translationService,
|
||||
imageCodecService,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_selectedItems.contains(BackupItem.channelFilters)) {
|
||||
await messageFilterService.load();
|
||||
}
|
||||
if (mounted) {
|
||||
_showMessage(l10n.backupRestore_restoreComplete);
|
||||
setState(() {
|
||||
_importContents = null;
|
||||
_importFileName = null;
|
||||
_availableItems = null;
|
||||
_selectedItems
|
||||
..clear()
|
||||
..addAll(
|
||||
BackupItem.values.where(
|
||||
(item) => !_defaultUncheckedItems.contains(item),
|
||||
),
|
||||
);
|
||||
_hasInitializedImportSelection = false;
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
if (mounted) {
|
||||
_showMessage(l10n.backupRestore_failed(error.toString()));
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _busy = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _offerMissingModels(
|
||||
AppSettingsService appSettingsService,
|
||||
TranslationService translationService,
|
||||
ImageCodecService imageCodecService,
|
||||
) async {
|
||||
if (PlatformInfo.isWeb) return;
|
||||
final settings = appSettingsService.settings;
|
||||
final translationId = settings.translationSelectedModelId;
|
||||
final imageCodecId = settings.imageCodecSelectedModelId;
|
||||
|
||||
TranslationModelRecord? translationModel;
|
||||
for (final model in settings.translationDownloadedModels) {
|
||||
if (model.id == translationId) {
|
||||
translationModel = model;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (final model in translationPresetModels) {
|
||||
if (model.id == translationId) {
|
||||
translationModel ??= model;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (translationModel == null &&
|
||||
translationId != null &&
|
||||
settings.translationModelSourceUrl != null) {
|
||||
final uri = Uri.tryParse(settings.translationModelSourceUrl!);
|
||||
final pathSegments = uri?.pathSegments ?? const <String>[];
|
||||
final fileName = pathSegments.isEmpty ? null : pathSegments.last;
|
||||
translationModel = TranslationModelRecord(
|
||||
id: translationId,
|
||||
name: fileName?.isNotEmpty == true ? fileName! : translationId,
|
||||
sourceUrl: settings.translationModelSourceUrl!,
|
||||
localPath: '',
|
||||
downloadedAt: DateTime.fromMillisecondsSinceEpoch(0),
|
||||
fileSizeBytes: 0,
|
||||
);
|
||||
}
|
||||
|
||||
ImageCodecModelRecord? imageCodecModel;
|
||||
for (final model in settings.imageCodecDownloadedModels) {
|
||||
if (model.id == imageCodecId) {
|
||||
imageCodecModel = model;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ImageCodecModelSpec? imageCodecSpec;
|
||||
for (final spec in imageCodecPresetModels) {
|
||||
if (spec.id == imageCodecId) {
|
||||
imageCodecSpec = spec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (imageCodecModel == null && imageCodecSpec != null) {
|
||||
final graph = imageCodecSpec.graph;
|
||||
imageCodecModel = ImageCodecModelRecord(
|
||||
id: imageCodecSpec.id,
|
||||
name: graph.fileName,
|
||||
sourceUrl: graph.sourceUrl,
|
||||
localPath: '',
|
||||
downloadedAt: DateTime.fromMillisecondsSinceEpoch(0),
|
||||
fileSizeBytes: imageCodecSpec.totalSizeBytes,
|
||||
assetFileNames: [
|
||||
for (final asset in imageCodecSpec.assets) asset.fileName,
|
||||
],
|
||||
bundleVersion: kImageCodecBundleVersion,
|
||||
);
|
||||
} else if (imageCodecModel == null &&
|
||||
imageCodecId != null &&
|
||||
settings.imageCodecModelSourceUrl != null) {
|
||||
final uri = Uri.tryParse(settings.imageCodecModelSourceUrl!);
|
||||
final pathSegments = uri?.pathSegments ?? const <String>[];
|
||||
final fileName = pathSegments.isEmpty ? null : pathSegments.last;
|
||||
imageCodecModel = ImageCodecModelRecord(
|
||||
id: imageCodecId,
|
||||
name: fileName?.isNotEmpty == true ? fileName! : imageCodecId,
|
||||
sourceUrl: settings.imageCodecModelSourceUrl!,
|
||||
localPath: '',
|
||||
downloadedAt: DateTime.fromMillisecondsSinceEpoch(0),
|
||||
fileSizeBytes: 0,
|
||||
);
|
||||
}
|
||||
|
||||
await translationService.refreshDownloadedModels(clearMissing: true);
|
||||
await imageCodecService.refreshDownloadedModels(clearMissing: true);
|
||||
|
||||
final translationRequest = translationModel;
|
||||
final translationMissing =
|
||||
translationRequest != null &&
|
||||
!translationService.availableModels.any(
|
||||
(model) =>
|
||||
model.id == translationRequest.id ||
|
||||
model.name == translationRequest.name,
|
||||
);
|
||||
ImageCodecModelRecord? installedCodec;
|
||||
if (imageCodecModel != null) {
|
||||
for (final model in imageCodecService.availableModels) {
|
||||
if (model.id == imageCodecModel.id ||
|
||||
model.name == imageCodecModel.name) {
|
||||
installedCodec = model;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
final codecRequest = imageCodecModel;
|
||||
final installedCodecForCheck = installedCodec;
|
||||
final imageCodecMissing =
|
||||
codecRequest != null &&
|
||||
(imageCodecSpec != null
|
||||
? !imageCodecSpec.hasCompleteInstalledRecord(
|
||||
imageCodecService.availableModels,
|
||||
)
|
||||
: installedCodecForCheck == null);
|
||||
if (!translationMissing && !imageCodecMissing) return;
|
||||
if (!mounted) return;
|
||||
|
||||
await _showModelDownloadDialog(
|
||||
translationModel: translationMissing ? translationRequest : null,
|
||||
imageCodecModel: imageCodecMissing ? codecRequest : null,
|
||||
imageCodecSpec: imageCodecMissing ? imageCodecSpec : null,
|
||||
translationService: translationService,
|
||||
imageCodecService: imageCodecService,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showModelDownloadDialog({
|
||||
required TranslationModelRecord? translationModel,
|
||||
required ImageCodecModelRecord? imageCodecModel,
|
||||
required ImageCodecModelSpec? imageCodecSpec,
|
||||
required TranslationService translationService,
|
||||
required ImageCodecService imageCodecService,
|
||||
}) async {
|
||||
final l10n = context.l10n;
|
||||
final modelNames = [
|
||||
if (translationModel != null)
|
||||
translationModelFriendlyName(translationModel),
|
||||
if (imageCodecModel != null)
|
||||
imageCodecSpec?.label ?? imageCodecModel.name,
|
||||
];
|
||||
var starting = false;
|
||||
var cancelRequested = false;
|
||||
var translationDone = translationModel == null;
|
||||
var imageCodecDone = imageCodecModel == null;
|
||||
String? currentModel;
|
||||
String? downloadError;
|
||||
final servicesListenable = Listenable.merge([
|
||||
translationService,
|
||||
imageCodecService,
|
||||
]);
|
||||
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (dialogContext, setDialogState) => AnimatedBuilder(
|
||||
animation: servicesListenable,
|
||||
builder: (context, _) {
|
||||
final isDownloading =
|
||||
starting ||
|
||||
translationService.isDownloading ||
|
||||
imageCodecService.isDownloading;
|
||||
final currentProgress = currentModel == translationModel?.name
|
||||
? translationService.downloadProgress
|
||||
: currentModel == imageCodecModel?.name
|
||||
? imageCodecService.downloadProgress
|
||||
: null;
|
||||
final currentFile = currentModel == translationModel?.name
|
||||
? translationService.downloadFileName
|
||||
: currentModel == imageCodecModel?.name
|
||||
? imageCodecService.downloadFileName
|
||||
: null;
|
||||
|
||||
void requestDownloadCancel() {
|
||||
cancelRequested = true;
|
||||
translationService.cancelDownload();
|
||||
imageCodecService.cancelDownload();
|
||||
}
|
||||
|
||||
return PopScope<void>(
|
||||
canPop: !isDownloading,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop && isDownloading) requestDownloadCancel();
|
||||
},
|
||||
child: AlertDialog(
|
||||
title: Text(l10n.backupRestore_missingModelsTitle),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l10n.backupRestore_missingModelsMessage(
|
||||
modelNames.join('\n'),
|
||||
),
|
||||
),
|
||||
if (isDownloading) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(currentFile ?? currentModel ?? ''),
|
||||
const SizedBox(height: 8),
|
||||
LinearProgressIndicator(value: currentProgress),
|
||||
],
|
||||
if (downloadError != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
l10n.backupRestore_failed(downloadError!),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (isDownloading) {
|
||||
requestDownloadCancel();
|
||||
} else {
|
||||
Navigator.pop(dialogContext);
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
isDownloading
|
||||
? l10n.backupRestore_cancelDownload
|
||||
: l10n.common_cancel,
|
||||
),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: isDownloading
|
||||
? null
|
||||
: () async {
|
||||
setDialogState(() {
|
||||
starting = true;
|
||||
currentModel = translationDone
|
||||
? imageCodecModel?.name
|
||||
: translationModel?.name;
|
||||
downloadError = null;
|
||||
});
|
||||
try {
|
||||
if (!translationDone) {
|
||||
final model = translationModel!;
|
||||
if (model.sourceUrl.isEmpty) {
|
||||
throw StateError(
|
||||
'No download address is available for ${model.name}',
|
||||
);
|
||||
}
|
||||
await translationService.downloadModel(
|
||||
sourceUrl: model.sourceUrl,
|
||||
fileName: model.name,
|
||||
id: model.id,
|
||||
);
|
||||
translationDone = true;
|
||||
setDialogState(() {
|
||||
currentModel = imageCodecModel?.name;
|
||||
});
|
||||
}
|
||||
if (!imageCodecDone) {
|
||||
final model = imageCodecModel!;
|
||||
final spec = imageCodecSpec;
|
||||
if (spec != null) {
|
||||
await imageCodecService.downloadPresetModel(
|
||||
spec,
|
||||
);
|
||||
} else if (model.sourceUrl.isNotEmpty) {
|
||||
await imageCodecService.downloadModel(
|
||||
sourceUrl: model.sourceUrl,
|
||||
fileName: model.name,
|
||||
id: model.id,
|
||||
);
|
||||
} else {
|
||||
throw StateError(
|
||||
'No download address is available for ${model.name}',
|
||||
);
|
||||
}
|
||||
imageCodecDone = true;
|
||||
}
|
||||
if (dialogContext.mounted) {
|
||||
Navigator.pop(dialogContext);
|
||||
}
|
||||
} catch (error) {
|
||||
if (dialogContext.mounted) {
|
||||
if (cancelRequested) {
|
||||
Navigator.pop(dialogContext);
|
||||
} else {
|
||||
setDialogState(() {
|
||||
starting = false;
|
||||
downloadError = error.toString();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
isDownloading
|
||||
? l10n.backupRestore_downloading
|
||||
: l10n.backupRestore_downloadModels,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> _confirmIdentityReplacement() async {
|
||||
final l10n = context.l10n;
|
||||
return await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(l10n.backupRestore_replaceIdentityTitle),
|
||||
content: Text(l10n.backupRestore_replaceIdentityMessage),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, false),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, true),
|
||||
child: Text(l10n.backupRestore_restore),
|
||||
),
|
||||
],
|
||||
),
|
||||
) ??
|
||||
false;
|
||||
}
|
||||
|
||||
void _showMessage(String message) {
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(context, content: Text(message));
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import '../connector/meshcore_protocol.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/confirm_clear_dialog.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
|
||||
enum _BleLogView { frames, rawLogRx }
|
||||
@@ -99,11 +100,11 @@ class _BleDebugLogScreenState extends State<BleDebugLogScreen> {
|
||||
segments: [
|
||||
ButtonSegment(
|
||||
value: _BleLogView.frames,
|
||||
label: Text(context.l10n.debugLog_frames),
|
||||
label: MeshSegmentLabel(context.l10n.debugLog_frames),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: _BleLogView.rawLogRx,
|
||||
label: Text(context.l10n.debugLog_rawLogRx),
|
||||
label: MeshSegmentLabel(context.l10n.debugLog_rawLogRx),
|
||||
),
|
||||
],
|
||||
selected: {_view},
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -553,6 +553,7 @@ class _ChannelMessagePathMapScreenState
|
||||
PathViewMode _viewMode = PathViewMode.single;
|
||||
final Set<String> _hiddenPathIds = {};
|
||||
bool _panelCollapsed = false;
|
||||
bool _panelExpanded = false;
|
||||
bool _animationEnabled = true;
|
||||
bool _followPacket = false;
|
||||
|
||||
@@ -1380,8 +1381,13 @@ class _ChannelMessagePathMapScreenState
|
||||
combined: combined,
|
||||
showInferredLegend: false,
|
||||
collapsed: _panelCollapsed,
|
||||
onToggleCollapsed: () =>
|
||||
setState(() => _panelCollapsed = !_panelCollapsed),
|
||||
onToggleCollapsed: () => setState(() {
|
||||
_panelCollapsed = !_panelCollapsed;
|
||||
// Reopening a collapsed panel returns to the normal height.
|
||||
if (_panelCollapsed) _panelExpanded = false;
|
||||
}),
|
||||
expanded: _panelExpanded,
|
||||
onToggleExpanded: () => setState(() => _panelExpanded = !_panelExpanded),
|
||||
playback: _playback,
|
||||
selected: selectedDisplay,
|
||||
animationEnabled: _animationEnabled,
|
||||
|
||||
+397
-402
@@ -18,10 +18,10 @@ import '../models/channel.dart';
|
||||
import '../models/community.dart';
|
||||
import '../storage/community_store.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../utils/dialog_utils.dart';
|
||||
import '../utils/disconnect_navigation_mixin.dart';
|
||||
import '../utils/radio_guard.dart';
|
||||
import '../utils/route_transitions.dart';
|
||||
import '../widgets/channel_notification_mode_sheet.dart';
|
||||
import '../widgets/connect_sheet.dart';
|
||||
import '../widgets/list_filter_widget.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
@@ -30,6 +30,7 @@ import '../widgets/qr_code_display.dart';
|
||||
import '../widgets/quick_switch_bar.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
import '../widgets/unread_badge.dart';
|
||||
import '../helpers/contact_share_message.dart';
|
||||
import '../helpers/gif_helper.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
@@ -50,8 +51,7 @@ class ChannelsScreen extends StatefulWidget {
|
||||
State<ChannelsScreen> createState() => _ChannelsScreenState();
|
||||
}
|
||||
|
||||
class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
with DisconnectNavigationMixin {
|
||||
class _ChannelsScreenState extends State<ChannelsScreen> {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final CommunityStore _communityStore = CommunityStore();
|
||||
final CommunityPskIndex _communityIndex = CommunityPskIndex();
|
||||
@@ -73,7 +73,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
|
||||
Future<void> _loadCommunities() async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
_communityStore.setPublicKeyHex = connector.selfPublicKeyHex;
|
||||
_communityStore.setPublicKeyHex = connector.storageKeyHex;
|
||||
final communities = await _communityStore.loadCommunities();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
@@ -110,11 +110,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
// No message filter in this tree (tests); previews ignore it.
|
||||
}
|
||||
|
||||
// Auto-navigate back to scanner if disconnected
|
||||
if (!checkConnectionAndNavigate(connector)) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final readOnly = isRadioReadOnly(connector);
|
||||
final allowBack = !connector.isConnected;
|
||||
|
||||
return PopScope(
|
||||
@@ -131,36 +127,18 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
// capture the screen's context — not the itemBuilder's menu
|
||||
// context, which is deactivated by then.
|
||||
itemBuilder: (menuContext) => [
|
||||
connectionMenuItem(context, menuContext),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.logout,
|
||||
color: Theme.of(menuContext).colorScheme.error,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(menuContext.l10n.common_disconnect),
|
||||
],
|
||||
),
|
||||
onTap: () => _disconnect(context),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.groups),
|
||||
const SizedBox(width: 8),
|
||||
Text(menuContext.l10n.community_manageCommunities),
|
||||
],
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.groups,
|
||||
label: menuContext.l10n.community_manageCommunities,
|
||||
),
|
||||
onTap: () => _showManageCommunitiesDialog(context),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const ThemedIcon(ThemeIconSlot.settings),
|
||||
const SizedBox(width: 8),
|
||||
Text(menuContext.l10n.settings_title),
|
||||
],
|
||||
child: MeshMenuItemRow(
|
||||
leading: const ThemedIcon(ThemeIconSlot.settings, size: 20),
|
||||
label: menuContext.l10n.settings_title,
|
||||
),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
@@ -180,6 +158,8 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
// Offline there is no radio to refresh from.
|
||||
if (readOnly) return;
|
||||
await context.read<MeshCoreConnector>().getChannels(
|
||||
force: true,
|
||||
);
|
||||
@@ -205,8 +185,9 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
icon: Icons.tag,
|
||||
title: context.l10n.channels_noChannelsConfigured,
|
||||
action: FilledButton.icon(
|
||||
onPressed: () =>
|
||||
_addPublicChannel(context, connector),
|
||||
onPressed: readOnly
|
||||
? null
|
||||
: () => _addPublicChannel(context, connector),
|
||||
icon: const Icon(Icons.public),
|
||||
label: Text(
|
||||
context.l10n.channels_addPublicChannel,
|
||||
@@ -354,11 +335,13 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => _showAddChannelDialog(context),
|
||||
tooltip: context.l10n.channels_addChannel,
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
floatingActionButton: readOnly
|
||||
? null
|
||||
: FloatingActionButton(
|
||||
onPressed: () => _showAddChannelDialog(context),
|
||||
tooltip: context.l10n.channels_addChannel,
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
bottomNavigationBar: SafeArea(
|
||||
top: false,
|
||||
child: QuickSwitchBar(
|
||||
@@ -437,10 +420,15 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
// become the preview.
|
||||
final lastMessage = connector.latestVisibleChannelMessage(channel);
|
||||
final lastMessageText = lastMessage?.text ?? '';
|
||||
final lastShare = parseContactShare(lastMessageText);
|
||||
final lastPreview =
|
||||
lastMessageText.isNotEmpty &&
|
||||
GifHelper.parseGif(lastMessageText) != null
|
||||
? context.l10n.chat_receivedGif
|
||||
: lastShare != null
|
||||
? context.l10n.contactShare_preview(
|
||||
lastShare.name.isEmpty ? lastShare.shortKey : lastShare.name,
|
||||
)
|
||||
: lastMessageText;
|
||||
final lastTime = lastMessage?.timestamp;
|
||||
|
||||
@@ -635,6 +623,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
Channel channel,
|
||||
) {
|
||||
final parentContext = context;
|
||||
final readOnly = isRadioReadOnly(connector);
|
||||
|
||||
showMeshSheet(
|
||||
parentContext,
|
||||
@@ -644,13 +633,14 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: const Icon(Icons.edit_outlined),
|
||||
title: Text(sheetContext.l10n.channels_editChannel),
|
||||
onTap: () async {
|
||||
Navigator.pop(sheetContext);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
if (parentContext.mounted) {
|
||||
_showEditChannelDialog(parentContext, connector, channel);
|
||||
showEditChannelSheet(parentContext, connector, channel);
|
||||
}
|
||||
},
|
||||
),
|
||||
@@ -671,21 +661,26 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: Icon(
|
||||
Icons.delete_outline,
|
||||
color: Theme.of(sheetContext).colorScheme.error,
|
||||
color: readOnly
|
||||
? null
|
||||
: Theme.of(sheetContext).colorScheme.error,
|
||||
),
|
||||
title: Text(
|
||||
sheetContext.l10n.channels_deleteChannel,
|
||||
style: TextStyle(
|
||||
color: Theme.of(sheetContext).colorScheme.error,
|
||||
color: readOnly
|
||||
? null
|
||||
: Theme.of(sheetContext).colorScheme.error,
|
||||
),
|
||||
),
|
||||
onTap: () async {
|
||||
Navigator.pop(sheetContext);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
if (parentContext.mounted) {
|
||||
_confirmDeleteChannel(parentContext, connector, channel);
|
||||
confirmDeleteChannel(parentContext, connector, channel);
|
||||
}
|
||||
},
|
||||
),
|
||||
@@ -715,11 +710,6 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _disconnect(BuildContext context) async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
await showDisconnectDialog(context, connector);
|
||||
}
|
||||
|
||||
Widget _buildFilterButton(UiViewStateService viewState) {
|
||||
return SortFilterMenu<ChannelSortOption>(
|
||||
tooltip: context.l10n.listFilter_tooltip,
|
||||
@@ -835,7 +825,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
bool isRegularHashtag = true;
|
||||
Community? selectedCommunity;
|
||||
|
||||
_communityStore.setPublicKeyHex = connector.selfPublicKeyHex;
|
||||
_communityStore.setPublicKeyHex = connector.storageKeyHex;
|
||||
|
||||
showMeshSheet(
|
||||
context,
|
||||
@@ -967,6 +957,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
Expanded(
|
||||
child: FilledButton(
|
||||
onPressed: () async {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
final name = nameController.text.trim();
|
||||
if (name.isEmpty) {
|
||||
showDismissibleSnackBar(
|
||||
@@ -1053,6 +1044,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
Expanded(
|
||||
child: FilledButton(
|
||||
onPressed: () {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
final name = nameController.text.trim();
|
||||
final pskHex = pskController.text.trim();
|
||||
if (name.isEmpty) {
|
||||
@@ -1119,6 +1111,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
Expanded(
|
||||
child: FilledButton(
|
||||
onPressed: () {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
final nextIndex = _resolveFreeChannelSlot(
|
||||
context,
|
||||
connector,
|
||||
@@ -1286,6 +1279,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
Expanded(
|
||||
child: FilledButton(
|
||||
onPressed: () async {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
var hashtag = hashtagController.text.trim();
|
||||
if (hashtag.isEmpty) {
|
||||
showDismissibleSnackBar(
|
||||
@@ -1475,6 +1469,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
Expanded(
|
||||
child: FilledButton(
|
||||
onPressed: () async {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
final name = nameController.text.trim();
|
||||
final publicLabel =
|
||||
context.l10n.channels_public;
|
||||
@@ -1659,323 +1654,6 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
);
|
||||
}
|
||||
|
||||
void _showEditChannelDialog(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
Channel channel,
|
||||
) {
|
||||
final appSettingsService = Provider.of<AppSettingsService>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
bool smazEnabled = connector.isChannelSmazEnabled(channel.index);
|
||||
bool cyr2latEnabled = connector.isChannelCyr2LatEnabled(channel.index);
|
||||
final initialUrlImagesEnabled = connector.isChannelUrlImagesEnabled(
|
||||
channel.index,
|
||||
);
|
||||
bool urlImagesEnabled = initialUrlImagesEnabled;
|
||||
final loadLinkImages = appSettingsService.settings.loadLinkImages;
|
||||
String? selectedCyr2LatProfileId = connector.getChannelCyr2LatProfileId(
|
||||
channel.index,
|
||||
);
|
||||
|
||||
showMeshSheet(
|
||||
context,
|
||||
builder: (sheetContext) => _SheetTextControllers(
|
||||
initialTexts: [channel.name, channel.pskHex],
|
||||
builder: (controllers) {
|
||||
final nameController = controllers[0];
|
||||
final pskController = controllers[1];
|
||||
return StatefulBuilder(
|
||||
builder: (sheetContext, setSheetState) => DraggableScrollableSheet(
|
||||
expand: false,
|
||||
initialChildSize: 0.65,
|
||||
minChildSize: 0.4,
|
||||
maxChildSize: 0.95,
|
||||
builder: (_, scrollController) => Column(
|
||||
children: [
|
||||
BottomSheetHeader(
|
||||
title: sheetContext.l10n.channels_editChannelTitle(
|
||||
channel.index,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
controller: scrollController,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
TextField(
|
||||
controller: nameController,
|
||||
decoration: InputDecoration(
|
||||
labelText: sheetContext.l10n.channels_channelName,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(
|
||||
maxRadioNameBytes,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: pskController,
|
||||
decoration: InputDecoration(
|
||||
labelText: sheetContext.l10n.channels_pskHex,
|
||||
border: const OutlineInputBorder(),
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.casino),
|
||||
tooltip:
|
||||
sheetContext.l10n.channels_generateRandomPsk,
|
||||
onPressed: () {
|
||||
final bytes = randomBytes(16);
|
||||
pskController.text = Channel.formatPskHex(
|
||||
bytes,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(
|
||||
sheetContext.l10n.channels_smazCompression,
|
||||
),
|
||||
value: smazEnabled,
|
||||
onChanged: (value) => setSheetState(() {
|
||||
smazEnabled = value;
|
||||
if (smazEnabled) {
|
||||
cyr2latEnabled = false;
|
||||
}
|
||||
}),
|
||||
),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(
|
||||
sheetContext.l10n.channels_cyr2latCompression,
|
||||
),
|
||||
subtitle: Text(
|
||||
sheetContext.l10n.channels_cyr2latCompressionDscr,
|
||||
),
|
||||
value: cyr2latEnabled,
|
||||
onChanged: (value) => setSheetState(() {
|
||||
cyr2latEnabled = value;
|
||||
if (cyr2latEnabled) {
|
||||
smazEnabled = false;
|
||||
}
|
||||
}),
|
||||
),
|
||||
if (cyr2latEnabled) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 8),
|
||||
child: DropdownButtonFormField<String>(
|
||||
isExpanded: true,
|
||||
initialValue: selectedCyr2LatProfileId,
|
||||
decoration: InputDecoration(
|
||||
labelText: sheetContext
|
||||
.l10n
|
||||
.channels_cyr2latSettingsSubheading,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
items: appSettingsService.settings.cyr2latProfiles
|
||||
.map((profile) {
|
||||
return DropdownMenuItem(
|
||||
value: profile.id,
|
||||
child: Text(
|
||||
profile.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
})
|
||||
.toList(),
|
||||
onChanged: (value) => setSheetState(() {
|
||||
selectedCyr2LatProfileId = value;
|
||||
}),
|
||||
),
|
||||
),
|
||||
],
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(sheetContext.l10n.urlImage_enable),
|
||||
subtitle: loadLinkImages
|
||||
? null
|
||||
: Text(
|
||||
sheetContext
|
||||
.l10n
|
||||
.urlImage_disabledInAppSettings,
|
||||
),
|
||||
value: urlImagesEnabled,
|
||||
onChanged: loadLinkImages
|
||||
? (value) => setSheetState(
|
||||
() => urlImagesEnabled = value,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: () => Navigator.pop(sheetContext),
|
||||
child: Text(sheetContext.l10n.common_cancel),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: FilledButton(
|
||||
onPressed: () async {
|
||||
final name = nameController.text.trim();
|
||||
final pskHex = pskController.text.trim();
|
||||
if (name.isEmpty) {
|
||||
showDismissibleSnackBar(
|
||||
sheetContext,
|
||||
content: Text(
|
||||
sheetContext.l10n.channels_enterChannelName,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Uint8List psk;
|
||||
try {
|
||||
psk = Channel.parsePskHex(pskHex);
|
||||
} on FormatException {
|
||||
showDismissibleSnackBar(
|
||||
sheetContext,
|
||||
content: Text(
|
||||
sheetContext.l10n.channels_pskMustBe32Hex,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Navigator.pop(sheetContext);
|
||||
try {
|
||||
await connector.setChannel(
|
||||
channel.index,
|
||||
name,
|
||||
psk,
|
||||
);
|
||||
await connector.setChannelSmazEnabled(
|
||||
channel.index,
|
||||
smazEnabled,
|
||||
);
|
||||
await connector.setChannelCyr2LatEnabled(
|
||||
channel.index,
|
||||
cyr2latEnabled,
|
||||
);
|
||||
if (urlImagesEnabled !=
|
||||
initialUrlImagesEnabled) {
|
||||
await connector.setChannelUrlImagesEnabled(
|
||||
channel.index,
|
||||
urlImagesEnabled,
|
||||
);
|
||||
}
|
||||
await connector.setChannelCyr2LatProfileId(
|
||||
channel.index,
|
||||
selectedCyr2LatProfileId,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
context.l10n.channels_channelUpdated(name),
|
||||
),
|
||||
);
|
||||
} catch (e, st) {
|
||||
debugPrint(st.toString());
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
context.l10n.channels_channelUpdateFailed(
|
||||
'$e',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Text(sheetContext.l10n.common_save),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _confirmDeleteChannel(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
Channel channel,
|
||||
) {
|
||||
final channelLabel = channel.name.isEmpty
|
||||
? context.l10n.channels_channelIndex(channel.index)
|
||||
: channel.name;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(dialogContext.l10n.channels_deleteChannel),
|
||||
content: Text(
|
||||
dialogContext.l10n.channels_deleteChannelConfirm(channelLabel),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(dialogContext.l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(dialogContext);
|
||||
try {
|
||||
await connector.deleteChannel(channel.index);
|
||||
|
||||
if (!context.mounted) return;
|
||||
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
context.l10n.channels_channelDeleted(channelLabel),
|
||||
),
|
||||
);
|
||||
} catch (e, st) {
|
||||
if (!context.mounted) return;
|
||||
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
context.l10n.channels_channelDeleteFailed(channelLabel),
|
||||
),
|
||||
);
|
||||
|
||||
// Preserve existing logging (if it was there)
|
||||
debugPrint('Failed to delete channel: $e\n$st');
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
dialogContext.l10n.common_delete,
|
||||
style: TextStyle(
|
||||
color: Theme.of(dialogContext).colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Picks a free channel slot at the moment the user commits, or shows why
|
||||
/// none can be used. Slots are only trusted after a complete channel sync:
|
||||
/// while syncing, a slot that hasn't been fetched yet looks empty and
|
||||
@@ -2006,6 +1684,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
}
|
||||
|
||||
void _addPublicChannel(BuildContext context, MeshCoreConnector connector) {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
final index = _resolveFreeChannelSlot(context, connector);
|
||||
if (index == null) return;
|
||||
final psk = Channel.parsePskHex(Channel.publicChannelPsk);
|
||||
@@ -2117,40 +1796,31 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
_confirmLeaveCommunity(this.context, community);
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
value: 'share',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.qr_code),
|
||||
const SizedBox(width: 12),
|
||||
Text(context.l10n.community_showQr),
|
||||
],
|
||||
itemBuilder: (context) {
|
||||
final readOnly = isRadioReadOnly(
|
||||
context.read<MeshCoreConnector>(),
|
||||
);
|
||||
return [
|
||||
PopupMenuItem(
|
||||
value: 'share',
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.qr_code,
|
||||
label: context.l10n.community_showQr,
|
||||
),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'leave',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.exit_to_app,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.error,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
context.l10n.community_delete,
|
||||
style: TextStyle(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
PopupMenuItem(
|
||||
value: 'leave',
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.exit_to_app,
|
||||
label: context.l10n.community_delete,
|
||||
color: readOnly
|
||||
? null
|
||||
: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
];
|
||||
},
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
@@ -2208,7 +1878,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
}
|
||||
|
||||
final channelCount = communityChannels.length;
|
||||
_communityStore.setPublicKeyHex = connector.selfPublicKeyHex;
|
||||
_communityStore.setPublicKeyHex = connector.storageKeyHex;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -2227,6 +1897,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(dialogContext);
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
|
||||
// Delete all community channels from the device
|
||||
for (final channel in communityChannels) {
|
||||
@@ -2257,6 +1928,330 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
}
|
||||
}
|
||||
|
||||
/// Edits a channel's name, PSK and per-channel options. [onSaved] runs with
|
||||
/// the saved channel once the radio accepted the change.
|
||||
void showEditChannelSheet(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
Channel channel, {
|
||||
void Function(Channel saved)? onSaved,
|
||||
}) {
|
||||
final appSettingsService = Provider.of<AppSettingsService>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
bool smazEnabled = connector.isChannelSmazEnabled(channel.index);
|
||||
bool cyr2latEnabled = connector.isChannelCyr2LatEnabled(channel.index);
|
||||
final initialUrlImagesEnabled = connector.isChannelUrlImagesEnabled(
|
||||
channel.index,
|
||||
);
|
||||
bool urlImagesEnabled = initialUrlImagesEnabled;
|
||||
final loadLinkImages = appSettingsService.settings.loadLinkImages;
|
||||
String? selectedCyr2LatProfileId = connector.getChannelCyr2LatProfileId(
|
||||
channel.index,
|
||||
);
|
||||
|
||||
showMeshSheet(
|
||||
context,
|
||||
builder: (sheetContext) => _SheetTextControllers(
|
||||
initialTexts: [channel.name, channel.pskHex],
|
||||
builder: (controllers) {
|
||||
final nameController = controllers[0];
|
||||
final pskController = controllers[1];
|
||||
return StatefulBuilder(
|
||||
builder: (sheetContext, setSheetState) => DraggableScrollableSheet(
|
||||
expand: false,
|
||||
initialChildSize: 0.65,
|
||||
minChildSize: 0.4,
|
||||
maxChildSize: 0.95,
|
||||
builder: (_, scrollController) => Column(
|
||||
children: [
|
||||
BottomSheetHeader(
|
||||
title: sheetContext.l10n.channels_editChannelTitle(
|
||||
channel.index,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
controller: scrollController,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
TextField(
|
||||
controller: nameController,
|
||||
decoration: InputDecoration(
|
||||
labelText: sheetContext.l10n.channels_channelName,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(
|
||||
maxRadioNameBytes,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: pskController,
|
||||
decoration: InputDecoration(
|
||||
labelText: sheetContext.l10n.channels_pskHex,
|
||||
border: const OutlineInputBorder(),
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.casino),
|
||||
tooltip:
|
||||
sheetContext.l10n.channels_generateRandomPsk,
|
||||
onPressed: () {
|
||||
final bytes = randomBytes(16);
|
||||
pskController.text = Channel.formatPskHex(bytes);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(sheetContext.l10n.channels_smazCompression),
|
||||
value: smazEnabled,
|
||||
onChanged: (value) => setSheetState(() {
|
||||
smazEnabled = value;
|
||||
if (smazEnabled) {
|
||||
cyr2latEnabled = false;
|
||||
}
|
||||
}),
|
||||
),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(
|
||||
sheetContext.l10n.channels_cyr2latCompression,
|
||||
),
|
||||
subtitle: Text(
|
||||
sheetContext.l10n.channels_cyr2latCompressionDscr,
|
||||
),
|
||||
value: cyr2latEnabled,
|
||||
onChanged: (value) => setSheetState(() {
|
||||
cyr2latEnabled = value;
|
||||
if (cyr2latEnabled) {
|
||||
smazEnabled = false;
|
||||
}
|
||||
}),
|
||||
),
|
||||
if (cyr2latEnabled) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 8),
|
||||
child: DropdownButtonFormField<String>(
|
||||
isExpanded: true,
|
||||
initialValue: selectedCyr2LatProfileId,
|
||||
decoration: InputDecoration(
|
||||
labelText: sheetContext
|
||||
.l10n
|
||||
.channels_cyr2latSettingsSubheading,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
items: appSettingsService.settings.cyr2latProfiles
|
||||
.map((profile) {
|
||||
return DropdownMenuItem(
|
||||
value: profile.id,
|
||||
child: Text(
|
||||
profile.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
})
|
||||
.toList(),
|
||||
onChanged: (value) => setSheetState(() {
|
||||
selectedCyr2LatProfileId = value;
|
||||
}),
|
||||
),
|
||||
),
|
||||
],
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(sheetContext.l10n.urlImage_enable),
|
||||
subtitle: loadLinkImages
|
||||
? null
|
||||
: Text(
|
||||
sheetContext
|
||||
.l10n
|
||||
.urlImage_disabledInAppSettings,
|
||||
),
|
||||
value: urlImagesEnabled,
|
||||
onChanged: loadLinkImages
|
||||
? (value) =>
|
||||
setSheetState(() => urlImagesEnabled = value)
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: () => Navigator.pop(sheetContext),
|
||||
child: Text(sheetContext.l10n.common_cancel),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: FilledButton(
|
||||
onPressed: () async {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
final name = nameController.text.trim();
|
||||
final pskHex = pskController.text.trim();
|
||||
if (name.isEmpty) {
|
||||
showDismissibleSnackBar(
|
||||
sheetContext,
|
||||
content: Text(
|
||||
sheetContext.l10n.channels_enterChannelName,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Uint8List psk;
|
||||
try {
|
||||
psk = Channel.parsePskHex(pskHex);
|
||||
} on FormatException {
|
||||
showDismissibleSnackBar(
|
||||
sheetContext,
|
||||
content: Text(
|
||||
sheetContext.l10n.channels_pskMustBe32Hex,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Navigator.pop(sheetContext);
|
||||
try {
|
||||
await connector.setChannel(
|
||||
channel.index,
|
||||
name,
|
||||
psk,
|
||||
);
|
||||
await connector.setChannelSmazEnabled(
|
||||
channel.index,
|
||||
smazEnabled,
|
||||
);
|
||||
await connector.setChannelCyr2LatEnabled(
|
||||
channel.index,
|
||||
cyr2latEnabled,
|
||||
);
|
||||
if (urlImagesEnabled != initialUrlImagesEnabled) {
|
||||
await connector.setChannelUrlImagesEnabled(
|
||||
channel.index,
|
||||
urlImagesEnabled,
|
||||
);
|
||||
}
|
||||
await connector.setChannelCyr2LatProfileId(
|
||||
channel.index,
|
||||
selectedCyr2LatProfileId,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
context.l10n.channels_channelUpdated(name),
|
||||
),
|
||||
);
|
||||
onSaved?.call(
|
||||
Channel(
|
||||
index: channel.index,
|
||||
name: name,
|
||||
psk: psk,
|
||||
),
|
||||
);
|
||||
} catch (e, st) {
|
||||
debugPrint(st.toString());
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
context.l10n.channels_channelUpdateFailed(
|
||||
'$e',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Text(sheetContext.l10n.common_save),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Asks before deleting a channel. [onDeleted] runs once the radio deleted it.
|
||||
void confirmDeleteChannel(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
Channel channel, {
|
||||
VoidCallback? onDeleted,
|
||||
}) {
|
||||
final channelLabel = channel.name.isEmpty
|
||||
? context.l10n.channels_channelIndex(channel.index)
|
||||
: channel.name;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(dialogContext.l10n.channels_deleteChannel),
|
||||
content: Text(
|
||||
dialogContext.l10n.channels_deleteChannelConfirm(channelLabel),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(dialogContext.l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(dialogContext);
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
try {
|
||||
await connector.deleteChannel(channel.index);
|
||||
|
||||
if (!context.mounted) return;
|
||||
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
context.l10n.channels_channelDeleted(channelLabel),
|
||||
),
|
||||
);
|
||||
onDeleted?.call();
|
||||
} catch (e, st) {
|
||||
if (!context.mounted) return;
|
||||
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
context.l10n.channels_channelDeleteFailed(channelLabel),
|
||||
),
|
||||
);
|
||||
|
||||
// Preserve existing logging (if it was there)
|
||||
debugPrint('Failed to delete channel: $e\n$st');
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
dialogContext.l10n.common_delete,
|
||||
style: TextStyle(color: Theme.of(dialogContext).colorScheme.error),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Owns a sheet's [TextEditingController]s so they are disposed together with
|
||||
/// the sheet's widgets (after its exit animation) instead of being leaked.
|
||||
class _SheetTextControllers extends StatefulWidget {
|
||||
|
||||
+503
-206
@@ -9,9 +9,11 @@ import 'package:provider/provider.dart';
|
||||
|
||||
import '../utils/app_logger.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
import '../utils/radio_guard.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/chat_jump.dart';
|
||||
import '../helpers/cyr2lat.dart';
|
||||
import '../helpers/message_url_image_helper.dart';
|
||||
import '../helpers/path_helper.dart';
|
||||
@@ -21,7 +23,10 @@ import '../widgets/empty_state.dart';
|
||||
import '../helpers/chat_scroll_controller.dart';
|
||||
import '../helpers/gif_helper.dart';
|
||||
import '../helpers/ipfs_link_attach_flow.dart';
|
||||
import '../helpers/contact_share_message.dart';
|
||||
import '../helpers/marker_message.dart';
|
||||
import '../helpers/message_search.dart';
|
||||
import '../widgets/chat_search_results.dart';
|
||||
import '../models/channel_message.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../l10n/contact_localization.dart';
|
||||
@@ -37,11 +42,14 @@ import '../widgets/message_bubble_frame.dart';
|
||||
import '../widgets/reaction_chips.dart';
|
||||
import '../widgets/chat_day_separator.dart';
|
||||
import 'channel_message_path_screen.dart';
|
||||
import 'contacts_screen.dart' show confirmRemoveContact;
|
||||
import 'map_screen.dart';
|
||||
import 'repeater_hub_screen.dart';
|
||||
import '../widgets/emoji_picker.dart';
|
||||
import '../widgets/gif_message.dart';
|
||||
import '../widgets/jump_to_bottom_button.dart';
|
||||
import '../widgets/routing_sheet.dart';
|
||||
import '../widgets/room_login_dialog.dart';
|
||||
import '../widgets/radio_stats_entry.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
import '../widgets/translated_message_content.dart';
|
||||
@@ -53,6 +61,8 @@ import '../theme/terminal_theme.dart';
|
||||
import '../widgets/terminal_message_line.dart';
|
||||
import '../widgets/future_timestamp_indicator.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/share_contact_sheet.dart';
|
||||
import '../widgets/shared_contact_card.dart';
|
||||
import 'telemetry_screen.dart';
|
||||
import '../services/chat_background_service.dart';
|
||||
import '../widgets/chat_background.dart';
|
||||
@@ -93,16 +103,53 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
String? _unreadDividerMessageId;
|
||||
final ChatSendGuard _sendGuard = ChatSendGuard();
|
||||
|
||||
/// Contact keys of the chat screens currently on the navigation stack, in
|
||||
/// push order. A room chat can push a nested ChatScreen for one of its
|
||||
/// posters; when that one is popped, the room underneath must become the
|
||||
/// active conversation again rather than none at all.
|
||||
static final List<String> _activeContactStack = [];
|
||||
/// The chat currently registered as the visible conversation. Screens
|
||||
/// register while their route is uncovered and unregister when a page is
|
||||
/// pushed over them (a nested room poster chat, a chat opened from a
|
||||
/// notification, …), re-registering when it is popped. Only the owner
|
||||
/// clears the registration, so a screen disposed after the one underneath
|
||||
/// re-registered cannot wipe it out.
|
||||
static _ChatScreenState? _activeOwner;
|
||||
ModalRoute<dynamic>? _route;
|
||||
|
||||
void _registerActive() {
|
||||
final connector = _connector;
|
||||
if (connector == null) return;
|
||||
_activeOwner = this;
|
||||
connector.setActiveContact(widget.contact.publicKeyHex);
|
||||
}
|
||||
|
||||
void _unregisterActive() {
|
||||
if (!identical(_activeOwner, this)) return;
|
||||
_activeOwner = null;
|
||||
_connector?.setActiveContact(null);
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final route = ModalRoute.of(context);
|
||||
if (!identical(route, _route)) {
|
||||
_route?.secondaryAnimation?.removeStatusListener(_onCoveringRouteStatus);
|
||||
_route = route;
|
||||
route?.secondaryAnimation?.addStatusListener(_onCoveringRouteStatus);
|
||||
}
|
||||
}
|
||||
|
||||
void _onCoveringRouteStatus(AnimationStatus status) {
|
||||
if (!mounted) return;
|
||||
if (status == AnimationStatus.dismissed) {
|
||||
_registerActive();
|
||||
} else {
|
||||
// Not just `forward`: a page pushed without a transition jumps
|
||||
// straight to `completed`.
|
||||
_unregisterActive();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_activeContactStack.add(widget.contact.publicKeyHex);
|
||||
_textFieldFocusNode.addListener(_onTextFieldFocusChange);
|
||||
_scrollController.onScrollNearTop = _loadOlderMessages;
|
||||
_scrollController.showJumpToBottom.addListener(_clearDividerAtBottom);
|
||||
@@ -110,7 +157,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
if (!mounted) return;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final settings = context.read<AppSettingsService>().settings;
|
||||
final keyHex = widget.contact.publicKeyHex;
|
||||
final unread = widget.initialUnreadCount;
|
||||
final messages = connector.getMessages(widget.contact);
|
||||
Message? anchor;
|
||||
@@ -123,8 +169,8 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
_pendingUnreadScrollTarget = anchor;
|
||||
}
|
||||
});
|
||||
connector.setActiveContact(keyHex);
|
||||
_connector = connector;
|
||||
if (_route?.isCurrent ?? true) _registerActive();
|
||||
if (anchor != null && settings.jumpToOldestUnread) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
@@ -191,221 +237,398 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
final index = _activeContactStack.lastIndexOf(widget.contact.publicKeyHex);
|
||||
final wasTop = index == _activeContactStack.length - 1;
|
||||
if (index >= 0) _activeContactStack.removeAt(index);
|
||||
if (wasTop) {
|
||||
// Restore whichever chat is now on top (e.g. the room this nested chat
|
||||
// was opened from), or clear when this was the only one.
|
||||
_connector?.setActiveContact(
|
||||
_activeContactStack.isEmpty ? null : _activeContactStack.last,
|
||||
);
|
||||
}
|
||||
_route?.secondaryAnimation?.removeStatusListener(_onCoveringRouteStatus);
|
||||
_unregisterActive();
|
||||
_scrollController.showJumpToBottom.removeListener(_clearDividerAtBottom);
|
||||
_textFieldFocusNode.removeListener(_onTextFieldFocusChange);
|
||||
_textFieldFocusNode.dispose();
|
||||
_textController.dispose();
|
||||
_searchController.dispose();
|
||||
_highlightTimer?.cancel();
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool _searching = false;
|
||||
String _searchQuery = '';
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
|
||||
bool get _showSearchResults => _searching && _searchQuery.trim().isNotEmpty;
|
||||
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchResults(
|
||||
Future<List<ChatSearchEntry>> Function() loadEntries,
|
||||
) {
|
||||
return ChatSearchResults(
|
||||
query: _searchQuery.trim(),
|
||||
loadEntries: loadEntries,
|
||||
textScale: context.watch<ChatTextScaleService>().scale,
|
||||
onSelect: (entry) => unawaited(_jumpToSearchResult(entry.id)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Message briefly highlighted after jumping to it from search.
|
||||
String? _highlightedMessageId;
|
||||
Timer? _highlightTimer;
|
||||
|
||||
/// Closes search and scrolls the conversation to [messageId], loading
|
||||
/// older pages first when the message is further back than what is loaded.
|
||||
Future<void> _jumpToSearchResult(String messageId) async {
|
||||
FocusScope.of(context).unfocus();
|
||||
_closeSearch();
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final keyHex = widget.contact.publicKeyHex;
|
||||
int indexOf() => connector
|
||||
.getMessages(widget.contact)
|
||||
.indexWhere((m) => m.messageId == messageId);
|
||||
for (var page = 0; page < 500 && indexOf() < 0; page++) {
|
||||
if (!mounted) return;
|
||||
if (_isLoadingOlder) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||
continue;
|
||||
}
|
||||
setState(() => _isLoadingOlder = true);
|
||||
final older = await connector.loadOlderMessages(keyHex);
|
||||
if (!mounted) return;
|
||||
setState(() => _isLoadingOlder = false);
|
||||
if (older.isEmpty) break;
|
||||
}
|
||||
// Let the list (rebuilt after closing search) lay out.
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
if (!mounted) return;
|
||||
final messages = connector.getMessages(widget.contact);
|
||||
final index = indexOf();
|
||||
// The list is reversed: newest message is row 0.
|
||||
final found =
|
||||
index >= 0 &&
|
||||
await scrollListToIndex(
|
||||
controller: _scrollController,
|
||||
targetIndex: messages.length - 1 - index,
|
||||
itemCount: messages.length,
|
||||
isMounted: () => mounted,
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (!found) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.chatSearch_jumpFailed),
|
||||
);
|
||||
return;
|
||||
}
|
||||
_highlightTimer?.cancel();
|
||||
setState(() => _highlightedMessageId = messageId);
|
||||
_highlightTimer = Timer(const Duration(seconds: 2), () {
|
||||
if (mounted) setState(() => _highlightedMessageId = null);
|
||||
});
|
||||
}
|
||||
|
||||
Future<List<ChatSearchEntry>> _loadSearchEntries() async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final contact = _resolveContact(connector);
|
||||
final isRoom = contact.type == advTypeRoom;
|
||||
final youLabel = context.l10n.notification_you;
|
||||
final messages = await connector.allMessagesForSearch(
|
||||
widget.contact.publicKeyHex,
|
||||
);
|
||||
String senderOf(Message m) {
|
||||
if (m.isOutgoing) return youLabel;
|
||||
if (!isRoom) return contact.name;
|
||||
// Room posts name their author by a 4-byte key prefix, as in the list.
|
||||
final key = m.fourByteRoomContactKey;
|
||||
final hex = key
|
||||
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||
.join()
|
||||
.toUpperCase();
|
||||
final author = key.isEmpty
|
||||
? null
|
||||
: _resolveContactFrom4Bytes(connector, key);
|
||||
return author != null ? '${author.name} [$hex]' : '[$hex]';
|
||||
}
|
||||
|
||||
return [
|
||||
for (final m in messages)
|
||||
if (!m.isCli)
|
||||
ChatSearchEntry(
|
||||
id: m.messageId,
|
||||
sender: senderOf(m),
|
||||
text: m.text,
|
||||
translatedText: m.translatedText,
|
||||
time: m.receivedAt,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
canPop: !_searching,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop && _searching) _closeSearch();
|
||||
},
|
||||
child: _buildScaffold(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildScaffold(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Consumer2<PathHistoryService, MeshCoreConnector>(
|
||||
builder: (context, pathService, connector, _) {
|
||||
final contact = _resolveContact(connector);
|
||||
final pathLabel = _currentPathLabel(contact);
|
||||
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(),
|
||||
actions: [
|
||||
const RadioStatsIconButton(),
|
||||
Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, _) {
|
||||
final contact = _resolveContact(connector);
|
||||
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 'background':
|
||||
showChatBackgroundSheet(
|
||||
context,
|
||||
ChatBackgroundService.contactKey(contact),
|
||||
);
|
||||
case 'telemetry':
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
TelemetryScreen(contact: widget.contact),
|
||||
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 '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,
|
||||
),
|
||||
),
|
||||
);
|
||||
case 'clearChat':
|
||||
_confirmClearChat(context, connector);
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
value: 'routing',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.route, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(context.l10n.routing_title),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'info',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(context.l10n.contact_info),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'telemetry',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.bar_chart, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(context.l10n.contact_telemetry),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'settings',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.settings, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(context.l10n.contact_settings),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'background',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.wallpaper, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Text(context.l10n.chatBackground_title),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'clearChat',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.delete,
|
||||
size: 20,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
PopupMenuItem(
|
||||
value: 'info',
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.info_outline,
|
||||
label: context.l10n.contact_info,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
context.l10n.contact_clearChat,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
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: '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: Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, child) {
|
||||
final messages = connector.getMessages(widget.contact);
|
||||
final newest = messages.isEmpty ? null : messages.last;
|
||||
_holidayWatcher.onNewest(
|
||||
context,
|
||||
id: newest?.messageId,
|
||||
texts: [newest?.text, newest?.translatedText],
|
||||
receivedAt: newest?.receivedAt,
|
||||
originOf: () => newestMessageOrigin(
|
||||
_messageAreaKey,
|
||||
isOutgoing: newest?.isOutgoing ?? false,
|
||||
),
|
||||
);
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ChatBackdrop(
|
||||
key: _messageAreaKey,
|
||||
chatKey: ChatBackgroundService.contactKey(widget.contact),
|
||||
child: Stack(
|
||||
children: [
|
||||
messages.isEmpty
|
||||
? _buildEmptyState()
|
||||
: _buildMessageList(messages, connector),
|
||||
JumpToBottomButton(scrollController: _scrollController),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
_buildInputBar(connector),
|
||||
],
|
||||
);
|
||||
},
|
||||
],
|
||||
),
|
||||
body: _showSearchResults
|
||||
? _buildSearchResults(_loadSearchEntries)
|
||||
: Consumer<MeshCoreConnector>(
|
||||
builder: (context, connector, child) {
|
||||
final messages = connector.getMessages(widget.contact);
|
||||
final newest = messages.isEmpty ? null : messages.last;
|
||||
_holidayWatcher.onNewest(
|
||||
context,
|
||||
id: newest?.messageId,
|
||||
texts: [newest?.text, newest?.translatedText],
|
||||
receivedAt: newest?.receivedAt,
|
||||
originOf: () => newestMessageOrigin(
|
||||
_messageAreaKey,
|
||||
isOutgoing: newest?.isOutgoing ?? false,
|
||||
),
|
||||
);
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ChatBackdrop(
|
||||
key: _messageAreaKey,
|
||||
chatKey: ChatBackgroundService.contactKey(
|
||||
widget.contact,
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
messages.isEmpty
|
||||
? _buildEmptyState()
|
||||
: _buildMessageList(messages, connector),
|
||||
JumpToBottomButton(
|
||||
scrollController: _scrollController,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildInputBar(connector),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -507,6 +730,19 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
reversedMessages[messageIndex + 1].receivedAt,
|
||||
message.receivedAt,
|
||||
);
|
||||
final highlighted = message.messageId == _highlightedMessageId;
|
||||
final shown = highlighted
|
||||
? AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.primary.withValues(alpha: 0.18),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
),
|
||||
child: bubble,
|
||||
)
|
||||
: bubble;
|
||||
final child = isUnreadAnchor || startsDay
|
||||
? Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -514,10 +750,10 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
if (startsDay)
|
||||
ChatDaySeparator(day: message.receivedAt),
|
||||
if (isUnreadAnchor) const UnreadDivider(),
|
||||
bubble,
|
||||
shown,
|
||||
],
|
||||
)
|
||||
: bubble;
|
||||
: shown;
|
||||
if (identical(message, _pendingUnreadScrollTarget)) {
|
||||
return KeyedSubtree(key: _unreadScrollKey, child: child);
|
||||
}
|
||||
@@ -585,6 +821,11 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
icon: Icons.my_location,
|
||||
label: context.l10n.chat_shareMyLocation,
|
||||
),
|
||||
ChatComposerAction(
|
||||
id: 'share-contact',
|
||||
icon: Icons.person_add_alt,
|
||||
label: context.l10n.contactShare_shareAction,
|
||||
),
|
||||
];
|
||||
},
|
||||
onAction: (action) {
|
||||
@@ -596,6 +837,12 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
_sendImageViaIpfs();
|
||||
case 'send-my-location':
|
||||
_shareMyLocation(context.read<MeshCoreConnector>());
|
||||
case 'share-contact':
|
||||
showShareContactSheet(
|
||||
context,
|
||||
_textController,
|
||||
focusNode: _textFieldFocusNode,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -616,7 +863,8 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
/// Shares the radio's own position as a map marker. Shares the text send
|
||||
/// guard and cooldown so it can't race or flood alongside typed messages.
|
||||
Future<void> _shareMyLocation(MeshCoreConnector connector) {
|
||||
Future<void> _shareMyLocation(MeshCoreConnector connector) async {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
return shareMyLocationMarker(
|
||||
context: context,
|
||||
connector: connector,
|
||||
@@ -633,10 +881,14 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
Future<void> _sendMessageInner(MeshCoreConnector connector) async {
|
||||
final text = _textController.text.trim();
|
||||
if (text.isEmpty) return;
|
||||
// Before anything clears the text box: offline the draft must stay.
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
if (!_sendGuard.checkCooldown(context)) return;
|
||||
|
||||
final translation = await translateOutgoingText(context, text);
|
||||
if (translation == null || !mounted) return;
|
||||
// The link can drop while the translation runs.
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
var outgoingText = translation.text;
|
||||
|
||||
final maxBytes = maxContactMessageBytes();
|
||||
@@ -688,7 +940,8 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
context,
|
||||
message: context.l10n.chat_clearChatConfirm,
|
||||
);
|
||||
if (confirmed) {
|
||||
if (!context.mounted) return;
|
||||
if (confirmed && ensureRadioConnected(context)) {
|
||||
connector.clearMessagesForContact(widget.contact);
|
||||
}
|
||||
}
|
||||
@@ -757,6 +1010,30 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
return PathHelper.splitPathBytes(pathBytes, hashWidth).length;
|
||||
}
|
||||
|
||||
/// Room management needs its own login (it may be as admin), as from the
|
||||
/// contact list.
|
||||
void _showRoomManagementLogin(Contact room) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => RoomLoginDialog(
|
||||
room: room,
|
||||
onLogin: (password, isAdmin) {
|
||||
if (!mounted) return;
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => RepeaterHubScreen(
|
||||
repeater: room,
|
||||
password: password,
|
||||
isAdmin: isAdmin,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showContactInfo(BuildContext context) {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final contact = _resolveContact(connector);
|
||||
@@ -1102,6 +1379,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
|
||||
void _showMessageActions(Message message, Contact contact) {
|
||||
final readOnly = isRadioReadOnly(context.read<MeshCoreConnector>());
|
||||
final translationService = context.read<TranslationService>();
|
||||
final canTranslateMessage =
|
||||
translationService.canTranslateIncoming(
|
||||
@@ -1126,6 +1404,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
// Can't react to your own messages
|
||||
if (!message.isOutgoing)
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: const Icon(Icons.add_reaction_outlined),
|
||||
title: Text(context.l10n.chat_addReaction),
|
||||
onTap: () {
|
||||
@@ -1184,6 +1463,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
),
|
||||
if (message.isOutgoing && message.status == MessageStatus.failed)
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: const Icon(Icons.refresh),
|
||||
title: Text(context.l10n.common_retry),
|
||||
onTap: () {
|
||||
@@ -1203,13 +1483,18 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: Icon(
|
||||
Icons.delete_outline,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
color: readOnly ? null : Theme.of(context).colorScheme.error,
|
||||
),
|
||||
title: Text(
|
||||
context.l10n.common_delete,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
style: TextStyle(
|
||||
color: readOnly
|
||||
? null
|
||||
: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
onTap: () async {
|
||||
Navigator.pop(sheetContext);
|
||||
@@ -1225,6 +1510,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
|
||||
Future<void> _deleteMessage(Message message) async {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
await context.read<MeshCoreConnector>().deleteMessage(message);
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
@@ -1234,6 +1520,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
|
||||
void _retryMessage(Message message) {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
connector.resendMessage(_resolveContact(connector), message);
|
||||
showDismissibleSnackBar(
|
||||
@@ -1254,6 +1541,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
|
||||
void _sendReaction(Message message, Contact senderContact, String emoji) {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final emojiIndex = ReactionHelper.emojiToIndex(emoji);
|
||||
if (emojiIndex == null) return; // Unknown emoji, skip
|
||||
@@ -1302,6 +1590,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final gifId = GifHelper.parseGif(message.text);
|
||||
final poi = parseMarkerText(message.text);
|
||||
final contactShare = parseContactShare(message.text);
|
||||
final isFailed = message.status == MessageStatus.failed;
|
||||
final urlImagesEnabled = context.select<MeshCoreConnector, bool>(
|
||||
(connector) => connector.isContactUrlImagesEnabled(sourceId),
|
||||
@@ -1405,7 +1694,15 @@ class _MessageBubble extends StatelessWidget {
|
||||
),
|
||||
if (gifId == null) const SizedBox(height: 2),
|
||||
],
|
||||
if (poi != null)
|
||||
if (contactShare != null)
|
||||
SharedContactCard(
|
||||
share: contactShare,
|
||||
isOutgoing: isOutgoing,
|
||||
textScale: textScale,
|
||||
textColor: textColor,
|
||||
metaColor: metaColor,
|
||||
)
|
||||
else if (poi != null)
|
||||
_buildPoiMessage(
|
||||
context,
|
||||
poi,
|
||||
|
||||
@@ -13,6 +13,7 @@ import '../models/community.dart';
|
||||
import '../storage/community_store.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../utils/channel_qr.dart';
|
||||
import '../utils/radio_guard.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/qr_scanner_widget.dart';
|
||||
@@ -89,7 +90,7 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
});
|
||||
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
_communityStore.setPublicKeyHex = connector.selfPublicKeyHex;
|
||||
_communityStore.setPublicKeyHex = connector.storageKeyHex;
|
||||
// Set when this screen is about to pop: keep the spinner up so the camera
|
||||
// doesn't restart on a closing route and detect the code again.
|
||||
var leaving = false;
|
||||
@@ -468,9 +469,10 @@ class _CommunityQrScannerScreenState extends State<CommunityQrScannerScreen> {
|
||||
Community community,
|
||||
bool addPublicChannel,
|
||||
) async {
|
||||
if (!ensureRadioConnected(context)) return false;
|
||||
// Save community to local storage
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
_communityStore.setPublicKeyHex = connector.selfPublicKeyHex;
|
||||
_communityStore.setPublicKeyHex = connector.storageKeyHex;
|
||||
await _communityStore.addCommunity(community);
|
||||
|
||||
// Optionally add the community public channel to the device. Only trust
|
||||
|
||||
@@ -4,12 +4,10 @@ import 'package:mobile_scanner/mobile_scanner.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 '../theme/mesh_theme.dart';
|
||||
import '../utils/contact_qr.dart';
|
||||
import '../utils/contact_qr_frame.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/qr_scanner_widget.dart';
|
||||
|
||||
@@ -183,25 +181,8 @@ class _ContactQrScannerScreenState extends State<ContactQrScannerScreen> {
|
||||
}
|
||||
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final publicKey = scanned.publicKey;
|
||||
// Saved contacts first (their flags matter), then discovery-only records,
|
||||
// which still carry a known name worth preserving.
|
||||
final existing = publicKey == null
|
||||
? null
|
||||
: connector.allContactsUnfiltered
|
||||
.where(
|
||||
(contact) => contact.publicKeyHex == pubKeyToHex(publicKey),
|
||||
)
|
||||
.firstOrNull;
|
||||
final frame = buildContactQrFrame(
|
||||
scanned,
|
||||
existing: existing,
|
||||
pathHashByteWidth: connector.pathHashByteWidth,
|
||||
);
|
||||
|
||||
try {
|
||||
await connector.sendFrame(frame, waitForGenericAck: true);
|
||||
await connector.refreshContacts();
|
||||
await connector.addContactFromCard(scanned);
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
|
||||
+236
-202
@@ -4,6 +4,7 @@ import 'dart:math' as math;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:meshcore_open/screens/path_trace_map.dart';
|
||||
import 'package:meshcore_open/screens/manual_path_trace_screen.dart';
|
||||
import 'package:meshcore_open/services/notification_service.dart';
|
||||
import 'package:meshcore_open/utils/app_logger.dart';
|
||||
import 'package:meshcore_open/utils/platform_info.dart';
|
||||
@@ -21,8 +22,8 @@ import '../theme/mesh_theme.dart';
|
||||
import '../theme/terminal_theme.dart';
|
||||
import '../utils/contact_search.dart';
|
||||
import '../storage/contact_group_store.dart';
|
||||
import '../utils/dialog_utils.dart';
|
||||
import '../utils/disconnect_navigation_mixin.dart';
|
||||
import '../widgets/connect_sheet.dart';
|
||||
import '../utils/radio_guard.dart';
|
||||
import '../utils/emoji_utils.dart';
|
||||
import '../utils/route_transitions.dart';
|
||||
import '../widgets/contact_visuals.dart';
|
||||
@@ -34,6 +35,7 @@ import '../widgets/repeater_login_dialog.dart';
|
||||
import '../widgets/room_login_dialog.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
import '../widgets/unread_badge.dart';
|
||||
import '../helpers/contact_share_message.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import 'channels_screen.dart';
|
||||
import 'chat_screen.dart';
|
||||
@@ -69,8 +71,7 @@ class ContactsScreen extends StatefulWidget {
|
||||
State<ContactsScreen> createState() => _ContactsScreenState();
|
||||
}
|
||||
|
||||
class _ContactsScreenState extends State<ContactsScreen>
|
||||
with DisconnectNavigationMixin {
|
||||
class _ContactsScreenState extends State<ContactsScreen> {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final ContactGroupStore _groupStore = ContactGroupStore();
|
||||
MeshCoreConnector? _scopeSyncConnector;
|
||||
@@ -204,7 +205,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
}
|
||||
|
||||
Future<void> _loadGroups() async {
|
||||
final selfPublicKeyHex = context.read<MeshCoreConnector>().selfPublicKeyHex;
|
||||
final selfPublicKeyHex = context.read<MeshCoreConnector>().storageKeyHex;
|
||||
if (selfPublicKeyHex.isEmpty) {
|
||||
return;
|
||||
}
|
||||
@@ -219,7 +220,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
}
|
||||
|
||||
Future<void> _saveGroups() async {
|
||||
final selfPublicKeyHex = context.read<MeshCoreConnector>().selfPublicKeyHex;
|
||||
final selfPublicKeyHex = context.read<MeshCoreConnector>().storageKeyHex;
|
||||
if (selfPublicKeyHex.isEmpty) {
|
||||
return;
|
||||
}
|
||||
@@ -228,11 +229,11 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
}
|
||||
|
||||
bool _hasGroupStoreScope(MeshCoreConnector connector) {
|
||||
return connector.selfPublicKeyHex.isNotEmpty;
|
||||
return connector.storageKeyHex.isNotEmpty;
|
||||
}
|
||||
|
||||
void _syncGroupScopeIfNeeded(MeshCoreConnector connector) {
|
||||
final selfPublicKeyHex = connector.selfPublicKeyHex;
|
||||
final selfPublicKeyHex = connector.storageKeyHex;
|
||||
if (selfPublicKeyHex.isEmpty ||
|
||||
selfPublicKeyHex == _loadedGroupScopeKeyHex) {
|
||||
return;
|
||||
@@ -356,6 +357,12 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
return;
|
||||
}
|
||||
final text = clipboardData.text!.trim();
|
||||
// A contact shared in chat (`<PUBKEY:TYPE:NAME>`) copied from the bubble.
|
||||
final share = findContactShare(text);
|
||||
if (share != null && !text.startsWith('meshcore://')) {
|
||||
await _importContactShare(connector, share);
|
||||
return;
|
||||
}
|
||||
if (!text.startsWith('meshcore://')) {
|
||||
if (mounted) {
|
||||
showDismissibleSnackBar(
|
||||
@@ -393,15 +400,37 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _importContactShare(
|
||||
MeshCoreConnector connector,
|
||||
ContactShare share,
|
||||
) async {
|
||||
if (!mounted) return;
|
||||
final l10n = context.l10n;
|
||||
if (share.publicKeyHex == connector.selfPublicKeyHex) {
|
||||
showDismissibleSnackBar(context, content: Text(l10n.contactShare_isYou));
|
||||
return;
|
||||
}
|
||||
var ok = true;
|
||||
try {
|
||||
await connector.addContactFromCard(share.toScannedContact());
|
||||
} catch (e) {
|
||||
appLogger.warn('Contact share import failed: $e', tag: 'ContactsScreen');
|
||||
ok = false;
|
||||
}
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
ok ? l10n.contacts_contactImported : l10n.contacts_contactImportFailed,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
|
||||
// Auto-navigate back to scanner if disconnected
|
||||
if (!checkConnectionAndNavigate(connector)) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final readOnly = isRadioReadOnly(connector);
|
||||
final allowBack = !connector.isConnected;
|
||||
return PopScope(
|
||||
canPop: allowBack,
|
||||
@@ -415,12 +444,9 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
tooltip: context.l10n.contacts_moreOptions,
|
||||
itemBuilder: (context) => <PopupMenuEntry<dynamic>>[
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.person_add_rounded),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.discoveredContacts_Title),
|
||||
],
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.person_add_rounded,
|
||||
label: context.l10n.discoveredContacts_Title,
|
||||
),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
@@ -430,22 +456,18 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.paste),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.contacts_addContactFromClipboard),
|
||||
],
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.paste,
|
||||
label: context.l10n.contacts_addContactFromClipboard,
|
||||
),
|
||||
onTap: () => _contactImport(),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.qr_code_scanner),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.contacts_scanQrCode),
|
||||
],
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.qr_code_scanner,
|
||||
label: context.l10n.contacts_scanQrCode,
|
||||
),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
@@ -456,56 +478,43 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.connect_without_contact),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.contacts_zeroHopAdvert),
|
||||
],
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.connect_without_contact,
|
||||
label: context.l10n.contacts_zeroHopAdvert,
|
||||
),
|
||||
onTap: () => _sendSelfAdvert(connector, flood: false),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.cell_tower),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.contacts_floodAdvert),
|
||||
],
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.cell_tower,
|
||||
label: context.l10n.contacts_floodAdvert,
|
||||
),
|
||||
onTap: () => _sendSelfAdvert(connector, flood: true),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.copy),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.contacts_copyAdvertToClipboard),
|
||||
],
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.copy,
|
||||
label: context.l10n.contacts_copyAdvertToClipboard,
|
||||
),
|
||||
onTap: () => _contactExport(Uint8List.fromList([])),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.logout,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.common_disconnect),
|
||||
],
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.radar,
|
||||
label: context.l10n.manualTrace_menuItem,
|
||||
),
|
||||
onTap: () => _disconnect(context, connector),
|
||||
onTap: () => ManualPathTraceScreen.open(context),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
connectionMenuItem(this.context, context),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const ThemedIcon(ThemeIconSlot.settings),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.settings_title),
|
||||
],
|
||||
child: MeshMenuItemRow(
|
||||
leading: const ThemedIcon(ThemeIconSlot.settings, size: 20),
|
||||
label: context.l10n.settings_title,
|
||||
),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
@@ -525,10 +534,12 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
Expanded(child: _buildContactsBody(context, connector)),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => _showAddContactSheet(context),
|
||||
child: const Icon(Icons.person_add),
|
||||
),
|
||||
floatingActionButton: readOnly
|
||||
? null
|
||||
: FloatingActionButton(
|
||||
onPressed: () => _showAddContactSheet(context),
|
||||
child: const Icon(Icons.person_add),
|
||||
),
|
||||
bottomNavigationBar: SafeArea(
|
||||
top: false,
|
||||
child: QuickSwitchBar(
|
||||
@@ -594,13 +605,6 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _disconnect(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
) async {
|
||||
await showDisconnectDialog(context, connector);
|
||||
}
|
||||
|
||||
ContactGroup? _selectedGroupForName(String selectedGroupName) {
|
||||
if (selectedGroupName == contactsAllGroupsValue) return null;
|
||||
for (final group in _groups) {
|
||||
@@ -781,17 +785,9 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
const PopupMenuDivider(),
|
||||
PopupMenuItem<String>(
|
||||
value: _manageGroupsValue,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.group_add),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
menuContext.l10n.contacts_manageGroups,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.group_add,
|
||||
label: menuContext.l10n.contacts_manageGroups,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -1069,7 +1065,11 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
),
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () => connector.getContacts(),
|
||||
// Offline there is no radio to refresh from.
|
||||
onRefresh: () async {
|
||||
if (isRadioReadOnly(connector)) return;
|
||||
await connector.getContacts();
|
||||
},
|
||||
child: filteredAndSorted.isEmpty
|
||||
? LayoutBuilder(
|
||||
builder: (context, constraints) => ListView(
|
||||
@@ -1244,9 +1244,12 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
// Check if this is a repeater
|
||||
if (contact.type == advTypeRepeater) {
|
||||
_showRepeaterLogin(context, contact);
|
||||
} else if (contact.type == advTypeRoom) {
|
||||
} else if (contact.type == advTypeRoom &&
|
||||
!isRadioReadOnly(context.read<MeshCoreConnector>())) {
|
||||
_showRoomLogin(context, contact, RoomLoginDestination.chat);
|
||||
} else {
|
||||
// Offline a room opens straight onto its saved history, read-only:
|
||||
// logging in needs the radio.
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final unread = connector.getUnreadCountForContactKey(
|
||||
contact.publicKeyHex,
|
||||
@@ -1293,6 +1296,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
}
|
||||
|
||||
void _showRepeaterLogin(BuildContext context, Contact repeater) {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => RepeaterLoginDialog(
|
||||
@@ -1319,6 +1323,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
Contact room,
|
||||
RoomLoginDestination destination,
|
||||
) {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => RoomLoginDialog(
|
||||
@@ -1579,6 +1584,9 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
final isRepeater = contact.type == advTypeRepeater;
|
||||
final isRoom = contact.type == advTypeRoom;
|
||||
final isFavorite = contact.isFavorite;
|
||||
// Everything here except the header talks to the radio.
|
||||
final readOnly = isRadioReadOnly(connector);
|
||||
Color? tint(Color color) => readOnly ? null : color;
|
||||
|
||||
showMeshSheet(
|
||||
context,
|
||||
@@ -1593,7 +1601,8 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
),
|
||||
if (isRepeater) ...[
|
||||
ListTile(
|
||||
leading: Icon(Icons.radar, color: MeshPalette.signal),
|
||||
enabled: !readOnly,
|
||||
leading: Icon(Icons.radar, color: tint(MeshPalette.signal)),
|
||||
title: Text(context.l10n.contacts_ping),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
@@ -1617,7 +1626,11 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.cell_tower, color: MeshPalette.warn),
|
||||
enabled: !readOnly,
|
||||
leading: Icon(
|
||||
Icons.cell_tower,
|
||||
color: tint(MeshPalette.warn),
|
||||
),
|
||||
title: Text(context.l10n.contacts_manageRepeater),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
@@ -1626,7 +1639,8 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
),
|
||||
] else if (isRoom) ...[
|
||||
ListTile(
|
||||
leading: Icon(Icons.radar, color: MeshPalette.signal),
|
||||
enabled: !readOnly,
|
||||
leading: Icon(Icons.radar, color: tint(MeshPalette.signal)),
|
||||
title: Text(context.l10n.contacts_pathTrace),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
@@ -1652,7 +1666,11 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.meeting_room, color: MeshPalette.blue),
|
||||
enabled: !readOnly,
|
||||
leading: Icon(
|
||||
Icons.meeting_room,
|
||||
color: tint(MeshPalette.blue),
|
||||
),
|
||||
title: Text(context.l10n.contacts_roomLogin),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
@@ -1660,9 +1678,10 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: Icon(
|
||||
Icons.room_preferences,
|
||||
color: MeshPalette.warn,
|
||||
color: tint(MeshPalette.warn),
|
||||
),
|
||||
title: Text(context.l10n.room_management),
|
||||
onTap: () {
|
||||
@@ -1677,7 +1696,8 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
] else ...[
|
||||
if (contact.pathLength > 0)
|
||||
ListTile(
|
||||
leading: Icon(Icons.radar, color: MeshPalette.signal),
|
||||
enabled: !readOnly,
|
||||
leading: Icon(Icons.radar, color: tint(MeshPalette.signal)),
|
||||
title: Text(context.l10n.contacts_chatTraceRoute),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
@@ -1702,9 +1722,10 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
),
|
||||
],
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: Icon(
|
||||
isFavorite ? Icons.star : Icons.star_border,
|
||||
color: MeshPalette.warn,
|
||||
color: tint(MeshPalette.warn),
|
||||
),
|
||||
title: Text(
|
||||
isFavorite
|
||||
@@ -1720,6 +1741,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: const Icon(Icons.copy),
|
||||
title: Text(context.l10n.contacts_ShareContact),
|
||||
onTap: () {
|
||||
@@ -1728,6 +1750,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: const Icon(Icons.connect_without_contact),
|
||||
title: Text(context.l10n.contacts_ShareContactZeroHop),
|
||||
onTap: () {
|
||||
@@ -1736,17 +1759,20 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: Icon(
|
||||
Icons.delete,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
color: tint(Theme.of(context).colorScheme.error),
|
||||
),
|
||||
title: Text(
|
||||
context.l10n.contacts_removeFromContacts,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
style: TextStyle(
|
||||
color: tint(Theme.of(context).colorScheme.error),
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_confirmDelete(context, connector, contact);
|
||||
confirmRemoveContact(context, connector, contact);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@@ -1766,81 +1792,84 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
.toInt();
|
||||
return Uint8List.fromList(contact.publicKey.sublist(0, width));
|
||||
}
|
||||
}
|
||||
|
||||
void _confirmDelete(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
Contact contact,
|
||||
) {
|
||||
var keepHistory = false;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (dialogContext, setDialogState) => AlertDialog(
|
||||
scrollable: true,
|
||||
title: Text(context.l10n.contacts_removeFromContacts),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
/// Asks before removing a contact from the radio. [onRemoved] runs once it
|
||||
/// was removed.
|
||||
void confirmRemoveContact(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
Contact contact, {
|
||||
VoidCallback? onRemoved,
|
||||
}) {
|
||||
var keepHistory = false;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (dialogContext, setDialogState) => AlertDialog(
|
||||
scrollable: true,
|
||||
title: Text(context.l10n.contacts_removeFromContacts),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(context.l10n.contacts_removeFromContactsConfirm(contact.name)),
|
||||
if (connector.autoAddsContactType(contact.type)) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
context.l10n.contacts_removeFromContactsConfirm(contact.name),
|
||||
),
|
||||
if (connector.autoAddsContactType(contact.type)) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
context.l10n.contacts_removeAutoAddNote,
|
||||
style: TextStyle(
|
||||
color: Theme.of(dialogContext).colorScheme.error,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
context.l10n.contacts_removeAutoAddNote,
|
||||
style: TextStyle(
|
||||
color: Theme.of(dialogContext).colorScheme.error,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
],
|
||||
CheckboxListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
value: keepHistory,
|
||||
title: Text(context.l10n.contacts_keepChatHistory),
|
||||
onChanged: (value) =>
|
||||
setDialogState(() => keepHistory = value ?? false),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(context.l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(dialogContext);
|
||||
try {
|
||||
await connector.removeContact(
|
||||
contact,
|
||||
keepMessages: keepHistory,
|
||||
);
|
||||
} catch (e) {
|
||||
appLogger.warn(
|
||||
'Remove contact failed: $e',
|
||||
tag: 'ContactsScreen',
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_removeFailed),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
context.l10n.contacts_remove,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
CheckboxListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
value: keepHistory,
|
||||
title: Text(context.l10n.contacts_keepChatHistory),
|
||||
onChanged: (value) =>
|
||||
setDialogState(() => keepHistory = value ?? false),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(context.l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(dialogContext);
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
try {
|
||||
await connector.removeContact(
|
||||
contact,
|
||||
keepMessages: keepHistory,
|
||||
);
|
||||
onRemoved?.call();
|
||||
} catch (e) {
|
||||
appLogger.warn(
|
||||
'Remove contact failed: $e',
|
||||
tag: 'ContactsScreen',
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_removeFailed),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
context.l10n.contacts_remove,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _ContactTile extends StatelessWidget {
|
||||
@@ -1958,44 +1987,49 @@ class _ContactTile extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
// Key prefix + path + last seen
|
||||
Row(
|
||||
// Key prefix + path, then last seen: on the same line when
|
||||
// both fit (time at the end), otherwise the time drops to
|
||||
// its own line instead of being cut off in long locales.
|
||||
Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
spacing: 8,
|
||||
runSpacing: 2,
|
||||
children: [
|
||||
_KeyPrefixBadge(
|
||||
prefix: contact.publicKeyPrefixHex(pathHashByteWidth),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_KeyPrefixBadge(
|
||||
prefix: contact.publicKeyPrefixHex(
|
||||
pathHashByteWidth,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Flexible(
|
||||
child: Text(
|
||||
contact.pathLabel(
|
||||
context.l10n,
|
||||
pathHashByteWidth: pathHashByteWidth,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Text(
|
||||
contact.pathLabel(
|
||||
context.l10n,
|
||||
pathHashByteWidth: pathHashByteWidth,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// Fills its share and right-aligns, so the time sits at
|
||||
// the row's end on wide screens too.
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
formatContactLastSeen(context.l10n, lastSeen),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.end,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12.5,
|
||||
color: unreadCount > 0
|
||||
? scheme.primary
|
||||
: scheme.onSurfaceVariant,
|
||||
),
|
||||
Text(
|
||||
formatContactLastSeen(context.l10n, lastSeen),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12.5,
|
||||
color: unreadCount > 0
|
||||
? scheme.primary
|
||||
: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -22,6 +22,7 @@ import '../widgets/list_filter_widget.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/node_scan_sheet.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../utils/radio_guard.dart';
|
||||
|
||||
class DiscoveryScreen extends StatefulWidget {
|
||||
const DiscoveryScreen({super.key});
|
||||
@@ -57,6 +58,7 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final readOnly = isRadioReadOnly(connector);
|
||||
|
||||
final discoveredContacts = connector.discoveredContacts;
|
||||
final filteredAndSorted = _filterAndSortContacts(
|
||||
@@ -96,36 +98,30 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
itemBuilder: (context) => <PopupMenuEntry<String>>[
|
||||
PopupMenuItem<String>(
|
||||
value: 'export',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.upload_file),
|
||||
const SizedBox(width: 8),
|
||||
Text(l10n.discoveredContacts_export),
|
||||
],
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.upload_file,
|
||||
label: l10n.discoveredContacts_export,
|
||||
),
|
||||
),
|
||||
PopupMenuItem<String>(
|
||||
value: 'import',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.download),
|
||||
const SizedBox(width: 8),
|
||||
Text(l10n.discoveredContacts_import),
|
||||
],
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.download,
|
||||
label: l10n.discoveredContacts_import,
|
||||
),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
PopupMenuItem<String>(
|
||||
value: 'delete_all',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.delete,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.discoveredContacts_deleteContactAll),
|
||||
],
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.delete,
|
||||
label: context.l10n.discoveredContacts_deleteContactAll,
|
||||
iconColor: readOnly
|
||||
? null
|
||||
: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -283,7 +279,9 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
IconButton(
|
||||
tooltip: context.l10n.discoveredContacts_addContact,
|
||||
icon: const Icon(Icons.person_add_alt_1),
|
||||
onPressed: () => _addContact(context, contact, connector),
|
||||
onPressed: isRadioReadOnly(connector)
|
||||
? null
|
||||
: () => _addContact(context, contact, connector),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -296,6 +294,7 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
Contact contact,
|
||||
MeshCoreConnector connector,
|
||||
) async {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
try {
|
||||
final imported = await connector.importDiscoveredContact(contact);
|
||||
if (!context.mounted) return;
|
||||
@@ -354,6 +353,7 @@ class _DiscoveryScreenState extends State<DiscoveryScreen> {
|
||||
onTap: () => Navigator.of(sheetContext).pop('copy_contact'),
|
||||
),
|
||||
ListTile(
|
||||
enabled: !isRadioReadOnly(connector),
|
||||
leading: const Icon(Icons.delete),
|
||||
title: Text(l10n.discoveredContacts_deleteContact),
|
||||
onTap: () => Navigator.of(sheetContext).pop('delete_contact'),
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:meshcore_open/utils/gpx_export.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../utils/share_origin.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/mesh_nav_tile.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
|
||||
class ExportScreen extends StatelessWidget {
|
||||
const ExportScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: AppBarTitle(
|
||||
l10n.settings_export,
|
||||
indicators: false,
|
||||
subtitle: false,
|
||||
),
|
||||
centerTitle: true,
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
|
||||
children: [
|
||||
SectionHeader(l10n.settings_export),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
MeshNavTile(
|
||||
icon: Icons.download_outlined,
|
||||
title: l10n.settings_gpxExportRepeaters,
|
||||
subtitle: l10n.settings_gpxExportRepeatersSubtitle,
|
||||
onTap: () {
|
||||
final exporter = GpxExport(connector)..addRepeaters();
|
||||
_gpxExport(
|
||||
context,
|
||||
exporter,
|
||||
l10n.map_repeater,
|
||||
l10n.settings_gpxExportRepeatersRoom,
|
||||
'meshcore_repeaters_',
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
icon: Icons.download_outlined,
|
||||
title: l10n.settings_gpxExportContacts,
|
||||
subtitle: l10n.settings_gpxExportContactsSubtitle,
|
||||
onTap: () {
|
||||
final exporter = GpxExport(connector)..addContacts();
|
||||
_gpxExport(
|
||||
context,
|
||||
exporter,
|
||||
l10n.map_repeater,
|
||||
l10n.settings_gpxExportChat,
|
||||
'meshcore_contacts_',
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
icon: Icons.download_outlined,
|
||||
title: l10n.settings_gpxExportAll,
|
||||
subtitle: l10n.settings_gpxExportAllSubtitle,
|
||||
onTap: () {
|
||||
final exporter = GpxExport(connector)..addAll();
|
||||
_gpxExport(
|
||||
context,
|
||||
exporter,
|
||||
l10n.map_repeater,
|
||||
l10n.settings_gpxExportAllContacts,
|
||||
'meshcore_all_',
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _gpxExport(
|
||||
BuildContext context,
|
||||
GpxExport exporter,
|
||||
String name,
|
||||
String description,
|
||||
String filename,
|
||||
) async {
|
||||
final l10n = context.l10n;
|
||||
final result = await exporter.exportGPX(
|
||||
name,
|
||||
description,
|
||||
filename,
|
||||
l10n.settings_gpxExportShareText,
|
||||
l10n.settings_gpxExportShareSubject,
|
||||
sharePositionOrigin: shareOriginOf(context),
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
final message = switch (result) {
|
||||
gpxExportSuccess => l10n.settings_gpxExportSuccess,
|
||||
gpxExportNoContacts => l10n.settings_gpxExportNoContacts,
|
||||
gpxExportNotAvailable => l10n.settings_gpxExportNotAvailable,
|
||||
gpxExportFailed => l10n.settings_gpxExportError,
|
||||
_ => l10n.settings_gpxExportError,
|
||||
};
|
||||
showDismissibleSnackBar(context, content: Text(message));
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import '../models/channel_message.dart';
|
||||
import '../models/message_filter.dart';
|
||||
import '../widgets/filtered_message_ghost.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/chat_send_pipeline.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
|
||||
@@ -33,6 +34,63 @@ String filteredMessageRowId(Channel channel, ChannelMessage message) =>
|
||||
class _FilteredMessagesScreenState extends State<FilteredMessagesScreen> {
|
||||
final Set<String> _revealed = <String>{};
|
||||
|
||||
/// Bulk selection: when on, taps toggle rows and the app bar holds the
|
||||
/// bulk actions.
|
||||
bool _selectMode = false;
|
||||
final Set<String> _selected = <String>{};
|
||||
|
||||
void _toggleSelected(String rowId) {
|
||||
setState(() {
|
||||
_selectMode = true;
|
||||
if (!_selected.remove(rowId)) _selected.add(rowId);
|
||||
});
|
||||
}
|
||||
|
||||
void _exitSelectMode() => setState(() {
|
||||
_selectMode = false;
|
||||
_selected.clear();
|
||||
});
|
||||
|
||||
List<(Channel, ChannelMessage)> _selectedEntries(
|
||||
List<(Channel, ChannelMessage)> entries,
|
||||
) => [
|
||||
for (final e in entries)
|
||||
if (_selected.contains(_rowId(e.$1, e.$2))) e,
|
||||
];
|
||||
|
||||
Future<void> _bulkNotSpam(List<(Channel, ChannelMessage)> items) async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final text = context.l10n.messageFilter_markedNotSpamCount(items.length);
|
||||
setState(() {
|
||||
for (final (channel, message) in items) {
|
||||
_revealed.remove(_rowId(channel, message));
|
||||
}
|
||||
_selectMode = false;
|
||||
_selected.clear();
|
||||
});
|
||||
await connector.markChannelMessagesNotSpam(items);
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(context, content: Text(text));
|
||||
}
|
||||
|
||||
Future<void> _bulkDelete(List<(Channel, ChannelMessage)> items) async {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final confirmed = await confirmBulkDelete(context, items.length);
|
||||
if (!confirmed || !mounted) return;
|
||||
setState(() {
|
||||
_selectMode = false;
|
||||
_selected.clear();
|
||||
});
|
||||
final removed = await connector.deleteChannelMessages(
|
||||
items.map((e) => e.$2),
|
||||
);
|
||||
if (!mounted || removed == 0) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.chat_messagesDeleted(removed)),
|
||||
);
|
||||
}
|
||||
|
||||
static String _rowId(Channel channel, ChannelMessage message) =>
|
||||
filteredMessageRowId(channel, message);
|
||||
|
||||
@@ -60,35 +118,86 @@ class _FilteredMessagesScreenState extends State<FilteredMessagesScreen> {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final entries = connector.recentFilteredChannelMessages();
|
||||
final selectedEntries = _selectedEntries(entries);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: AdaptiveAppBarTitle(l10n.messageFilter_displayTitle),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: entries.isEmpty
|
||||
? EmptyState(
|
||||
icon: Icons.filter_alt_outlined,
|
||||
title: l10n.messageFilter_filteredMessagesEmpty,
|
||||
return PopScope(
|
||||
canPop: !_selectMode,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop && _selectMode) _exitSelectMode();
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: _selectMode
|
||||
? AppBar(
|
||||
leading: IconButton(
|
||||
tooltip: l10n.chat_clearSelection,
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: _exitSelectMode,
|
||||
),
|
||||
title: Text(l10n.chat_selectedCount(selectedEntries.length)),
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: l10n.chat_selectAll,
|
||||
icon: const Icon(Icons.select_all),
|
||||
onPressed: () => setState(() {
|
||||
_selected.addAll(entries.map((e) => _rowId(e.$1, e.$2)));
|
||||
}),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.messageFilter_notSpam,
|
||||
icon: const Icon(Icons.check_circle_outline),
|
||||
onPressed: selectedEntries.isEmpty
|
||||
? null
|
||||
: () => _bulkNotSpam(selectedEntries),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.common_delete,
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
onPressed: selectedEntries.isEmpty
|
||||
? null
|
||||
: () => _bulkDelete(selectedEntries),
|
||||
),
|
||||
],
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
|
||||
itemCount: entries.length,
|
||||
itemBuilder: (context, index) {
|
||||
final (channel, message) = entries[index];
|
||||
final id = _rowId(channel, message);
|
||||
return _FilteredMessageCard(
|
||||
key: ValueKey('filtered_$id'),
|
||||
channel: channel,
|
||||
message: message,
|
||||
revealed: _revealed.contains(id),
|
||||
onToggle: () => _toggle(id),
|
||||
onNotSpam: () => _markNotSpam(channel, message),
|
||||
);
|
||||
},
|
||||
: AppBar(
|
||||
title: AdaptiveAppBarTitle(l10n.messageFilter_displayTitle),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
if (entries.isNotEmpty)
|
||||
IconButton(
|
||||
tooltip: l10n.chat_selectMessages,
|
||||
icon: const Icon(Icons.checklist),
|
||||
onPressed: () => setState(() => _selectMode = true),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: entries.isEmpty
|
||||
? EmptyState(
|
||||
icon: Icons.filter_alt_outlined,
|
||||
title: l10n.messageFilter_filteredMessagesEmpty,
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
|
||||
itemCount: entries.length,
|
||||
itemBuilder: (context, index) {
|
||||
final (channel, message) = entries[index];
|
||||
final id = _rowId(channel, message);
|
||||
return _FilteredMessageCard(
|
||||
key: ValueKey('filtered_$id'),
|
||||
channel: channel,
|
||||
message: message,
|
||||
revealed: _revealed.contains(id),
|
||||
selectMode: _selectMode,
|
||||
selected: _selected.contains(id),
|
||||
onToggle: () =>
|
||||
_selectMode ? _toggleSelected(id) : _toggle(id),
|
||||
onLongPress: () => _toggleSelected(id),
|
||||
onNotSpam: () => _markNotSpam(channel, message),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -98,7 +207,10 @@ class _FilteredMessageCard extends StatelessWidget {
|
||||
final Channel channel;
|
||||
final ChannelMessage message;
|
||||
final bool revealed;
|
||||
final bool selectMode;
|
||||
final bool selected;
|
||||
final VoidCallback onToggle;
|
||||
final VoidCallback onLongPress;
|
||||
final VoidCallback onNotSpam;
|
||||
|
||||
const _FilteredMessageCard({
|
||||
@@ -106,7 +218,10 @@ class _FilteredMessageCard extends StatelessWidget {
|
||||
required this.channel,
|
||||
required this.message,
|
||||
required this.revealed,
|
||||
required this.selectMode,
|
||||
required this.selected,
|
||||
required this.onToggle,
|
||||
required this.onLongPress,
|
||||
required this.onNotSpam,
|
||||
});
|
||||
|
||||
@@ -131,9 +246,11 @@ class _FilteredMessageCard extends StatelessWidget {
|
||||
color: scheme.onSurfaceVariant,
|
||||
);
|
||||
|
||||
return MeshCard(
|
||||
final card = MeshCard(
|
||||
onTap: onToggle,
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 8, 4),
|
||||
onLongPress: onLongPress,
|
||||
color: selected ? scheme.primary.withValues(alpha: 0.16) : null,
|
||||
padding: EdgeInsets.fromLTRB(16, 12, 8, selectMode ? 12 : 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -208,15 +325,33 @@ class _FilteredMessageCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: TextButton.icon(
|
||||
style: TextButton.styleFrom(minimumSize: const Size(0, 48)),
|
||||
onPressed: onNotSpam,
|
||||
icon: const Icon(Icons.check_circle_outline, size: 22),
|
||||
label: Text(l10n.messageFilter_notSpam),
|
||||
if (!selectMode)
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: TextButton.icon(
|
||||
style: TextButton.styleFrom(minimumSize: const Size(0, 48)),
|
||||
onPressed: onNotSpam,
|
||||
icon: const Icon(Icons.check_circle_outline, size: 22),
|
||||
label: Text(l10n.messageFilter_notSpam),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (!selectMode) return card;
|
||||
return Semantics(
|
||||
selected: selected,
|
||||
child: Row(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 12),
|
||||
child: Icon(
|
||||
selected ? Icons.check_circle : Icons.radio_button_unchecked,
|
||||
size: 28,
|
||||
color: selected ? scheme.primary : scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
Expanded(child: card),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -18,6 +18,7 @@ import '../services/map_tile_cache_service.dart';
|
||||
import '../utils/route_transitions.dart';
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/path_map_scaffold.dart';
|
||||
import '../widgets/quick_switch_bar.dart';
|
||||
import '../icons/los_icon.dart';
|
||||
@@ -372,12 +373,9 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
PopupMenuItem(
|
||||
value: 'clear',
|
||||
enabled: !_loading,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.delete_outline),
|
||||
const SizedBox(width: 10),
|
||||
Text(context.l10n.losClearAllPoints),
|
||||
],
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.delete_outline,
|
||||
label: context.l10n.losClearAllPoints,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -563,20 +561,28 @@ class _LineOfSightMapScreenState extends State<LineOfSightMapScreen> {
|
||||
}
|
||||
|
||||
Widget _headerMetric(IconData icon, String value) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, color: LosPalette.textMuted, size: 16),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
value,
|
||||
style: MeshTheme.mono(
|
||||
color: LosPalette.text,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
// Capped so very large text scales shrink the reading instead of pushing
|
||||
// the panel off a narrow screen.
|
||||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 80),
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, color: LosPalette.textMuted, size: 16),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
value,
|
||||
style: MeshTheme.mono(
|
||||
color: LosPalette.text,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,277 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/path_helper.dart';
|
||||
import '../helpers/path_trace_input.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../models/map_path_trace_draft.dart';
|
||||
import '../services/ui_view_state_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import 'path_trace_map.dart';
|
||||
|
||||
class ManualPathTraceScreen extends StatefulWidget {
|
||||
/// Optional prefill; when null the last entry of this session is restored.
|
||||
final String? initialText;
|
||||
final bool? initialReturnPath;
|
||||
|
||||
const ManualPathTraceScreen({
|
||||
super.key,
|
||||
this.initialText,
|
||||
this.initialReturnPath,
|
||||
});
|
||||
|
||||
static void open(
|
||||
BuildContext context, {
|
||||
String? initialText,
|
||||
bool? initialReturnPath,
|
||||
}) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => ManualPathTraceScreen(
|
||||
initialText: initialText,
|
||||
initialReturnPath: initialReturnPath,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<ManualPathTraceScreen> createState() => _ManualPathTraceScreenState();
|
||||
}
|
||||
|
||||
class _ManualPathTraceScreenState extends State<ManualPathTraceScreen> {
|
||||
late final MapPathTraceDraft _draft;
|
||||
late final TextEditingController _controller;
|
||||
late bool _returnPath;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Read here, not lazily: dispose() writes back to it and can't look up
|
||||
// providers from a deactivated context.
|
||||
_draft = context.read<UiViewStateService>().mapPathTrace;
|
||||
_controller = TextEditingController(
|
||||
text: widget.initialText ?? _draft.manualText,
|
||||
);
|
||||
_returnPath = widget.initialReturnPath ?? _draft.manualReturnPath;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_draft.manualText = _controller.text;
|
||||
_draft.manualReturnPath = _returnPath;
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String _example(int width) => width == 1
|
||||
? 'A1,B2,C3'
|
||||
: width == 2
|
||||
? 'A1B2,C3D4'
|
||||
: 'A1B2C3,D4E5F6';
|
||||
|
||||
List<Contact> _matches(MeshCoreConnector connector, Uint8List hop) {
|
||||
return connector.allContactsUnfiltered.where((c) {
|
||||
if (c.type != advTypeRepeater && c.type != advTypeRoom) return false;
|
||||
if (c.publicKey.length < hop.length) return false;
|
||||
for (var i = 0; i < hop.length; i++) {
|
||||
if (c.publicKey[i] != hop[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
String? _errorText(PathTraceInputError error) {
|
||||
final l10n = context.l10n;
|
||||
switch (error) {
|
||||
case PathTraceInputError.empty:
|
||||
return null;
|
||||
case PathTraceInputError.invalidHex:
|
||||
return l10n.manualTrace_errorInvalidHex;
|
||||
case PathTraceInputError.oddLength:
|
||||
return l10n.manualTrace_errorOddLength;
|
||||
case PathTraceInputError.mixedWidths:
|
||||
return l10n.manualTrace_errorMixedWidths;
|
||||
case PathTraceInputError.unsupportedWidth:
|
||||
return l10n.manualTrace_errorUnsupportedWidth;
|
||||
case PathTraceInputError.tooManyHops:
|
||||
return l10n.manualTrace_errorTooManyHops(maxPathSize);
|
||||
}
|
||||
}
|
||||
|
||||
void _run(MeshCoreConnector connector, PathTraceInput input) {
|
||||
final contacts = <Contact>[];
|
||||
for (final hop in input.hops) {
|
||||
final m = _matches(connector, hop);
|
||||
if (m.length == 1) contacts.add(m.first);
|
||||
}
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PathTraceMapScreen(
|
||||
title: context.l10n.contacts_pathTrace,
|
||||
path: input.bytes,
|
||||
pathHashByteWidth: input.hopWidth,
|
||||
flipPathAround: _returnPath,
|
||||
pathContacts: contacts,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final result = PathTraceInputParser.parse(
|
||||
_controller.text,
|
||||
connector.pathHashByteWidth,
|
||||
);
|
||||
final input = result.input;
|
||||
final fits =
|
||||
input == null || traceFitsInRequest(input, roundTrip: _returnPath);
|
||||
final errorText = result.error != null
|
||||
? _errorText(result.error!)
|
||||
: (fits ? null : l10n.manualTrace_errorTraceTooLong);
|
||||
final exampleWidth = input?.hopWidth ?? connector.pathHashByteWidth;
|
||||
final canRun = input != null && fits && connector.isConnected;
|
||||
const buttonSize = Size(48, 48);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: AppBarTitle(l10n.contacts_pathTrace),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
TextField(
|
||||
controller: _controller,
|
||||
autofocus: _controller.text.isEmpty,
|
||||
minLines: 2,
|
||||
maxLines: 4,
|
||||
autocorrect: false,
|
||||
enableSuggestions: false,
|
||||
textCapitalization: TextCapitalization.characters,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 19,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.manualTrace_inputLabel,
|
||||
helperText: l10n.manualTrace_helper(_example(exampleWidth)),
|
||||
helperMaxLines: 2,
|
||||
helperStyle: const TextStyle(fontSize: 14),
|
||||
errorText: errorText,
|
||||
errorMaxLines: 3,
|
||||
errorStyle: const TextStyle(fontSize: 14),
|
||||
),
|
||||
onChanged: (_) => setState(() {}),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (input != null) ...[
|
||||
Text(
|
||||
l10n.manualTrace_previewTitle(input.hops.length),
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
for (final hop in input.hops)
|
||||
_hopRow(context, hop, _matches(connector, hop)),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
SegmentedButton<bool>(
|
||||
segments: [
|
||||
ButtonSegment(
|
||||
value: true,
|
||||
icon: const Icon(Icons.sync_alt),
|
||||
label: MeshSegmentLabel(l10n.map_pathTraceModeRoundTrip),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: false,
|
||||
icon: const Icon(Icons.arrow_forward),
|
||||
label: MeshSegmentLabel(l10n.map_pathTraceModeAsEntered),
|
||||
),
|
||||
],
|
||||
selected: {_returnPath},
|
||||
onSelectionChanged: (s) => setState(() => _returnPath = s.first),
|
||||
style: SegmentedButton.styleFrom(minimumSize: buttonSize),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_returnPath
|
||||
? l10n.map_pathTraceModeRoundTripHint
|
||||
: l10n.map_pathTraceModeAsEnteredHint,
|
||||
style: TextStyle(fontSize: 14, color: scheme.onSurfaceVariant),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
FilledButton.icon(
|
||||
onPressed: canRun ? () => _run(connector, input) : null,
|
||||
style: FilledButton.styleFrom(minimumSize: const Size(48, 52)),
|
||||
icon: const Icon(Icons.radar),
|
||||
label: Text(
|
||||
l10n.manualTrace_run,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
if (!connector.isConnected) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
l10n.manualTrace_notConnected,
|
||||
style: TextStyle(fontSize: 14, color: scheme.error),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _hopRow(BuildContext context, Uint8List hop, List<Contact> matches) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final known = matches.isNotEmpty;
|
||||
return MeshCard(
|
||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
PathHelper.formatHopHex(hop),
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Text(
|
||||
known
|
||||
? matches.map((c) => c.name).join(' | ')
|
||||
: context.l10n.manualTrace_unknownNode,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: known ? scheme.onSurface : scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+149
-110
@@ -29,9 +29,10 @@ import '../services/network_map/network_map_api_client.dart';
|
||||
import '../services/ui_view_state_service.dart';
|
||||
import '../storage/prefs_manager.dart';
|
||||
import '../utils/contact_search.dart';
|
||||
import '../utils/disconnect_navigation_mixin.dart';
|
||||
import '../utils/radio_guard.dart';
|
||||
import '../utils/battery_utils.dart';
|
||||
import '../utils/route_transitions.dart';
|
||||
import '../widgets/connect_sheet.dart';
|
||||
import '../widgets/map_poi_cluster.dart';
|
||||
import '../widgets/marker_label_dialog.dart';
|
||||
import '../widgets/network_map_online_layer.dart';
|
||||
@@ -39,6 +40,7 @@ import '../widgets/quick_switch_bar.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
import '../icons/los_icon.dart';
|
||||
import 'channels_screen.dart';
|
||||
import 'manual_path_trace_screen.dart';
|
||||
import 'chat_screen.dart';
|
||||
import 'contacts_screen.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
@@ -74,7 +76,7 @@ class MapScreen extends StatefulWidget {
|
||||
State<MapScreen> createState() => _MapScreenState();
|
||||
}
|
||||
|
||||
class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
|
||||
// Zoom level at which node labels start to appear
|
||||
static const double _labelZoomThreshold = 14.0;
|
||||
// Below this zoom, nearby nodes collapse into clusters.
|
||||
@@ -134,6 +136,9 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
({LatLng center, double zoom})? _initialCamera;
|
||||
|
||||
static const String _lastCameraKey = 'map_last_camera';
|
||||
static const Duration _cameraSaveDelay = Duration(milliseconds: 500);
|
||||
Timer? _cameraSaveTimer;
|
||||
List<String>? _pendingCamera;
|
||||
|
||||
({LatLng center, double zoom}) _fallbackCamera(MeshCoreConnector connector) {
|
||||
final lat = connector.selfLatitude;
|
||||
@@ -151,23 +156,58 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
return (center: const LatLng(20, 0), zoom: _mapMinZoom);
|
||||
}
|
||||
|
||||
void _saveLastCamera() {
|
||||
void _scheduleCameraSave() {
|
||||
try {
|
||||
final camera = _mapController.camera;
|
||||
PrefsManager.instance.setStringList(_lastCameraKey, [
|
||||
final value = [
|
||||
camera.center.latitude.toString(),
|
||||
camera.center.longitude.toString(),
|
||||
camera.zoom.toString(),
|
||||
]);
|
||||
];
|
||||
_cameraSaveTimer?.cancel();
|
||||
_cameraSaveTimer = null;
|
||||
_pendingCamera =
|
||||
listEquals(value, PrefsManager.instance.getStringList(_lastCameraKey))
|
||||
? null
|
||||
: value;
|
||||
if (_pendingCamera != null) {
|
||||
_cameraSaveTimer = Timer(_cameraSaveDelay, _flushCameraSave);
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
void _flushCameraSave() {
|
||||
_cameraSaveTimer?.cancel();
|
||||
_cameraSaveTimer = null;
|
||||
final value = _pendingCamera;
|
||||
_pendingCamera = null;
|
||||
if (value == null) return;
|
||||
final prefs = PrefsManager.instance;
|
||||
if (listEquals(value, prefs.getStringList(_lastCameraKey))) return;
|
||||
unawaited(
|
||||
prefs.setStringList(_lastCameraKey, value).catchError((Object error) {
|
||||
debugPrint('Saving map camera failed: $error');
|
||||
return false;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state != AppLifecycleState.resumed) {
|
||||
_scheduleCameraSave();
|
||||
_flushCameraSave();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_ageTimer?.cancel();
|
||||
_online.removeListener(_onOnlineChanged);
|
||||
_online.dispose();
|
||||
_saveLastCamera();
|
||||
_scheduleCameraSave();
|
||||
_flushCameraSave();
|
||||
_searchController.dispose();
|
||||
_searchFocus.dispose();
|
||||
_mapController.dispose();
|
||||
@@ -289,6 +329,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_loadRemovedMarkers();
|
||||
_online.addListener(_onOnlineChanged);
|
||||
_ageTimer = Timer.periodic(const Duration(seconds: 60), (_) {
|
||||
@@ -525,9 +566,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
_MapConnectorSnapshot.fromConnector,
|
||||
);
|
||||
final connector = connectorSnapshot.connector;
|
||||
if (!checkConnectionAndNavigate(connector)) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final readOnly = isRadioReadOnly(connector);
|
||||
final settings = context.select<AppSettingsService, AppSettings>(
|
||||
(service) => service.settings,
|
||||
);
|
||||
@@ -544,7 +583,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
final tileCache = context.read<MapTileCacheService>();
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final isDesktop = _isDesktopPlatform(defaultTargetPlatform);
|
||||
final allContacts = connector.allContacts;
|
||||
final allContacts = connectorSnapshot.allContacts;
|
||||
|
||||
final contacts = settings.mapShowDiscoveryContacts
|
||||
? allContacts
|
||||
@@ -779,12 +818,9 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
connector.selfLatitude != null &&
|
||||
connector.selfLongitude != null)
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.radar),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.contacts_pathTrace),
|
||||
],
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.radar,
|
||||
label: context.l10n.contacts_pathTrace,
|
||||
),
|
||||
onTap: () => _openPathTrace(
|
||||
connector,
|
||||
@@ -796,12 +832,18 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
),
|
||||
if (!_isBuildingPathTrace)
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const LosIcon(),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.map_lineOfSight),
|
||||
],
|
||||
enabled: !readOnly,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.radar,
|
||||
label: context.l10n.manualTrace_menuItem,
|
||||
),
|
||||
onTap: () => ManualPathTraceScreen.open(context),
|
||||
),
|
||||
if (!_isBuildingPathTrace)
|
||||
PopupMenuItem(
|
||||
child: MeshMenuItemRow(
|
||||
leading: const LosIcon(size: 20),
|
||||
label: context.l10n.map_lineOfSight,
|
||||
),
|
||||
onTap: () {
|
||||
final candidates = <LineOfSightEndpoint>[];
|
||||
@@ -840,26 +882,14 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
);
|
||||
},
|
||||
),
|
||||
connectionMenuItem(this.context, context),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.logout,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.common_disconnect),
|
||||
],
|
||||
),
|
||||
onTap: () => _disconnect(context, connector),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
const ThemedIcon(ThemeIconSlot.settings),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.settings_title),
|
||||
],
|
||||
child: MeshMenuItemRow(
|
||||
leading: const ThemedIcon(
|
||||
ThemeIconSlot.settings,
|
||||
size: 20,
|
||||
),
|
||||
label: context.l10n.settings_title,
|
||||
),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
@@ -934,11 +964,12 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
event is MapEventFlingAnimationEnd ||
|
||||
event is MapEventScrollWheelZoom ||
|
||||
event is MapEventDoubleTapZoomEnd) {
|
||||
_saveLastCamera();
|
||||
_scheduleCameraSave();
|
||||
if (showOnline) _requestOnlineData();
|
||||
}
|
||||
},
|
||||
onPositionChanged: (camera, hasGesture) {
|
||||
_scheduleCameraSave();
|
||||
// Track zoom in half-step buckets so cluster/marker
|
||||
// detail levels update without rebuilding every frame.
|
||||
final bucket = (camera.zoom * 2).roundToDouble() / 2;
|
||||
@@ -1109,13 +1140,19 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
),
|
||||
bottomNavigationBar: SafeArea(
|
||||
top: false,
|
||||
child: QuickSwitchBar(
|
||||
selectedIndex: 2,
|
||||
onDestinationSelected: (index) =>
|
||||
_handleQuickSwitch(index, context),
|
||||
contactsUnreadCount: connector.getTotalContactsUnreadCount(),
|
||||
channelsUnreadCount: connector.getTotalChannelsUnreadCount(),
|
||||
highContrast: _usePaletteOverlay,
|
||||
child: Selector<MeshCoreConnector, (int, int)>(
|
||||
selector: (_, connector) => (
|
||||
connector.getTotalContactsUnreadCount(),
|
||||
connector.getTotalChannelsUnreadCount(),
|
||||
),
|
||||
builder: (context, unread, child) => QuickSwitchBar(
|
||||
selectedIndex: 2,
|
||||
onDestinationSelected: (index) =>
|
||||
_handleQuickSwitch(index, context),
|
||||
contactsUnreadCount: unread.$1,
|
||||
channelsUnreadCount: unread.$2,
|
||||
highContrast: _usePaletteOverlay,
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButton:
|
||||
@@ -1152,8 +1189,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
}) {
|
||||
final visibleContactsSignature = Object.hashAll(
|
||||
contacts.map(
|
||||
(contact) =>
|
||||
Object.hash(_mapContactSignature(contact), _ageOf(contact)),
|
||||
(contact) => Object.hash(contact.publicKeyHex, _ageOf(contact)),
|
||||
),
|
||||
);
|
||||
final key = _NodeMarkersCacheKey(
|
||||
@@ -1711,33 +1747,37 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
],
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'$count',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: count >= 100 ? 13 : 15,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: MapPalette.markerOutline,
|
||||
),
|
||||
),
|
||||
if (online > 0)
|
||||
Container(
|
||||
width: 7,
|
||||
height: 7,
|
||||
margin: const EdgeInsets.only(top: 1),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: MapPalette.online,
|
||||
border: Border.all(
|
||||
color: MapPalette.markerOutline,
|
||||
width: 1,
|
||||
),
|
||||
// The marker has a fixed size; large text scales shrink to fit it.
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'$count',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: count >= 100 ? 13 : 15,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: MapPalette.markerOutline,
|
||||
),
|
||||
),
|
||||
],
|
||||
if (online > 0)
|
||||
Container(
|
||||
width: 7,
|
||||
height: 7,
|
||||
margin: const EdgeInsets.only(top: 1),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: MapPalette.online,
|
||||
border: Border.all(
|
||||
color: MapPalette.markerOutline,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -2205,19 +2245,19 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
ButtonSegment(
|
||||
value: MapSourceOption.local,
|
||||
icon: const Icon(Icons.radio, size: 20),
|
||||
label: Text(l10n.networkMap_sourceLocal),
|
||||
label: MeshSegmentLabel(l10n.networkMap_sourceLocal),
|
||||
tooltip: l10n.networkMap_sourceLocalHint,
|
||||
),
|
||||
ButtonSegment(
|
||||
value: MapSourceOption.online,
|
||||
icon: const Icon(Icons.public, size: 20),
|
||||
label: Text(l10n.networkMap_sourceOnline),
|
||||
label: MeshSegmentLabel(l10n.networkMap_sourceOnline),
|
||||
tooltip: l10n.networkMap_sourceOnlineHint,
|
||||
),
|
||||
ButtonSegment(
|
||||
value: MapSourceOption.both,
|
||||
icon: const Icon(Icons.layers, size: 20),
|
||||
label: Text(l10n.networkMap_sourceBoth),
|
||||
label: MeshSegmentLabel(l10n.networkMap_sourceBoth),
|
||||
tooltip: l10n.networkMap_sourceBothHint,
|
||||
),
|
||||
],
|
||||
@@ -3201,33 +3241,6 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _disconnect(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(context.l10n.common_disconnect),
|
||||
content: Text(context.l10n.map_disconnectConfirm),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, false),
|
||||
child: Text(context.l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, true),
|
||||
child: Text(context.l10n.common_disconnect),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true) {
|
||||
await connector.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void _showMarkerInfo(_SharedMarker marker) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -3349,6 +3362,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
required MeshCoreConnector connector,
|
||||
required LatLng position,
|
||||
}) {
|
||||
final readOnly = isRadioReadOnly(connector);
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (sheetContext) => SafeArea(
|
||||
@@ -3356,6 +3370,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: const Icon(Icons.place),
|
||||
title: Text(context.l10n.map_shareMarkerHere),
|
||||
onTap: () {
|
||||
@@ -3370,6 +3385,7 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: const Icon(Icons.my_location),
|
||||
title: Text(context.l10n.map_setAsMyLocation),
|
||||
onTap: () {
|
||||
@@ -4018,6 +4034,18 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
});
|
||||
}
|
||||
|
||||
void _openManualEntry() {
|
||||
final text = PathHelper.splitPathBytes(
|
||||
_pathTrace,
|
||||
context.read<MeshCoreConnector>().pathHashByteWidth,
|
||||
).map(PathHelper.formatHopHex).join(',');
|
||||
ManualPathTraceScreen.open(
|
||||
context,
|
||||
initialText: text,
|
||||
initialReturnPath: _traceDraft.returnPath,
|
||||
);
|
||||
}
|
||||
|
||||
void _openTraceResult({required bool reuseLastResult}) {
|
||||
final draft = _traceDraft;
|
||||
final path = Uint8List.fromList(_pathTrace);
|
||||
@@ -4144,6 +4172,12 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
icon: const Icon(Icons.undo),
|
||||
label: Text(l10n.map_removeLast),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: _openManualEntry,
|
||||
style: TextButton.styleFrom(minimumSize: buttonSize),
|
||||
icon: const Icon(Icons.keyboard),
|
||||
label: Text(l10n.manualTrace_enterHashes),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: _clearPath,
|
||||
style: TextButton.styleFrom(minimumSize: buttonSize),
|
||||
@@ -4158,12 +4192,16 @@ class _MapScreenState extends State<MapScreen> with DisconnectNavigationMixin {
|
||||
ButtonSegment(
|
||||
value: true,
|
||||
icon: const Icon(Icons.sync_alt),
|
||||
label: Text(l10n.map_pathTraceModeRoundTrip),
|
||||
label: MeshSegmentLabel(
|
||||
l10n.map_pathTraceModeRoundTrip,
|
||||
),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: false,
|
||||
icon: const Icon(Icons.arrow_forward),
|
||||
label: Text(l10n.map_pathTraceModeAsEntered),
|
||||
label: MeshSegmentLabel(
|
||||
l10n.map_pathTraceModeAsEntered,
|
||||
),
|
||||
),
|
||||
],
|
||||
selected: {returnPath},
|
||||
@@ -4246,6 +4284,7 @@ int _mapContactSignature(Contact contact) {
|
||||
|
||||
class _MapConnectorSnapshot {
|
||||
final MeshCoreConnector connector;
|
||||
final List<Contact> allContacts;
|
||||
final int contactsSignature;
|
||||
final int markerSignature;
|
||||
final int batterySignature;
|
||||
@@ -4253,6 +4292,7 @@ class _MapConnectorSnapshot {
|
||||
|
||||
const _MapConnectorSnapshot({
|
||||
required this.connector,
|
||||
required this.allContacts,
|
||||
required this.contactsSignature,
|
||||
required this.markerSignature,
|
||||
required this.batterySignature,
|
||||
@@ -4305,6 +4345,7 @@ class _MapConnectorSnapshot {
|
||||
|
||||
return _MapConnectorSnapshot(
|
||||
connector: connector,
|
||||
allContacts: allContacts,
|
||||
contactsSignature: contactsSignature,
|
||||
markerSignature: Object.hashAll(markerParts),
|
||||
batterySignature: batterySignature,
|
||||
@@ -4316,8 +4357,6 @@ class _MapConnectorSnapshot {
|
||||
connector.currentBwHz,
|
||||
connector.currentSf,
|
||||
connector.currentTxPower,
|
||||
connector.getTotalContactsUnreadCount(),
|
||||
connector.getTotalChannelsUnreadCount(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,50 +30,52 @@ class MessageFilterSettingsScreen extends StatelessWidget {
|
||||
title: AdaptiveAppBarTitle(l10n.messageFilter_title),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
|
||||
children: [
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: SwitchListTile(
|
||||
key: const ValueKey('messageFilter_enabledSwitch'),
|
||||
contentPadding: _tilePadding,
|
||||
secondary: const Icon(Icons.filter_alt_outlined, size: 24),
|
||||
title: Text(l10n.messageFilter_enabled),
|
||||
subtitle: Text(l10n.messageFilter_enabledSubtitle),
|
||||
value: settings.enabled,
|
||||
onChanged: (value) => service.updateSettings(
|
||||
service.settings.copyWith(enabled: value),
|
||||
body: MeshSettingsTileTheme(
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
|
||||
children: [
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: SwitchListTile(
|
||||
key: const ValueKey('messageFilter_enabledSwitch'),
|
||||
contentPadding: _tilePadding,
|
||||
secondary: const Icon(Icons.filter_alt_outlined, size: 24),
|
||||
title: Text(l10n.messageFilter_enabled),
|
||||
subtitle: Text(l10n.messageFilter_enabledSubtitle),
|
||||
value: settings.enabled,
|
||||
onChanged: (value) => service.updateSettings(
|
||||
service.settings.copyWith(enabled: value),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
SectionHeader(l10n.messageFilter_displayTitle),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
_DisplayModeOptions(service: service),
|
||||
const Divider(height: 1, indent: 16),
|
||||
const _FilteredMessagesTile(),
|
||||
],
|
||||
SectionHeader(l10n.messageFilter_displayTitle),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
_DisplayModeOptions(service: service),
|
||||
const Divider(height: 1, indent: 16),
|
||||
const _FilteredMessagesTile(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
SectionHeader(l10n.messageFilter_rulesSection),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _RulesList(service: service),
|
||||
),
|
||||
SectionHeader(l10n.messageFilter_rulesSection),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _RulesList(service: service),
|
||||
),
|
||||
|
||||
SectionHeader(l10n.messageFilter_automaticSection),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _AutomaticOptions(service: service),
|
||||
),
|
||||
],
|
||||
SectionHeader(l10n.messageFilter_automaticSection),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _AutomaticOptions(service: service),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -366,6 +368,36 @@ class _AutomaticOptions extends StatelessWidget {
|
||||
service.settings.copyWith(duplicates: value),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
key: const ValueKey('messageFilter_repeatSends'),
|
||||
contentPadding: padding,
|
||||
enabled: settings.duplicates,
|
||||
leading: const Icon(Icons.repeat, size: 24),
|
||||
title: Text(l10n.messageFilter_repeatSends),
|
||||
subtitle: Text(
|
||||
l10n.messageFilter_repeatSendsSubtitle(settings.repeatSends),
|
||||
),
|
||||
trailing: DropdownButton<int>(
|
||||
key: const ValueKey('messageFilter_repeatSendsDropdown'),
|
||||
value: settings.repeatSends,
|
||||
onChanged: settings.duplicates
|
||||
? (value) {
|
||||
if (value == null) return;
|
||||
service.updateSettings(
|
||||
service.settings.copyWith(repeatSends: value),
|
||||
);
|
||||
}
|
||||
: null,
|
||||
items: [
|
||||
for (
|
||||
var n = MessageFilterSettings.minRepeatSends;
|
||||
n <= MessageFilterSettings.maxRepeatSends;
|
||||
n++
|
||||
)
|
||||
DropdownMenuItem(value: n, child: Text('$n')),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
SwitchListTile(
|
||||
key: const ValueKey('messageFilter_repeatedCharactersSwitch'),
|
||||
|
||||
@@ -139,6 +139,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
String _selectedPathId = 'primary';
|
||||
final Set<String> _hiddenPathIds = {};
|
||||
bool _panelCollapsed = false;
|
||||
bool _panelExpanded = false;
|
||||
bool _animationEnabled = true;
|
||||
bool _followPacket = false;
|
||||
|
||||
@@ -444,6 +445,20 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
flags, // flag
|
||||
payload: tracePayload,
|
||||
);
|
||||
if (frame.length > maxFrameSize) {
|
||||
// Too many hops for one request (round trips double them); the radio
|
||||
// would reject or truncate it.
|
||||
appLogger.warn(
|
||||
'Path trace request too large: ${frame.length} bytes',
|
||||
tag: 'PathTraceMapScreen',
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_failed2Loaded = true;
|
||||
});
|
||||
return;
|
||||
}
|
||||
_awaitingTraceSent = true;
|
||||
_timeoutTimer?.cancel();
|
||||
// Fallback in case RESP_CODE_SENT / RESP_CODE_ERR never arrives; the
|
||||
@@ -1641,8 +1656,13 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
combined: combined,
|
||||
showInferredLegend: true,
|
||||
collapsed: _panelCollapsed,
|
||||
onToggleCollapsed: () =>
|
||||
setState(() => _panelCollapsed = !_panelCollapsed),
|
||||
onToggleCollapsed: () => setState(() {
|
||||
_panelCollapsed = !_panelCollapsed;
|
||||
// Reopening a collapsed panel returns to the normal height.
|
||||
if (_panelCollapsed) _panelExpanded = false;
|
||||
}),
|
||||
expanded: _panelExpanded,
|
||||
onToggleExpanded: () => setState(() => _panelExpanded = !_panelExpanded),
|
||||
playback: _playback,
|
||||
selected: selected,
|
||||
animationEnabled: _animationEnabled,
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:meshcore_open/l10n/l10n.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
import 'package:meshcore_open/storage/region_store.dart';
|
||||
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||
import 'package:meshcore_open/utils/radio_guard.dart';
|
||||
import 'package:meshcore_open/widgets/mesh_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -56,7 +57,7 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
_regionStore.setPublicKeyHex = connector.selfPublicKeyHex;
|
||||
_regionStore.setPublicKeyHex = connector.storageKeyHex;
|
||||
_loadRegions();
|
||||
}
|
||||
|
||||
@@ -72,6 +73,8 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
// Fetching asks repeaters over the mesh; offline it is unavailable.
|
||||
final canFetch = !_isFetchingRegions && !context.radioReadOnly;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(l10n.settings_regionManagement_screenTitle),
|
||||
@@ -91,7 +94,7 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.travel_explore),
|
||||
onPressed: _isFetchingRegions ? null : _showFetchRegionsDialog,
|
||||
onPressed: canFetch ? _showFetchRegionsDialog : null,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -123,6 +126,7 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
|
||||
Widget _buildEmptyState(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final canFetch = !_isFetchingRegions && !context.radioReadOnly;
|
||||
return Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
@@ -148,7 +152,7 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
FilledButton.icon(
|
||||
icon: const Icon(Icons.travel_explore),
|
||||
label: Text(l10n.settings_regionFetchFromRepeaters),
|
||||
onPressed: _isFetchingRegions ? null : _showFetchRegionsDialog,
|
||||
onPressed: canFetch ? _showFetchRegionsDialog : null,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
OutlinedButton.icon(
|
||||
@@ -294,13 +298,7 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
|
||||
if (!connector.isConnected) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_notConnectedError),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
final knownRepeaters = connector.contacts
|
||||
.where((contact) => contact.type == advTypeRepeater)
|
||||
.toList();
|
||||
|
||||
@@ -10,6 +10,7 @@ import '../connector/meshcore_protocol.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/confirm_clear_dialog.dart';
|
||||
import '../widgets/debug_frame_viewer.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/radio_disconnected_banner.dart';
|
||||
import '../services/repeater_command_service.dart';
|
||||
import '../widgets/routing_sheet.dart';
|
||||
@@ -435,34 +436,25 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
PopupMenuItem(
|
||||
value: 'copy',
|
||||
enabled: hasHistory,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.copy),
|
||||
const SizedBox(width: 8),
|
||||
Text(l10n.repeater_cliCopyTranscript),
|
||||
],
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.copy,
|
||||
label: l10n.repeater_cliCopyTranscript,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'share',
|
||||
enabled: hasHistory,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.share),
|
||||
const SizedBox(width: 8),
|
||||
Text(l10n.repeater_cliShareTranscript),
|
||||
],
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.share,
|
||||
label: l10n.repeater_cliShareTranscript,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'debug',
|
||||
enabled: connected,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.bug_report),
|
||||
const SizedBox(width: 8),
|
||||
Text(l10n.repeater_debugNextCommand),
|
||||
],
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.bug_report,
|
||||
label: l10n.repeater_debugNextCommand,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -13,6 +13,7 @@ import '../services/app_settings_service.dart';
|
||||
import '../services/repeater_command_service.dart';
|
||||
import '../services/storage_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/mesh_nav_tile.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../widgets/radio_disconnected_banner.dart';
|
||||
import '../widgets/routing_sheet.dart';
|
||||
@@ -895,83 +896,85 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
)
|
||||
: null,
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: _isLoading && _controller('name').text.isEmpty
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ListView(
|
||||
padding: const EdgeInsets.only(bottom: 32),
|
||||
children: [
|
||||
const RadioDisconnectedBanner(),
|
||||
// Keep this slot when the hint hides: shifting the cards
|
||||
// below would hand their state (e.g. an expanded
|
||||
// Advanced card) to the wrong card.
|
||||
if (_loadedKeys.isEmpty && !_loadingAll)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: MeshCard(
|
||||
// The button sits under the message so neither is
|
||||
// squeezed on narrow screens or large text.
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
context.l10n.repeater_settingsNotLoaded,
|
||||
body: MeshSettingsTileTheme(
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: _isLoading && _controller('name').text.isEmpty
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ListView(
|
||||
padding: const EdgeInsets.only(bottom: 32),
|
||||
children: [
|
||||
const RadioDisconnectedBanner(),
|
||||
// Keep this slot when the hint hides: shifting the cards
|
||||
// below would hand their state (e.g. an expanded
|
||||
// Advanced card) to the wrong card.
|
||||
if (_loadedKeys.isEmpty && !_loadingAll)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: MeshCard(
|
||||
// The button sits under the message so neither is
|
||||
// squeezed on narrow screens or large text.
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline, size: 20),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
context.l10n.repeater_settingsNotLoaded,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _isLoading || !connected
|
||||
? null
|
||||
: _refreshAll,
|
||||
child: Text(context.l10n.repeater_refreshAll),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _isLoading || !connected
|
||||
? null
|
||||
: _refreshAll,
|
||||
child: Text(context.l10n.repeater_refreshAll),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
const SizedBox.shrink(),
|
||||
_buildSectionCard(
|
||||
l10n.repeater_basicSettings,
|
||||
RepeaterSettingSection.basic,
|
||||
extra: _buildPasswordFields(),
|
||||
),
|
||||
_buildRadioSettingsCard(),
|
||||
_buildSectionCard(
|
||||
l10n.repeater_locationSettings,
|
||||
RepeaterSettingSection.location,
|
||||
),
|
||||
_buildSectionCard(
|
||||
l10n.repeater_features,
|
||||
RepeaterSettingSection.features,
|
||||
extra: [_buildClockSyncToggle()],
|
||||
),
|
||||
_buildSectionCard(
|
||||
l10n.repeater_networkHealth,
|
||||
RepeaterSettingSection.networkHealth,
|
||||
),
|
||||
_buildSectionCard(
|
||||
l10n.repeater_advertisementSettings,
|
||||
RepeaterSettingSection.advertisement,
|
||||
),
|
||||
_buildSectionCard(
|
||||
l10n.repeater_ownerInfo,
|
||||
RepeaterSettingSection.ownerInfo,
|
||||
),
|
||||
_buildActionsCard(),
|
||||
_buildAdvancedCard(),
|
||||
_buildKeysCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildDangerZoneCard(),
|
||||
],
|
||||
),
|
||||
)
|
||||
else
|
||||
const SizedBox.shrink(),
|
||||
_buildSectionCard(
|
||||
l10n.repeater_basicSettings,
|
||||
RepeaterSettingSection.basic,
|
||||
extra: _buildPasswordFields(),
|
||||
),
|
||||
_buildRadioSettingsCard(),
|
||||
_buildSectionCard(
|
||||
l10n.repeater_locationSettings,
|
||||
RepeaterSettingSection.location,
|
||||
),
|
||||
_buildSectionCard(
|
||||
l10n.repeater_features,
|
||||
RepeaterSettingSection.features,
|
||||
extra: [_buildClockSyncToggle()],
|
||||
),
|
||||
_buildSectionCard(
|
||||
l10n.repeater_networkHealth,
|
||||
RepeaterSettingSection.networkHealth,
|
||||
),
|
||||
_buildSectionCard(
|
||||
l10n.repeater_advertisementSettings,
|
||||
RepeaterSettingSection.advertisement,
|
||||
),
|
||||
_buildSectionCard(
|
||||
l10n.repeater_ownerInfo,
|
||||
RepeaterSettingSection.ownerInfo,
|
||||
),
|
||||
_buildActionsCard(),
|
||||
_buildAdvancedCard(),
|
||||
_buildKeysCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildDangerZoneCard(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -1115,22 +1118,36 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Dims a control whose remote value has not been fetched (or set) yet,
|
||||
/// so a placeholder position is not mistaken for the repeater's value.
|
||||
/// The control stays usable: setting it makes the value known.
|
||||
Widget _dimIfUnknown(String key, Widget child) {
|
||||
return AnimatedOpacity(
|
||||
opacity: _known(key) ? 1 : 0.6,
|
||||
duration: const Duration(milliseconds: 150),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildToggleControl(RepeaterSettingSpec spec) {
|
||||
final l10n = context.l10n;
|
||||
final helper = spec.helper?.call(l10n);
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SwitchListTile(
|
||||
title: Text(spec.label(l10n)),
|
||||
subtitle: helper == null ? null : Text(helper),
|
||||
// An unknown setting shows as off until fetched or set.
|
||||
value: _known(spec.key) && _values[spec.key] == true,
|
||||
onChanged: (value) {
|
||||
setState(() => _values[spec.key] = value);
|
||||
_markChanged(spec.key);
|
||||
},
|
||||
contentPadding: EdgeInsets.zero,
|
||||
child: _dimIfUnknown(
|
||||
spec.key,
|
||||
SwitchListTile(
|
||||
title: Text(spec.label(l10n)),
|
||||
subtitle: helper == null ? null : Text(helper),
|
||||
// An unknown setting shows as off until fetched or set.
|
||||
value: _known(spec.key) && _values[spec.key] == true,
|
||||
onChanged: (value) {
|
||||
setState(() => _values[spec.key] = value);
|
||||
_markChanged(spec.key);
|
||||
},
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildSpecRefreshButton(spec),
|
||||
@@ -1191,29 +1208,32 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: title),
|
||||
Expanded(child: _dimIfUnknown(key, title)),
|
||||
_buildSpecRefreshButton(spec),
|
||||
],
|
||||
),
|
||||
Slider(
|
||||
value: (value ?? lo).clamp(lo, hi).toDouble(),
|
||||
min: lo.toDouble(),
|
||||
max: hi.toDouble(),
|
||||
divisions: divisions,
|
||||
label: value == null ? null : display,
|
||||
onChanged: canDisable && (value == null || isOff)
|
||||
? null
|
||||
: (v) {
|
||||
// Snap to the step, counting from the low end.
|
||||
final snapped =
|
||||
lo + ((v - lo) / spec.step).floor() * spec.step;
|
||||
setState(
|
||||
() => _values[key] = spec.isInteger
|
||||
? snapped.round()
|
||||
: snapped,
|
||||
);
|
||||
_markChanged(key);
|
||||
},
|
||||
_dimIfUnknown(
|
||||
key,
|
||||
Slider(
|
||||
value: (value ?? lo).clamp(lo, hi).toDouble(),
|
||||
min: lo.toDouble(),
|
||||
max: hi.toDouble(),
|
||||
divisions: divisions,
|
||||
label: value == null ? null : display,
|
||||
onChanged: canDisable && (value == null || isOff)
|
||||
? null
|
||||
: (v) {
|
||||
// Snap to the step, counting from the low end.
|
||||
final snapped =
|
||||
lo + ((v - lo) / spec.step).floor() * spec.step;
|
||||
setState(
|
||||
() => _values[key] = spec.isInteger
|
||||
? snapped.round()
|
||||
: snapped,
|
||||
);
|
||||
_markChanged(key);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -16,7 +16,7 @@ import '../widgets/empty_state.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../review_mode/review_mode_entry.dart';
|
||||
import 'channels_screen.dart';
|
||||
import '../utils/main_navigation.dart';
|
||||
import 'tcp_screen.dart';
|
||||
import 'usb_screen.dart';
|
||||
|
||||
@@ -55,9 +55,7 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||
isCurrentRoute &&
|
||||
!_changedNavigation) {
|
||||
_changedNavigation = true;
|
||||
Navigator.of(
|
||||
context,
|
||||
).push(MaterialPageRoute(builder: (context) => const ChannelsScreen()));
|
||||
navigateToMainAfterConnect(context);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -85,7 +83,14 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||
void dispose() {
|
||||
_connector.removeListener(_connectionListener);
|
||||
unawaited(_bluetoothStateSubscription.cancel());
|
||||
if (!_changedNavigation) {
|
||||
// Only cancel a Bluetooth connection this screen started; a pending
|
||||
// auto-reconnect (state disconnected) or a USB/TCP/review link is left
|
||||
// alone, so peeking at the scanner from the main screens is harmless.
|
||||
final state = _connector.state;
|
||||
if (!_changedNavigation &&
|
||||
_connector.activeTransport == MeshCoreTransportType.bluetooth &&
|
||||
(state == MeshCoreConnectionState.connecting ||
|
||||
state == MeshCoreConnectionState.connected)) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
unawaited(_connector.disconnect(manual: true));
|
||||
});
|
||||
@@ -247,16 +252,6 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||
subtitle: isBluetoothOff
|
||||
? context.l10n.scanner_bluetoothOffMessage
|
||||
: null,
|
||||
action: (isBluetoothOff || isScanning)
|
||||
? null
|
||||
: FilledButton.icon(
|
||||
onPressed: () {
|
||||
HapticFeedback.lightImpact();
|
||||
_toggleScan(connector);
|
||||
},
|
||||
icon: const Icon(Icons.bluetooth_searching),
|
||||
label: Text(context.l10n.scanner_scan),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:meshcore_open/utils/gpx_export.dart';
|
||||
import 'package:meshcore_open/widgets/elements_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
@@ -24,7 +23,9 @@ import '../widgets/radio_stats_entry.dart';
|
||||
import 'telemetry_screen.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
import 'region_management_screen.dart';
|
||||
import '../utils/share_origin.dart';
|
||||
import 'backup_restore_screen.dart';
|
||||
import 'export_screen.dart';
|
||||
import '../utils/radio_guard.dart';
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
const SettingsScreen({super.key});
|
||||
@@ -164,13 +165,34 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
),
|
||||
),
|
||||
|
||||
// EXPORT section
|
||||
SectionHeader(l10n.settings_gpxExportRepeaters),
|
||||
// BACKUP AND EXPORT
|
||||
SectionHeader(l10n.settings_export),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _buildExportCardContent(
|
||||
context,
|
||||
context.read<MeshCoreConnector>(),
|
||||
child: Column(
|
||||
children: [
|
||||
MeshNavTile(
|
||||
icon: Icons.backup_outlined,
|
||||
title: l10n.backupRestore_title,
|
||||
subtitle: l10n.backupRestore_subtitle,
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const BackupRestoreScreen(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
icon: Icons.download_outlined,
|
||||
title: l10n.settings_export,
|
||||
subtitle: l10n.settings_exportSubtitle,
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const ExportScreen()),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -217,14 +239,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
/// Guards a radio command: returns false (after telling the user) when the
|
||||
/// radio is not connected, because the connector silently ignores commands
|
||||
/// sent while disconnected and a success message would be a lie.
|
||||
bool _ensureConnected(BuildContext context, MeshCoreConnector connector) {
|
||||
if (connector.isConnected) return true;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.settings_notConnectedError),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
bool _ensureConnected(BuildContext context, MeshCoreConnector connector) =>
|
||||
ensureRadioConnected(context);
|
||||
|
||||
Widget _buildIdentityCardContent(
|
||||
BuildContext context,
|
||||
@@ -576,33 +592,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
? () => pushSelfTelemetryScreen(context)
|
||||
: null,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
icon: Icons.route_outlined,
|
||||
title: l10n.repeater_pathHashMode,
|
||||
subtitle: !connected
|
||||
? offline
|
||||
: !connector.supportsPathHashMode
|
||||
? l10n.settings_requiresFirmware('v1.14')
|
||||
: _pathHashModeSubtitle(context, connector.pathHashByteWidth),
|
||||
onTap: connector.isConnected && connector.supportsPathHashMode
|
||||
? () => _editPathHashMode(context, connector)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _pathHashModeSubtitle(BuildContext context, int pathHashByteWidth) {
|
||||
final l10n = context.l10n;
|
||||
return switch (pathHashByteWidth.clamp(1, 4).toInt()) {
|
||||
1 => l10n.repeater_pathHashModeOption0,
|
||||
2 => l10n.repeater_pathHashModeOption1,
|
||||
3 => l10n.repeater_pathHashModeOption2,
|
||||
_ => l10n.repeater_pathHashModeOption3,
|
||||
};
|
||||
}
|
||||
|
||||
Widget _buildLocationCardContent(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
@@ -682,70 +675,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildExportCardContent(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
) {
|
||||
final l10n = context.l10n;
|
||||
return Column(
|
||||
children: [
|
||||
MeshNavTile(
|
||||
icon: Icons.download_outlined,
|
||||
title: l10n.settings_gpxExportRepeaters,
|
||||
subtitle: l10n.settings_gpxExportRepeatersSubtitle,
|
||||
onTap: () async {
|
||||
final exporter = GpxExport(connector);
|
||||
exporter.addRepeaters();
|
||||
_gpxExport(
|
||||
exporter,
|
||||
l10n.map_repeater,
|
||||
l10n.settings_gpxExportRepeatersRoom,
|
||||
'meshcore_repeaters_',
|
||||
l10n.settings_gpxExportShareText,
|
||||
l10n.settings_gpxExportShareSubject,
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
icon: Icons.download_outlined,
|
||||
title: l10n.settings_gpxExportContacts,
|
||||
subtitle: l10n.settings_gpxExportContactsSubtitle,
|
||||
onTap: () async {
|
||||
final exporter = GpxExport(connector);
|
||||
exporter.addContacts();
|
||||
_gpxExport(
|
||||
exporter,
|
||||
l10n.map_repeater,
|
||||
l10n.settings_gpxExportChat,
|
||||
'meshcore_contacts_',
|
||||
l10n.settings_gpxExportShareText,
|
||||
l10n.settings_gpxExportShareSubject,
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
MeshNavTile(
|
||||
icon: Icons.download_outlined,
|
||||
title: l10n.settings_gpxExportAll,
|
||||
subtitle: l10n.settings_gpxExportAllSubtitle,
|
||||
onTap: () async {
|
||||
final exporter = GpxExport(connector);
|
||||
exporter.addAll();
|
||||
_gpxExport(
|
||||
exporter,
|
||||
l10n.map_repeater,
|
||||
l10n.settings_gpxExportAllContacts,
|
||||
'meshcore_all_',
|
||||
l10n.settings_gpxExportShareText,
|
||||
l10n.settings_gpxExportShareSubject,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDebugCardContent(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
return Column(
|
||||
@@ -816,95 +745,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _editPathHashMode(BuildContext context, MeshCoreConnector connector) {
|
||||
final l10n = context.l10n;
|
||||
var selectedMode = (connector.pathHashByteWidth - 1).clamp(0, 2).toInt();
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (builderContext, setDialogState) => AlertDialog(
|
||||
scrollable: true,
|
||||
title: Text(l10n.repeater_pathHashMode),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
DropdownButtonFormField<int>(
|
||||
isExpanded: true,
|
||||
initialValue: selectedMode,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_pathHashMode,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
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;
|
||||
setDialogState(() => selectedMode = value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
l10n.settings_pathHashModeHelper,
|
||||
style: Theme.of(builderContext).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(dialogContext);
|
||||
if (!_ensureConnected(context, connector)) return;
|
||||
try {
|
||||
await connector.setPathHashMode(selectedMode);
|
||||
await connector.refreshDeviceInfo();
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.repeater_settingsSaved),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_error(e.toString())),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Text(l10n.common_save),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _editLocation(
|
||||
BuildContext context,
|
||||
MeshCoreConnector connector,
|
||||
@@ -1066,51 +906,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _gpxExport(
|
||||
GpxExport exporter,
|
||||
String name,
|
||||
String description,
|
||||
String filename,
|
||||
String shareText,
|
||||
String subject,
|
||||
) async {
|
||||
final l10n = context.l10n;
|
||||
final result = await exporter.exportGPX(
|
||||
name,
|
||||
description,
|
||||
filename,
|
||||
shareText,
|
||||
subject,
|
||||
sharePositionOrigin: shareOriginOf(context),
|
||||
);
|
||||
if (!mounted) return;
|
||||
switch (result) {
|
||||
case gpxExportSuccess:
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_gpxExportSuccess),
|
||||
);
|
||||
case gpxExportNoContacts:
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_gpxExportNoContacts),
|
||||
);
|
||||
break;
|
||||
case gpxExportNotAvailable:
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_gpxExportNotAvailable),
|
||||
);
|
||||
break;
|
||||
case gpxExportFailed:
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_gpxExportError),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _editAutoAddConfig(BuildContext context, MeshCoreConnector connector) {
|
||||
final l10n = context.l10n;
|
||||
// The dialog's context is gone once it pops; report through the screen.
|
||||
@@ -1348,14 +1143,13 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SwitchListTile(
|
||||
title: Text(l10n.settings_multiAck),
|
||||
subtitle: Text(l10n.settings_multiAckSubtitle),
|
||||
FeatureToggleRow(
|
||||
title: l10n.settings_multiAck,
|
||||
subtitle: l10n.settings_multiAckSubtitle,
|
||||
value: multiAcks == 1,
|
||||
onChanged: (value) {
|
||||
setDialogState(() => multiAcks = value ? 1 : 0);
|
||||
},
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<int>(
|
||||
|
||||
@@ -12,7 +12,7 @@ import '../utils/platform_info.dart';
|
||||
import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import 'channels_screen.dart';
|
||||
import '../utils/main_navigation.dart';
|
||||
import 'usb_screen.dart';
|
||||
|
||||
class TcpScreen extends StatefulWidget {
|
||||
@@ -63,9 +63,7 @@ class _TcpScreenState extends State<TcpScreen> {
|
||||
int.tryParse(_portController.text) ?? 0,
|
||||
);
|
||||
_navigatedToChannels = true;
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(builder: (_) => const ChannelsScreen()),
|
||||
);
|
||||
navigateToMainAfterConnect(context);
|
||||
}
|
||||
};
|
||||
_connector.addListener(_connectionListener);
|
||||
|
||||
@@ -38,22 +38,25 @@ class ThemesScreen extends StatelessWidget {
|
||||
itemBuilder: (_) => [
|
||||
PopupMenuItem(
|
||||
onTap: () => _importFile(context, settingsService),
|
||||
child: _MenuRow(
|
||||
Icons.file_open_outlined,
|
||||
l10n.themes_importFile,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.file_open_outlined,
|
||||
label: l10n.themes_importFile,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () => _showImportDialog(context, settingsService),
|
||||
child: _MenuRow(
|
||||
Icons.content_paste_go_outlined,
|
||||
l10n.themes_pasteCode,
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.content_paste_go_outlined,
|
||||
label: l10n.themes_pasteCode,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
enabled: myThemes.isNotEmpty,
|
||||
onTap: () => _exportFile(context, myThemes, 'meshcore-themes'),
|
||||
child: _MenuRow(Icons.ios_share, l10n.themes_exportAll),
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.ios_share,
|
||||
label: l10n.themes_exportAll,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -164,11 +167,17 @@ class ThemesScreen extends StatelessWidget {
|
||||
startFrom: preset,
|
||||
copyName: l10n.themes_copyName(preset.name),
|
||||
),
|
||||
child: _MenuRow(Icons.tune, l10n.themes_customize),
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.tune,
|
||||
label: l10n.themes_customize,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () => _copyCode(context, preset),
|
||||
child: _MenuRow(Icons.copy, l10n.themes_copyCode),
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.copy,
|
||||
label: l10n.themes_copyCode,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -186,19 +195,28 @@ class ThemesScreen extends StatelessWidget {
|
||||
itemBuilder: (_) => [
|
||||
PopupMenuItem(
|
||||
onTap: () => _openEditor(context, existing: theme),
|
||||
child: _MenuRow(Icons.edit_outlined, l10n.common_edit),
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.edit_outlined,
|
||||
label: l10n.common_edit,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () => _copyCode(context, theme),
|
||||
child: _MenuRow(Icons.copy, l10n.themes_copyCode),
|
||||
child: MeshMenuItemRow(icon: Icons.copy, label: l10n.themes_copyCode),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () => _exportFile(context, [theme], themeFileStem(theme.name)),
|
||||
child: _MenuRow(Icons.ios_share, l10n.themes_exportFile),
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.ios_share,
|
||||
label: l10n.themes_exportFile,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () => _confirmDelete(context, settingsService, theme),
|
||||
child: _MenuRow(Icons.delete_outline, l10n.common_delete),
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.delete_outline,
|
||||
label: l10n.common_delete,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -422,24 +440,6 @@ class _AutoHolidayNote extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _MenuRow extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
|
||||
const _MenuRow(this.icon, this.label);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, size: 22),
|
||||
const SizedBox(width: 12),
|
||||
Flexible(child: Text(label)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ThemeTile extends StatelessWidget {
|
||||
final String name;
|
||||
final String? subtitle;
|
||||
|
||||
@@ -14,7 +14,7 @@ import '../widgets/adaptive_app_bar_title.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import 'channels_screen.dart';
|
||||
import '../utils/main_navigation.dart';
|
||||
import 'tcp_screen.dart';
|
||||
|
||||
class UsbScreen extends StatefulWidget {
|
||||
@@ -56,9 +56,7 @@ class _UsbScreenState extends State<UsbScreen> with WidgetsBindingObserver {
|
||||
_connector.isUsbTransportConnected &&
|
||||
!_navigatedToChannels) {
|
||||
_navigatedToChannels = true;
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(builder: (_) => const ChannelsScreen()),
|
||||
);
|
||||
navigateToMainAfterConnect(context);
|
||||
}
|
||||
};
|
||||
_connector.addListener(_connectionListener);
|
||||
|
||||
Reference in new issue
Block a user