fix: filter long badges from short badge strips
This commit is contained in:
parent
57ce270b4f
commit
9f012fdb27
@ -32,18 +32,23 @@ class SCUserBadgeRes {
|
|||||||
final List<WearBadge> longBadges;
|
final List<WearBadge> longBadges;
|
||||||
final List<WearBadge> shortBadges;
|
final List<WearBadge> shortBadges;
|
||||||
|
|
||||||
List<WearBadge> get displayBadges {
|
List<WearBadge> get allBadges {
|
||||||
if (longBadges.isNotEmpty || shortBadges.isNotEmpty) {
|
if (longBadges.isNotEmpty || shortBadges.isNotEmpty) {
|
||||||
return <WearBadge>[...longBadges, ...shortBadges];
|
return <WearBadge>[...longBadges, ...shortBadges];
|
||||||
}
|
}
|
||||||
return badges;
|
return badges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<WearBadge> get displayBadges {
|
||||||
|
final source = shortBadges.isNotEmpty ? shortBadges : badges;
|
||||||
|
return source.where(isShortDisplayBadge).toList();
|
||||||
|
}
|
||||||
|
|
||||||
List<WearBadge> get honorWallBadges {
|
List<WearBadge> get honorWallBadges {
|
||||||
final source =
|
final source =
|
||||||
shortBadges.isNotEmpty
|
shortBadges.isNotEmpty
|
||||||
? shortBadges
|
? shortBadges.where(_isHonorWallBadge).toList()
|
||||||
: displayBadges.where(_isHonorWallBadge).toList();
|
: allBadges.where(_isHonorWallBadge).toList();
|
||||||
final result =
|
final result =
|
||||||
source.where((badge) => _badgeUrl(badge).isNotEmpty).toList();
|
source.where((badge) => _badgeUrl(badge).isNotEmpty).toList();
|
||||||
result.sort((a, b) => _badgeSortValue(b).compareTo(_badgeSortValue(a)));
|
result.sort((a, b) => _badgeSortValue(b).compareTo(_badgeSortValue(a)));
|
||||||
@ -103,20 +108,30 @@ class SCUserBadgeRes {
|
|||||||
type == "ACHIEVEMENT";
|
type == "ACHIEVEMENT";
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool _isHonorWallBadge(WearBadge badge) {
|
static bool isShortDisplayBadge(WearBadge badge) {
|
||||||
final sourceType = badge.sourceType?.trim().toUpperCase() ?? "";
|
final sourceType = badge.sourceType?.trim().toUpperCase() ?? "";
|
||||||
final type = badge.type?.trim().toUpperCase() ?? "";
|
final type = badge.type?.trim().toUpperCase() ?? "";
|
||||||
if (type == "LONG" || type == "VIP" || sourceType == "VIP") {
|
if (type == "LONG" || type == "VIP" || sourceType == "VIP") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (sourceType.isNotEmpty) {
|
if (sourceType.isNotEmpty) {
|
||||||
return sourceType == "ACTIVITY" || sourceType == "ACHIEVEMENT";
|
return sourceType == "ACTIVITY" ||
|
||||||
|
sourceType == "ACHIEVEMENT" ||
|
||||||
|
sourceType == "HONOR_ACTIVITY" ||
|
||||||
|
sourceType == "HONOR_ADMIN";
|
||||||
}
|
}
|
||||||
return type == "SHORT" ||
|
if (type.isNotEmpty) {
|
||||||
type == "ACTIVITY" ||
|
return type == "SHORT" ||
|
||||||
type == "ACHIEVEMENT" ||
|
type == "ACTIVITY" ||
|
||||||
type == "HONOR_ACTIVITY" ||
|
type == "ACHIEVEMENT" ||
|
||||||
type == "HONOR_ADMIN";
|
type == "HONOR_ACTIVITY" ||
|
||||||
|
type == "HONOR_ADMIN";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool _isHonorWallBadge(WearBadge badge) {
|
||||||
|
return isShortDisplayBadge(badge);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _badgeSortValue(WearBadge badge) {
|
static int _badgeSortValue(WearBadge badge) {
|
||||||
|
|||||||
@ -110,6 +110,7 @@ class _SCUserBadgeStripState extends State<SCUserBadgeStrip> {
|
|||||||
|
|
||||||
List<WearBadge> get _fallbackBadges {
|
List<WearBadge> get _fallbackBadges {
|
||||||
return widget.fallbackBadges
|
return widget.fallbackBadges
|
||||||
|
.where(SCUserBadgeRes.isShortDisplayBadge)
|
||||||
.where((badge) => _badgeUrl(badge).isNotEmpty)
|
.where((badge) => _badgeUrl(badge).isNotEmpty)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,11 +32,8 @@ void main() {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.displayBadges.map((badge) => badge.id), [
|
expect(result.allBadges.map((badge) => badge.id), ['vip', 'old', 'new']);
|
||||||
'vip',
|
expect(result.displayBadges.map((badge) => badge.id), ['old', 'new']);
|
||||||
'old',
|
|
||||||
'new',
|
|
||||||
]);
|
|
||||||
expect(result.honorWallBadges.map((badge) => badge.id), ['new', 'old']);
|
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), [
|
expect(result.honorWallBadges.map((badge) => badge.id), [
|
||||||
'achievement',
|
'achievement',
|
||||||
'activity',
|
'activity',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user