TF-4193 Add Label to Preferences in Setting
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/ai_scribe_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/default_preferences_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/empty_preferences_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/label_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_setting.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/spam_report_config.dart';
|
||||
@@ -20,6 +21,8 @@ class PreferencesSettingManager {
|
||||
'${_preferencesSettingKey}_TEXT_FORMATTING_MENU';
|
||||
static const String _preferencesSettingAIScribeKey =
|
||||
'${_preferencesSettingKey}_AI_SCRIBE';
|
||||
static const String _preferencesSettingLabelKey =
|
||||
'${_preferencesSettingKey}_LABEL';
|
||||
|
||||
const PreferencesSettingManager(this._sharedPreferences);
|
||||
|
||||
@@ -46,6 +49,8 @@ class PreferencesSettingManager {
|
||||
return TextFormattingMenuConfig.fromJson(jsonDecoded);
|
||||
case _preferencesSettingAIScribeKey:
|
||||
return AIScribeConfig.fromJson(jsonDecoded);
|
||||
case _preferencesSettingLabelKey:
|
||||
return LabelConfig.fromJson(jsonDecoded);
|
||||
default:
|
||||
return DefaultPreferencesConfig.fromJson(jsonDecoded);
|
||||
}
|
||||
@@ -60,35 +65,29 @@ class PreferencesSettingManager {
|
||||
return PreferencesSetting(listConfigs);
|
||||
}
|
||||
|
||||
Future<void> savePreferences(PreferencesConfig config) async {
|
||||
String _getPreferencesConfig(PreferencesConfig config) {
|
||||
if (config is ThreadDetailConfig) {
|
||||
await _sharedPreferences.setString(
|
||||
_preferencesSettingThreadKey,
|
||||
jsonEncode(config.toJson()),
|
||||
);
|
||||
return _preferencesSettingThreadKey;
|
||||
} else if (config is SpamReportConfig) {
|
||||
await _sharedPreferences.setString(
|
||||
_preferencesSettingSpamReportKey,
|
||||
jsonEncode(config.toJson()),
|
||||
);
|
||||
return _preferencesSettingSpamReportKey;
|
||||
} else if (config is TextFormattingMenuConfig) {
|
||||
await _sharedPreferences.setString(
|
||||
_preferencesSettingTextFormattingMenuKey,
|
||||
jsonEncode(config.toJson()),
|
||||
);
|
||||
return _preferencesSettingTextFormattingMenuKey;
|
||||
} else if (config is AIScribeConfig) {
|
||||
await _sharedPreferences.setString(
|
||||
_preferencesSettingAIScribeKey,
|
||||
jsonEncode(config.toJson()),
|
||||
);
|
||||
return _preferencesSettingAIScribeKey;
|
||||
} else if (config is LabelConfig) {
|
||||
return _preferencesSettingLabelKey;
|
||||
} else {
|
||||
await _sharedPreferences.setString(
|
||||
_preferencesSettingKey,
|
||||
jsonEncode(config.toJson()),
|
||||
);
|
||||
return _preferencesSettingKey;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> savePreferences(PreferencesConfig config) async {
|
||||
await _sharedPreferences.setString(
|
||||
_getPreferencesConfig(config),
|
||||
jsonEncode(config.toJson()),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> updateThread(bool isEnabled) async {
|
||||
final currentConfig = await getThreadConfig();
|
||||
final updatedConfig = currentConfig.copyWith(isEnabled: isEnabled);
|
||||
@@ -166,4 +165,22 @@ class PreferencesSettingManager {
|
||||
final updatedConfig = currentConfig.copyWith(isEnabled: isEnabled);
|
||||
await savePreferences(updatedConfig);
|
||||
}
|
||||
|
||||
Future<LabelConfig> getLabelConfig() async {
|
||||
await _sharedPreferences.reload();
|
||||
|
||||
final jsonString = _sharedPreferences.getString(
|
||||
_preferencesSettingLabelKey,
|
||||
);
|
||||
|
||||
return jsonString == null
|
||||
? LabelConfig.initial()
|
||||
: LabelConfig.fromJson(jsonDecode(jsonString));
|
||||
}
|
||||
|
||||
Future<void> updateLabel(bool isEnabled) async {
|
||||
final currentConfig = await getLabelConfig();
|
||||
final updatedConfig = currentConfig.copyWith(isEnabled: isEnabled);
|
||||
await savePreferences(updatedConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
|
||||
part 'label_config.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class LabelConfig extends PreferencesConfig {
|
||||
final bool isEnabled;
|
||||
|
||||
LabelConfig({this.isEnabled = false});
|
||||
|
||||
factory LabelConfig.initial() => LabelConfig();
|
||||
|
||||
factory LabelConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$LabelConfigFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$LabelConfigToJson(this);
|
||||
|
||||
@override
|
||||
List<Object> get props => [isEnabled];
|
||||
}
|
||||
|
||||
extension LabelConfigExtension on LabelConfig {
|
||||
LabelConfig copyWith({bool? isEnabled}) {
|
||||
return LabelConfig(
|
||||
isEnabled: isEnabled ?? this.isEnabled,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/ai_scribe_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/label_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/spam_report_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/text_formatting_menu_config.dart';
|
||||
@@ -60,6 +61,16 @@ class PreferencesSetting with EquatableMixin {
|
||||
}
|
||||
}
|
||||
|
||||
LabelConfig get labelConfig {
|
||||
final labelConfig =
|
||||
configs.firstWhereOrNull((config) => config is LabelConfig);
|
||||
if (labelConfig != null) {
|
||||
return labelConfig as LabelConfig;
|
||||
} else {
|
||||
return LabelConfig.initial();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [configs];
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ enum PreferencesOptionType {
|
||||
thread(isLocal: true),
|
||||
spamReport(isLocal: true),
|
||||
aiScribe(isLocal: true),
|
||||
aiNeedsAction(isLocal: false);
|
||||
aiNeedsAction(isLocal: false),
|
||||
label(isLocal: true);
|
||||
|
||||
final bool isLocal;
|
||||
|
||||
@@ -30,6 +31,8 @@ enum PreferencesOptionType {
|
||||
return appLocalizations.aiScribe;
|
||||
case PreferencesOptionType.aiNeedsAction:
|
||||
return appLocalizations.aiNeedsAction;
|
||||
case PreferencesOptionType.label:
|
||||
return appLocalizations.labelVisibility;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +50,8 @@ enum PreferencesOptionType {
|
||||
return appLocalizations.aiScribeSettingExplanation;
|
||||
case PreferencesOptionType.aiNeedsAction:
|
||||
return appLocalizations.aiNeedsActionSettingExplanation;
|
||||
case PreferencesOptionType.label:
|
||||
return appLocalizations.labelVisibilitySettingExplanation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +69,8 @@ enum PreferencesOptionType {
|
||||
return appLocalizations.aiScribeToggleDescription;
|
||||
case PreferencesOptionType.aiNeedsAction:
|
||||
return appLocalizations.aiNeedsActionToggleDescription;
|
||||
case PreferencesOptionType.label:
|
||||
return appLocalizations.labelVisibilityToggleDescription;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +91,8 @@ enum PreferencesOptionType {
|
||||
return preferencesSetting.aiScribeConfig.isEnabled;
|
||||
case PreferencesOptionType.aiNeedsAction:
|
||||
return settingOption?.isAINeedsActionEnabled ?? false;
|
||||
case PreferencesOptionType.label:
|
||||
return preferencesSetting.labelConfig.isEnabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5265,5 +5265,23 @@
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"labelVisibility": "Label visibility",
|
||||
"@labelVisibility": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"labelVisibilitySettingExplanation": "Show labels assigned to emails directly in your message list for easier categorization.",
|
||||
"@labelVisibilitySettingExplanation": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"labelVisibilityToggleDescription": "Display labels",
|
||||
"@labelVisibilityToggleDescription": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
}
|
||||
}
|
||||
@@ -5591,4 +5591,25 @@ class AppLocalizations {
|
||||
name: 'createNewLabelFailure',
|
||||
);
|
||||
}
|
||||
|
||||
String get labelVisibility {
|
||||
return Intl.message(
|
||||
'Label visibility',
|
||||
name: 'labelVisibility',
|
||||
);
|
||||
}
|
||||
|
||||
String get labelVisibilitySettingExplanation {
|
||||
return Intl.message(
|
||||
'Show labels assigned to emails directly in your message list for easier categorization.',
|
||||
name: 'labelVisibilitySettingExplanation',
|
||||
);
|
||||
}
|
||||
|
||||
String get labelVisibilityToggleDescription {
|
||||
return Intl.message(
|
||||
'Display labels',
|
||||
name: 'labelVisibilityToggleDescription',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user