Compare commits

...

2 Commits

Author SHA1 Message Date
zhx
d009f9cc01 fix: show long badges on room user card 2026-05-18 11:13:36 +08:00
zhx
9f012fdb27 fix: filter long badges from short badge strips 2026-05-18 11:09:55 +08:00
4 changed files with 85 additions and 17 deletions

View File

@ -32,18 +32,32 @@ 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 {
return shortDisplayBadges;
}
List<WearBadge> get shortDisplayBadges {
final source = shortBadges.isNotEmpty ? shortBadges : badges;
return source.where(isShortDisplayBadge).toList();
}
List<WearBadge> get longDisplayBadges {
final source = longBadges.isNotEmpty ? longBadges : badges;
return source.where(isLongDisplayBadge).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 +117,36 @@ 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 isLongDisplayBadge(WearBadge badge) {
final sourceType = badge.sourceType?.trim().toUpperCase() ?? "";
final type = badge.type?.trim().toUpperCase() ?? "";
return type == "LONG" || type == "VIP" || sourceType == "VIP";
}
static bool _isHonorWallBadge(WearBadge badge) {
return isShortDisplayBadge(badge);
}
static int _badgeSortValue(WearBadge badge) {

View File

@ -6,11 +6,14 @@ import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart';
import 'package:yumi/ui_kit/components/sc_compontent.dart';
enum SCUserBadgeDisplayScope { short, long, all }
class SCUserBadgeStrip extends StatefulWidget {
const SCUserBadgeStrip({
super.key,
this.userId,
this.fallbackBadges = const <WearBadge>[],
this.displayScope = SCUserBadgeDisplayScope.short,
this.height,
this.badgeHeight,
this.longBadgeWidth,
@ -23,6 +26,7 @@ class SCUserBadgeStrip extends StatefulWidget {
final String? userId;
final List<WearBadge> fallbackBadges;
final SCUserBadgeDisplayScope displayScope;
final double? height;
final double? badgeHeight;
final double? longBadgeWidth;
@ -100,8 +104,7 @@ class _SCUserBadgeStripState extends State<SCUserBadgeStrip> {
return FutureBuilder<SCUserBadgeRes>(
future: future,
builder: (context, snapshot) {
final remoteBadges =
snapshot.data?.displayBadges ?? const <WearBadge>[];
final remoteBadges = _remoteBadges(snapshot.data);
final badges = remoteBadges.isNotEmpty ? remoteBadges : _fallbackBadges;
return _buildBadges(badges, stripHeight);
},
@ -110,10 +113,38 @@ class _SCUserBadgeStripState extends State<SCUserBadgeStrip> {
List<WearBadge> get _fallbackBadges {
return widget.fallbackBadges
.where(_matchesDisplayScope)
.where((badge) => _badgeUrl(badge).isNotEmpty)
.toList();
}
List<WearBadge> _remoteBadges(SCUserBadgeRes? data) {
if (data == null) {
return const <WearBadge>[];
}
switch (widget.displayScope) {
case SCUserBadgeDisplayScope.long:
return data.longDisplayBadges;
case SCUserBadgeDisplayScope.all:
return data.allBadges
.where((badge) => _badgeUrl(badge).isNotEmpty)
.toList();
case SCUserBadgeDisplayScope.short:
return data.shortDisplayBadges;
}
}
bool _matchesDisplayScope(WearBadge badge) {
switch (widget.displayScope) {
case SCUserBadgeDisplayScope.long:
return SCUserBadgeRes.isLongDisplayBadge(badge);
case SCUserBadgeDisplayScope.all:
return true;
case SCUserBadgeDisplayScope.short:
return SCUserBadgeRes.isShortDisplayBadge(badge);
}
}
Widget _buildBadges(List<WearBadge> rawBadges, double stripHeight) {
final badges =
widget.maxBadges == null

View File

@ -498,6 +498,7 @@ class _RoomUserInfoCardState extends State<RoomUserInfoCard> {
return SCUserBadgeStrip(
userId: userId,
fallbackBadges: _roomCardFallbackBadges(ref, profile),
displayScope: SCUserBadgeDisplayScope.long,
height: 82.w,
badgeHeight: 34.5.w,
longBadgeWidth: 87.w,

View File

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