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

+4 -5
View File
@@ -4476,7 +4476,7 @@
"chatCompression_title": "Compression",
"chatCompression_label": "Compression: {mode}",
"@chatCompression_label": {
"description": "Always-visible control at the top of a chat; mode is Off, SMAZ or Cyr2Lat",
"description": "Chat menu item that opens the compression page; mode is Off, SMAZ or Cyr2Lat",
"placeholders": {
"mode": {
"type": "String"
@@ -4486,11 +4486,10 @@
"chatCompression_off": "Off",
"chatCompression_smaz": "SMAZ",
"chatCompression_cyr2lat": "Cyr2Lat",
"chatCompression_changeHint": "Change compression for this chat",
"chatCompression_sheetSubtitle": "Applies to messages you send in this chat. Saved on this phone.",
"chatCompression_offDescription": "No compression. Sends your text exactly as typed. Every app can read it. Saves no bytes.",
"chatCompression_smazDescription": "Lossless compression for short text. The recipient's app must support SMAZ; other apps show unreadable \"s:…\" text. Only used when it makes a message smaller, so not every message is compressed.",
"chatCompression_cyr2latDescription": "Not lossless. Swaps some Cyrillic letters for lookalike Latin ones (А→A, З→3) to save bytes. Readable in any app with no decoding, but the exact characters change, including your own sent messages here. Copying, search and technical text may be affected. Results depend on the chosen profile.",
"chatCompression_offDescription": "Sends your text as typed. Every app can read it.",
"chatCompression_smazDescription": "Shrinks English text. Used only when the message gets shorter. Apps without SMAZ show \"s:…\" instead of your text.",
"chatCompression_cyr2latDescription": "Swaps Cyrillic letters for similar Latin ones (А→A). Every app can read it, but the characters change. Not lossless.",
"chatCompression_profile": "Cyr2Lat profile",
"chatCompression_noStorageId": "Can't change compression until this channel has synced from the radio.",
"chatCompression_saveFailed": "Couldn't save the compression setting. Showing the saved setting.",
+4 -10
View File
@@ -12964,7 +12964,7 @@ abstract class AppLocalizations {
/// **'Compression'**
String get chatCompression_title;
/// Always-visible control at the top of a chat; mode is Off, SMAZ or Cyr2Lat
/// Chat menu item that opens the compression page; mode is Off, SMAZ or Cyr2Lat
///
/// In en, this message translates to:
/// **'Compression: {mode}'**
@@ -12988,12 +12988,6 @@ abstract class AppLocalizations {
/// **'Cyr2Lat'**
String get chatCompression_cyr2lat;
/// No description provided for @chatCompression_changeHint.
///
/// In en, this message translates to:
/// **'Change compression for this chat'**
String get chatCompression_changeHint;
/// No description provided for @chatCompression_sheetSubtitle.
///
/// In en, this message translates to:
@@ -13003,19 +12997,19 @@ abstract class AppLocalizations {
/// No description provided for @chatCompression_offDescription.
///
/// In en, this message translates to:
/// **'No compression. Sends your text exactly as typed. Every app can read it. Saves no bytes.'**
/// **'Sends your text as typed. Every app can read it.'**
String get chatCompression_offDescription;
/// No description provided for @chatCompression_smazDescription.
///
/// In en, this message translates to:
/// **'Lossless compression for short text. The recipient\'s app must support SMAZ; other apps show unreadable \"s:…\" text. Only used when it makes a message smaller, so not every message is compressed.'**
/// **'Shrinks English text. Used only when the message gets shorter. Apps without SMAZ show \"s:…\" instead of your text.'**
String get chatCompression_smazDescription;
/// No description provided for @chatCompression_cyr2latDescription.
///
/// In en, this message translates to:
/// **'Not lossless. Swaps some Cyrillic letters for lookalike Latin ones (А→A, З→3) to save bytes. Readable in any app with no decoding, but the exact characters change, including your own sent messages here. Copying, search and technical text may be affected. Results depend on the chosen profile.'**
/// **'Swaps Cyrillic letters for similar Latin ones (А→A). Every app can read it, but the characters change. Not lossless.'**
String get chatCompression_cyr2latDescription;
/// No description provided for @chatCompression_profile.
-3
View File
@@ -7809,9 +7809,6 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Кир→Лат';
@override
String get chatCompression_changeHint => 'Промяна на компресията за този чат';
@override
String get chatCompression_sheetSubtitle =>
'Важи за съобщенията, които изпращате в този чат. Запазва се на този телефон.';
-3
View File
@@ -7783,9 +7783,6 @@ class AppLocalizationsCs extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Změnit kompresi pro tento chat';
@override
String get chatCompression_sheetSubtitle =>
'Platí pro zprávy odeslané v tomto chatu. Uloženo v tomto telefonu.';
-3
View File
@@ -7820,9 +7820,6 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Kompression für diesen Chat ändern';
@override
String get chatCompression_sheetSubtitle =>
'Gilt für Nachrichten, die Sie in diesem Chat senden. Auf diesem Telefon gespeichert.';
+3 -6
View File
@@ -7694,24 +7694,21 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Change compression for this chat';
@override
String get chatCompression_sheetSubtitle =>
'Applies to messages you send in this chat. Saved on this phone.';
@override
String get chatCompression_offDescription =>
'No compression. Sends your text exactly as typed. Every app can read it. Saves no bytes.';
'Sends your text as typed. Every app can read it.';
@override
String get chatCompression_smazDescription =>
'Lossless compression for short text. The recipient\'s app must support SMAZ; other apps show unreadable \"s:…\" text. Only used when it makes a message smaller, so not every message is compressed.';
'Shrinks English text. Used only when the message gets shorter. Apps without SMAZ show \"s:…\" instead of your text.';
@override
String get chatCompression_cyr2latDescription =>
'Not lossless. Swaps some Cyrillic letters for lookalike Latin ones (А→A, З→3) to save bytes. Readable in any app with no decoding, but the exact characters change, including your own sent messages here. Copying, search and technical text may be affected. Results depend on the chosen profile.';
'Swaps Cyrillic letters for similar Latin ones (А→A). Every app can read it, but the characters change. Not lossless.';
@override
String get chatCompression_profile => 'Cyr2Lat profile';
-3
View File
@@ -7801,9 +7801,6 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Cambiar la compresión de este chat';
@override
String get chatCompression_sheetSubtitle =>
'Se aplica a los mensajes que envíes en este chat. Se guarda en este teléfono.';
-4
View File
@@ -7824,10 +7824,6 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint =>
'Modifier la compression de cette discussion';
@override
String get chatCompression_sheetSubtitle =>
'S\'applique aux messages que vous envoyez dans cette discussion. Enregistré sur ce téléphone.';
-4
View File
@@ -7790,10 +7790,6 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint =>
'Tömörítés módosítása ebben a csevegésben';
@override
String get chatCompression_sheetSubtitle =>
'Az ebben a csevegésben küldött üzenetekre vonatkozik. Ezen a telefonon van mentve.';
-4
View File
@@ -7812,10 +7812,6 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint =>
'Cambia la compressione per questa chat';
@override
String get chatCompression_sheetSubtitle =>
'Si applica ai messaggi che invii in questa chat. Salvato su questo telefono.';
-3
View File
@@ -7454,9 +7454,6 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'このチャットの圧縮設定を変更';
@override
String get chatCompression_sheetSubtitle =>
'このチャットで送信するメッセージに適用されます。このスマートフォンに保存されます。';
-3
View File
@@ -7463,9 +7463,6 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => '이 채팅의 압축 설정 변경';
@override
String get chatCompression_sheetSubtitle =>
'이 채팅에서 보내는 메시지에 적용됩니다. 이 휴대폰에 저장됩니다.';
-3
View File
@@ -7765,9 +7765,6 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Compressie voor deze chat wijzigen';
@override
String get chatCompression_sheetSubtitle =>
'Geldt voor berichten die je in deze chat verstuurt. Opgeslagen op deze telefoon.';
-3
View File
@@ -7854,9 +7854,6 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Zmień kompresję w tej rozmowie';
@override
String get chatCompression_sheetSubtitle =>
'Dotyczy wiadomości wysyłanych w tej rozmowie. Zapisane na tym telefonie.';
-8
View File
@@ -7789,10 +7789,6 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint =>
'Alterar a compressão desta conversa';
@override
String get chatCompression_sheetSubtitle =>
'Vale para as mensagens que você envia nesta conversa. Salvo neste celular.';
@@ -16052,10 +16048,6 @@ class AppLocalizationsPtPt extends AppLocalizationsPt {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint =>
'Alterar a compressão desta conversa';
@override
String get chatCompression_sheetSubtitle =>
'Aplica-se às mensagens que envia nesta conversa. Guardado neste telemóvel.';
-3
View File
@@ -7833,9 +7833,6 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Кир→Лат';
@override
String get chatCompression_changeHint => 'Изменить сжатие для этого чата';
@override
String get chatCompression_sheetSubtitle =>
'Действует для сообщений, которые вы отправляете в этом чате. Сохраняется на этом телефоне.';
-3
View File
@@ -7792,9 +7792,6 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Zmeniť kompresiu pre tento chat';
@override
String get chatCompression_sheetSubtitle =>
'Platí pre správy, ktoré v tomto chate odošlete. Uložené v tomto telefóne.';
-3
View File
@@ -7792,9 +7792,6 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => 'Spremeni stiskanje za ta klepet';
@override
String get chatCompression_sheetSubtitle =>
'Velja za sporočila, ki jih pošljete v tem klepetu. Shranjeno v tem telefonu.';
-4
View File
@@ -7741,10 +7741,6 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint =>
'Ändra komprimering för den här chatten';
@override
String get chatCompression_sheetSubtitle =>
'Gäller meddelanden du skickar i den här chatten. Sparas på den här telefonen.';
-3
View File
@@ -7847,9 +7847,6 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Кир→Лат';
@override
String get chatCompression_changeHint => 'Змінити стиснення для цього чату';
@override
String get chatCompression_sheetSubtitle =>
'Діє для повідомлень, які ви надсилаєте в цьому чаті. Зберігається на цьому телефоні.';
-3
View File
@@ -7300,9 +7300,6 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get chatCompression_cyr2lat => 'Cyr2Lat';
@override
String get chatCompression_changeHint => '更改此聊天的压缩设置';
@override
String get chatCompression_sheetSubtitle => '适用于你在此聊天中发送的消息。保存在本机。';
+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),
);
},
),
),
);
}
-364
View File
@@ -1,364 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import '../l10n/l10n.dart';
import '../models/app_settings.dart';
import '../models/chat_compression_mode.dart';
import '../theme/mesh_theme.dart';
import 'mesh_nav_tile.dart';
import 'mesh_ui.dart';
export '../models/chat_compression_mode.dart';
/// Always-visible "Compression: Off / SMAZ / Cyr2Lat" strip for the top of a
/// DM or channel chat. Tapping it opens one sheet with the three choices,
/// what each does, and the Cyr2Lat profile picker.
///
/// The parent supplies the saved state and persists changes through the
/// callbacks; this widget only shows a new mode once the parent rebuilds it
/// with that mode. A callback that throws leaves the saved mode in place and
/// shows an error in the sheet.
class ChatCompressionSelector extends StatefulWidget {
final ChatCompressionMode mode;
/// False disables the strip and the sheet; [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;
final Future<void> Function(ChatCompressionMode mode) onModeChanged;
final Future<void> Function(String profileId) onProfileChanged;
const ChatCompressionSelector({
super.key,
required this.mode,
required this.enabled,
this.disabledReason,
required this.profiles,
required this.profileId,
this.defaultProfileId,
required this.onModeChanged,
required this.onProfileChanged,
});
/// 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;
}
@override
State<ChatCompressionSelector> createState() =>
_ChatCompressionSelectorState();
}
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 open sheet renders. The sheet is a separate route, so it listens
/// to this instead of rebuilding with the strip.
class _SelectorView {
final ChatCompressionMode mode;
final bool enabled;
final List<Cyr2LatProfile> profiles;
final String? profileId;
final bool busy;
final bool failed;
/// Counts failed saves, so the profile picker drops an unsaved choice.
final int failures;
const _SelectorView({
required this.mode,
required this.enabled,
required this.profiles,
required this.profileId,
required this.busy,
required this.failed,
required this.failures,
});
}
class _ChatCompressionSelectorState extends State<ChatCompressionSelector> {
late final ValueNotifier<_SelectorView> _view = ValueNotifier(_snapshot());
bool _busy = false;
bool _failed = false;
int _failures = 0;
_SelectorView _snapshot() => _SelectorView(
mode: widget.mode,
enabled: widget.enabled,
profiles: widget.profiles,
profileId: widget.effectiveProfileId,
busy: _busy,
failed: _failed,
failures: _failures,
);
@override
void didUpdateWidget(covariant ChatCompressionSelector oldWidget) {
super.didUpdateWidget(oldWidget);
// The sheet route is not below this widget, so it can't be marked dirty
// during this build.
SchedulerBinding.instance.addPostFrameCallback((_) {
if (mounted) _view.value = _snapshot();
});
}
@override
void dispose() {
_view.dispose();
super.dispose();
}
void _setBusy(bool busy, {required bool failed}) {
setState(() {
_busy = busy;
_failed = failed;
if (failed) _failures++;
});
_view.value = _snapshot();
}
/// Runs one save; returns whether it succeeded.
Future<bool> _save(Future<void> Function() write) async {
if (_busy || !widget.enabled) return false;
_setBusy(true, failed: false);
var ok = false;
try {
await write();
ok = true;
} catch (e) {
debugPrint('[ChatCompressionSelector] save failed: $e');
}
if (mounted) _setBusy(false, failed: !ok);
return ok;
}
Future<void> _openSheet() async {
if (_failed) _setBusy(false, failed: false);
await showMeshSheet<void>(
context,
builder: (sheetContext) => ValueListenableBuilder<_SelectorView>(
valueListenable: _view,
builder: (sheetContext, view, _) => _buildSheet(sheetContext, view),
),
);
}
Widget _buildSheet(BuildContext context, _SelectorView view) {
final l10n = context.l10n;
final scheme = Theme.of(context).colorScheme;
final canChange = view.enabled && !view.busy;
MeshSheetOption option(ChatCompressionMode mode, String description) {
return MeshSheetOption(
label: chatCompressionModeLabel(context, mode),
subtitle: description,
selected: view.mode == mode,
onTap: canChange
? () async {
final ok = await _save(() => widget.onModeChanged(mode));
// Cyr2Lat stays open so its profile can be picked.
if (ok && mode != ChatCompressionMode.cyr2lat) {
if (context.mounted) Navigator.of(context).maybePop();
}
}
: null,
);
}
final profileValue = view.profileId;
return Column(
mainAxisSize: MainAxisSize.min,
children: [
BottomSheetHeader(
title: l10n.chatCompression_title,
subtitle: l10n.chatCompression_sheetSubtitle,
trailing: view.busy
? const Padding(
padding: EdgeInsets.all(8),
child: SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
),
)
: null,
),
Flexible(
child: SingleChildScrollView(
padding: const EdgeInsets.only(bottom: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (view.failed)
Container(
margin: const EdgeInsets.fromLTRB(16, 8, 16, 8),
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: scheme.errorContainer,
borderRadius: BorderRadius.circular(MeshRadii.sm),
),
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 && widget.disabledReason != null)
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
child: Text(
widget.disabledReason!,
style: Theme.of(context).textTheme.bodyMedium,
),
),
option(
ChatCompressionMode.off,
l10n.chatCompression_offDescription,
),
option(
ChatCompressionMode.smaz,
l10n.chatCompression_smazDescription,
),
option(
ChatCompressionMode.cyr2lat,
l10n.chatCompression_cyr2latDescription,
),
if (view.mode == ChatCompressionMode.cyr2lat &&
view.profiles.isNotEmpty)
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
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#${view.failures}'),
isExpanded: true,
initialValue: profileValue,
decoration: InputDecoration(
labelText: l10n.chatCompression_profile,
border: const OutlineInputBorder(),
),
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,
),
),
],
),
),
),
],
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
final l10n = context.l10n;
final label = l10n.chatCompression_label(
chatCompressionModeLabel(context, widget.mode),
);
final reason = widget.enabled ? null : widget.disabledReason;
// One short row: the chat already leaves little room for messages at
// large text sizes, so a disabled strip explains itself in the sheet.
return Material(
color: scheme.surfaceContainerLow,
child: DecoratedBox(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: scheme.outlineVariant)),
),
child: MergeSemantics(
child: Semantics(
button: true,
enabled: !_busy,
label: reason == null ? label : '$label. $reason',
hint: l10n.chatCompression_changeHint,
child: InkWell(
onTap: _busy ? null : _openSheet,
child: ExcludeSemantics(
child: ConstrainedBox(
constraints: const BoxConstraints(minHeight: 48),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: [
Flexible(
child: Text(
label,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
color: scheme.onSurface,
),
),
),
const SizedBox(width: 4),
if (_busy)
const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
)
else
Icon(
widget.enabled
? Icons.arrow_drop_down
: Icons.lock_outline,
color: scheme.onSurfaceVariant,
),
],
),
),
),
),
),
),
),
),
);
}
}