Files
buzz/mobile/lib/shared/theme/community_theme_preference.dart
klopez4212 5fefec604f fix(mobile): restore channel icons and align chat colors with desktop (#8478)
## Summary
- Restores `#` and lock icons for public and private channels on Home,
with matching loading placeholders.
- Updates the dark-mode navigation colors to the desktop design-system
tokens (read and unread text, section headings).
- Replaces the chat color picker with the seven desktop accents (Gray,
Chartreuse, Flame, Magenta, Iris, Cobalt, Jade). Saved legacy colors map
to the closest one.
- Uses white text in your own bubbles, and black where white falls below
4.5:1 (Chartreuse, dark-mode Gray). Links (underlined), quotes, tables
and code use the same text color.
- Insets code blocks in bubbles evenly, with corners concentric to the
bubble and even inner padding.
- The swipe-to-reply indicator uses the chosen chat color.

## Testing
- `flutter analyze` and `dart format` are clean. The full mobile suite
passes (3,705 tests).
- Installed and checked on a Pixel 10 and an iPhone Air against a real
community.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Co-authored-by: Queue <874bf2d815c2c4b459b90438c669c57f2702f3a76bb6e16fa97184259aac3e9e@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 13:48:12 -04:00

175 lines
5.6 KiB
Dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'accent_colors.dart';
import 'chat_colors.dart';
import 'theme_catalog.dart';
import 'theme_provider.dart' show effectiveTheme, schemeForAppearanceMode;
const communityThemeDTag = 'community-theme';
const defaultCommunityTheme = CommunityThemePreference(
theme: 'buzz',
// Seeded without a picker action, so it must stay readable by older clients.
accent: '#3b82f6', // Cobalt
followSystem: true,
);
class CommunityThemePreference {
final int version;
final String theme;
final String accent;
final bool followSystem;
const CommunityThemePreference({
this.version = 1,
required this.theme,
required this.accent,
required this.followSystem,
});
factory CommunityThemePreference.fromJson(Map<String, dynamic> json) {
if (json['version'] != 1 ||
json['theme'] is! String ||
findTheme(json['theme'] as String) == null ||
json['accent'] is! String ||
(accentIndexForWireValue(json['accent'] as String) == null &&
previewFamilyWireValue(json['accent'] as String) == null) ||
json['followSystem'] is! bool) {
throw const FormatException('Invalid community theme preference');
}
return CommunityThemePreference(
theme: json['theme'] as String,
accent:
previewFamilyWireValue(json['accent'] as String) ??
json['accent'] as String,
followSystem: json['followSystem'] as bool,
);
}
Map<String, dynamic> toJson() => {
'version': version,
'theme': theme,
'accent': accent,
'followSystem': followSystem,
};
ThemeMode get mode {
if (followSystem) return ThemeMode.system;
return findTheme(theme)?.isDark == true ? ThemeMode.dark : ThemeMode.light;
}
@override
bool operator ==(Object other) =>
other is CommunityThemePreference &&
theme == other.theme &&
accent == other.accent &&
followSystem == other.followSystem;
@override
int get hashCode => Object.hash(theme, accent, followSystem);
}
class CommunityThemeStorage {
static const _prefix = 'buzz-community-theme.v1';
static const _outboxPrefix = 'buzz-community-theme-outbox.v1';
static const _migrationPrefix = 'buzz-community-theme-migrated.v1';
static const _localPreferenceKey = 'buzz-local-theme.v1';
static const _legacyModeKey = 'buzz_theme_mode';
static const _legacyAccentKey = 'buzz_accent_color';
static const _legacySchemeKey = 'buzz_color_scheme';
final SharedPreferences prefs;
const CommunityThemeStorage(this.prefs);
String key(String pubkey, String relayUrl) =>
'$_prefix:$pubkey:${Uri.encodeComponent(normalizeCommunityRelayUrl(relayUrl))}';
String outboxKey(String pubkey, String relayUrl) =>
'$_outboxPrefix:$pubkey:${Uri.encodeComponent(normalizeCommunityRelayUrl(relayUrl))}';
CommunityThemePreference? _readKey(String storageKey) {
try {
final raw = prefs.getString(storageKey);
if (raw == null) return null;
final decoded = jsonDecode(raw);
if (decoded is! Map<String, dynamic>) return null;
return CommunityThemePreference.fromJson(decoded);
} catch (_) {
return null;
}
}
CommunityThemePreference? read(String pubkey, String relayUrl) =>
_readKey(key(pubkey, relayUrl));
CommunityThemePreference? readOutbox(String pubkey, String relayUrl) =>
_readKey(outboxKey(pubkey, relayUrl));
Future<bool> write(
String pubkey,
String relayUrl,
CommunityThemePreference preference,
) => prefs.setString(key(pubkey, relayUrl), jsonEncode(preference.toJson()));
Future<bool> writeOutbox(
String pubkey,
String relayUrl,
CommunityThemePreference preference,
) => prefs.setString(
outboxKey(pubkey, relayUrl),
jsonEncode(preference.toJson()),
);
Future<void> clearOutbox(
String pubkey,
String relayUrl,
CommunityThemePreference acknowledged,
) async {
if (readOutbox(pubkey, relayUrl) == acknowledged) {
await prefs.remove(outboxKey(pubkey, relayUrl));
}
}
bool hasMigrated(String pubkey) =>
prefs.getBool('$_migrationPrefix:$pubkey') == true;
Future<bool> markMigrated(String pubkey) =>
prefs.setBool('$_migrationPrefix:$pubkey', true);
Future<void> writeLegacy(CommunityThemePreference preference) async {
// New writes use one versioned snapshot. Historical integer indexes remain
// read-only migration input and must never encode the current palette.
await prefs.setString(_localPreferenceKey, jsonEncode(preference.toJson()));
}
CommunityThemePreference legacyPreference() {
final local = _readKey(_localPreferenceKey);
if (local != null) return local;
final modeName = prefs.getString(_legacyModeKey);
final mode =
ThemeMode.values.where((value) => value.name == modeName).firstOrNull ??
ThemeMode.system;
final storedTheme = prefs.getString(_legacySchemeKey);
final theme = findTheme(storedTheme ?? 'buzz')?.name ?? 'buzz';
final legacyAccent = prefs.getInt(_legacyAccentKey);
final resolvedTheme = switch (mode) {
ThemeMode.system => schemeForAppearanceMode(theme, mode) ?? theme,
ThemeMode.light ||
ThemeMode.dark => effectiveTheme(theme, mode)?.name ?? theme,
};
return CommunityThemePreference(
theme: resolvedTheme,
accent: legacyAccent == null
? defaultCommunityTheme.accent
: legacyAccentWireValue(legacyAccent),
followSystem: mode == ThemeMode.system,
);
}
}
String normalizeCommunityRelayUrl(String relayUrl) =>
relayUrl.trim().replaceFirst(RegExp(r'/+$'), '').toLowerCase();