Compare commits
No commits in common. "d009f9cc018c68a6f533d9cd9169d6df9b2be0ca" and "57ce270b4f810b1eb6b4dbaa1f04f14473587743" have entirely different histories.
d009f9cc01
...
57ce270b4f
@ -32,32 +32,18 @@ class SCUserBadgeRes {
|
||||
final List<WearBadge> longBadges;
|
||||
final List<WearBadge> shortBadges;
|
||||
|
||||
List<WearBadge> get allBadges {
|
||||
List<WearBadge> get displayBadges {
|
||||
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.where(_isHonorWallBadge).toList()
|
||||
: allBadges.where(_isHonorWallBadge).toList();
|
||||
? shortBadges
|
||||
: displayBadges.where(_isHonorWallBadge).toList();
|
||||
final result =
|
||||
source.where((badge) => _badgeUrl(badge).isNotEmpty).toList();
|
||||
result.sort((a, b) => _badgeSortValue(b).compareTo(_badgeSortValue(a)));
|
||||
@ -117,36 +103,20 @@ class SCUserBadgeRes {
|
||||
type == "ACHIEVEMENT";
|
||||
}
|
||||
|
||||
static bool isShortDisplayBadge(WearBadge badge) {
|
||||
static bool _isHonorWallBadge(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" ||
|
||||
sourceType == "HONOR_ACTIVITY" ||
|
||||
sourceType == "HONOR_ADMIN";
|
||||
return sourceType == "ACTIVITY" || sourceType == "ACHIEVEMENT";
|
||||
}
|
||||
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);
|
||||
return type == "SHORT" ||
|
||||
type == "ACTIVITY" ||
|
||||
type == "ACHIEVEMENT" ||
|
||||
type == "HONOR_ACTIVITY" ||
|
||||
type == "HONOR_ADMIN";
|
||||
}
|
||||
|
||||
static int _badgeSortValue(WearBadge badge) {
|
||||
|
||||
@ -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/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,
|
||||
@ -26,7 +23,6 @@ class SCUserBadgeStrip extends StatefulWidget {
|
||||
|
||||
final String? userId;
|
||||
final List<WearBadge> fallbackBadges;
|
||||
final SCUserBadgeDisplayScope displayScope;
|
||||
final double? height;
|
||||
final double? badgeHeight;
|
||||
final double? longBadgeWidth;
|
||||
@ -104,7 +100,8 @@ class _SCUserBadgeStripState extends State<SCUserBadgeStrip> {
|
||||
return FutureBuilder<SCUserBadgeRes>(
|
||||
future: future,
|
||||
builder: (context, snapshot) {
|
||||
final remoteBadges = _remoteBadges(snapshot.data);
|
||||
final remoteBadges =
|
||||
snapshot.data?.displayBadges ?? const <WearBadge>[];
|
||||
final badges = remoteBadges.isNotEmpty ? remoteBadges : _fallbackBadges;
|
||||
return _buildBadges(badges, stripHeight);
|
||||
},
|
||||
@ -113,38 +110,10 @@ 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
|
||||
|
||||
@ -498,7 +498,6 @@ 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,
|
||||
|
||||
@ -32,9 +32,11 @@ void main() {
|
||||
],
|
||||
});
|
||||
|
||||
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.displayBadges.map((badge) => badge.id), [
|
||||
'vip',
|
||||
'old',
|
||||
'new',
|
||||
]);
|
||||
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), [
|
||||
'achievement',
|
||||
'activity',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user