diff --git a/lib/models/dynamics/result.dart b/lib/models/dynamics/result.dart index 78991418..79a385b3 100644 --- a/lib/models/dynamics/result.dart +++ b/lib/models/dynamics/result.dart @@ -408,6 +408,7 @@ class DynamicMajorModel { this.live, this.none, this.type, + this.courses, }); DynamicArchiveModel? archive; @@ -422,6 +423,7 @@ class DynamicMajorModel { // MAJOR_TYPE_ARCHIVE 视频 // MAJOR_TYPE_OPUS 图文/文章 String? type; + Map? courses; DynamicMajorModel.fromJson(Map json) { archive = json['archive'] != null @@ -444,6 +446,7 @@ class DynamicMajorModel { none = json['none'] != null ? DynamicNoneModel.fromJson(json['none']) : null; type = json['type']; + courses = json['courses'] ?? {}; } } diff --git a/lib/pages/dynamics/controller.dart b/lib/pages/dynamics/controller.dart index 2656ba73..d8417d50 100644 --- a/lib/pages/dynamics/controller.dart +++ b/lib/pages/dynamics/controller.dart @@ -70,6 +70,10 @@ class DynamicsController extends GetxController { if (type == 'init') { dynamicsList.clear(); } + // 下拉刷新数据渲染时会触发onLoad + if (type == 'onLoad' && page == 1) { + return; + } isLoadingDynamic.value = true; var res = await DynamicsHttp.followDynamic( page: type == 'init' ? 1 : page, @@ -79,6 +83,10 @@ class DynamicsController extends GetxController { ); isLoadingDynamic.value = false; if (res['status']) { + if (type == 'onLoad' && res['data'].items.isEmpty) { + SmartDialog.showToast('没有更多了'); + return; + } if (type == 'init') { dynamicsList.value = res['data'].items; } else { @@ -219,6 +227,7 @@ class DynamicsController extends GetxController { onRefresh() async { page = 1; + print('onRefresh'); await queryFollowUp(); await queryFollowDynamic(); } diff --git a/lib/pages/dynamics/view.dart b/lib/pages/dynamics/view.dart index dbeee1fc..a29e1f91 100644 --- a/lib/pages/dynamics/view.dart +++ b/lib/pages/dynamics/view.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:custom_sliding_segmented_control/custom_sliding_segmented_control.dart'; +import 'package:easy_debounce/easy_throttle.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:get/get.dart'; @@ -30,7 +31,6 @@ class _DynamicsPageState extends State final DynamicsController _dynamicsController = Get.put(DynamicsController()); late Future _futureBuilderFuture; late Future _futureBuilderFutureUp; - bool _isLoadingMore = false; Box userInfoCache = GStrorage.userInfo; EventBus eventBus = EventBus(); late ScrollController scrollController; @@ -50,11 +50,10 @@ class _DynamicsPageState extends State () async { if (scrollController.position.pixels >= scrollController.position.maxScrollExtent - 200) { - if (!_isLoadingMore) { - _isLoadingMore = true; - await _dynamicsController.queryFollowDynamic(type: 'onLoad'); - _isLoadingMore = false; - } + EasyThrottle.throttle( + 'queryFollowDynamic', const Duration(seconds: 1), () { + _dynamicsController.queryFollowDynamic(type: 'onLoad'); + }); } final ScrollDirection direction = @@ -277,6 +276,7 @@ class _DynamicsPageState extends State } }, ), + const SliverToBoxAdapter(child: SizedBox(height: 40)) ], ), ), diff --git a/lib/pages/dynamics/widgets/action_panel.dart b/lib/pages/dynamics/widgets/action_panel.dart index 34b7f6af..53c9e497 100644 --- a/lib/pages/dynamics/widgets/action_panel.dart +++ b/lib/pages/dynamics/widgets/action_panel.dart @@ -37,7 +37,7 @@ class _ActionPanelState extends State { String dynamicId = item.idStr!; // 1 已点赞 2 不喜欢 0 未操作 Like like = item.modules.moduleStat.like; - int count = int.parse(like.count!); + int count = like.count == '点赞' ? 0 : int.parse(like.count ?? '0'); bool status = like.status!; int up = status ? 2 : 1; var res = await DynamicsHttp.likeDynamic(dynamicId: dynamicId, up: up); @@ -47,7 +47,11 @@ class _ActionPanelState extends State { item.modules.moduleStat.like.count = (count + 1).toString(); item.modules.moduleStat.like.status = true; } else { - item.modules.moduleStat.like.count = (count - 1).toString(); + if (count == 1) { + item.modules.moduleStat.like.count = '点赞'; + } else { + item.modules.moduleStat.like.count = (count - 1).toString(); + } item.modules.moduleStat.like.status = false; } setState(() {}); @@ -63,54 +67,63 @@ class _ActionPanelState extends State { return Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - TextButton.icon( - onPressed: () {}, - icon: const Icon( - FontAwesomeIcons.shareFromSquare, - size: 16, + Expanded( + flex: 1, + child: TextButton.icon( + onPressed: () {}, + icon: const Icon( + FontAwesomeIcons.shareFromSquare, + size: 16, + ), + style: TextButton.styleFrom( + padding: const EdgeInsets.fromLTRB(15, 0, 15, 0), + foregroundColor: Theme.of(context).colorScheme.outline, + ), + label: Text(stat.forward!.count ?? '转发'), ), - style: TextButton.styleFrom( - padding: const EdgeInsets.fromLTRB(15, 0, 15, 0), - foregroundColor: Theme.of(context).colorScheme.outline, - ), - label: Text(stat.forward!.count ?? '转发'), ), - TextButton.icon( - onPressed: () => - _dynamicsController.pushDetail(widget.item, 1, action: 'comment'), - icon: const Icon( - FontAwesomeIcons.comment, - size: 16, + Expanded( + flex: 1, + child: TextButton.icon( + onPressed: () => _dynamicsController.pushDetail(widget.item, 1, + action: 'comment'), + icon: const Icon( + FontAwesomeIcons.comment, + size: 16, + ), + style: TextButton.styleFrom( + padding: const EdgeInsets.fromLTRB(15, 0, 15, 0), + foregroundColor: Theme.of(context).colorScheme.outline, + ), + label: Text(stat.comment!.count ?? '评论'), ), - style: TextButton.styleFrom( - padding: const EdgeInsets.fromLTRB(15, 0, 15, 0), - foregroundColor: Theme.of(context).colorScheme.outline, - ), - label: Text(stat.comment!.count ?? '评论'), ), - TextButton.icon( - onPressed: () => onLikeDynamic(), - icon: Icon( - stat.like!.status! - ? FontAwesomeIcons.solidThumbsUp - : FontAwesomeIcons.thumbsUp, - size: 16, - color: stat.like!.status! ? primary : color, - ), - style: TextButton.styleFrom( - padding: const EdgeInsets.fromLTRB(15, 0, 15, 0), - foregroundColor: Theme.of(context).colorScheme.outline, - ), - label: AnimatedSwitcher( - duration: const Duration(milliseconds: 400), - transitionBuilder: (Widget child, Animation animation) { - return ScaleTransition(scale: animation, child: child); - }, - child: Text( - stat.like!.count ?? '点赞', - key: ValueKey(stat.like!.count ?? '点赞'), - style: TextStyle( - color: stat.like!.status! ? primary : color, + Expanded( + flex: 1, + child: TextButton.icon( + onPressed: () => onLikeDynamic(), + icon: Icon( + stat.like!.status! + ? FontAwesomeIcons.solidThumbsUp + : FontAwesomeIcons.thumbsUp, + size: 16, + color: stat.like!.status! ? primary : color, + ), + style: TextButton.styleFrom( + padding: const EdgeInsets.fromLTRB(15, 0, 15, 0), + foregroundColor: Theme.of(context).colorScheme.outline, + ), + label: AnimatedSwitcher( + duration: const Duration(milliseconds: 400), + transitionBuilder: (Widget child, Animation animation) { + return ScaleTransition(scale: animation, child: child); + }, + child: Text( + stat.like!.count ?? '点赞', + key: ValueKey(stat.like!.count ?? '点赞'), + style: TextStyle( + color: stat.like!.status! ? primary : color, + ), ), ), ), diff --git a/lib/pages/dynamics/widgets/forward_panel.dart b/lib/pages/dynamics/widgets/forward_panel.dart index e9e290b3..55972e37 100644 --- a/lib/pages/dynamics/widgets/forward_panel.dart +++ b/lib/pages/dynamics/widgets/forward_panel.dart @@ -100,6 +100,7 @@ Widget forWard(item, context, ctr, source, {floor = 1}) { // 直播 case 'DYNAMIC_TYPE_LIVE_RCMD': return liveRcmdPanel(item, context, floor: floor); + // 直播 case 'DYNAMIC_TYPE_LIVE': return livePanel(item, context, floor: floor); // 合集 @@ -147,6 +148,7 @@ Widget forWard(item, context, ctr, source, {floor = 1}) { return videoSeasonWidget(item, context, 'pgc', floor: floor); case 'DYNAMIC_TYPE_PGC_UNION': return videoSeasonWidget(item, context, 'pgc', floor: floor); + // 直播结束 case 'DYNAMIC_TYPE_NONE': return Row( children: [ @@ -158,7 +160,23 @@ Widget forWard(item, context, ctr, source, {floor = 1}) { Text(item.modules.moduleDynamic.major.none.tips) ], ); + // 课堂 + case 'DYNAMIC_TYPE_COURSES_SEASON': + return Row( + children: [ + Expanded( + child: Text( + "课堂💪:${item.modules.moduleDynamic.major.courses['title']}", + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ) + ], + ); default: - return const SizedBox(height: 0); + return const SizedBox( + width: double.infinity, + child: Text('🙏 暂未支持的类型,请联系开发者反馈 '), + ); } }