mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refa: opus (#762)
* feat: opus * fix * fix * fix * fix * . * fix * remove * wbi sign * fix * opus content null check Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
committed by
GitHub
parent
3722ff1f33
commit
bd3c76ef43
@@ -1,6 +1,7 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/models/dynamics/result.dart' show DynamicStat;
|
||||
import 'package:PiliPlus/pages/article/widgets/opus_content.dart';
|
||||
import 'package:PiliPlus/pages/article/widgets/html_render.dart';
|
||||
import 'package:PiliPlus/common/widgets/http_error.dart';
|
||||
@@ -338,101 +339,98 @@ class _ArticlePageState extends State<ArticlePage>
|
||||
sliver: Obx(
|
||||
() {
|
||||
if (_articleCtr.isLoaded.value) {
|
||||
if (_articleCtr.type == 'read') {
|
||||
late final res = parser.parse(_articleCtr.articleData.content);
|
||||
return SliverMainAxisGroup(
|
||||
slivers: [
|
||||
if (_articleCtr.articleData.title != null)
|
||||
SliverToBoxAdapter(
|
||||
child: Text(
|
||||
_articleCtr.articleData.title!,
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
'/member?mid=${_articleCtr.articleData.author?.mid}');
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
NetworkImgLayer(
|
||||
width: 40,
|
||||
height: 40,
|
||||
type: 'avatar',
|
||||
src: _articleCtr.articleData.author?.face,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_articleCtr.articleData.author?.name ?? "",
|
||||
style: TextStyle(
|
||||
fontSize: Theme.of(context)
|
||||
.textTheme
|
||||
.titleSmall!
|
||||
.fontSize,
|
||||
),
|
||||
),
|
||||
if (_articleCtr.articleData.publishTime !=
|
||||
null)
|
||||
Text(
|
||||
Utils.dateFormat(
|
||||
_articleCtr.articleData.publishTime),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.outline,
|
||||
fontSize: Theme.of(context)
|
||||
.textTheme
|
||||
.labelSmall!
|
||||
.fontSize,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_articleCtr.articleData.modules?.isNotEmpty == true
|
||||
? opusContent(
|
||||
context: context,
|
||||
modules: _articleCtr.articleData.modules,
|
||||
callback: _getImageCallback,
|
||||
maxWidth: maxWidth,
|
||||
)
|
||||
: SliverList.separated(
|
||||
itemCount: res.body!.children.length,
|
||||
itemBuilder: (context, index) {
|
||||
return htmlRender(
|
||||
context: context,
|
||||
element: res.body!.children[index],
|
||||
maxWidth: maxWidth,
|
||||
callback: _getImageCallback,
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) =>
|
||||
const SizedBox(height: 10),
|
||||
),
|
||||
],
|
||||
late Widget content;
|
||||
if (_articleCtr.opus == null) {
|
||||
debugPrint('html page');
|
||||
final res = parser.parse(_articleCtr.articleData!.content!);
|
||||
content = SliverList.separated(
|
||||
itemCount: res.body!.children.length,
|
||||
itemBuilder: (context, index) {
|
||||
return htmlRender(
|
||||
context: context,
|
||||
element: res.body!.children[index],
|
||||
maxWidth: maxWidth,
|
||||
callback: _getImageCallback,
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) =>
|
||||
const SizedBox(height: 10),
|
||||
);
|
||||
} else {
|
||||
return opusContent(
|
||||
debugPrint('json page');
|
||||
content = opusContent(
|
||||
context: context,
|
||||
modules: _articleCtr.opusData.item?.modules,
|
||||
opus: _articleCtr.opus!,
|
||||
callback: _getImageCallback,
|
||||
maxWidth: maxWidth,
|
||||
);
|
||||
}
|
||||
|
||||
int? pubTime =
|
||||
_articleCtr.opusData?.modules.moduleAuthor?.pubTs ??
|
||||
_articleCtr.articleData?.publishTime;
|
||||
return SliverMainAxisGroup(
|
||||
slivers: [
|
||||
if (_articleCtr.summary.title != null)
|
||||
SliverToBoxAdapter(
|
||||
child: Text(
|
||||
_articleCtr.summary.title!,
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: GestureDetector(
|
||||
onTap: () => Get.toNamed(
|
||||
'/member?mid=${_articleCtr.summary.author?.mid}'),
|
||||
child: Row(
|
||||
children: [
|
||||
NetworkImgLayer(
|
||||
// TODO Avatar
|
||||
width: 40,
|
||||
height: 40,
|
||||
type: 'avatar',
|
||||
src: _articleCtr.summary.author?.face,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_articleCtr.summary.author?.name ?? '',
|
||||
style: TextStyle(
|
||||
fontSize: Theme.of(context)
|
||||
.textTheme
|
||||
.titleSmall!
|
||||
.fontSize,
|
||||
),
|
||||
),
|
||||
if (pubTime != null)
|
||||
Text(
|
||||
Utils.dateFormat(pubTime),
|
||||
style: TextStyle(
|
||||
color:
|
||||
Theme.of(context).colorScheme.outline,
|
||||
fontSize: Theme.of(context)
|
||||
.textTheme
|
||||
.labelSmall!
|
||||
.fontSize,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
content,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return const SliverToBoxAdapter();
|
||||
@@ -543,11 +541,7 @@ class _ArticlePageState extends State<ArticlePage>
|
||||
PreferredSizeWidget get _buildAppBar => AppBar(
|
||||
title: Obx(() {
|
||||
if (_articleCtr.isLoaded.value && _articleCtr.showTitle.value) {
|
||||
return Text(_articleCtr.type == 'read'
|
||||
? _articleCtr.articleData.title ?? ''
|
||||
: _articleCtr.opusData.item?.modules?.firstOrNull?.moduleTitle
|
||||
?.text ??
|
||||
'');
|
||||
return Text(_articleCtr.summary.title ?? '');
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
}),
|
||||
@@ -628,23 +622,21 @@ class _ArticlePageState extends State<ArticlePage>
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_articleCtr.type == 'read' && _articleCtr.favStat['status'])
|
||||
if (_articleCtr.commentType == 12 &&
|
||||
_articleCtr.stats.value != null)
|
||||
PopupMenuItem(
|
||||
onTap: () {
|
||||
try {
|
||||
PageUtils.pmShare(
|
||||
content: {
|
||||
"id": _articleCtr.id,
|
||||
"id": _articleCtr.commentId,
|
||||
"title": "- 哔哩哔哩专栏",
|
||||
"headline": _articleCtr.favStat['data']['title'],
|
||||
"headline": _articleCtr.summary.title!, // throw
|
||||
"source": 6,
|
||||
"thumb": (_articleCtr.favStat['data']
|
||||
['origin_image_urls'] as List?)
|
||||
?.firstOrNull ??
|
||||
'',
|
||||
"author": _articleCtr.favStat['data']['author_name'],
|
||||
"thumb": _articleCtr.summary.cover!,
|
||||
"author": _articleCtr.summary.author!.name,
|
||||
"author_id":
|
||||
_articleCtr.favStat['data']['mid'].toString(),
|
||||
_articleCtr.summary.author!.mid.toString(),
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
@@ -704,8 +696,38 @@ class _ArticlePageState extends State<ArticlePage>
|
||||
child: button(),
|
||||
),
|
||||
)
|
||||
: Obx(
|
||||
() => Column(
|
||||
: Obx(() {
|
||||
Widget textIconButton({
|
||||
required IconData icon,
|
||||
required String text,
|
||||
required DynamicStat? stat,
|
||||
required VoidCallback callback,
|
||||
IconData? activitedIcon,
|
||||
}) {
|
||||
final show = stat?.status == true;
|
||||
final color = show
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Theme.of(context).colorScheme.outline;
|
||||
return TextButton.icon(
|
||||
onPressed: callback,
|
||||
icon: Icon(
|
||||
stat?.status == true ? activitedIcon : icon,
|
||||
size: 16,
|
||||
color: color,
|
||||
semanticLabel: text,
|
||||
),
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15),
|
||||
foregroundColor:
|
||||
Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
label: Text(stat?.count != null
|
||||
? Utils.numFormat(stat!.count)
|
||||
: text),
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
@@ -713,13 +735,13 @@ class _ArticlePageState extends State<ArticlePage>
|
||||
padding: EdgeInsets.only(
|
||||
right: 14,
|
||||
bottom: 14 +
|
||||
(_articleCtr.favStat['status']
|
||||
(_articleCtr.stats.value != null
|
||||
? 0
|
||||
: MediaQuery.of(context).padding.bottom),
|
||||
),
|
||||
child: button(),
|
||||
),
|
||||
_articleCtr.favStat['status']
|
||||
_articleCtr.stats.value != null
|
||||
? Container(
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
@@ -743,34 +765,36 @@ class _ArticlePageState extends State<ArticlePage>
|
||||
Expanded(
|
||||
child: Builder(
|
||||
builder: (btnContext) =>
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
textIconButton(
|
||||
text: '转发',
|
||||
icon: FontAwesomeIcons
|
||||
.shareFromSquare,
|
||||
stat: _articleCtr
|
||||
.stats.value?.forward,
|
||||
callback: () {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
useSafeArea: true,
|
||||
builder: (context) =>
|
||||
RepostPanel(
|
||||
item: _articleCtr.item.value,
|
||||
item: _articleCtr.opusData,
|
||||
pic:
|
||||
_articleCtr.summary.cover,
|
||||
title:
|
||||
_articleCtr.summary.title,
|
||||
callback: () {
|
||||
int count = int.tryParse(
|
||||
_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
?.moduleStat
|
||||
?.forward
|
||||
?.count ??
|
||||
'0') ??
|
||||
int count = _articleCtr
|
||||
.stats
|
||||
.value
|
||||
?.forward
|
||||
?.count ??
|
||||
0;
|
||||
_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
?.moduleStat
|
||||
?.forward!
|
||||
.count =
|
||||
(count + 1).toString();
|
||||
.stats
|
||||
.value
|
||||
?.forward
|
||||
?.count = count + 1;
|
||||
if (btnContext.mounted) {
|
||||
(btnContext as Element?)
|
||||
?.markNeedsBuild();
|
||||
@@ -779,108 +803,34 @@ class _ArticlePageState extends State<ArticlePage>
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.shareFromSquare,
|
||||
size: 16,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.outline,
|
||||
semanticLabel: "转发",
|
||||
),
|
||||
style: TextButton.styleFrom(
|
||||
padding:
|
||||
const EdgeInsets.fromLTRB(
|
||||
15, 0, 15, 0),
|
||||
foregroundColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.outline,
|
||||
),
|
||||
label: Text(
|
||||
_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
?.moduleStat
|
||||
?.forward!
|
||||
.count !=
|
||||
null
|
||||
? Utils.numFormat(_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
?.moduleStat
|
||||
?.forward!
|
||||
.count)
|
||||
: '转发',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: TextButton.icon(
|
||||
onPressed: () {
|
||||
Utils.shareText(_articleCtr.url);
|
||||
},
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.shareNodes,
|
||||
size: 16,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.outline,
|
||||
semanticLabel: "分享",
|
||||
),
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
15, 0, 15, 0),
|
||||
foregroundColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.outline,
|
||||
),
|
||||
label: const Text('分享'),
|
||||
),
|
||||
),
|
||||
if (_articleCtr.favStat['status'])
|
||||
child: textIconButton(
|
||||
text: '分享',
|
||||
icon: FontAwesomeIcons.shareNodes,
|
||||
stat: null,
|
||||
callback: () =>
|
||||
Utils.shareText(_articleCtr.url),
|
||||
)),
|
||||
if (_articleCtr.stats.value != null)
|
||||
Expanded(
|
||||
child: TextButton.icon(
|
||||
onPressed: () {
|
||||
_articleCtr.onFav();
|
||||
},
|
||||
icon: Icon(
|
||||
_articleCtr.favStat['isFav'] ==
|
||||
true
|
||||
? FontAwesomeIcons.solidStar
|
||||
: FontAwesomeIcons.star,
|
||||
size: 16,
|
||||
color: _articleCtr
|
||||
.favStat['isFav'] ==
|
||||
true
|
||||
? Theme.of(context)
|
||||
.colorScheme
|
||||
.primary
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.outline,
|
||||
semanticLabel: "收藏",
|
||||
),
|
||||
style: TextButton.styleFrom(
|
||||
padding:
|
||||
const EdgeInsets.fromLTRB(
|
||||
15, 0, 15, 0),
|
||||
foregroundColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.outline,
|
||||
),
|
||||
label: Text(_articleCtr
|
||||
.favStat['favNum']
|
||||
.toString()),
|
||||
),
|
||||
),
|
||||
child: textIconButton(
|
||||
icon: FontAwesomeIcons.star,
|
||||
activitedIcon:
|
||||
FontAwesomeIcons.solidStar,
|
||||
text: '收藏',
|
||||
stat:
|
||||
_articleCtr.stats.value!.favorite,
|
||||
callback: _articleCtr.onFav,
|
||||
)),
|
||||
Expanded(
|
||||
child: Builder(
|
||||
builder: (context) => TextButton.icon(
|
||||
onPressed: () =>
|
||||
RequestUtils.onLikeDynamic(
|
||||
_articleCtr.item.value,
|
||||
_articleCtr.opusData!,
|
||||
() {
|
||||
if (context.mounted) {
|
||||
(context as Element?)
|
||||
@@ -889,25 +839,15 @@ class _ArticlePageState extends State<ArticlePage>
|
||||
},
|
||||
),
|
||||
icon: Icon(
|
||||
_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
?.moduleStat
|
||||
?.like
|
||||
_articleCtr.stats.value?.like
|
||||
?.status ==
|
||||
true
|
||||
? FontAwesomeIcons
|
||||
.solidThumbsUp
|
||||
: FontAwesomeIcons.thumbsUp,
|
||||
size: 16,
|
||||
color: _articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
?.moduleStat
|
||||
?.like
|
||||
?.status ==
|
||||
color: _articleCtr.stats.value
|
||||
?.like?.status ==
|
||||
true
|
||||
? Theme.of(context)
|
||||
.colorScheme
|
||||
@@ -916,10 +856,8 @@ class _ArticlePageState extends State<ArticlePage>
|
||||
.colorScheme
|
||||
.outline,
|
||||
semanticLabel: _articleCtr
|
||||
.item
|
||||
.stats
|
||||
.value
|
||||
.modules
|
||||
?.moduleStat
|
||||
?.like
|
||||
?.status ==
|
||||
true
|
||||
@@ -928,8 +866,8 @@ class _ArticlePageState extends State<ArticlePage>
|
||||
),
|
||||
style: TextButton.styleFrom(
|
||||
padding:
|
||||
const EdgeInsets.fromLTRB(
|
||||
15, 0, 15, 0),
|
||||
const EdgeInsets.symmetric(
|
||||
horizontal: 15),
|
||||
foregroundColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.outline,
|
||||
@@ -944,31 +882,16 @@ class _ArticlePageState extends State<ArticlePage>
|
||||
child: child);
|
||||
},
|
||||
child: Text(
|
||||
_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
?.moduleStat
|
||||
?.like
|
||||
_articleCtr.stats.value?.like
|
||||
?.count !=
|
||||
null
|
||||
? Utils.numFormat(
|
||||
_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules!
|
||||
.moduleStat!
|
||||
.like!
|
||||
.count)
|
||||
_articleCtr.stats.value!
|
||||
.like!.count)
|
||||
: '点赞',
|
||||
style: TextStyle(
|
||||
color: _articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
?.moduleStat
|
||||
?.like
|
||||
?.status ==
|
||||
color: _articleCtr.stats.value
|
||||
?.like?.status ==
|
||||
true
|
||||
? Theme.of(context)
|
||||
.colorScheme
|
||||
@@ -987,8 +910,8 @@ class _ArticlePageState extends State<ArticlePage>
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
],
|
||||
),
|
||||
);
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user