feat: space opus

Closes #833

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-05-08 22:39:29 +08:00
parent bcd0d63db7
commit 2d75d89825
28 changed files with 1107 additions and 511 deletions

View File

@@ -0,0 +1,31 @@
class SpaceTabFilter {
SpaceTabFilter({
this.text,
required this.meta,
this.tabName,
});
String? text;
late String meta;
String? tabName;
SpaceTabFilter.fromJson(Map<String, dynamic> json) {
text = json['text'];
meta = json['meta'] ?? 'all';
tabName = json['tab_ame'];
}
@override
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
if (other is SpaceTabFilter) {
return meta == other.meta;
}
return false;
}
@override
int get hashCode => meta.hashCode;
}

View File

@@ -1,3 +1,4 @@
import 'package:PiliPlus/models/space/filter.dart';
import 'package:json_annotation/json_annotation.dart';
part 'item.g.dart';
@@ -56,6 +57,7 @@ class SpaceItem {
int? iconType;
@JsonKey(name: 'publish_time_text')
String? publishTimeText;
List<SpaceTabFilter>? filter;
SpaceItem({
this.title,
@@ -92,6 +94,7 @@ class SpaceItem {
this.viewContent,
this.iconType,
this.publishTimeText,
this.filter,
});
factory SpaceItem.fromJson(Map<String, dynamic> json) => _$ItemFromJson(json);

View File

@@ -43,6 +43,9 @@ SpaceItem _$ItemFromJson(Map<String, dynamic> json) => SpaceItem(
viewContent: json['view_content'] as String?,
iconType: (json['icon_type'] as num?)?.toInt(),
publishTimeText: json['publish_time_text'] as String?,
filter: (json['filter'] as List?)
?.map((e) => SpaceTabFilter.fromJson(e))
.toList(),
);
Map<String, dynamic> _$ItemToJson(SpaceItem instance) => <String, dynamic>{

View File

@@ -0,0 +1,27 @@
import 'package:flutter/foundation.dart';
class Cover {
int? height;
String? url;
int? width;
late double ratio;
Cover({this.height, this.url, this.width, required this.ratio});
Cover.fromJson(Map<String, dynamic> json) {
height = json['height'] as int?;
url = json['url'] as String?;
width = json['width'] as int?;
if (height != null && width != null) {
ratio = clampDouble(height! / width!, 0.68, 2.7);
} else {
ratio = 1;
}
}
Map<String, dynamic> toJson() => {
'height': height,
'url': url,
'width': width,
};
}

View File

@@ -0,0 +1,26 @@
import 'package:PiliPlus/models/space_opus/item.dart';
class SpaceOpusData {
bool? hasMore;
List<SpaceOpusItemModel>? items;
String? offset;
int? updateNum;
SpaceOpusData({this.hasMore, this.items, this.offset, this.updateNum});
factory SpaceOpusData.fromJson(Map<String, dynamic> json) => SpaceOpusData(
hasMore: json['has_more'] as bool?,
items: (json['items'] as List<dynamic>?)
?.map((e) => SpaceOpusItemModel.fromJson(e as Map<String, dynamic>))
.toList(),
offset: json['offset'] as String?,
updateNum: json['update_num'] as int?,
);
Map<String, dynamic> toJson() => {
'has_more': hasMore,
'items': items?.map((e) => e.toJson()).toList(),
'offset': offset,
'update_num': updateNum,
};
}

View File

@@ -0,0 +1,34 @@
import 'package:PiliPlus/models/space_opus/cover.dart';
import 'package:PiliPlus/models/space_opus/stat.dart';
class SpaceOpusItemModel {
String? content;
String? jumpUrl;
String? opusId;
Stat? stat;
Cover? cover;
SpaceOpusItemModel(
{this.content, this.jumpUrl, this.opusId, this.stat, this.cover});
factory SpaceOpusItemModel.fromJson(Map<String, dynamic> json) =>
SpaceOpusItemModel(
content: json['content'] as String?,
jumpUrl: json['jump_url'] as String?,
opusId: json['opus_id'] as String?,
stat: json['stat'] == null
? null
: Stat.fromJson(json['stat'] as Map<String, dynamic>),
cover: json['cover'] == null
? null
: Cover.fromJson(json['cover'] as Map<String, dynamic>),
);
Map<String, dynamic> toJson() => {
'content': content,
'jump_url': jumpUrl,
'opus_id': opusId,
'stat': stat?.toJson(),
'cover': cover?.toJson(),
};
}

View File

@@ -0,0 +1,13 @@
class Stat {
String? like;
Stat({this.like});
factory Stat.fromJson(Map<String, dynamic> json) => Stat(
like: json['like'] as String?,
);
Map<String, dynamic> toJson() => {
'like': like,
};
}