Compare commits

..

No commits in common. "d009f9cc018c68a6f533d9cd9169d6df9b2be0ca" and "57ce270b4f810b1eb6b4dbaa1f04f14473587743" have entirely different histories.

4 changed files with 17 additions and 85 deletions

View File

@ -32,32 +32,18 @@ class SCUserBadgeRes {
final List<WearBadge> longBadges; final List<WearBadge> longBadges;
final List<WearBadge> shortBadges; final List<WearBadge> shortBadges;
List<WearBadge> get allBadges { List<WearBadge> get displayBadges {
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 {
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 { List<WearBadge> get honorWallBadges {
final source = final source =
shortBadges.isNotEmpty shortBadges.isNotEmpty
? shortBadges.where(_isHonorWallBadge).toList() ? shortBadges
: allBadges.where(_isHonorWallBadge).toList(); : displayBadges.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)));
@ -117,36 +103,20 @@ class SCUserBadgeRes {
type == "ACHIEVEMENT"; type == "ACHIEVEMENT";
} }
static bool isShortDisplayBadge(WearBadge badge) { static bool _isHonorWallBadge(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" || return sourceType == "ACTIVITY" || sourceType == "ACHIEVEMENT";
sourceType == "ACHIEVEMENT" ||
sourceType == "HONOR_ACTIVITY" ||
sourceType == "HONOR_ADMIN";
} }
if (type.isNotEmpty) { return type == "SHORT" ||
return type == "SHORT" || type == "ACTIVITY" ||
type == "ACTIVITY" || type == "ACHIEVEMENT" ||
type == "ACHIEVEMENT" || type == "HONOR_ACTIVITY" ||
type == "HONOR_ACTIVITY" || type == "HONOR_ADMIN";
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) { static int _badgeSortValue(WearBadge badge) {

View File

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

View File

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

View File

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