Merge pull request #705 from zjs81/feat/compression-menu-page

Move chat compression to the menu with its own page
This commit is contained in:
zjs81 authored and GitHub committed 2026-11-23 20:33:06 -07:00
commit 6748d5f0f2
33 files changed
+798 -846

No files matched your search

+41 -17
View File
@@ -54,7 +54,6 @@ import '../widgets/empty_state.dart';
import '../widgets/filter_rule_dialog.dart';
import '../widgets/filtered_message_ghost.dart';
import '../widgets/chat_composer.dart';
import '../widgets/chat_compression_selector.dart';
import '../widgets/chat_send_pipeline.dart';
import '../widgets/chat_zoom_wrapper.dart';
import '../widgets/message_bubble_frame.dart';
@@ -76,6 +75,7 @@ import '../widgets/share_contact_sheet.dart';
import '../widgets/shared_contact_card.dart';
import 'app_settings_screen.dart';
import 'channel_chat_transcript_grouping.dart';
import 'chat_compression_screen.dart';
import 'channels_screen.dart' show confirmDeleteChannel, showEditChannelSheet;
import 'channel_message_path_screen.dart';
import 'map_screen.dart';
@@ -599,6 +599,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
_toggleChannelFiltering();
case 'notifications':
showChannelNotificationModeSheet(context, muteKey);
case 'compression':
_openCompressionScreen();
case 'region':
openRegionSelectDialog(widget.channel);
case 'editChannel':
@@ -656,6 +658,20 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
),
),
),
PopupMenuItem(
value: 'compression',
child: _menuRow(
Icons.compress,
context.l10n.chatCompression_label(
chatCompressionModeLabel(
context,
context.read<MeshCoreConnector>().channelCompressionMode(
widget.channel.index,
),
),
),
),
),
PopupMenuItem(
value: 'region',
child: _menuRow(
@@ -880,7 +896,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
bottom: false,
child: Column(
children: [
_buildCompressionSelector(),
Expanded(
child: ChatBackdrop(
contentKey: _messageAreaKey,
@@ -2804,26 +2819,35 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
/// Compression is stored on this phone under the channel's storage ID, so
/// it can change while the radio is offline, but not before the slot has
/// one.
Widget _buildCompressionSelector() {
void _openCompressionScreen() {
final slot = widget.channel.index;
return Consumer2<MeshCoreConnector, AppSettingsService>(
builder: (context, connector, settingsService, _) {
final hasStorageId = connector.channelIdForSlot(slot) != null;
return ChatCompressionSelector(
mode: connector.channelCompressionMode(slot),
enabled: hasStorageId,
disabledReason: hasStorageId
? null
: context.l10n.chatCompression_noStorageId,
profiles: settingsService.settings.cyr2latProfiles,
profileId: connector.getChannelCyr2LatProfileId(slot),
defaultProfileId: settingsService.settings.selectedCyr2latProfileId,
final connector = context.read<MeshCoreConnector>();
final settingsService = context.read<AppSettingsService>();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChatCompressionScreen(
listenable: Listenable.merge([connector, settingsService]),
read: () {
final hasStorageId = connector.channelIdForSlot(slot) != null;
return ChatCompressionState(
mode: connector.channelCompressionMode(slot),
enabled: hasStorageId,
disabledReason: hasStorageId
? null
: context.l10n.chatCompression_noStorageId,
profiles: settingsService.settings.cyr2latProfiles,
profileId: connector.getChannelCyr2LatProfileId(slot),
defaultProfileId:
settingsService.settings.selectedCyr2latProfileId,
);
},
onModeChanged: (mode) =>
connector.setChannelCompressionMode(slot, mode),
onProfileChanged: (id) =>
connector.setChannelCyr2LatProfileId(slot, id),
);
},
),
),
);
}
+236
View File
@@ -0,0 +1,236 @@
import 'package:flutter/material.dart';
import '../l10n/l10n.dart';
import '../models/app_settings.dart';
import '../models/chat_compression_mode.dart';
import '../widgets/adaptive_app_bar_title.dart';
import '../widgets/mesh_nav_tile.dart';
import '../widgets/mesh_ui.dart';
export '../models/chat_compression_mode.dart';
String chatCompressionModeLabel(BuildContext context, ChatCompressionMode m) {
final l10n = context.l10n;
return switch (m) {
ChatCompressionMode.off => l10n.chatCompression_off,
ChatCompressionMode.smaz => l10n.chatCompression_smaz,
ChatCompressionMode.cyr2lat => l10n.chatCompression_cyr2lat,
};
}
/// What the page shows for one chat, read fresh each time [listenable] fires.
class ChatCompressionState {
final ChatCompressionMode mode;
/// False locks the choices; [disabledReason] says why.
final bool enabled;
final String? disabledReason;
final List<Cyr2LatProfile> profiles;
/// The Cyr2Lat profile saved for this chat, if any.
final String? profileId;
/// The app-wide profile, which sending uses when [profileId] is unset or
/// no longer exists.
final String? defaultProfileId;
const ChatCompressionState({
required this.mode,
required this.enabled,
this.disabledReason,
required this.profiles,
required this.profileId,
this.defaultProfileId,
});
/// The profile sending actually uses, matching the connector's fallback.
String? get effectiveProfileId {
bool known(String? id) => profiles.any((p) => p.id == id);
if (known(profileId)) return profileId;
if (known(defaultProfileId)) return defaultProfileId;
return profiles.isEmpty ? null : profiles.first.id;
}
}
/// The page behind the chat menu's "Compression: ..." item. Shows the three
/// choices with a short note each, plus the Cyr2Lat profile picker.
///
/// The caller supplies the saved state through [read] (re-read whenever
/// [listenable] notifies) and persists changes through the callbacks. A new
/// choice shows only once the saved state changes; a callback that throws
/// leaves the saved choice in place and shows an error.
class ChatCompressionScreen extends StatefulWidget {
final Listenable listenable;
final ChatCompressionState Function() read;
final Future<void> Function(ChatCompressionMode mode) onModeChanged;
final Future<void> Function(String profileId) onProfileChanged;
const ChatCompressionScreen({
super.key,
required this.listenable,
required this.read,
required this.onModeChanged,
required this.onProfileChanged,
});
@override
State<ChatCompressionScreen> createState() => _ChatCompressionScreenState();
}
class _ChatCompressionScreenState extends State<ChatCompressionScreen> {
bool _busy = false;
bool _failed = false;
/// Counts failed saves, so the profile picker drops an unsaved choice.
int _failures = 0;
/// Runs one save; a failure keeps the saved state and shows an error.
Future<void> _save(Future<void> Function() write) async {
if (_busy || !widget.read().enabled) return;
setState(() {
_busy = true;
_failed = false;
});
var ok = false;
try {
await write();
ok = true;
} catch (e) {
debugPrint('[ChatCompressionScreen] save failed: $e');
}
if (!mounted) return;
setState(() {
_busy = false;
_failed = !ok;
if (!ok) _failures++;
});
}
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
return Scaffold(
appBar: AppBar(
title: AdaptiveAppBarTitle(l10n.chatCompression_title),
centerTitle: true,
actions: [
if (_busy)
const Padding(
padding: EdgeInsets.all(14),
child: SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
),
),
],
),
body: SafeArea(
top: false,
child: ListenableBuilder(
listenable: widget.listenable,
builder: (context, _) => _buildBody(context, widget.read()),
),
),
);
}
Widget _buildBody(BuildContext context, ChatCompressionState view) {
final l10n = context.l10n;
final scheme = Theme.of(context).colorScheme;
final canChange = view.enabled && !_busy;
Widget option(ChatCompressionMode mode, String description) {
return MeshSheetOption(
label: chatCompressionModeLabel(context, mode),
subtitle: description,
selected: view.mode == mode,
onTap: canChange ? () => _save(() => widget.onModeChanged(mode)) : null,
);
}
final profileValue = view.effectiveProfileId;
return ListView(
padding: const EdgeInsets.only(bottom: 24),
children: [
if (_failed)
MeshCard(
color: scheme.errorContainer,
borderColor: scheme.errorContainer,
child: Row(
children: [
Icon(Icons.error_outline, color: scheme.onErrorContainer),
const SizedBox(width: 12),
Expanded(
child: Text(
l10n.chatCompression_saveFailed,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: scheme.onErrorContainer,
),
),
),
],
),
),
if (!view.enabled && view.disabledReason != null)
MeshInfoCard(view.disabledReason!),
SectionHeader(
l10n.chatCompression_title,
description: l10n.chatCompression_sheetSubtitle,
),
MeshCard(
padding: EdgeInsets.zero,
child: Column(
children: [
option(
ChatCompressionMode.off,
l10n.chatCompression_offDescription,
),
const Divider(height: 1, indent: 16),
option(
ChatCompressionMode.smaz,
l10n.chatCompression_smazDescription,
),
const Divider(height: 1, indent: 16),
option(
ChatCompressionMode.cyr2lat,
l10n.chatCompression_cyr2latDescription,
),
],
),
),
if (view.mode == ChatCompressionMode.cyr2lat &&
view.profiles.isNotEmpty) ...[
SectionHeader(l10n.chatCompression_profile),
MeshCard(
child: DropdownButtonFormField<String>(
// The field keeps a picked value internally, so rebuild it
// with the saved value after a change or a failure.
key: ValueKey('$profileValue#$_failures'),
isExpanded: true,
initialValue: profileValue,
decoration: InputDecoration(
labelText: l10n.chatCompression_profile,
),
items: [
for (final profile in view.profiles)
DropdownMenuItem(
value: profile.id,
child: Text(profile.name, overflow: TextOverflow.ellipsis),
),
],
onChanged: canChange
? (id) {
if (id == null || id == profileValue) return;
_save(() => widget.onProfileChanged(id));
}
: null,
),
),
],
],
);
}
}
+34 -13
View File
@@ -38,13 +38,13 @@ import '../services/chat_text_scale_service.dart';
import '../services/path_history_service.dart';
import '../services/translation_service.dart';
import '../widgets/chat_composer.dart';
import '../widgets/chat_compression_selector.dart';
import '../widgets/chat_send_pipeline.dart';
import '../widgets/chat_zoom_wrapper.dart';
import '../widgets/message_bubble_frame.dart';
import '../widgets/reaction_chips.dart';
import '../widgets/chat_day_separator.dart';
import 'channel_message_path_screen.dart';
import 'chat_compression_screen.dart';
import 'contacts_screen.dart' show confirmRemoveContact;
import 'map_screen.dart';
import 'repeater_hub_screen.dart';
@@ -510,6 +510,8 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
ContactRoutingSheet.show(context, contact: contact);
case 'info':
_showContactInfo(context);
case 'compression':
_openCompressionScreen();
case 'settings':
_showContactSettings(context);
case 'showBookmarks':
@@ -576,6 +578,20 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
label: context.l10n.room_management,
),
),
PopupMenuItem(
value: 'compression',
child: MeshMenuItemRow(
icon: Icons.compress,
label: context.l10n.chatCompression_label(
chatCompressionModeLabel(
context,
connector.contactCompressionMode(
widget.contact.publicKeyHex,
),
),
),
),
),
PopupMenuItem(
value: 'settings',
child: MeshMenuItemRow(
@@ -648,7 +664,6 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
);
return Column(
children: [
_buildCompressionSelector(connector),
Expanded(
child: ChatBackdrop(
contentKey: _messageAreaKey,
@@ -677,22 +692,28 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
/// Compression is stored on this phone per contact, so it can change
/// while the radio is offline.
Widget _buildCompressionSelector(MeshCoreConnector connector) {
void _openCompressionScreen() {
final keyHex = widget.contact.publicKeyHex;
return Consumer<AppSettingsService>(
builder: (context, settingsService, _) {
return ChatCompressionSelector(
mode: connector.contactCompressionMode(keyHex),
enabled: true,
profiles: settingsService.settings.cyr2latProfiles,
profileId: connector.getContactCyr2LatProfileId(keyHex),
defaultProfileId: settingsService.settings.selectedCyr2latProfileId,
final connector = context.read<MeshCoreConnector>();
final settingsService = context.read<AppSettingsService>();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChatCompressionScreen(
listenable: Listenable.merge([connector, settingsService]),
read: () => ChatCompressionState(
mode: connector.contactCompressionMode(keyHex),
enabled: true,
profiles: settingsService.settings.cyr2latProfiles,
profileId: connector.getContactCyr2LatProfileId(keyHex),
defaultProfileId: settingsService.settings.selectedCyr2latProfileId,
),
onModeChanged: (mode) =>
connector.setContactCompressionMode(keyHex, mode),
onProfileChanged: (id) =>
connector.setContactCyr2LatProfileId(keyHex, id),
);
},
),
),
);
}