Skip to content

Commit

Permalink
89: Add release date sorting in user list page
Browse files Browse the repository at this point in the history
  • Loading branch information
JICA98 committed Aug 16, 2024
1 parent efa13e7 commit 94d8113
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 9 deletions.
6 changes: 3 additions & 3 deletions dal-api/dal_commons/lib/src/model/dal/commonV4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mixin ToJson {

mixin DataUnion {
Map<String, dynamic> toJson();
static DataUnion? fromJson(DataUnionType type, dynamic json) {
static DataUnion? fromJson(DataUnionType type, dynamic json, dynamic data) {
switch (type) {
case DataUnionType.character:
return CharacterV4Data.fromJson(json);
Expand All @@ -26,7 +26,7 @@ mixin DataUnion {
case DataUnionType.about:
return About.fromJson(json);
case DataUnionType.friend:
return FriendV4List.fromList(json as List);
return FriendV4List.fromList(json as List, data);
case DataUnionType.club:
return ClubV4List.fromList(json as List);
case DataUnionType.favorites:
Expand Down Expand Up @@ -67,7 +67,7 @@ class JikanV4Result<T extends DataUnion> {

JikanV4Result.fromJson(DataUnionType type, Map<String, dynamic>? json) {
if (json == null) return;
data = json['data'] != null ? DataUnion.fromJson(type, json['data']) as T? : null;
data = json['data'] != null ? DataUnion.fromJson(type, json['data'], json) as T? : null;
pagination = json['pagination'] != null
? Pagination.fromJson(json['pagination'])
: null;
Expand Down
9 changes: 6 additions & 3 deletions dal-api/dal_commons/lib/src/model/dal/friendv4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import 'commonV4.dart';

class FriendV4List implements DataUnion {
List<FriendV4>? friends;
FriendV4List.fromList(List<dynamic>? list) {
int? count;
FriendV4List.fromList(List<dynamic>? list, data) {
friends = list?.map<FriendV4>((e) => FriendV4.fromJson(e)).toList() ?? [];
count = data['count'];
}
FriendV4List.fromJson(Map<String, dynamic>? json) {
if (json == null) return;
friends = ((json['friends'] ?? []) as List)
.map<FriendV4>((e) => FriendV4.fromJson(e))
.toList() ??
[];
count = json['count'];
}
@override
Map<String, dynamic> toJson() {
return {'friends': friends};
return {'friends': friends, 'count': count};
}
}

Expand All @@ -25,7 +28,7 @@ class FriendV4 {

FriendV4({this.user, this.lastOnline, this.friendsSince});

FriendV4.fromJson(Map<String, dynamic> ?json) {
FriendV4.fromJson(Map<String, dynamic>? json) {
if (json == null) return;
user = json['user'] != null ? UserV4.fromJson(json['user']) : null;
lastOnline = json['last_online'];
Expand Down
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_en_US.dart
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,8 @@ class MessageLookup extends MessageLookupByLibrary {
"Reincarnation": MessageLookupByLibrary.simpleMessage("Reincarnation"),
"Related": MessageLookupByLibrary.simpleMessage("Related"),
"Related_Anime": MessageLookupByLibrary.simpleMessage("Related Anime"),
"ReleaseStartDate":
MessageLookupByLibrary.simpleMessage("Release Date"),
"Remove_Image":
MessageLookupByLibrary.simpleMessage("Remove Image from Home Page"),
"Remove_Image_desc": MessageLookupByLibrary.simpleMessage(
Expand Down
10 changes: 10 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -941,5 +941,6 @@
"Search": "Search",
"NextShow": "Next Show",
"Show": "Show",
"ReleaseStartDate": "Release Date",
"AnimeCalendar": "Anime Calendar"
}
23 changes: 23 additions & 0 deletions lib/widgets/listsortfilter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,25 @@ List<BaseNode> _sortListCustom(
n2Value = _getEpisodes(scheduleForMalIds[n2.id]) ?? n2Value;
}
break;
case 'release_date':
try {
final int? t1 = scheduleForMalIds[n1.id]?.timestamp;
final int? t2 = scheduleForMalIds[n2.id]?.timestamp;
final now = DateTime.now();
if (t1 != null) {
var dateTime = DateTime.fromMillisecondsSinceEpoch(t1 * 1000);
n1Value = -dateTime.difference(now).inMinutes;
} else {
n1Value = asc ? 100000 : -100000;
}
if (t2 != null) {
var dateTime = DateTime.fromMillisecondsSinceEpoch(t2 * 1000);
n2Value = -dateTime.difference(now).inMinutes;
} else {
n2Value = asc ? 100000 : -100000;
}
} catch (e) {}
break;
case 'popularity':
final temp = n1Value;
n1Value = n2Value;
Expand Down Expand Up @@ -454,6 +473,10 @@ class SortFilterOptions {
name: S.current.broadCastEndDate,
value: 'end_date',
),
SortOption(
name: S.current.ReleaseStartDate,
value: 'release_date',
),
];
} else {
return [
Expand Down
15 changes: 14 additions & 1 deletion lib/widgets/user/contentlistwidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ Widget buildBaseNodePageItem(
bool? showStatus,
}) {
Widget fromItem(int index, BaseNode node, [HomePageTileSize? tileSize]) {
if (node.content == null) {
return SB.z;
}
return _baseBaseNode(
category,
node,
Expand All @@ -293,12 +296,13 @@ Widget buildBaseNodePageItem(
return fromItem(index, item.rowItems.first);
} else {
homePageTileSize = _axisTileSizeMap[gridAxisCount];
final list = _padList(item.rowItems, gridAxisCount);
return SizedBox(
height: gridHeight,
child: Padding(
padding: const EdgeInsets.only(bottom: 7.0),
child: Row(
children: item.rowItems
children: list
.asMap()
.entries
.map((e) =>
Expand All @@ -310,6 +314,15 @@ Widget buildBaseNodePageItem(
}
}

List<BaseNode> _padList(List<BaseNode> list, int gridAxisCount) {
final padCount = gridAxisCount - list.length % gridAxisCount;
final newList = List<BaseNode>.from(list);
if (padCount != gridAxisCount) {
newList.addAll(List.generate(padCount, (_) => BaseNode()));
}
return newList;
}

Widget horizontalList({
required String category,
required List<BaseNode> items,
Expand Down
11 changes: 9 additions & 2 deletions lib/widgets/user/user_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ class UserHeader {
future: DalApi.i.getUserFriends(username),
builder: (_, snapshot) {
if (snapshot.hasData) {
final friends = snapshot.data?.friends ?? [];
final data = snapshot.data;
final friends = data?.friends ?? [];
int count;
if (friends.length == 100) {
count = data?.count ?? friends.length;
} else {
count = friends.length;
}
if (friends.isNotEmpty) {
return ListView(
padding: EdgeInsets.zero,
Expand All @@ -97,7 +104,7 @@ class UserHeader {
),
Padding(
padding: EdgeInsets.only(left: 20),
child: title("(${friends.length} ${S.current.friends})",
child: title("($count ${S.current.friends})",
fontStyle: FontStyle.italic)),
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
Expand Down

0 comments on commit 94d8113

Please sign in to comment.