Skip to content

Commit a8067d0

Browse files
committed
refactor(settings): migrate to ht_shared types
- Use types from ht_shared package - Update theme settings - Add font weight setting
1 parent fa40ea9 commit a8067d0

File tree

1 file changed

+106
-59
lines changed

1 file changed

+106
-59
lines changed

lib/settings/view/appearance_settings_page.dart

Lines changed: 106 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
33
import 'package:ht_main/l10n/l10n.dart';
44
import 'package:ht_main/settings/bloc/settings_bloc.dart';
55
import 'package:ht_main/shared/constants/constants.dart';
6-
import 'package:ht_preferences_client/ht_preferences_client.dart';
6+
import 'package:ht_shared/ht_shared.dart'; // Use types from ht_shared
77

88
/// {@template appearance_settings_page}
99
/// A page for configuring appearance-related settings like theme and fonts.
@@ -12,47 +12,69 @@ class AppearanceSettingsPage extends StatelessWidget {
1212
/// {@macro appearance_settings_page}
1313
const AppearanceSettingsPage({super.key});
1414

15-
// Helper to map AppThemeMode enum to user-friendly strings
16-
String _themeModeToString(AppThemeMode mode, AppLocalizations l10n) {
15+
// Helper to map AppBaseTheme enum to user-friendly strings
16+
String _baseThemeToString(AppBaseTheme mode, AppLocalizations l10n) {
1717
switch (mode) {
18-
case AppThemeMode.light:
19-
return l10n.settingsAppearanceThemeModeLight; // Add l10n key
20-
case AppThemeMode.dark:
21-
return l10n.settingsAppearanceThemeModeDark; // Add l10n key
22-
case AppThemeMode.system:
23-
return l10n.settingsAppearanceThemeModeSystem; // Add l10n key
18+
case AppBaseTheme.light:
19+
return l10n.settingsAppearanceThemeModeLight;
20+
case AppBaseTheme.dark:
21+
return l10n.settingsAppearanceThemeModeDark;
22+
case AppBaseTheme.system:
23+
return l10n.settingsAppearanceThemeModeSystem;
2424
}
2525
}
2626

27-
// Helper to map AppThemeName enum to user-friendly strings
28-
String _themeNameToString(AppThemeName name, AppLocalizations l10n) {
27+
// Helper to map AppAccentTheme enum to user-friendly strings
28+
String _accentThemeToString(AppAccentTheme name, AppLocalizations l10n) {
2929
switch (name) {
30-
case AppThemeName.red:
31-
return l10n.settingsAppearanceThemeNameRed; // Add l10n key
32-
case AppThemeName.blue:
33-
return l10n.settingsAppearanceThemeNameBlue; // Add l10n key
34-
case AppThemeName.grey:
35-
return l10n.settingsAppearanceThemeNameGrey; // Add l10n key
30+
case AppAccentTheme.newsRed:
31+
return l10n.settingsAppearanceThemeNameRed;
32+
case AppAccentTheme.defaultBlue:
33+
return l10n.settingsAppearanceThemeNameBlue;
34+
case AppAccentTheme.graphiteGray:
35+
return l10n.settingsAppearanceThemeNameGrey;
3636
}
3737
}
3838

39-
// Helper to map FontSize enum to user-friendly strings
40-
String _fontSizeToString(FontSize size, AppLocalizations l10n) {
39+
// Helper to map AppTextScaleFactor enum to user-friendly strings
40+
String _textScaleFactorToString(
41+
AppTextScaleFactor size,
42+
AppLocalizations l10n,
43+
) {
4144
switch (size) {
42-
case FontSize.small:
43-
return l10n.settingsAppearanceFontSizeSmall; // Add l10n key
44-
case FontSize.large:
45-
return l10n.settingsAppearanceFontSizeLarge; // Add l10n key
46-
case FontSize.medium:
47-
return l10n.settingsAppearanceFontSizeMedium; // Add l10n key
45+
case AppTextScaleFactor.small:
46+
return l10n.settingsAppearanceFontSizeSmall;
47+
case AppTextScaleFactor.large:
48+
return l10n.settingsAppearanceFontSizeLarge;
49+
case AppTextScaleFactor.medium:
50+
return l10n.settingsAppearanceFontSizeMedium;
51+
case AppTextScaleFactor.extraLarge:
52+
return l10n.settingsAppearanceFontSizeExtraLarge; // Add l10n key
4853
}
4954
}
5055

51-
// Helper to map AppFontType enum to user-friendly strings
52-
// (Using the enum name directly might be sufficient if they are clear)
53-
String _fontTypeToString(AppFontType type, AppLocalizations l10n) {
56+
// Helper to map font family string to user-friendly strings
57+
String _fontFamilyToString(String fontFamily, AppLocalizations l10n) {
58+
// This mapping might need to be more sophisticated if supporting multiple
59+
// specific fonts. For now, just return the string or a placeholder.
5460
// Consider adding specific l10n keys if needed, e.g., l10n.fontRoboto
55-
return type.name; // Example: 'roboto', 'openSans'
61+
return fontFamily == 'SystemDefault'
62+
? l10n
63+
.settingsAppearanceFontFamilySystemDefault // Add l10n key
64+
: fontFamily;
65+
}
66+
67+
// TODO(cline): Replace with localized strings once localization issue is resolved.
68+
// Helper to map AppFontWeight enum to user-friendly strings (currently uses enum name)
69+
String _fontWeightToString(AppFontWeight weight, AppLocalizations l10n) {
70+
switch (weight) {
71+
case AppFontWeight.light:
72+
return 'Light'; // Temporary: Use enum name or placeholder
73+
case AppFontWeight.regular:
74+
return 'Regular'; // Temporary: Use enum name or placeholder
75+
case AppFontWeight.bold:
76+
return 'Bold'; // Temporary: Use enum name or placeholder
77+
}
5678
}
5779

5880
@override
@@ -73,19 +95,17 @@ class AppearanceSettingsPage extends StatelessWidget {
7395
}
7496

7597
return Scaffold(
76-
appBar: AppBar(
77-
title: Text(l10n.settingsAppearanceTitle), // Reuse title key
78-
),
98+
appBar: AppBar(title: Text(l10n.settingsAppearanceTitle)),
7999
body: ListView(
80100
padding: const EdgeInsets.all(AppSpacing.lg),
81101
children: [
82-
// --- Theme Mode ---
83-
_buildDropdownSetting<AppThemeMode>(
102+
// --- Base Theme ---
103+
_buildDropdownSetting<AppBaseTheme>(
84104
context: context,
85-
title: l10n.settingsAppearanceThemeModeLabel, // Add l10n key
86-
currentValue: state.themeSettings.themeMode,
87-
items: AppThemeMode.values,
88-
itemToString: (mode) => _themeModeToString(mode, l10n),
105+
title: l10n.settingsAppearanceThemeModeLabel,
106+
currentValue: state.userAppSettings.displaySettings.baseTheme,
107+
items: AppBaseTheme.values,
108+
itemToString: (mode) => _baseThemeToString(mode, l10n),
89109
onChanged: (value) {
90110
if (value != null) {
91111
settingsBloc.add(SettingsAppThemeModeChanged(value));
@@ -94,46 +114,73 @@ class AppearanceSettingsPage extends StatelessWidget {
94114
),
95115
const SizedBox(height: AppSpacing.lg),
96116

97-
// --- Theme Name ---
98-
_buildDropdownSetting<AppThemeName>(
117+
// --- Accent Theme ---
118+
_buildDropdownSetting<AppAccentTheme>(
99119
context: context,
100-
title: l10n.settingsAppearanceThemeNameLabel, // Add l10n key
101-
currentValue: state.themeSettings.themeName,
102-
items: AppThemeName.values,
103-
itemToString: (name) => _themeNameToString(name, l10n),
120+
title: l10n.settingsAppearanceThemeNameLabel,
121+
currentValue: state.userAppSettings.displaySettings.accentTheme,
122+
items: AppAccentTheme.values,
123+
itemToString: (name) => _accentThemeToString(name, l10n),
104124
onChanged: (value) {
105125
if (value != null) {
106-
settingsBloc.add(SettingsAppThemeNameChanged(value));
126+
context.read<SettingsBloc>().add(
127+
SettingsAppThemeNameChanged(value),
128+
);
107129
}
108130
},
109131
),
110132
const SizedBox(height: AppSpacing.lg),
111133

112-
// --- App Font Size ---
113-
_buildDropdownSetting<FontSize>(
134+
// --- Text Scale Factor ---
135+
_buildDropdownSetting<AppTextScaleFactor>(
114136
context: context,
115-
title: l10n.settingsAppearanceAppFontSizeLabel, // Add l10n key
116-
currentValue: state.appSettings.appFontSize,
117-
items: FontSize.values,
118-
itemToString: (size) => _fontSizeToString(size, l10n),
137+
title:
138+
l10n.settingsAppearanceAppFontSizeLabel, // Reusing key for text size
139+
currentValue: state.userAppSettings.displaySettings.textScaleFactor,
140+
items: AppTextScaleFactor.values,
141+
itemToString: (size) => _textScaleFactorToString(size, l10n),
119142
onChanged: (value) {
120143
if (value != null) {
121-
settingsBloc.add(SettingsAppFontSizeChanged(value));
144+
context.read<SettingsBloc>().add(
145+
SettingsAppFontSizeChanged(value),
146+
);
147+
}
148+
},
149+
),
150+
const SizedBox(height: AppSpacing.lg),
151+
152+
// --- Font Family ---
153+
_buildDropdownSetting<String>(
154+
// Font family is a String
155+
context: context,
156+
title:
157+
l10n.settingsAppearanceAppFontTypeLabel, // Reusing key for font family
158+
currentValue: state.userAppSettings.displaySettings.fontFamily,
159+
items: const [
160+
'SystemDefault',
161+
], // Only SystemDefault supported for now
162+
itemToString: (fontFamily) => _fontFamilyToString(fontFamily, l10n),
163+
onChanged: (value) {
164+
if (value != null) {
165+
context.read<SettingsBloc>().add(
166+
SettingsAppFontTypeChanged(value),
167+
);
122168
}
123169
},
124170
),
125171
const SizedBox(height: AppSpacing.lg),
126172

127-
// --- App Font Type ---
128-
_buildDropdownSetting<AppFontType>(
173+
// --- Font Weight ---
174+
_buildDropdownSetting<AppFontWeight>(
129175
context: context,
130-
title: l10n.settingsAppearanceAppFontTypeLabel, // Add l10n key
131-
currentValue: state.appSettings.appFontType,
132-
items: AppFontType.values,
133-
itemToString: (type) => _fontTypeToString(type, l10n),
176+
title: l10n.settingsAppearanceFontWeightLabel, // Add l10n key
177+
currentValue: state.userAppSettings.displaySettings.fontWeight,
178+
items: AppFontWeight.values,
179+
itemToString:
180+
(weight) => _fontWeightToString(weight, l10n), // Use helper
134181
onChanged: (value) {
135182
if (value != null) {
136-
settingsBloc.add(SettingsAppFontTypeChanged(value));
183+
settingsBloc.add(SettingsAppFontWeightChanged(value));
137184
}
138185
},
139186
),

0 commit comments

Comments
 (0)