@@ -121,11 +121,11 @@ class Auth2Account {
121
121
final List <Auth2StringEntry >? roles;
122
122
final List <Auth2StringEntry >? groups;
123
123
final List <Auth2Type >? authTypes;
124
+ final Map <String , dynamic >? systemConfigs;
124
125
125
-
126
- Auth2Account ({this .id, this .profile, this .prefs, this .permissions, this .roles, this .groups, this .authTypes});
126
+ Auth2Account ({this .id, this .profile, this .prefs, this .permissions, this .roles, this .groups, this .authTypes, this .systemConfigs});
127
127
128
- factory Auth2Account .fromOther (Auth2Account ? other, {String ? id, Auth2UserProfile ? profile, Auth2UserPrefs ? prefs, List <Auth2StringEntry >? permissions, List <Auth2StringEntry >? roles, List <Auth2StringEntry >? groups, List <Auth2Type >? authTypes}) {
128
+ factory Auth2Account .fromOther (Auth2Account ? other, {String ? id, Auth2UserProfile ? profile, Auth2UserPrefs ? prefs, List <Auth2StringEntry >? permissions, List <Auth2StringEntry >? roles, List <Auth2StringEntry >? groups, List <Auth2Type >? authTypes, Map < String , dynamic > ? systemConfigs }) {
129
129
return Auth2Account (
130
130
id: id ?? other? .id,
131
131
profile: profile ?? other? .profile,
@@ -134,6 +134,7 @@ class Auth2Account {
134
134
roles: roles ?? other? .roles,
135
135
groups: groups ?? other? .groups,
136
136
authTypes: authTypes ?? other? .authTypes,
137
+ systemConfigs: systemConfigs ?? other? .systemConfigs,
137
138
);
138
139
}
139
140
@@ -146,6 +147,7 @@ class Auth2Account {
146
147
roles: Auth2StringEntry .listFromJson (JsonUtils .listValue (json['roles' ])),
147
148
groups: Auth2StringEntry .listFromJson (JsonUtils .listValue (json['groups' ])),
148
149
authTypes: Auth2Type .listFromJson (JsonUtils .listValue (json['auth_types' ])),
150
+ systemConfigs: JsonUtils .mapValue (json['system_configs' ]),
149
151
) : null ;
150
152
}
151
153
@@ -158,6 +160,7 @@ class Auth2Account {
158
160
'roles' : roles,
159
161
'groups' : groups,
160
162
'auth_types' : authTypes,
163
+ 'system_configs' : systemConfigs,
161
164
};
162
165
}
163
166
@@ -169,7 +172,8 @@ class Auth2Account {
169
172
const DeepCollectionEquality ().equals (other.permissions, permissions) &&
170
173
const DeepCollectionEquality ().equals (other.roles, roles) &&
171
174
const DeepCollectionEquality ().equals (other.groups, groups) &&
172
- const DeepCollectionEquality ().equals (other.authTypes, authTypes);
175
+ const DeepCollectionEquality ().equals (other.authTypes, authTypes) &&
176
+ const DeepCollectionEquality ().equals (other.systemConfigs, systemConfigs);
173
177
174
178
@override
175
179
int get hashCode =>
@@ -178,7 +182,8 @@ class Auth2Account {
178
182
(const DeepCollectionEquality ().hash (permissions)) ^
179
183
(const DeepCollectionEquality ().hash (roles)) ^
180
184
(const DeepCollectionEquality ().hash (groups)) ^
181
- (const DeepCollectionEquality ().hash (authTypes));
185
+ (const DeepCollectionEquality ().hash (authTypes)) ^
186
+ (const DeepCollectionEquality ().hash (systemConfigs));
182
187
183
188
bool get isValid {
184
189
return (id != null ) && id! .isNotEmpty /* && (profile != null) && profile.isValid*/ ;
@@ -214,6 +219,7 @@ class Auth2Account {
214
219
bool hasRole (String role) => (Auth2StringEntry .findInList (roles, name: role) != null );
215
220
bool hasPermission (String premission) => (Auth2StringEntry .findInList (permissions, name: premission) != null );
216
221
bool bellongsToGroup (String group) => (Auth2StringEntry .findInList (groups, name: group) != null );
222
+ bool get isAnalyticsProcessed => (MapUtils .get (systemConfigs, 'analytics_processed_date' ) != null );
217
223
}
218
224
219
225
////////////////////////////////
@@ -960,6 +966,8 @@ class Auth2UserPrefs {
960
966
961
967
// Favorites
962
968
969
+ Iterable <String >? get favoritesKeys => _favorites? .keys;
970
+
963
971
LinkedHashSet <String >? getFavorites (String favoriteKey) {
964
972
return (_favorites != null ) ? _favorites! [favoriteKey] : null ;
965
973
}
@@ -1036,7 +1044,34 @@ class Auth2UserPrefs {
1036
1044
}
1037
1045
}
1038
1046
1039
- bool isListFavorite (List <Favorite >? favorites) {
1047
+ void setFavorite (Favorite ? favorite, bool value) {
1048
+ if ((favorite != null ) && (favorite.favoriteId != null )) {
1049
+ LinkedHashSet <String >? favoriteIdsForKey = (_favorites != null ) ? _favorites! [favorite.favoriteKey] : null ;
1050
+ bool isFavorite = (favoriteIdsForKey != null ) && favoriteIdsForKey.contains (favorite.favoriteId);
1051
+ bool isModified = false ;
1052
+ if (value && ! isFavorite) {
1053
+ if (favoriteIdsForKey == null ) {
1054
+ _favorites ?? = < String , LinkedHashSet <String >> {};
1055
+ // ignore: prefer_collection_literals
1056
+ _favorites! [favorite.favoriteKey] = favoriteIdsForKey = LinkedHashSet <String >();
1057
+ }
1058
+ favoriteIdsForKey.add (favorite.favoriteId! );
1059
+ isModified = true ;
1060
+ }
1061
+ else if (! value && isFavorite) {
1062
+ favoriteIdsForKey.remove (favorite.favoriteId);
1063
+ isModified = true ;
1064
+ }
1065
+
1066
+ if (isModified) {
1067
+ NotificationService ().notify (notifyFavoriteChanged, favorite);
1068
+ NotificationService ().notify (notifyFavoritesChanged);
1069
+ NotificationService ().notify (notifyChanged, this );
1070
+ }
1071
+ }
1072
+ }
1073
+
1074
+ bool isListFavorite (Iterable <Favorite >? favorites) {
1040
1075
if ((favorites != null ) && (_favorites != null )) {
1041
1076
for (Favorite favorite in favorites) {
1042
1077
if (! isFavorite (favorite)) {
@@ -1048,34 +1083,40 @@ class Auth2UserPrefs {
1048
1083
return false ;
1049
1084
}
1050
1085
1051
- void setListFavorite (List <Favorite >? favorites, bool shouldFavorite, {Favorite ? sourceFavorite}) {
1086
+ void setListFavorite (Iterable <Favorite >? favorites, bool shouldFavorite, {Favorite ? sourceFavorite}) {
1052
1087
if (favorites != null ) {
1053
- _favorites ?? = < String , LinkedHashSet <String >> {};
1054
1088
1089
+ bool isModified = false ;
1055
1090
for (Favorite favorite in favorites) {
1056
- LinkedHashSet <String >? favoriteIdsForKey = _favorites! [favorite.favoriteKey];
1057
- bool isFavorite = (favoriteIdsForKey != null ) && favoriteIdsForKey.contains (favorite.favoriteId);
1058
- if (isFavorite && ! shouldFavorite) {
1059
- favoriteIdsForKey.remove (favorite.favoriteId);
1060
- }
1061
- else if (! isFavorite && shouldFavorite) {
1062
- if (favoriteIdsForKey == null ) {
1063
- // ignore: prefer_collection_literals
1064
- _favorites! [favorite.favoriteKey] = favoriteIdsForKey = LinkedHashSet <String >();
1091
+ if (favorite.favoriteId != null ) {
1092
+ LinkedHashSet <String >? favoriteIdsForKey = (_favorites != null ) ? _favorites! [favorite.favoriteKey] : null ;
1093
+ bool isFavorite = (favoriteIdsForKey != null ) && favoriteIdsForKey.contains (favorite.favoriteId);
1094
+ if (shouldFavorite && ! isFavorite) {
1095
+ if (favoriteIdsForKey == null ) {
1096
+ _favorites ?? = < String , LinkedHashSet <String >> {};
1097
+ // ignore: prefer_collection_literals
1098
+ _favorites! [favorite.favoriteKey] = favoriteIdsForKey = LinkedHashSet <String >();
1099
+ }
1100
+ favoriteIdsForKey.add (favorite.favoriteId! );
1101
+ }
1102
+ else if (! shouldFavorite && isFavorite) {
1103
+ favoriteIdsForKey.remove (favorite.favoriteId);
1065
1104
}
1066
- SetUtils .add (favoriteIdsForKey, favorite.favoriteId);
1105
+ NotificationService ().notify (notifyFavoriteChanged, favorite);
1106
+ isModified = true ;
1067
1107
}
1068
- NotificationService ().notify (notifyFavoriteChanged, favorite);
1069
1108
}
1070
- if (sourceFavorite != null ) {
1071
- NotificationService ().notify (notifyFavoriteChanged, sourceFavorite);
1109
+ if (isModified) {
1110
+ if (sourceFavorite != null ) {
1111
+ NotificationService ().notify (notifyFavoriteChanged, sourceFavorite);
1112
+ }
1113
+ NotificationService ().notify (notifyFavoritesChanged);
1114
+ NotificationService ().notify (notifyChanged, this );
1072
1115
}
1073
- NotificationService ().notify (notifyFavoritesChanged);
1074
- NotificationService ().notify (notifyChanged, this );
1075
1116
}
1076
1117
}
1077
1118
1078
- void toggleListFavorite (List <Favorite >? favorites, {Favorite ? sourceFavorite}) {
1119
+ void toggleListFavorite (Iterable <Favorite >? favorites, {Favorite ? sourceFavorite}) {
1079
1120
setListFavorite (favorites, ! isListFavorite (favorites), sourceFavorite: sourceFavorite);
1080
1121
}
1081
1122
@@ -1384,22 +1425,23 @@ class Auth2UserPrefs {
1384
1425
}
1385
1426
// Settings
1386
1427
1387
- bool ? getBoolSetting ({String ? settingName, bool ? defaultValue}){
1388
- return JsonUtils .boolValue (getSetting (settingName: settingName)) ?? defaultValue;
1389
- }
1428
+ bool ? getBoolSetting (String ? settingName, { bool ? defaultValue }) =>
1429
+ JsonUtils .boolValue (getSetting (settingName)) ?? defaultValue;
1390
1430
1391
- dynamic getSetting ({String ? settingName}){
1392
- if (_settings? .isNotEmpty ?? false ){
1393
- return _settings! [settingName];
1394
- }
1431
+ int ? getIntSetting (String ? settingName, { int ? defaultValue }) =>
1432
+ JsonUtils .intValue (getSetting (settingName)) ?? defaultValue;
1395
1433
1396
- return null ;//consider default TBD
1397
- }
1398
-
1399
- void applySetting (String settingName, dynamic settingValue){
1400
- _settings ?? = < String , dynamic > {};
1401
- _settings! [settingName] = settingValue;
1434
+ dynamic getSetting (String ? settingName) =>
1435
+ (_settings != null ) ? _settings! [settingName] : null ;
1402
1436
1437
+ void applySetting (String settingName, dynamic settingValue) {
1438
+ if (settingValue != null ) {
1439
+ _settings ?? = < String , dynamic > {};
1440
+ _settings! [settingName] = settingValue;
1441
+ }
1442
+ else if (_settings != null ) {
1443
+ _settings! .remove (settingName);
1444
+ }
1403
1445
NotificationService ().notify (notifySettingsChanged);
1404
1446
NotificationService ().notify (notifyChanged, this );
1405
1447
}
0 commit comments