diff --git a/lib/pages/article/controller.dart b/lib/pages/article/controller.dart index 681b243a..9d8bcb5c 100644 --- a/lib/pages/article/controller.dart +++ b/lib/pages/article/controller.dart @@ -11,7 +11,7 @@ import 'package:PiliPlus/models/space_article/item.dart'; import 'package:PiliPlus/pages/common/reply_controller.dart'; import 'package:PiliPlus/pages/mine/controller.dart'; import 'package:PiliPlus/utils/storage.dart'; -import 'package:flutter/material.dart'; +import 'package:PiliPlus/utils/url_utils.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:PiliPlus/http/reply.dart'; @@ -21,9 +21,7 @@ class ArticleController extends ReplyController { late String id; late String type; - late String url = type == 'read' - ? 'https://www.bilibili.com/read/cv$id' - : 'https://www.bilibili.com/opus/$id'; + late String url; late int commentType; late int commentId; final summary = Summary(); @@ -50,12 +48,31 @@ class ArticleController extends ReplyController { id = Get.parameters['id']!; type = Get.parameters['type']!; - commentType = type == 'picture' ? 11 : 12; - - _queryContent(); // lazy to opus + // to opus + if (type == 'read') { + UrlUtils.parseRedirectUrl('https://www.bilibili.com/read/cv$id/') + .then((url) { + if (url != null) { + id = url.split('/').last; + type = 'opus'; + } + init(); + }); + } else { + init(); + } } - Future _queryOpus(opusId) async { + init() { + url = type == 'read' + ? 'https://www.bilibili.com/read/cv$id' + : 'https://www.bilibili.com/opus/$id'; + commentType = type == 'picture' ? 11 : 12; + + _queryContent(); + } + + Future queryOpus(opusId) async { final res = await DynamicsHttp.opusDetail(opusId: opusId); if (res.isSuccess) { final opusData = res.data; @@ -63,49 +80,42 @@ class ArticleController extends ReplyController { if (opusData.fallback?.id != null) { id = opusData.fallback!.id!; type = 'read'; - if (articleData?.content == null) { - await _queryRead(id, false); - } - return; + init(); + return false; } this.opusData = opusData; commentType = opusData.basic!.commentType!; commentId = int.parse(opusData.basic!.commentIdStr!); - if (showDynActionBar && opusData.modules.moduleStat != null) { - stats.value = opusData.modules.moduleStat; + if (showDynActionBar) { + if (opusData.modules.moduleStat != null) { + stats.value = opusData.modules.moduleStat; + } else { + getArticleInfo(); + } } summary ..author ??= opusData.modules.moduleAuthor ..title ??= opusData.modules.moduleTag?.text; - isLoaded.value = true; + return true; } + return false; } - Future _queryRead(cvId, [bool toOpus = false]) async { - final res = await DynamicsHttp.articleView(cvId: cvId); + Future queryRead(cvid) async { + final res = await DynamicsHttp.articleView(cvId: cvid); if (res.isSuccess) { articleData = res.data; summary ..author ??= articleData!.author ..title ??= articleData!.title ..cover ??= articleData!.originImageUrls?.firstOrNull; - isLoaded.value = true; - if (toOpus && - articleData!.dynIdStr != null && - articleData?.opus?.content?.isNotEmpty != true) { - await _queryOpus(articleData!.dynIdStr); - if (opusData != null) { - id = articleData!.dynIdStr!; - type = 'opus'; - isLoaded.refresh(); - } - } - if (showDynActionBar && stats.value == null) { - // _queryReadAsDyn(articleData!.dynIdStr); + if (showDynActionBar) { getArticleInfo(); } + return true; } + return false; } // stats @@ -116,7 +126,7 @@ class ArticleController extends ReplyController { ..cover ??= (res['data']?['origin_image_urls'] as List?)?.firstOrNull ..title ??= res['data']?['title']; - stats.value = ModuleStatModel( + stats.value ??= ModuleStatModel( comment: DynamicStat(count: res['data']?['stats']?['reply']), forward: DynamicStat(count: res['data']?['stats']?['share']), like: DynamicStat( @@ -130,18 +140,17 @@ class ArticleController extends ReplyController { ); return true; } - SmartDialog.showToast(res['msg']); return false; } // 请求动态内容 Future _queryContent() async { if (type != 'read') { - await _queryOpus(id); + isLoaded.value = await queryOpus(id); } else { commentId = int.parse(id); commentType = 12; - await _queryRead(commentId, true); + isLoaded.value = await queryRead(commentId); } if (isLoaded.value) { queryData(); @@ -191,7 +200,7 @@ class ArticleController extends ReplyController { } } - Future onLike(VoidCallback callback) async { + Future onLike() async { bool isLike = stats.value?.like?.status == true; final res = await DynamicsHttp.likeDynamic( dynamicId: opusData?.idStr ?? articleData?.dynIdStr, diff --git a/lib/pages/article/view.dart b/lib/pages/article/view.dart index 5e4db98d..38343e5a 100644 --- a/lib/pages/article/view.dart +++ b/lib/pages/article/view.dart @@ -440,7 +440,7 @@ class _ArticlePageState extends State Widget _buildReplyList(LoadingState?> loadingState) { return switch (loadingState) { Loading() => SliverList.builder( - itemCount: 5, + itemCount: 12, itemBuilder: (context, index) { return const VideoReplySkeleton(); }, @@ -778,6 +778,15 @@ class _ArticlePageState extends State stat: _articleCtr .stats.value?.forward, callback: () { + if (_articleCtr.opusData == + null && + _articleCtr.articleData + ?.dynIdStr == + null) { + SmartDialog.showToast( + 'err: ${_articleCtr.id}'); + return; + } showModalBottomSheet( context: context, isScrollControlled: true, @@ -785,10 +794,14 @@ class _ArticlePageState extends State builder: (context) => RepostPanel( item: _articleCtr.opusData, + dynIdStr: _articleCtr + .articleData?.dynIdStr, pic: _articleCtr.summary.cover, title: _articleCtr.summary.title, + uname: _articleCtr + .summary.author?.name, callback: () { int count = _articleCtr .stats @@ -834,16 +847,7 @@ class _ArticlePageState extends State Expanded( child: Builder( builder: (context) => TextButton.icon( - onPressed: () { - _articleCtr.onLike( - () { - if (context.mounted) { - (context as Element?) - ?.markNeedsBuild(); - } - }, - ); - }, + onPressed: _articleCtr.onLike, icon: Icon( _articleCtr.stats.value?.like ?.status == diff --git a/lib/pages/dynamics/repost_dyn_panel.dart b/lib/pages/dynamics/repost_dyn_panel.dart index a1be0447..20bb1881 100644 --- a/lib/pages/dynamics/repost_dyn_panel.dart +++ b/lib/pages/dynamics/repost_dyn_panel.dart @@ -16,6 +16,7 @@ class RepostPanel extends CommonPublishPage { const RepostPanel({ super.key, this.item, + this.dynIdStr, this.callback, // video this.rid, @@ -35,6 +36,7 @@ class RepostPanel extends CommonPublishPage { final bool? isMax; final DynamicItemModel? item; + final String? dynIdStr; final VoidCallback? callback; @override @@ -343,7 +345,7 @@ class _RepostPanelState extends CommonPublishPageState { Future onCustomPublish({required String message, List? pictures}) async { dynamic result = await MsgHttp.createDynamic( mid: Accounts.main.mid, - dynIdStr: widget.item?.idStr, + dynIdStr: widget.item?.idStr ?? widget.dynIdStr, rid: widget.rid, dynType: widget.dynType, rawText: editController.text,