Skip to content

Commit aebee9d

Browse files
committed
feat(profile): automatically parse dynamic attr types
This commit removed hard-coded dynamic attr types and parsing types automatically. Added support for the optional second dynamic attr.
1 parent 16d7d4a commit aebee9d

File tree

5 files changed

+60
-50
lines changed

5 files changed

+60
-50
lines changed

lib/features/profile/bloc/profile_bloc.dart

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> with LoggerMixin {
337337
String? specialAttr;
338338
// Name of special attr.
339339
String? specialAttrName;
340+
// Special attr that changes over time. Optionally used.
341+
String? specialAttr2;
342+
// Name of special attr. Optionally used.
343+
String? specialAttrName2;
340344

341345
final statisticsInfoList = profileRootNode
342346
.querySelectorAll('div#psts > ul > li')
@@ -358,26 +362,16 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> with LoggerMixin {
358362
scheming = stat.$2;
359363
case '精灵':
360364
spirit = stat.$2;
361-
// Special attr that changes over time.
362-
// 2023 春节
363-
case '龙之印章':
364-
specialAttr = stat.$2;
365-
specialAttrName = '龙之印章';
366-
// 2024 夏日
367-
case '西瓜':
368-
specialAttr = stat.$2;
369-
specialAttrName = '西瓜';
370-
// 2024 坛庆
371-
case '爱心❤':
372-
specialAttr = stat.$2;
373-
specialAttrName = '爱心';
374-
case '金蛋':
375-
specialAttr = stat.$2;
376-
specialAttrName = '金蛋';
377-
// 2025 坛庆
378-
case '魔法石':
379-
specialAttr = stat.$2;
380-
specialAttrName = '魔法石';
365+
default:
366+
{
367+
if (specialAttr == null) {
368+
specialAttr = stat.$2;
369+
specialAttrName = stat.$1.trim().replaceFirst(':', '');
370+
} else {
371+
specialAttr2 = stat.$2;
372+
specialAttrName2 = stat.$1.trim().replaceFirst(':', '');
373+
}
374+
}
381375
}
382376
}
383377

@@ -441,6 +435,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> with LoggerMixin {
441435
spirit: spirit,
442436
specialAttr: specialAttr,
443437
specialAttrName: specialAttrName,
438+
specialAttr2: specialAttr2,
439+
specialAttrName2: specialAttrName2,
444440
);
445441

446442
return TaskEither.right(profile);

lib/features/profile/models/user_profile.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class UserProfile with UserProfileMappable {
5454
required this.spirit,
5555
required this.specialAttr,
5656
required this.specialAttrName,
57+
required this.specialAttr2,
58+
required this.specialAttrName2,
5759
});
5860

5961
/// Url of user avatar.
@@ -240,10 +242,18 @@ class UserProfile with UserProfileMappable {
240242
final String? spirit;
241243

242244
/// Special attr changes over time.
243-
///
244-
/// 龙之印章/西瓜/爱心/金蛋/魔法石
245245
final String? specialAttr;
246246

247247
/// Special attr name.
248248
final String? specialAttrName;
249+
250+
/// Special attr changes over time.
251+
///
252+
/// The other attr, optionally used.
253+
final String? specialAttr2;
254+
255+
/// Special attr name.
256+
///
257+
/// The other attr, optionally used.
258+
final String? specialAttrName2;
249259
}

lib/features/profile/view/profile_page.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,8 @@ class _ProfilePageState extends State<ProfilePage> {
839839
// Here is dynamic and not translated.
840840
if (userProfile.specialAttr != null && userProfile.specialAttrName != null)
841841
AttrBlock(name: userProfile.specialAttrName!, value: userProfile.specialAttr!),
842+
if (userProfile.specialAttr2 != null && userProfile.specialAttrName2 != null)
843+
AttrBlock(name: userProfile.specialAttrName2!, value: userProfile.specialAttr2!),
842844
],
843845
),
844846
];

