From dcc99083a445a8c42aa091da1fefb5c1c70d732a Mon Sep 17 00:00:00 2001 From: guozhigq Date: Wed, 19 Apr 2023 16:43:15 +0800 Subject: [PATCH] mod: model_hot_video_item --- lib/common/widgets/video_card_h.dart | 18 +- lib/models/model_hot_video_item.dart | 162 ++++++++++++++++++ lib/models/model_owner.dart | 17 ++ ...eo_item.dart => model_rec_video_item.dart} | 24 +-- lib/pages/home/controller.dart | 2 +- lib/pages/hot/controller.dart | 14 +- 6 files changed, 202 insertions(+), 35 deletions(-) create mode 100644 lib/models/model_hot_video_item.dart create mode 100644 lib/models/model_owner.dart rename lib/models/{models_rec_video_item.dart => model_rec_video_item.dart} (82%) diff --git a/lib/common/widgets/video_card_h.dart b/lib/common/widgets/video_card_h.dart index 4003ce3b..5333ad72 100644 --- a/lib/common/widgets/video_card_h.dart +++ b/lib/common/widgets/video_card_h.dart @@ -47,7 +47,7 @@ class VideoCardH extends StatelessWidget { NetworkImgLayer( // src: videoItem['pic'] + // '@${(maxWidth * 2).toInt()}w', - src: videoItem['pic'] + '@.webp', + src: videoItem.pic + '@.webp', width: maxWidth, height: maxHeight, ), @@ -62,7 +62,7 @@ class VideoCardH extends StatelessWidget { borderRadius: BorderRadius.circular(4), color: Colors.black54.withOpacity(0.4)), child: Text( - Utils.timeFormat(videoItem['duration']!), + Utils.timeFormat(videoItem.duration!), style: const TextStyle( fontSize: 11, color: Colors.white), ), @@ -100,7 +100,7 @@ class VideoContent extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - videoItem['title'], + videoItem.title, textAlign: TextAlign.start, style: TextStyle( fontSize: Theme.of(context).textTheme.titleSmall!.fontSize, @@ -109,8 +109,8 @@ class VideoContent extends StatelessWidget { overflow: TextOverflow.ellipsis, ), const Spacer(), - if (videoItem['rcmd_reason'] != '' && - videoItem['rcmd_reason']['content'] != '') + if (videoItem.rcmdReason != '' && + videoItem.rcmdReason.content != '') Container( padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 5), decoration: BoxDecoration( @@ -119,7 +119,7 @@ class VideoContent extends StatelessWidget { color: Theme.of(context).colorScheme.surfaceTint), ), child: Text( - videoItem['rcmd_reason']['content'], + videoItem.rcmdReason.content, style: TextStyle( fontSize: 9, color: Theme.of(context).colorScheme.surfaceTint), @@ -135,7 +135,7 @@ class VideoContent extends StatelessWidget { ), const SizedBox(width: 2), Text( - videoItem['owner']['name'], + videoItem.owner.name, style: TextStyle( fontSize: Theme.of(context).textTheme.labelSmall!.fontSize, color: Theme.of(context).colorScheme.outline, @@ -147,11 +147,11 @@ class VideoContent extends StatelessWidget { children: [ StatView( theme: 'gray', - view: videoItem['stat']['view'], + view: videoItem.stat.view, ), const SizedBox(width: 8), Text( - Utils.dateFormat(videoItem['pubdate']!), + Utils.dateFormat(videoItem.pubdate!), style: TextStyle( fontSize: 11, color: Theme.of(context).colorScheme.outline), diff --git a/lib/models/model_hot_video_item.dart b/lib/models/model_hot_video_item.dart new file mode 100644 index 00000000..7c30dcd4 --- /dev/null +++ b/lib/models/model_hot_video_item.dart @@ -0,0 +1,162 @@ +import './model_owner.dart'; + +class HotVideoItemModel { + HotVideoItemModel({ + this.aid, + this.cid, + this.bvid, + this.videos, + this.tid, + this.tname, + this.copyright, + this.pic, + this.title, + this.pubdate, + this.ctime, + this.desc, + this.state, + this.duration, + this.middionId, + this.owner, + this.stat, + this.vDynamic, + this.dimension, + this.shortLinkV2, + this.firstFrame, + this.pubLocation, + this.seasontype, + this.isOgv, + this.rcmdReason, + }); + + int? aid; + int? cid; + String? bvid; + int? videos; + int? tid; + String? tname; + int? copyright; + String? pic; + String? title; + int? pubdate; + int? ctime; + String? desc; + int? state; + int? duration; + int? middionId; + Owner? owner; + Stat? stat; + String? vDynamic; + Dimension? dimension; + String? shortLinkV2; + String? firstFrame; + String? pubLocation; + int? seasontype; + bool? isOgv; + RcmdReason? rcmdReason; + + HotVideoItemModel.fromJson(Map json) { + aid = json["aid"]; + cid = json["cid"]; + bvid = json["bvid"]; + videos = json["videos"]; + tid = json["tid"]; + tname = json["tname"]; + copyright = json["copyright"]; + pic = json["pic"]; + title = json["title"]; + pubdate = json["pubdate"]; + ctime = json["ctime"]; + desc = json["desc"]; + state = json["state"]; + duration = json["duration"]; + middionId = json["middion_id"]; + owner = Owner.fromJson(json["owner"]); + stat = Stat.fromJson(json['stat']); + vDynamic = json["vDynamic"]; + dimension = Dimension.fromMap(json['dimension']); + shortLinkV2 = json["short_link_v2"]; + firstFrame = json["first_frame"]; + pubLocation = json["pub_location"]; + seasontype = json["seasontype"]; + isOgv = json["isOgv"]; + rcmdReason = RcmdReason.fromJson(json['rcmd_reason']); + } +} + +class Stat { + Stat({ + this.aid, + this.view, + this.danmaku, + this.reply, + this.favorite, + this.coin, + this.share, + this.nowRank, + this.hisRank, + this.like, + this.dislike, + this.vt, + this.vv, + }); + + int? aid; + int? view; + int? danmaku; + int? reply; + int? favorite; + int? coin; + int? share; + int? nowRank; + int? hisRank; + int? like; + int? dislike; + int? vt; + int? vv; + + Stat.fromJson(Map json) { + aid = json["aid"]; + view = json["view"]; + danmaku = json['danmaku']; + reply = json["reply"]; + favorite = json["favorite"]; + coin = json['coin']; + share = json["share"]; + nowRank = json["now_rank"]; + hisRank = json['his_rank']; + like = json["like"]; + dislike = json["dislike"]; + vt = json['vt']; + vv = json["vv"]; + } +} + +class Dimension { + Dimension({this.width, this.height, this.rotate}); + + int? width; + int? height; + int? rotate; + + Dimension.fromMap(Map json) { + width = json["width"]; + height = json["height"]; + rotate = json["rotate"]; + } +} + +class RcmdReason { + RcmdReason({ + this.rcornerMark, + this.content, + }); + + int? rcornerMark; + String? content = ''; + + RcmdReason.fromJson(Map json) { + rcornerMark = json["corner_mark"]; + content = json["content"] ?? ''; + } +} diff --git a/lib/models/model_owner.dart b/lib/models/model_owner.dart new file mode 100644 index 00000000..6ef425eb --- /dev/null +++ b/lib/models/model_owner.dart @@ -0,0 +1,17 @@ +class Owner { + Owner({ + this.mid, + this.name, + this.face, + }); + + int? mid; + String? name; + String? face; + + Owner.fromJson(Map json) { + mid = json["mid"]; + name = json["name"]; + face = json['face']; + } +} diff --git a/lib/models/models_rec_video_item.dart b/lib/models/model_rec_video_item.dart similarity index 82% rename from lib/models/models_rec_video_item.dart rename to lib/models/model_rec_video_item.dart index b37988a7..849def9f 100644 --- a/lib/models/models_rec_video_item.dart +++ b/lib/models/model_rec_video_item.dart @@ -1,3 +1,5 @@ +import './model_owner.dart'; + class RecVideoItemModel { RecVideoItemModel({ this.id, @@ -23,7 +25,7 @@ class RecVideoItemModel { String? title = ''; int? duration = -1; int? pubdate = -1; - Onwer? owner; + Owner? owner; Stat? stat; RcmdReason? rcmdReason; @@ -37,7 +39,7 @@ class RecVideoItemModel { title = json["title"]; duration = json["duration"]; pubdate = json["pubdate"]; - owner = Onwer.fromJson(json["owner"]); + owner = Owner.fromJson(json["owner"]); stat = Stat.fromJson(json["stat"]); rcmdReason = json["rcmd_reason"] != null ? RcmdReason.fromJson(json["rcmd_reason"]) @@ -45,24 +47,6 @@ class RecVideoItemModel { } } -class Onwer { - Onwer({ - this.mid, - this.name, - this.face, - }); - - int? mid; - String? name; - String? face; - - Onwer.fromJson(Map json) { - mid = json["mid"]; - name = json["name"]; - face = json['face']; - } -} - class Stat { Stat({ this.view, diff --git a/lib/pages/home/controller.dart b/lib/pages/home/controller.dart index 32aa8111..a81b9591 100644 --- a/lib/pages/home/controller.dart +++ b/lib/pages/home/controller.dart @@ -2,7 +2,7 @@ import 'package:flutter/cupertino.dart'; import 'package:get/get.dart'; import 'package:pilipala/http/api.dart'; import 'package:pilipala/http/init.dart'; -import 'package:pilipala/models/models_rec_video_item.dart'; +import 'package:pilipala/models/model_rec_video_item.dart'; class HomeController extends GetxController { final ScrollController scrollController = ScrollController(); diff --git a/lib/pages/hot/controller.dart b/lib/pages/hot/controller.dart index 1df71824..ced43a7b 100644 --- a/lib/pages/hot/controller.dart +++ b/lib/pages/hot/controller.dart @@ -3,12 +3,13 @@ import 'package:flutter/cupertino.dart'; import 'package:get/get.dart'; import 'package:pilipala/http/api.dart'; import 'package:pilipala/http/init.dart'; +import 'package:pilipala/models/model_hot_video_item.dart'; class HotController extends GetxController { final ScrollController scrollController = ScrollController(); final int _count = 20; int _currentPage = 1; - RxList videoList = [].obs; + RxList videoList = [HotVideoItemModel()].obs; bool isLoadingMore = false; bool flag = false; @@ -24,13 +25,16 @@ class HotController extends GetxController { Api.hotList, data: {'pn': _currentPage, 'ps': _count}, ); - var data = res.data['data']['list']; + List list = []; + for (var i in res.data['data']['list']) { + list.add(HotVideoItemModel.fromJson(i)); + } if (type == 'init') { - videoList.value = data; + videoList.value = list; } else if (type == 'onRefresh') { - videoList.insertAll(0, data); + videoList.insertAll(0, list); } else if (type == 'onLoad') { - videoList.addAll(data); + videoList.addAll(list); } _currentPage += 1; isLoadingMore = false;