Offline (read-only) mode - The last connected radio is remembered; with no radio the app opens on its saved contacts, channels, messages and unread counts. - Main screens stay open on disconnect. A Connect button replaces the battery and signal indicators, with a sheet to reconnect, choose a radio or stop a pending reconnect. - While disconnected everything is read-only: the composer becomes a "connect to send" bar (drafts kept) and controls that change the radio or stored history are disabled or hidden. - Resending while disconnected no longer deletes the message; a different radio no longer shows the previous radio's channels. - Notification taps open the saved chat while offline. Chats and menus - Channel chat menu: notifications, edit channel, delete channel; the filter row lines up with the others; bell moved out of the app bar. - DM and room menus: remove from contacts; rooms get room management. - Search field uses the full app bar; long-press a result to copy. - Hashtag channel titles no longer read "# #name"; more room around the radio activity dot. - Repeat filter: short messages from one sender are caught at the same count as long ones. Layout - Shared menu row (wraps to two lines) and segment label (never splits a word) used across the app. - One Scan button on the scanner; consistent settings tile titles; contact "last seen" wraps instead of truncating; unfetched repeater settings are dimmed. Localization - New European Portuguese locale (pt_PT); regional locales are handled by the language picker, notifications and the background service. - Fill 67 missing strings per locale, including backup and restore. - Keep "Flood" and "Zero Hop" untranslated, shorten "last seen" and routing labels, and fix mistranslated scan, theme and hop strings. - Received-image strings, badge and caption come from translations. - Regenerate the Czech localizations, which were missing strings. Docs - Add documentation/design.md (UI reference) and offline-mode.md; update channel, chat, navigation and scanner docs.
167 lines
5.5 KiB
Dart
167 lines
5.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../connector/meshcore_connector.dart';
|
|
import '../helpers/snack_bar_builder.dart';
|
|
import '../l10n/l10n.dart';
|
|
import '../screens/scanner_screen.dart';
|
|
import '../screens/usb_screen.dart';
|
|
import '../storage/last_radio_store.dart';
|
|
import '../utils/dialog_utils.dart';
|
|
import '../utils/platform_info.dart';
|
|
import 'mesh_ui.dart';
|
|
|
|
/// Ways to get a radio connected: reconnect to the last one, pick another,
|
|
/// or stop a pending automatic reconnect.
|
|
Future<void> showConnectSheet(BuildContext context) {
|
|
return showMeshSheet<void>(
|
|
context,
|
|
builder: (sheetContext) => _ConnectSheet(hostContext: context),
|
|
);
|
|
}
|
|
|
|
class _ConnectSheet extends StatelessWidget {
|
|
/// Context of the screen that opened the sheet; it outlives the sheet.
|
|
final BuildContext hostContext;
|
|
|
|
const _ConnectSheet({required this.hostContext});
|
|
|
|
Future<void> _reconnect(BuildContext context, String name) async {
|
|
final connector = context.read<MeshCoreConnector>();
|
|
Navigator.of(context).pop();
|
|
final connected = await connector.reconnectToLastRadio();
|
|
if (connected || !hostContext.mounted) return;
|
|
showDismissibleSnackBar(
|
|
hostContext,
|
|
content: Text(hostContext.l10n.connectSheet_reconnectFailed(name)),
|
|
);
|
|
}
|
|
|
|
void _chooseRadio(BuildContext context, LastRadio? lastRadio) {
|
|
Navigator.of(context).pop();
|
|
if (!hostContext.mounted) return;
|
|
final usb =
|
|
PlatformInfo.isWeb ||
|
|
(lastRadio?.transport == LastRadio.transportUsb &&
|
|
PlatformInfo.supportsUsbSerial);
|
|
Navigator.of(hostContext).push(
|
|
MaterialPageRoute(
|
|
builder: (_) => usb ? const UsbScreen() : const ScannerScreen(),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = context.l10n;
|
|
final textTheme = Theme.of(context).textTheme;
|
|
final connector = context.watch<MeshCoreConnector>();
|
|
final lastRadio = connector.lastRadio;
|
|
final name = connector.lastRadioName ?? '';
|
|
final connecting = connector.state == MeshCoreConnectionState.connecting;
|
|
final canReconnect =
|
|
!PlatformInfo.isWeb &&
|
|
lastRadio != null &&
|
|
name.isNotEmpty &&
|
|
(lastRadio.canReconnectBle || lastRadio.canReconnectTcp);
|
|
final titleStyle = textTheme.titleMedium;
|
|
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
BottomSheetHeader(title: l10n.connectSheet_title),
|
|
if (canReconnect)
|
|
ListTile(
|
|
minTileHeight: 64,
|
|
leading: connecting
|
|
? const SizedBox.square(
|
|
dimension: 28,
|
|
child: CircularProgressIndicator(strokeWidth: 3),
|
|
)
|
|
: Icon(
|
|
lastRadio.canReconnectTcp ? Icons.lan : Icons.bluetooth,
|
|
size: 28,
|
|
),
|
|
title: Text(l10n.connectSheet_reconnect(name), style: titleStyle),
|
|
enabled: !connecting,
|
|
onTap: () => _reconnect(context, name),
|
|
),
|
|
ListTile(
|
|
minTileHeight: 64,
|
|
leading: const Icon(Icons.radio, size: 28),
|
|
title: Text(l10n.connectSheet_chooseRadio, style: titleStyle),
|
|
subtitle: Text(l10n.connectSheet_chooseRadioSubtitle),
|
|
onTap: () => _chooseRadio(context, lastRadio),
|
|
),
|
|
if (connector.isAutoReconnectScheduled)
|
|
ListTile(
|
|
minTileHeight: 64,
|
|
leading: const Icon(Icons.sync_disabled, size: 28),
|
|
title: Text(l10n.connectSheet_stopReconnecting, style: titleStyle),
|
|
onTap: () {
|
|
connector.cancelAutoReconnect();
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
const SizedBox(height: 12),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Compact Connect button for app bars and read-only bars.
|
|
class ConnectButton extends StatelessWidget {
|
|
/// Icon only, for narrow app bars.
|
|
final bool iconOnly;
|
|
|
|
const ConnectButton({super.key, this.iconOnly = false});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final label = context.l10n.common_connect;
|
|
if (iconOnly) {
|
|
return IconButton(
|
|
icon: const Icon(Icons.link),
|
|
tooltip: label,
|
|
onPressed: () => showConnectSheet(context),
|
|
);
|
|
}
|
|
return FilledButton.tonalIcon(
|
|
style: FilledButton.styleFrom(
|
|
minimumSize: const Size(48, 48),
|
|
padding: const EdgeInsets.symmetric(horizontal: 14),
|
|
visualDensity: VisualDensity.standard,
|
|
),
|
|
icon: const Icon(Icons.link, size: 20),
|
|
label: Text(label),
|
|
onPressed: () => showConnectSheet(context),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Overflow-menu entry of the main screens: Disconnect (after confirming,
|
|
/// staying on the screen offline) while connected, Connect otherwise.
|
|
/// [screenContext] must outlive the menu, as onTap runs after it closes.
|
|
PopupMenuItem<T> connectionMenuItem<T>(
|
|
BuildContext screenContext,
|
|
BuildContext menuContext,
|
|
) {
|
|
final connector = screenContext.read<MeshCoreConnector>();
|
|
final l10n = menuContext.l10n;
|
|
if (connector.isConnected) {
|
|
return PopupMenuItem<T>(
|
|
child: MeshMenuItemRow(
|
|
icon: Icons.logout,
|
|
iconColor: Theme.of(menuContext).colorScheme.error,
|
|
label: l10n.common_disconnect,
|
|
),
|
|
onTap: () => showDisconnectDialog(screenContext, connector),
|
|
);
|
|
}
|
|
return PopupMenuItem<T>(
|
|
child: MeshMenuItemRow(icon: Icons.link, label: l10n.common_connect),
|
|
onTap: () => showConnectSheet(screenContext),
|
|
);
|
|
}
|