lib/shared/models/user_brief_profile.dart

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ final class UserBriefProfile with UserBriefProfileMappable {
2323
required this.spirit,
2424
required this.specialAttr,
2525
required this.specialAttrName,
26+
required this.specialAttr2,
27+
required this.specialAttrName2,
2628
required this.couple,
2729
required this.privilege,
2830
required this.registrationDate,
@@ -111,13 +113,17 @@ final class UserBriefProfile with UserBriefProfileMappable {
111113
final String spirit;
112114

113115
/// Special attr that changes over time.
114-
///
115-
/// 龙之印章/西瓜/爱心/金蛋/魔法石
116116
final String specialAttr;
117117

118118
/// Name of [specialAttr].
119119
final String specialAttrName;
120120

121+
/// Special attr that changes over time.
122+
final String? specialAttr2;
123+
124+
/// Name of [specialAttr].
125+
final String? specialAttrName2;
126+
121127
// TODO: Reserve as link.
122128
/// Couple username.
123129
///
@@ -201,8 +207,9 @@ final class UserBriefProfile with UserBriefProfileMappable {
201207
String? scheming;
202208
String? spirit;
203209
String? specialAttr;
204-
// Name of special attr.
205210
String? specialAttrName;
211+
String? specialAttr2;
212+
String? specialAttrName2;
206213
String? couple;
207214
String? privilege;
208215
String? registrationDate;
@@ -231,33 +238,18 @@ final class UserBriefProfile with UserBriefProfileMappable {
231238
'阅读权限:' => privilege = data,
232239
'注册时间:' => registrationDate = data,
233240
'来自:' => comeFrom = data,
234-
// Special attr that changes over time.
235-
// 2024 春节
236-
'龙之印章:' => () {
237-
specialAttr = data;
238-
specialAttrName = '龙之印章';
239-
}(),
240-
// 2024 夏日
241-
'西瓜:' => () {
242-
specialAttr = data;
243-
specialAttrName = '西瓜';
244-
}(),
245-
// 2024 坛庆
246-
'爱心❤:' => () {
247-
specialAttr = data;
248-
specialAttrName = '爱心';
249-
}(),
250-
// 2025 春节
251-
'金蛋:' => () {
252-
specialAttr = data;
253-
specialAttrName = '金蛋';
241+
'状态:' => () {
242+
/* Do nothing */
254243
}(),
255-
// 2025 坛庆
256-
'魔法石:' => () {
257-
specialAttr = data;
258-
specialAttrName = '魔法石';
244+
final String v => () {
245+
if (specialAttr == null) {
246+
specialAttr = data;
247+
specialAttrName = v.trim().replaceFirst(':', '');
248+
} else {
249+
specialAttr2 = data;
250+
specialAttrName2 = v.trim().replaceFirst(':', '');
251+
}
259252
}(),
260-
_ => '',
261253
};
262254
}
263255

@@ -282,6 +274,8 @@ final class UserBriefProfile with UserBriefProfileMappable {
282274
spirit: spirit ?? '',
283275
specialAttr: specialAttr ?? '',
284276
specialAttrName: specialAttrName ?? '',
277+
specialAttr2: specialAttr2,
278+
specialAttrName2: specialAttrName2,
285279
couple: couple ?? '',
286280
privilege: privilege ?? '',
287281
registrationDate: registrationDate ?? '',

lib/widgets/card/post_card/show_user_brief_profile_dialog.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ class _UserBriefProfileDialogState extends State<_UserBriefProfileDialog> {
191191
widget.profile.specialAttr,
192192
Colors.purple[colorOffset],
193193
),
194+
// Optional special attr, dynamic and not tranlsated.
195+
if (widget.profile.specialAttr2 != null && widget.profile.specialAttrName2 != null)
196+
_UserProfilePair(
197+
MdiIcons.heartOutline,
198+
widget.profile.specialAttrName2!,
199+
widget.profile.specialAttr2,
200+
Colors.purple[colorOffset],
201+
),
194202
if (widget.profile.couple != null && widget.profile.couple!.isNotEmpty)
195203
_UserProfilePair(Icons.diversity_1_outlined, tr.cp, widget.profile.couple, Colors.pink[colorOffset]),
196204
_UserProfilePair(Icons.feedback_outlined, tr.privilege, widget.profile.privilege, Colors.orange[colorOffset]),

0 commit comments

Comments
 (0)