TF-3977 Separate settings keys for easier in conflict
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/converters/default_preferences_config_converter.dart';
|
||||
|
||||
class DefaultPreferencesConfig extends PreferencesConfig {
|
||||
final dynamic data;
|
||||
|
||||
DefaultPreferencesConfig(this.data);
|
||||
|
||||
factory DefaultPreferencesConfig.fromJson(Map<String, dynamic> json) =>
|
||||
const DefaultPreferencesConfigConverter().fromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() =>
|
||||
const DefaultPreferencesConfigConverter().toJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [data];
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
|
||||
class EmptyPreferencesConfig extends PreferencesConfig {
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => {};
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
abstract class PreferencesConfig with EquatableMixin {
|
||||
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:equatable/equatable.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/thread_detail_config.dart';
|
||||
|
||||
class PreferencesSetting with EquatableMixin {
|
||||
final List<PreferencesConfig> configs;
|
||||
|
||||
PreferencesSetting(this.configs);
|
||||
|
||||
factory PreferencesSetting.initial() {
|
||||
return PreferencesSetting([
|
||||
ThreadDetailConfig.initial(),
|
||||
SpamReportConfig.initial(),
|
||||
]);
|
||||
}
|
||||
|
||||
ThreadDetailConfig get threadConfig {
|
||||
final threadConfig =
|
||||
configs.firstWhereOrNull((config) => config is ThreadDetailConfig);
|
||||
if (threadConfig != null) {
|
||||
return threadConfig as ThreadDetailConfig;
|
||||
} else {
|
||||
return ThreadDetailConfig.initial();
|
||||
}
|
||||
}
|
||||
|
||||
SpamReportConfig get spamReportConfig {
|
||||
final spamConfig =
|
||||
configs.firstWhereOrNull((config) => config is SpamReportConfig);
|
||||
if (spamConfig != null) {
|
||||
return spamConfig as SpamReportConfig;
|
||||
} else {
|
||||
return SpamReportConfig.initial();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [configs];
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/model/spam_report_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
|
||||
part 'spam_report_config.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class SpamReportConfig extends PreferencesConfig {
|
||||
final bool isEnabled;
|
||||
final int lastTimeDismissedMilliseconds;
|
||||
|
||||
SpamReportConfig({
|
||||
this.isEnabled = true,
|
||||
this.lastTimeDismissedMilliseconds = 0,
|
||||
});
|
||||
|
||||
factory SpamReportConfig.initial() {
|
||||
return SpamReportConfig(
|
||||
isEnabled: true,
|
||||
lastTimeDismissedMilliseconds: 0,
|
||||
);
|
||||
}
|
||||
|
||||
factory SpamReportConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$SpamReportConfigFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$SpamReportConfigToJson(this);
|
||||
|
||||
@override
|
||||
List<Object> get props => [isEnabled, lastTimeDismissedMilliseconds];
|
||||
}
|
||||
|
||||
extension SpamReportConfigExtension on SpamReportConfig {
|
||||
SpamReportConfig copyWith({
|
||||
bool? isEnabled,
|
||||
int? lastTimeDismissedMilliseconds,
|
||||
}) {
|
||||
return SpamReportConfig(
|
||||
isEnabled: isEnabled ?? this.isEnabled,
|
||||
lastTimeDismissedMilliseconds:
|
||||
lastTimeDismissedMilliseconds ?? this.lastTimeDismissedMilliseconds,
|
||||
);
|
||||
}
|
||||
|
||||
SpamReportState get spamReportState =>
|
||||
isEnabled ? SpamReportState.enabled : SpamReportState.disabled;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/preferences/preferences_config.dart';
|
||||
|
||||
part 'thread_detail_config.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class ThreadDetailConfig extends PreferencesConfig {
|
||||
final bool isEnabled;
|
||||
|
||||
ThreadDetailConfig({this.isEnabled = false});
|
||||
|
||||
factory ThreadDetailConfig.initial() {
|
||||
return ThreadDetailConfig(
|
||||
isEnabled: false,
|
||||
);
|
||||
}
|
||||
|
||||
factory ThreadDetailConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$ThreadDetailConfigFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$ThreadDetailConfigToJson(this);
|
||||
|
||||
@override
|
||||
List<Object> get props => [isEnabled];
|
||||
}
|
||||
|
||||
extension ThreadDetailConfigExtension on ThreadDetailConfig {
|
||||
ThreadDetailConfig copyWith({bool? isEnabled}) {
|
||||
return ThreadDetailConfig(
|
||||
isEnabled: isEnabled ?? this.isEnabled,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user