From ac26022da1033005a652f613587bde2e0f99dc62 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Thu, 28 Aug 2025 16:07:32 +0800 Subject: [PATCH] feat: fold dyn Closes #1153 Signed-off-by: bggRGjQaUbCoE --- lib/models/dynamics/result.dart | 17 +++++++ lib/pages/dynamics/widgets/dynamic_panel.dart | 50 ++++++++++++++++++- lib/pages/dynamics_tab/controller.dart | 13 +++++ lib/pages/dynamics_tab/view.dart | 5 +- 4 files changed, 82 insertions(+), 3 deletions(-) diff --git a/lib/models/dynamics/result.dart b/lib/models/dynamics/result.dart index c6a2afdd..149d7bbf 100644 --- a/lib/models/dynamics/result.dart +++ b/lib/models/dynamics/result.dart @@ -5,6 +5,7 @@ import 'package:PiliPlus/models/common/dynamic/dynamics_type.dart'; import 'package:PiliPlus/models/dynamics/article_content_model.dart'; import 'package:PiliPlus/models/model_avatar.dart'; import 'package:PiliPlus/models_new/live/live_feed_index/watched_show.dart'; +import 'package:PiliPlus/utils/extension.dart'; import 'package:PiliPlus/utils/storage_pref.dart'; class DynamicsDataModel { @@ -162,6 +163,7 @@ class ItemModulesModel { List? moduleExtend; // opus的tag List? moduleContent; ModuleBlocked? moduleBlocked; + ModuleFold? moduleFold; // moduleBottom @@ -179,6 +181,9 @@ class ItemModulesModel { moduleTag = json['module_tag'] != null ? ModuleTag.fromJson(json['module_tag']) : null; + moduleFold = json['module_fold'] != null + ? ModuleFold.fromJson(json['module_fold']) + : null; } ItemModulesModel.fromOpusJson(List json) { @@ -233,6 +238,18 @@ class ItemModulesModel { } } +class ModuleFold { + List? ids; + String? statement; + int? type; + + ModuleFold.fromJson(Map json) { + ids = (json['ids'] as List?)?.fromCast(); + statement = json['statement']; + type = json['type']; + } +} + class ModuleCollection { String? count; int? id; diff --git a/lib/pages/dynamics/widgets/dynamic_panel.dart b/lib/pages/dynamics/widgets/dynamic_panel.dart index a08df399..f6c93b66 100644 --- a/lib/pages/dynamics/widgets/dynamic_panel.dart +++ b/lib/pages/dynamics/widgets/dynamic_panel.dart @@ -20,6 +20,7 @@ class DynamicPanel extends StatelessWidget { final bool isSave; final Function(bool isTop, dynamic dynId)? onSetTop; final VoidCallback? onBlock; + final VoidCallback? onUnfold; const DynamicPanel({ super.key, @@ -31,10 +32,14 @@ class DynamicPanel extends StatelessWidget { this.isSave = false, this.onSetTop, this.onBlock, + this.onUnfold, }); @override Widget build(BuildContext context) { + if (item.visible == false) { + return const SizedBox.shrink(); + } final theme = Theme.of(context); final authorWidget = AuthorPanel( item: item, @@ -98,8 +103,49 @@ class DynamicPanel extends StatelessWidget { maxWidth: maxWidth, ), const SizedBox(height: 2), - if (!isDetail) ActionPanel(item: item), - if (isDetail && !isSave) const SizedBox(height: 12), + if (!isDetail) ...[ + ActionPanel(item: item), + if (item.modules.moduleFold case ModuleFold moduleFold) ...[ + Divider( + height: 1, + color: theme.dividerColor.withValues(alpha: 0.1), + ), + InkWell( + onTap: onUnfold, + child: Container( + alignment: Alignment.center, + padding: const EdgeInsets.symmetric(vertical: 10), + child: Text.rich( + textAlign: TextAlign.center, + style: TextStyle( + height: 1, + fontSize: 13, + color: theme.colorScheme.outline, + ), + strutStyle: const StrutStyle( + height: 1, + leading: 0, + fontSize: 13, + ), + TextSpan( + children: [ + TextSpan(text: moduleFold.statement ?? '展开'), + WidgetSpan( + alignment: PlaceholderAlignment.middle, + child: Icon( + size: 19, + Icons.keyboard_arrow_down, + color: theme.colorScheme.outline, + ), + ), + ], + ), + ), + ), + ), + ], + ] else if (!isSave) + const SizedBox(height: 12), ], ), ), diff --git a/lib/pages/dynamics_tab/controller.dart b/lib/pages/dynamics_tab/controller.dart index 8b1bf53f..bc3bcf64 100644 --- a/lib/pages/dynamics_tab/controller.dart +++ b/lib/pages/dynamics_tab/controller.dart @@ -74,4 +74,17 @@ class DynamicsTabController ..refresh(); } } + + void onUnfold(DynamicItemModel item, int index) { + try { + final list = loadingState.value.data!; + final ids = item.modules.moduleFold!.ids!; + final flag = index + ids.length + 1; + for (int i = index + 1; i < flag; i++) { + list[i].visible = true; + } + item.modules.moduleFold = null; + loadingState.refresh(); + } catch (_) {} + } } diff --git a/lib/pages/dynamics_tab/view.dart b/lib/pages/dynamics_tab/view.dart index 7258f329..429fb7b1 100644 --- a/lib/pages/dynamics_tab/view.dart +++ b/lib/pages/dynamics_tab/view.dart @@ -112,12 +112,14 @@ class _DynamicsTabPageState if (index == response.length - 1) { controller.onLoadMore(); } + final item = response[index]; return DynamicPanel( - item: response[index], + item: item, onRemove: (idStr) => controller.onRemove(index, idStr), onBlock: () => controller.onBlock(index), maxWidth: maxWidth, + onUnfold: () => controller.onUnfold(item, index), ); }, childCount: response!.length, @@ -135,6 +137,7 @@ class _DynamicsTabPageState controller.onRemove(index, idStr), onBlock: () => controller.onBlock(index), maxWidth: maxWidth, + onUnfold: () => controller.onUnfold(item, index), ); }, itemCount: response!.length,