fix: filter long badges from short badge strips

This commit is contained in:
zhx 2026-05-18 11:09:55 +08:00
parent 57ce270b4f
commit 9f012fdb27
3 changed files with 32 additions and 15 deletions

View File

@ -32,18 +32,23 @@ class SCUserBadgeRes {
final List<WearBadge> longBadges;
final List<WearBadge> shortBadges;
List<WearBadge> get displayBadges {
List<WearBadge> get allBadges {
if (longBadges.isNotEmpty || shortBadges.isNotEmpty) {
return <WearBadge>[...longBadges, ...shortBadges];
}
return badges;
}
List<WearBadge> get displayBadges {
final source = shortBadges.isNotEmpty ? shortBadges : badges;
return source.where(isShortDisplayBadge).toList();
}
List<WearBadge> get honorWallBadges {
final source =
shortBadges.isNotEmpty
? shortBadges
: displayBadges.where(_isHonorWallBadge).toList();
? shortBadges.where(_isHonorWallBadge).toList()
: allBadges.where(_isHonorWallBadge).toList();
final result =
source.where((badge) => _badgeUrl(badge).isNotEmpty).toList();
result.sort((a, b) => _badgeSortValue(b).compareTo(_badgeSortValue(a)));
@ -103,20 +108,30 @@ class SCUserBadgeRes {
type == "ACHIEVEMENT";
}
static bool _isHonorWallBadge(WearBadge badge) {
static bool isShortDisplayBadge(WearBadge badge) {
final sourceType = badge.sourceType?.trim().toUpperCase() ?? "";
final type = badge.type?.trim().toUpperCase() ?? "";
if (type == "LONG" || type == "VIP" || sourceType == "VIP") {
return false;
}
if (sourceType.isNotEmpty) {
return sourceType == "ACTIVITY" || sourceType == "ACHIEVEMENT";
return sourceType == "ACTIVITY" ||
sourceType == "ACHIEVEMENT" ||
sourceType == "HONOR_ACTIVITY" ||
sourceType == "HONOR_ADMIN";
}
return type == "SHORT" ||
type == "ACTIVITY" ||
type == "ACHIEVEMENT" ||
type == "HONOR_ACTIVITY" ||
type == "HONOR_ADMIN";
if (type.isNotEmpty) {
return type == "SHORT" ||
type == "ACTIVITY" ||
type == "ACHIEVEMENT" ||
type == "HONOR_ACTIVITY" ||
type == "HONOR_ADMIN";
}
return true;
}
static bool _isHonorWallBadge(WearBadge badge) {
return isShortDisplayBadge(badge);
}
static int _badgeSortValue(WearBadge badge) {

View File

@ -110,6 +110,7 @@ class _SCUserBadgeStripState extends State<SCUserBadgeStrip> {
List<WearBadge> get _fallbackBadges {
return widget.fallbackBadges
.where(SCUserBadgeRes.isShortDisplayBadge)
.where((badge) => _badgeUrl(badge).isNotEmpty)
.toList();
}

View File

@ -32,11 +32,8 @@ void main() {
],
});
expect(result.displayBadges.map((badge) => badge.id), [
'vip',
'old',
'new',
]);
expect(result.allBadges.map((badge) => badge.id), ['vip', 'old', 'new']);
expect(result.displayBadges.map((badge) => badge.id), ['old', 'new']);
expect(result.honorWallBadges.map((badge) => badge.id), ['new', 'old']);
});
@ -73,6 +70,10 @@ void main() {
],
});
expect(result.displayBadges.map((badge) => badge.id), [
'activity',
'achievement',
]);
expect(result.honorWallBadges.map((badge) => badge.id), [
'achievement',
'activity',