mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refa: article (#757)
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
198
lib/pages/article/controller.dart
Normal file
198
lib/pages/article/controller.dart
Normal file
@@ -0,0 +1,198 @@
|
||||
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.dart';
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/models/dynamics/article_view/data.dart';
|
||||
import 'package:PiliPlus/models/dynamics/opus_detail/data.dart';
|
||||
import 'package:PiliPlus/models/dynamics/opus_detail/favorite.dart';
|
||||
import 'package:PiliPlus/models/dynamics/result.dart';
|
||||
import 'package:PiliPlus/pages/common/reply_controller.dart';
|
||||
import 'package:PiliPlus/pages/mine/controller.dart';
|
||||
import 'package:PiliPlus/utils/storage.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';
|
||||
import 'package:fixnum/fixnum.dart' as $fixnum;
|
||||
|
||||
class ArticleController extends ReplyController<MainListReply> {
|
||||
late String id;
|
||||
late String type;
|
||||
|
||||
late final String url;
|
||||
late int commentType;
|
||||
dynamic commentId;
|
||||
|
||||
RxBool showTitle = false.obs;
|
||||
|
||||
late final horizontalPreview = GStorage.horizontalPreview;
|
||||
late final showDynActionBar = GStorage.showDynActionBar;
|
||||
|
||||
@override
|
||||
dynamic get sourceId => id;
|
||||
|
||||
RxBool isLoaded = false.obs;
|
||||
late ArticleData articleData;
|
||||
late OpusData opusData;
|
||||
|
||||
late final Rx<DynamicItemModel> item = DynamicItemModel().obs;
|
||||
late final RxMap favStat = <dynamic, dynamic>{'status': false}.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
id = Get.parameters['id']!;
|
||||
type = Get.parameters['type']!;
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
url = type == 'read'
|
||||
? 'https://www.bilibili.com/read/cv$id'
|
||||
: 'https://www.bilibili.com/opus/$id';
|
||||
commentType = type == 'picture' ? 11 : 12;
|
||||
|
||||
if (Get.arguments?['item'] is DynamicItemModel) {
|
||||
item.value = Get.arguments['item'];
|
||||
}
|
||||
|
||||
_queryDynItem();
|
||||
_queryContent();
|
||||
}
|
||||
|
||||
_queryDynItem() async {
|
||||
if (showDynActionBar) {
|
||||
if (type == 'read') {
|
||||
if (item.value.idStr == null) {
|
||||
UrlUtils.parseRedirectUrl('https://www.bilibili.com/read/cv$id/')
|
||||
.then((url) {
|
||||
if (url != null) {
|
||||
_queryDyn(url.split('/').last);
|
||||
}
|
||||
});
|
||||
}
|
||||
_queryInfo();
|
||||
} else {
|
||||
_queryDyn(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_queryInfo() {
|
||||
DynamicsHttp.articleInfo(cvId: id).then((res) {
|
||||
if (res['status']) {
|
||||
favStat.addAll({
|
||||
'status': true,
|
||||
'isFav': res['data']?['favorite'] ?? false,
|
||||
'favNum': res['data']?['stats']?['favorite'] ?? 0,
|
||||
'data': res['data'],
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_queryDyn(id) {
|
||||
if (item.value.idStr != null) {
|
||||
return;
|
||||
}
|
||||
DynamicsHttp.dynamicDetail(id: id).then((res) {
|
||||
if (res['status']) {
|
||||
item.value = res['data'];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future _queryContent() async {
|
||||
final res = type == 'read'
|
||||
? await DynamicsHttp.articleView(cvId: id)
|
||||
: await DynamicsHttp.opusDetail(opusId: id);
|
||||
if (res['status']) {
|
||||
if (type == 'read') {
|
||||
articleData = res['data'];
|
||||
commentId = int.parse(id);
|
||||
} else {
|
||||
opusData = res['data'];
|
||||
// fallback
|
||||
if (opusData.fallback?.id != null) {
|
||||
id = opusData.fallback!.id!;
|
||||
type = 'read';
|
||||
commentType = 12;
|
||||
_queryInfo();
|
||||
_queryContent();
|
||||
return;
|
||||
} else {
|
||||
commentType = opusData.item?.basic?.commentType ??
|
||||
(type == 'picture' ? 11 : 12);
|
||||
commentId = int.parse(opusData.item!.basic!.commentIdStr!);
|
||||
Favorite? favorite =
|
||||
opusData.item?.modules?.lastOrNull?.moduleStat?.favorite;
|
||||
favStat.addAll({
|
||||
'status': true,
|
||||
'isFav': favorite?.status ?? false,
|
||||
'favNum': favorite?.count ?? 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isLoaded.value = true;
|
||||
|
||||
if (isLogin && !MineController.anonymity.value) {
|
||||
VideoHttp.historyReport(aid: commentId, type: 5);
|
||||
}
|
||||
|
||||
queryData();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<ReplyInfo>? getDataList(MainListReply response) {
|
||||
return response.replies;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<MainListReply>> customGetData() {
|
||||
return ReplyHttp.replyListGrpc(
|
||||
type: commentType,
|
||||
oid: commentId,
|
||||
cursor: CursorReq(
|
||||
next: cursor?.next ?? $fixnum.Int64(0),
|
||||
mode: mode.value,
|
||||
),
|
||||
antiGoodsReply: antiGoodsReply,
|
||||
);
|
||||
}
|
||||
|
||||
Future onFav() async {
|
||||
bool isFav = favStat['isFav'] == true;
|
||||
final res = type == 'read'
|
||||
? isFav
|
||||
? await UserHttp.delFavArticle(id: id)
|
||||
: await UserHttp.addFavArticle(id: id)
|
||||
: await UserHttp.communityAction(opusId: id, action: isFav ? 4 : 3);
|
||||
if (res['status']) {
|
||||
favStat['isFav'] = !isFav;
|
||||
if (isFav) {
|
||||
favStat['favNum'] -= 1;
|
||||
} else {
|
||||
favStat['favNum'] += 1;
|
||||
}
|
||||
SmartDialog.showToast('${isFav ? '取消' : ''}收藏成功');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/article_content.dart';
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
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';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.dart';
|
||||
import 'package:PiliPlus/http/constants.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/common/reply_sort_type.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/repost_dyn_panel.dart';
|
||||
@@ -21,8 +22,6 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/common/skeleton/video_reply.dart';
|
||||
import 'package:PiliPlus/common/widgets/html_render.dart';
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/models/common/reply_type.dart';
|
||||
import 'package:PiliPlus/pages/video/detail/reply_reply/index.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
@@ -31,24 +30,19 @@ import 'package:html/parser.dart' as parser;
|
||||
import '../../utils/grid.dart';
|
||||
import 'controller.dart';
|
||||
|
||||
class HtmlRenderPage extends StatefulWidget {
|
||||
const HtmlRenderPage({super.key});
|
||||
class ArticlePage extends StatefulWidget {
|
||||
const ArticlePage({super.key});
|
||||
|
||||
@override
|
||||
State<HtmlRenderPage> createState() => _HtmlRenderPageState();
|
||||
State<ArticlePage> createState() => _ArticlePageState();
|
||||
}
|
||||
|
||||
class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
class _ArticlePageState extends State<ArticlePage>
|
||||
with TickerProviderStateMixin {
|
||||
late final HtmlRenderController _htmlRenderCtr = Get.put(
|
||||
HtmlRenderController(),
|
||||
tag: Utils.makeHeroTag(id),
|
||||
final ArticleController _articleCtr = Get.put(
|
||||
ArticleController(),
|
||||
tag: Utils.generateRandomString(8),
|
||||
);
|
||||
late String title;
|
||||
late String id;
|
||||
late String url;
|
||||
late String dynamicType;
|
||||
late int type;
|
||||
bool _isFabVisible = true;
|
||||
bool? _imageStatus;
|
||||
late AnimationController fabAnimationCtr;
|
||||
@@ -57,7 +51,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
|
||||
bool get _horizontalPreview =>
|
||||
context.orientation == Orientation.landscape &&
|
||||
_htmlRenderCtr.horizontalPreview;
|
||||
_articleCtr.horizontalPreview;
|
||||
|
||||
late final _key = GlobalKey<ScaffoldState>();
|
||||
|
||||
@@ -104,35 +98,39 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
title = Get.parameters['title']!;
|
||||
id = Get.parameters['id']!;
|
||||
url = Get.parameters['url']!;
|
||||
dynamicType = Get.parameters['dynamicType']!;
|
||||
type = dynamicType == 'picture' ? 11 : 12;
|
||||
fabAnimationCtr = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
);
|
||||
fabAnimationCtr.forward();
|
||||
scrollListener();
|
||||
_articleCtr.scrollController.addListener(listener);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
fabAnimationCtr.dispose();
|
||||
_htmlRenderCtr.scrollController.removeListener(listener);
|
||||
_articleCtr.scrollController.removeListener(listener);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void scrollListener() {
|
||||
_htmlRenderCtr.scrollController.addListener(listener);
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_articleCtr.scrollController.hasClients) {
|
||||
_articleCtr.showTitle.value =
|
||||
_articleCtr.scrollController.positions.last.pixels >= 45;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void listener() {
|
||||
_articleCtr.showTitle.value =
|
||||
_articleCtr.scrollController.positions.last.pixels >= 45;
|
||||
final ScrollDirection direction1 =
|
||||
_htmlRenderCtr.scrollController.positions.first.userScrollDirection;
|
||||
_articleCtr.scrollController.positions.first.userScrollDirection;
|
||||
late final ScrollDirection direction2 =
|
||||
_htmlRenderCtr.scrollController.positions.last.userScrollDirection;
|
||||
_articleCtr.scrollController.positions.last.userScrollDirection;
|
||||
if (direction1 == ScrollDirection.forward ||
|
||||
direction2 == ScrollDirection.forward) {
|
||||
_showFab();
|
||||
@@ -178,7 +176,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
oid: oid,
|
||||
rpid: rpid,
|
||||
source: 'dynamic',
|
||||
replyType: ReplyType.values[type],
|
||||
replyType: ReplyType.values[_articleCtr.commentType],
|
||||
firstFloor: replyItem,
|
||||
onDispose: onDispose,
|
||||
),
|
||||
@@ -189,7 +187,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
replyReplyPage,
|
||||
routeName: 'htmlRender-Copy',
|
||||
arguments: {
|
||||
'id': _htmlRenderCtr.id,
|
||||
'id': _articleCtr.id,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
@@ -219,7 +217,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
replyReplyPage,
|
||||
routeName: 'htmlRender-Copy',
|
||||
arguments: {
|
||||
'id': _htmlRenderCtr.id,
|
||||
'id': _articleCtr.id,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -248,10 +246,9 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: padding),
|
||||
child: CustomScrollView(
|
||||
controller: _htmlRenderCtr.scrollController,
|
||||
controller: _articleCtr.scrollController,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
_buildHeader,
|
||||
_buildContent(maxWidth),
|
||||
SliverToBoxAdapter(
|
||||
child: Divider(
|
||||
@@ -262,8 +259,8 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
),
|
||||
),
|
||||
_buildReplyHeader,
|
||||
Obx(() => _buildReplyList(
|
||||
_htmlRenderCtr.loadingState.value)),
|
||||
Obx(() =>
|
||||
_buildReplyList(_articleCtr.loadingState.value)),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -279,13 +276,9 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
final maxWidth =
|
||||
constraints.maxWidth - padding / 4 - 24;
|
||||
return CustomScrollView(
|
||||
controller: _htmlRenderCtr.scrollController,
|
||||
controller: _articleCtr.scrollController,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(left: padding / 4),
|
||||
sliver: _buildHeader,
|
||||
),
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
left: padding / 4,
|
||||
@@ -311,17 +304,17 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
backgroundColor: Colors.transparent,
|
||||
body: refreshIndicator(
|
||||
onRefresh: () async {
|
||||
await _htmlRenderCtr.onRefresh();
|
||||
await _articleCtr.onRefresh();
|
||||
},
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(right: padding / 4),
|
||||
child: CustomScrollView(
|
||||
controller: _htmlRenderCtr.scrollController,
|
||||
controller: _articleCtr.scrollController,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
_buildReplyHeader,
|
||||
Obx(() => _buildReplyList(
|
||||
_htmlRenderCtr.loadingState.value)),
|
||||
_articleCtr.loadingState.value)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -344,29 +337,95 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
sliver: Obx(
|
||||
() {
|
||||
if (_htmlRenderCtr.loaded.value) {
|
||||
if (_htmlRenderCtr.response['isJsonContent'] == true) {
|
||||
return articleContent(
|
||||
if (_articleCtr.isLoaded.value) {
|
||||
if (_articleCtr.type == 'read') {
|
||||
var 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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
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(
|
||||
context: context,
|
||||
list: _htmlRenderCtr.response['content'],
|
||||
modules: _articleCtr.opusData.item?.modules,
|
||||
callback: _getImageCallback,
|
||||
maxWidth: maxWidth,
|
||||
);
|
||||
}
|
||||
|
||||
// html
|
||||
var res = parser.parse(_htmlRenderCtr.response['content']);
|
||||
return SliverList.builder(
|
||||
itemCount: res.body!.children.length,
|
||||
itemBuilder: (context, index) {
|
||||
return htmlRender(
|
||||
context: context,
|
||||
element: res.body!.children[index],
|
||||
maxWidth: maxWidth,
|
||||
callback: _getImageCallback,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return const SliverToBoxAdapter();
|
||||
@@ -387,14 +446,14 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
itemCount: loadingState.response!.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == loadingState.response!.length) {
|
||||
_htmlRenderCtr.onLoadMore();
|
||||
_articleCtr.onLoadMore();
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
margin: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).padding.bottom),
|
||||
height: 125,
|
||||
child: Text(
|
||||
_htmlRenderCtr.isEnd.not
|
||||
_articleCtr.isEnd.not
|
||||
? '加载中...'
|
||||
: loadingState.response!.isEmpty
|
||||
? '还没有评论'
|
||||
@@ -412,22 +471,22 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
replyReply: (replyItem, id) =>
|
||||
replyReply(context, replyItem, id),
|
||||
onReply: () {
|
||||
_htmlRenderCtr.onReply(
|
||||
_articleCtr.onReply(
|
||||
context,
|
||||
replyItem: loadingState.response![index],
|
||||
index: index,
|
||||
);
|
||||
},
|
||||
onDelete: (subIndex) =>
|
||||
_htmlRenderCtr.onRemove(index, subIndex),
|
||||
upMid: _htmlRenderCtr.upMid,
|
||||
_articleCtr.onRemove(index, subIndex),
|
||||
upMid: _articleCtr.upMid,
|
||||
callback: _getImageCallback,
|
||||
onCheckReply: (item) =>
|
||||
_htmlRenderCtr.onCheckReply(context, item),
|
||||
onToggleTop: (isUpTop, rpid) => _htmlRenderCtr.onToggleTop(
|
||||
_articleCtr.onCheckReply(context, item),
|
||||
onToggleTop: (isUpTop, rpid) => _articleCtr.onToggleTop(
|
||||
index,
|
||||
_htmlRenderCtr.oid,
|
||||
_htmlRenderCtr.type,
|
||||
_articleCtr.commentId,
|
||||
_articleCtr.commentType,
|
||||
isUpTop,
|
||||
rpid,
|
||||
),
|
||||
@@ -436,11 +495,11 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
},
|
||||
)
|
||||
: HttpError(
|
||||
onReload: _htmlRenderCtr.onReload,
|
||||
onReload: _articleCtr.onReload,
|
||||
),
|
||||
Error() => HttpError(
|
||||
errMsg: loadingState.errMsg,
|
||||
onReload: _htmlRenderCtr.onReload,
|
||||
onReload: _articleCtr.onReload,
|
||||
),
|
||||
LoadingState() => throw UnimplementedError(),
|
||||
};
|
||||
@@ -458,11 +517,11 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
SizedBox(
|
||||
height: 35,
|
||||
child: TextButton.icon(
|
||||
onPressed: () => _htmlRenderCtr.queryBySort(),
|
||||
onPressed: () => _articleCtr.queryBySort(),
|
||||
icon: const Icon(Icons.sort, size: 16),
|
||||
label: Obx(
|
||||
() => Text(
|
||||
_htmlRenderCtr.sortType.value.label,
|
||||
_articleCtr.sortType.value.label,
|
||||
style: const TextStyle(fontSize: 13),
|
||||
),
|
||||
),
|
||||
@@ -474,61 +533,17 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget get _buildHeader => SliverToBoxAdapter(
|
||||
child: Obx(
|
||||
() => _htmlRenderCtr.loaded.value
|
||||
? Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 8),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (_htmlRenderCtr.mid != null) {
|
||||
Get.toNamed('/member?mid=${_htmlRenderCtr.mid}');
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
NetworkImgLayer(
|
||||
width: 40,
|
||||
height: 40,
|
||||
type: 'avatar',
|
||||
src: _htmlRenderCtr.response['avatar']!,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_htmlRenderCtr.response['uname'],
|
||||
style: TextStyle(
|
||||
fontSize: Theme.of(context)
|
||||
.textTheme
|
||||
.titleSmall!
|
||||
.fontSize,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
_htmlRenderCtr.response['updateTime'],
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
fontSize: Theme.of(context)
|
||||
.textTheme
|
||||
.labelSmall!
|
||||
.fontSize,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
);
|
||||
|
||||
PreferredSizeWidget get _buildAppBar => AppBar(
|
||||
title: Text(title),
|
||||
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 const SizedBox.shrink();
|
||||
}),
|
||||
actions: [
|
||||
const SizedBox(width: 4),
|
||||
if (context.orientation == Orientation.landscape)
|
||||
@@ -577,8 +592,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
IconButton(
|
||||
tooltip: '浏览器打开',
|
||||
onPressed: () {
|
||||
PageUtils.inAppWebview(
|
||||
url.startsWith('http') ? url : 'https:$url');
|
||||
PageUtils.inAppWebview(_articleCtr.url);
|
||||
},
|
||||
icon: const Icon(Icons.open_in_browser_outlined, size: 19),
|
||||
),
|
||||
@@ -586,34 +600,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
icon: const Icon(Icons.more_vert, size: 19),
|
||||
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
|
||||
PopupMenuItem(
|
||||
onTap: () => {
|
||||
_htmlRenderCtr.reqHtml(),
|
||||
},
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.refresh, size: 19),
|
||||
SizedBox(width: 10),
|
||||
Text('刷新'),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () {
|
||||
PageUtils.inAppWebview(
|
||||
url.startsWith('http') ? url : 'https:$url');
|
||||
},
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.open_in_new, size: 19),
|
||||
SizedBox(width: 10),
|
||||
Text('浏览器打开'),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () => Utils.copyText(url),
|
||||
onTap: () => Utils.copyText(_articleCtr.url),
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@@ -624,7 +611,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () => Utils.shareText(url),
|
||||
onTap: () => Utils.shareText(_articleCtr.url),
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@@ -634,25 +621,23 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_htmlRenderCtr.dynamicType == 'read' &&
|
||||
_htmlRenderCtr.favStat['status'])
|
||||
if (_articleCtr.type == 'read' && _articleCtr.favStat['status'])
|
||||
PopupMenuItem(
|
||||
onTap: () {
|
||||
try {
|
||||
PageUtils.pmShare(
|
||||
content: {
|
||||
"id": _htmlRenderCtr.id.substring(2),
|
||||
"id": _articleCtr.id,
|
||||
"title": "- 哔哩哔哩专栏",
|
||||
"headline": _htmlRenderCtr.favStat['data']['title'],
|
||||
"headline": _articleCtr.favStat['data']['title'],
|
||||
"source": 6,
|
||||
"thumb": (_htmlRenderCtr.favStat['data']
|
||||
"thumb": (_articleCtr.favStat['data']
|
||||
['origin_image_urls'] as List?)
|
||||
?.firstOrNull ??
|
||||
'',
|
||||
"author": _htmlRenderCtr.favStat['data']
|
||||
['author_name'],
|
||||
"author": _articleCtr.favStat['data']['author_name'],
|
||||
"author_id":
|
||||
_htmlRenderCtr.favStat['data']['mid'].toString(),
|
||||
_articleCtr.favStat['data']['mid'].toString(),
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
@@ -692,16 +677,16 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
heroTag: null,
|
||||
onPressed: () {
|
||||
feedBack();
|
||||
_htmlRenderCtr.onReply(
|
||||
_articleCtr.onReply(
|
||||
context,
|
||||
oid: _htmlRenderCtr.oid.value,
|
||||
replyType: ReplyType.values[type],
|
||||
oid: _articleCtr.commentId,
|
||||
replyType: ReplyType.values[_articleCtr.commentType],
|
||||
);
|
||||
},
|
||||
tooltip: '评论动态',
|
||||
child: const Icon(Icons.reply),
|
||||
);
|
||||
return _htmlRenderCtr.showDynActionBar.not
|
||||
return _articleCtr.showDynActionBar.not
|
||||
? Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Padding(
|
||||
@@ -721,13 +706,13 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
padding: EdgeInsets.only(
|
||||
right: 14,
|
||||
bottom: 14 +
|
||||
(_htmlRenderCtr.item.value.idStr != null
|
||||
(_articleCtr.favStat['status']
|
||||
? 0
|
||||
: MediaQuery.of(context).padding.bottom),
|
||||
),
|
||||
child: button(),
|
||||
),
|
||||
_htmlRenderCtr.item.value.idStr != null
|
||||
_articleCtr.favStat['status']
|
||||
? Container(
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
@@ -759,11 +744,10 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
useSafeArea: true,
|
||||
builder: (context) =>
|
||||
RepostPanel(
|
||||
item:
|
||||
_htmlRenderCtr.item.value,
|
||||
item: _articleCtr.item.value,
|
||||
callback: () {
|
||||
int count = int.tryParse(
|
||||
_htmlRenderCtr
|
||||
_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
@@ -772,7 +756,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
?.count ??
|
||||
'0') ??
|
||||
0;
|
||||
_htmlRenderCtr
|
||||
_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
@@ -805,7 +789,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
.outline,
|
||||
),
|
||||
label: Text(
|
||||
_htmlRenderCtr
|
||||
_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
@@ -813,14 +797,13 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
?.forward!
|
||||
.count !=
|
||||
null
|
||||
? Utils.numFormat(
|
||||
_htmlRenderCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
?.moduleStat
|
||||
?.forward!
|
||||
.count)
|
||||
? Utils.numFormat(_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
?.moduleStat
|
||||
?.forward!
|
||||
.count)
|
||||
: '转发',
|
||||
),
|
||||
),
|
||||
@@ -829,8 +812,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
Expanded(
|
||||
child: TextButton.icon(
|
||||
onPressed: () {
|
||||
Utils.shareText(
|
||||
'${HttpString.dynamicShareBaseUrl}/${_htmlRenderCtr.item.value.idStr}');
|
||||
Utils.shareText(_articleCtr.url);
|
||||
},
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.shareNodes,
|
||||
@@ -850,19 +832,19 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
label: const Text('分享'),
|
||||
),
|
||||
),
|
||||
if (_htmlRenderCtr.favStat['status'])
|
||||
if (_articleCtr.favStat['status'])
|
||||
Expanded(
|
||||
child: TextButton.icon(
|
||||
onPressed: () {
|
||||
_htmlRenderCtr.onFav();
|
||||
_articleCtr.onFav();
|
||||
},
|
||||
icon: Icon(
|
||||
_htmlRenderCtr.favStat['isFav'] ==
|
||||
_articleCtr.favStat['isFav'] ==
|
||||
true
|
||||
? FontAwesomeIcons.solidStar
|
||||
: FontAwesomeIcons.star,
|
||||
size: 16,
|
||||
color: _htmlRenderCtr
|
||||
color: _articleCtr
|
||||
.favStat['isFav'] ==
|
||||
true
|
||||
? Theme.of(context)
|
||||
@@ -881,7 +863,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
.colorScheme
|
||||
.outline,
|
||||
),
|
||||
label: Text(_htmlRenderCtr
|
||||
label: Text(_articleCtr
|
||||
.favStat['favNum']
|
||||
.toString()),
|
||||
),
|
||||
@@ -891,7 +873,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
builder: (context) => TextButton.icon(
|
||||
onPressed: () =>
|
||||
RequestUtils.onLikeDynamic(
|
||||
_htmlRenderCtr.item.value,
|
||||
_articleCtr.item.value,
|
||||
() {
|
||||
if (context.mounted) {
|
||||
(context as Element?)
|
||||
@@ -900,7 +882,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
},
|
||||
),
|
||||
icon: Icon(
|
||||
_htmlRenderCtr
|
||||
_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
@@ -912,7 +894,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
.solidThumbsUp
|
||||
: FontAwesomeIcons.thumbsUp,
|
||||
size: 16,
|
||||
color: _htmlRenderCtr
|
||||
color: _articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
@@ -926,7 +908,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.outline,
|
||||
semanticLabel: _htmlRenderCtr
|
||||
semanticLabel: _articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
@@ -955,7 +937,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
child: child);
|
||||
},
|
||||
child: Text(
|
||||
_htmlRenderCtr
|
||||
_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
@@ -964,7 +946,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
?.count !=
|
||||
null
|
||||
? Utils.numFormat(
|
||||
_htmlRenderCtr
|
||||
_articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules!
|
||||
@@ -973,7 +955,7 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
|
||||
.count)
|
||||
: '点赞',
|
||||
style: TextStyle(
|
||||
color: _htmlRenderCtr
|
||||
color: _articleCtr
|
||||
.item
|
||||
.value
|
||||
.modules
|
||||
128
lib/pages/article/widgets/html_render.dart
Normal file
128
lib/pages/article/widgets/html_render.dart
Normal file
@@ -0,0 +1,128 @@
|
||||
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart'
|
||||
show SourceModel;
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_html/flutter_html.dart';
|
||||
import '../../../common/widgets/network_img_layer.dart';
|
||||
import 'package:html/dom.dart' as dom;
|
||||
|
||||
Widget htmlRender({
|
||||
required BuildContext context,
|
||||
required dom.Element element,
|
||||
int? imgCount,
|
||||
List<String>? imgList,
|
||||
required double maxWidth,
|
||||
Function(List<String>, int)? callback,
|
||||
}) {
|
||||
debugPrint('htmlRender');
|
||||
return SelectionArea(
|
||||
child: Html.fromElement(
|
||||
documentElement: element,
|
||||
onLinkTap: (String? url, Map<String, String> buildContext, attributes) {},
|
||||
extensions: [
|
||||
TagExtension(
|
||||
tagsToExtend: <String>{'img'},
|
||||
builder: (ExtensionContext extensionContext) {
|
||||
try {
|
||||
final Map<String, dynamic> attributes = extensionContext.attributes;
|
||||
final List<dynamic> key = attributes.keys.toList();
|
||||
String imgUrl = key.contains('src')
|
||||
? attributes['src'] as String
|
||||
: attributes['data-src'] as String;
|
||||
imgUrl = imgUrl.contains('@') ? imgUrl.split('@').first : imgUrl;
|
||||
final bool isEmote = imgUrl.contains('/emote/');
|
||||
final bool isMall = imgUrl.contains('/mall/');
|
||||
if (isMall) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
String? clazz = attributes['class'];
|
||||
String? height = RegExp(r'max-height:(\d+)px')
|
||||
.firstMatch('${attributes['style']}')
|
||||
?.group(1);
|
||||
if (clazz?.contains('cut-off') == true || height != null) {
|
||||
return CachedNetworkImage(
|
||||
width: maxWidth,
|
||||
height: height != null ? double.parse(height) : null,
|
||||
imageUrl: Utils.thumbnailImgUrl(imgUrl),
|
||||
fit: BoxFit.contain,
|
||||
);
|
||||
}
|
||||
return Hero(
|
||||
tag: imgUrl,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (callback != null) {
|
||||
callback([imgUrl], 0);
|
||||
} else {
|
||||
context.imageView(
|
||||
imgList: [SourceModel(url: imgUrl)],
|
||||
);
|
||||
}
|
||||
},
|
||||
child: NetworkImgLayer(
|
||||
width: isEmote ? 22 : maxWidth,
|
||||
height: isEmote ? 22 : null,
|
||||
src: imgUrl,
|
||||
),
|
||||
),
|
||||
);
|
||||
} catch (err) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
style: {
|
||||
'html': Style(
|
||||
fontSize: FontSize(16),
|
||||
lineHeight: LineHeight.percent(160),
|
||||
letterSpacing: 0.3,
|
||||
),
|
||||
'body': Style(margin: Margins.zero, padding: HtmlPaddings.zero),
|
||||
'a': Style(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
textDecoration: TextDecoration.none,
|
||||
),
|
||||
'br': Style(
|
||||
lineHeight: LineHeight.percent(-1),
|
||||
),
|
||||
'p': Style(
|
||||
margin: Margins.only(bottom: 4),
|
||||
),
|
||||
'span': Style(
|
||||
fontSize: FontSize.large,
|
||||
height: Height(1.8),
|
||||
),
|
||||
'div': Style(height: Height.auto()),
|
||||
'li > p': Style(
|
||||
display: Display.inline,
|
||||
),
|
||||
'li': Style(
|
||||
padding: HtmlPaddings.only(bottom: 4),
|
||||
textAlign: TextAlign.justify,
|
||||
),
|
||||
'img': Style(margin: Margins.only(top: 4, bottom: 4)),
|
||||
'h1,h2': Style(
|
||||
fontSize: FontSize.xLarge,
|
||||
fontWeight: FontWeight.bold,
|
||||
margin: Margins.only(bottom: 8),
|
||||
),
|
||||
'h3,h4,h5': Style(
|
||||
fontSize: FontSize(16),
|
||||
fontWeight: FontWeight.bold,
|
||||
margin: Margins.only(bottom: 4),
|
||||
),
|
||||
'figcaption': Style(
|
||||
fontSize: FontSize.large,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
'strong': Style(fontWeight: FontWeight.bold),
|
||||
'figure': Style(
|
||||
margin: Margins.zero,
|
||||
),
|
||||
},
|
||||
));
|
||||
}
|
||||
196
lib/pages/article/widgets/opus_content.dart
Normal file
196
lib/pages/article/widgets/opus_content.dart
Normal file
@@ -0,0 +1,196 @@
|
||||
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart'
|
||||
show SourceModel;
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/models/dynamics/opus_detail/module.dart';
|
||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
Widget opusContent({
|
||||
required BuildContext context,
|
||||
required List<OpusModule>? modules,
|
||||
Function(List<String>, int)? callback,
|
||||
required double maxWidth,
|
||||
}) {
|
||||
debugPrint('opusContent');
|
||||
|
||||
if (modules.isNullOrEmpty) {
|
||||
return const SliverToBoxAdapter();
|
||||
}
|
||||
|
||||
return SliverMainAxisGroup(
|
||||
slivers: modules!.map<Widget>((item) {
|
||||
try {
|
||||
return switch (item.moduleType) {
|
||||
//
|
||||
'MODULE_TYPE_TITLE' => SliverToBoxAdapter(
|
||||
child: Text(
|
||||
item.moduleTitle!.text!,
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
//
|
||||
'MODULE_TYPE_AUTHOR' => SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Get.toNamed('/member?mid=${item.moduleAuthor?.mid}');
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
NetworkImgLayer(
|
||||
width: 40,
|
||||
height: 40,
|
||||
type: 'avatar',
|
||||
src: item.moduleAuthor?.face,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
item.moduleAuthor!.name!,
|
||||
style: TextStyle(
|
||||
fontSize: Theme.of(context)
|
||||
.textTheme
|
||||
.titleSmall!
|
||||
.fontSize,
|
||||
),
|
||||
),
|
||||
if (item.moduleAuthor?.pubTime != null)
|
||||
Text(
|
||||
item.moduleAuthor!.pubTime!,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
fontSize: Theme.of(context)
|
||||
.textTheme
|
||||
.labelSmall!
|
||||
.fontSize,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
//
|
||||
'MODULE_TYPE_CONTENT' => SliverList.separated(
|
||||
itemCount: item.moduleContent!.paragraphs!.length,
|
||||
itemBuilder: (context, index) {
|
||||
final element = item.moduleContent!.paragraphs![index];
|
||||
|
||||
if ((element.paraType == 1 || element.paraType == 4)) {
|
||||
return SelectableText.rich(
|
||||
textAlign: element.align == 1 ? TextAlign.center : null,
|
||||
TextSpan(
|
||||
children: element.text?.nodes!.map<TextSpan>((item) {
|
||||
if (item.rich != null) {
|
||||
return TextSpan(
|
||||
text: '\u{1F517}${item.rich?.text}',
|
||||
style: TextStyle(
|
||||
decoration: item.rich?.style?.strikethrough == true
|
||||
? TextDecoration.lineThrough
|
||||
: null,
|
||||
fontStyle: item.rich?.style?.italic == true
|
||||
? FontStyle.italic
|
||||
: null,
|
||||
fontWeight: item.rich?.style?.bold == true
|
||||
? FontWeight.bold
|
||||
: null,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
if (item.rich!.jumpUrl != null) {
|
||||
PiliScheme.routePushFromUrl(
|
||||
item.rich!.jumpUrl!);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
return TextSpan(
|
||||
text: item.word?.words,
|
||||
style: TextStyle(
|
||||
decoration: item.word?.style?.strikethrough == true
|
||||
? TextDecoration.lineThrough
|
||||
: null,
|
||||
fontStyle: item.word?.style?.italic == true
|
||||
? FontStyle.italic
|
||||
: null,
|
||||
fontWeight: item.word?.style?.bold == true
|
||||
? FontWeight.bold
|
||||
: null,
|
||||
color: item.word?.color != null
|
||||
? Color(item.word!.color!)
|
||||
: null,
|
||||
fontSize: item.word?.fontSize,
|
||||
),
|
||||
);
|
||||
}).toList()),
|
||||
);
|
||||
}
|
||||
|
||||
if (element.paraType == 2) {
|
||||
element.pic!.pics!.first.onCalHeight(maxWidth);
|
||||
return Hero(
|
||||
tag: element.pic!.pics!.first.url!,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (callback != null) {
|
||||
callback(
|
||||
[element.pic!.pics!.first.url!],
|
||||
0,
|
||||
);
|
||||
} else {
|
||||
context.imageView(
|
||||
initialPage: 0,
|
||||
imgList: [
|
||||
SourceModel(url: element.pic!.pics!.first.url!)
|
||||
],
|
||||
);
|
||||
}
|
||||
},
|
||||
child: NetworkImgLayer(
|
||||
width: maxWidth,
|
||||
height: element.pic!.pics!.first.calHeight,
|
||||
src: element.pic!.pics!.first.url!,
|
||||
quality: 60,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (element.paraType == 3) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: Utils.thumbnailImgUrl(element.line!.pic!.url!),
|
||||
height: element.line?.pic?.height,
|
||||
);
|
||||
}
|
||||
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
const SizedBox(height: 10),
|
||||
),
|
||||
|
||||
//
|
||||
_ => const SliverToBoxAdapter(),
|
||||
};
|
||||
} catch (e) {
|
||||
return SliverToBoxAdapter(child: Text(e.toString()));
|
||||
}
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.dart';
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/common/reply_type.dart';
|
||||
import 'package:PiliPlus/models/dynamics/opus_detail/data.dart';
|
||||
import 'package:PiliPlus/models/dynamics/result.dart';
|
||||
import 'package:PiliPlus/pages/common/reply_controller.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/http/html.dart';
|
||||
import 'package:PiliPlus/http/reply.dart';
|
||||
import 'package:fixnum/fixnum.dart' as $fixnum;
|
||||
|
||||
@@ -38,12 +39,14 @@ class DynamicDetailController extends ReplyController<MainListReply> {
|
||||
}
|
||||
}
|
||||
|
||||
// 根据jumpUrl获取动态html
|
||||
reqHtmlByOpusId(int id) async {
|
||||
var res = await HtmlHttp.reqHtml(id, 'opus');
|
||||
type = res['commentType'];
|
||||
oid = res['commentId'];
|
||||
queryData();
|
||||
getCommentParams(int id) async {
|
||||
var res = await DynamicsHttp.opusDetail(opusId: id);
|
||||
if (res['status']) {
|
||||
OpusData data = res['data'];
|
||||
type = data.item!.basic!.commentType!;
|
||||
oid = int.parse(data.item!.basic!.commentIdStr!);
|
||||
queryData();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -109,8 +109,7 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
||||
duration: const Duration(milliseconds: 300),
|
||||
);
|
||||
_fabAnimationCtr?.forward();
|
||||
// 滚动事件监听
|
||||
scrollListener();
|
||||
_dynamicDetailController.scrollController.addListener(listener);
|
||||
}
|
||||
|
||||
// 页面初始化
|
||||
@@ -139,7 +138,7 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
||||
DynamicDetailController(oid, replyType),
|
||||
tag: Utils.makeHeroTag(opusId),
|
||||
);
|
||||
await _dynamicDetailController.reqHtmlByOpusId(opusId!);
|
||||
await _dynamicDetailController.getCommentParams(opusId!);
|
||||
setState(() {});
|
||||
}
|
||||
} else {
|
||||
@@ -227,17 +226,22 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
||||
});
|
||||
}
|
||||
|
||||
// 滑动事件监听
|
||||
void scrollListener() {
|
||||
_dynamicDetailController.scrollController.addListener(listener);
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_dynamicDetailController.scrollController.hasClients) {
|
||||
_visibleTitle.value =
|
||||
_dynamicDetailController.scrollController.positions.first.pixels >
|
||||
55;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void listener() {
|
||||
// 标题
|
||||
if (_dynamicDetailController.scrollController.positions.length == 1) {
|
||||
_visibleTitle.value =
|
||||
_dynamicDetailController.scrollController.offset > 55;
|
||||
}
|
||||
_visibleTitle.value =
|
||||
_dynamicDetailController.scrollController.positions.first.pixels > 55;
|
||||
|
||||
// fab按钮
|
||||
final ScrollDirection direction1 = _dynamicDetailController
|
||||
|
||||
@@ -2,8 +2,8 @@ import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/stat.dart';
|
||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class FavArticleItem extends StatelessWidget {
|
||||
const FavArticleItem({
|
||||
@@ -24,7 +24,13 @@ class FavArticleItem extends StatelessWidget {
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () {
|
||||
PiliScheme.routePushFromUrl(item['jump_url']);
|
||||
Get.toNamed(
|
||||
'/articlePage',
|
||||
parameters: {
|
||||
'id': item['opus_id'],
|
||||
'type': 'opus',
|
||||
},
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
|
||||
@@ -48,12 +48,12 @@ class HistoryItem extends StatelessWidget {
|
||||
}
|
||||
if (videoItem.history.business?.contains('article') == true) {
|
||||
PageUtils.toDupNamed(
|
||||
'/htmlRender',
|
||||
'/articlePage',
|
||||
parameters: {
|
||||
'url': 'https://www.bilibili.com/read/cv${videoItem.history.oid}',
|
||||
'title': '',
|
||||
'id': 'cv${videoItem.history.oid}',
|
||||
'dynamicType': 'read'
|
||||
'id': videoItem.history.business == 'article-list'
|
||||
? '${videoItem.history.cid}'
|
||||
: '${videoItem.history.oid}',
|
||||
'type': 'read',
|
||||
},
|
||||
);
|
||||
} else if (videoItem.history.business == 'live') {
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
import 'package:PiliPlus/grpc/app/main/community/reply/v1/reply.pb.dart';
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/models/dynamics/result.dart';
|
||||
import 'package:PiliPlus/pages/common/reply_controller.dart';
|
||||
import 'package:PiliPlus/pages/mine/controller.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/url_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/http/html.dart';
|
||||
import 'package:PiliPlus/http/reply.dart';
|
||||
import 'package:fixnum/fixnum.dart' as $fixnum;
|
||||
|
||||
class HtmlRenderController extends ReplyController<MainListReply> {
|
||||
late String id;
|
||||
late String dynamicType;
|
||||
late int type;
|
||||
RxInt oid = (-1).obs;
|
||||
late Map response;
|
||||
int? floor;
|
||||
dynamic mid;
|
||||
|
||||
Rx<DynamicItemModel> item = DynamicItemModel().obs;
|
||||
|
||||
final RxMap favStat = <dynamic, dynamic>{'status': false}.obs;
|
||||
final RxBool loaded = false.obs;
|
||||
|
||||
late final horizontalPreview = GStorage.horizontalPreview;
|
||||
late final showDynActionBar = GStorage.showDynActionBar;
|
||||
|
||||
@override
|
||||
dynamic get sourceId => id;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
id = Get.parameters['id']!;
|
||||
dynamicType = Get.parameters['dynamicType']!;
|
||||
type = dynamicType == 'picture' ? 11 : 12;
|
||||
|
||||
if (showDynActionBar) {
|
||||
if (dynamicType == 'read') {
|
||||
UrlUtils.parseRedirectUrl('https://www.bilibili.com/read/$id/')
|
||||
.then((url) {
|
||||
if (url != null) {
|
||||
_queryDyn(url.split('/').last);
|
||||
}
|
||||
});
|
||||
DynamicsHttp.articleInfo(cvId: id.substring(2)).then((res) {
|
||||
if (res['status']) {
|
||||
favStat.addAll({
|
||||
'status': true,
|
||||
'isFav': res['data']?['favorite'] ?? false,
|
||||
'favNum': res['data']?['stats']?['favorite'] ?? 0,
|
||||
'data': res['data'],
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
_queryDyn(id);
|
||||
}
|
||||
}
|
||||
|
||||
reqHtml();
|
||||
}
|
||||
|
||||
_queryDyn(id) {
|
||||
DynamicsHttp.dynamicDetail(id: id).then((res) {
|
||||
if (res['status']) {
|
||||
item.value = res['data'];
|
||||
} else {
|
||||
debugPrint('${res['msg']}');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 请求动态内容
|
||||
Future reqHtml() async {
|
||||
late dynamic res;
|
||||
if (dynamicType == 'opus' || dynamicType == 'picture') {
|
||||
res = await HtmlHttp.reqHtml(id, dynamicType);
|
||||
if (res != null) {
|
||||
if (res['commentType'] is int) {
|
||||
type = res['commentType'];
|
||||
}
|
||||
if (res['favorite'] != null) {
|
||||
favStat.addAll({
|
||||
'status': true,
|
||||
'isFav': res['favorite']['status'] ?? false,
|
||||
'favNum': res['favorite']['count'] ?? 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = await HtmlHttp.reqReadHtml(id, dynamicType);
|
||||
}
|
||||
if (res != null) {
|
||||
response = res;
|
||||
mid = res['mid'];
|
||||
oid.value = res['commentId'];
|
||||
if (isLogin && !MineController.anonymity.value) {
|
||||
VideoHttp.historyReport(aid: oid.value, type: 5);
|
||||
}
|
||||
queryData();
|
||||
if (res['status'] == true) {
|
||||
loaded.value = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<ReplyInfo>? getDataList(MainListReply response) {
|
||||
return response.replies;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<MainListReply>> customGetData() {
|
||||
return ReplyHttp.replyListGrpc(
|
||||
type: type,
|
||||
oid: oid.value,
|
||||
cursor: CursorReq(
|
||||
next: cursor?.next ?? $fixnum.Int64(0),
|
||||
mode: mode.value,
|
||||
),
|
||||
antiGoodsReply: antiGoodsReply,
|
||||
);
|
||||
}
|
||||
|
||||
Future onFav() async {
|
||||
bool isFav = favStat['isFav'] == true;
|
||||
final res = dynamicType == 'read'
|
||||
? isFav
|
||||
? await UserHttp.delFavArticle(id: id.substring(2))
|
||||
: await UserHttp.addFavArticle(id: id.substring(2))
|
||||
: await UserHttp.communityAction(opusId: id, action: isFav ? 4 : 3);
|
||||
if (res['status']) {
|
||||
favStat['isFav'] = !isFav;
|
||||
if (isFav) {
|
||||
favStat['favNum'] -= 1;
|
||||
} else {
|
||||
favStat['favNum'] += 1;
|
||||
}
|
||||
SmartDialog.showToast('${isFav ? '取消' : ''}收藏成功');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
library html_render;
|
||||
|
||||
export './controller.dart';
|
||||
export './view.dart';
|
||||
@@ -28,12 +28,10 @@ class SearchArticleController
|
||||
if (cvid != null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Get.toNamed(
|
||||
'/htmlRender',
|
||||
'/articlePage',
|
||||
parameters: {
|
||||
'url': 'https://www.bilibili.com/read/cv$cvid',
|
||||
'title': '',
|
||||
'id': 'cv$cvid',
|
||||
'dynamicType': 'read'
|
||||
'id': cvid,
|
||||
'type': 'read',
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -122,12 +122,13 @@ class _SearchArticlePanelState extends CommonSearchPanelState<
|
||||
final item = list[index];
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Get.toNamed('/htmlRender', parameters: {
|
||||
'url': 'www.bilibili.com/read/cv${item.id}',
|
||||
'title': item.subTitle ?? '',
|
||||
'id': 'cv${item.id}',
|
||||
'dynamicType': 'read'
|
||||
});
|
||||
Get.toNamed(
|
||||
'/articlePage',
|
||||
parameters: {
|
||||
'id': '${item.id}',
|
||||
'type': 'read',
|
||||
},
|
||||
);
|
||||
},
|
||||
onLongPress: () => imageSaveDialog(
|
||||
context: context,
|
||||
|
||||
@@ -793,12 +793,13 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
firstMatch?.group(2) ??
|
||||
firstMatch?.group(3);
|
||||
if (cvid != null) {
|
||||
Get.toNamed('/htmlRender', parameters: {
|
||||
'url': 'https://www.bilibili.com/read/cv$cvid',
|
||||
'title': title,
|
||||
'id': 'cv$cvid',
|
||||
'dynamicType': 'read'
|
||||
});
|
||||
Get.toNamed(
|
||||
'/articlePage',
|
||||
parameters: {
|
||||
'id': cvid,
|
||||
'type': 'read',
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
PageUtils.handleWebview(matchStr);
|
||||
@@ -902,12 +903,13 @@ class ReplyItemGrpc extends StatelessWidget {
|
||||
.firstMatch(patternStr)
|
||||
?.group(1);
|
||||
if (cvid != null) {
|
||||
Get.toNamed('/htmlRender', parameters: {
|
||||
'url': 'https://www.bilibili.com/read/cv$cvid',
|
||||
'title': '',
|
||||
'id': 'cv$cvid',
|
||||
'dynamicType': 'read'
|
||||
});
|
||||
Get.toNamed(
|
||||
'/articlePage',
|
||||
parameters: {
|
||||
'id': cvid,
|
||||
'type': 'read',
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -219,12 +219,10 @@ class ChatItem extends StatelessWidget {
|
||||
type = '专栏';
|
||||
onTap = () {
|
||||
Get.toNamed(
|
||||
'/htmlRender',
|
||||
'/articlePage',
|
||||
parameters: {
|
||||
'url': 'www.bilibili.com/opus/cv${content['id']}',
|
||||
'title': '',
|
||||
'id': 'cv${content['id']}',
|
||||
'dynamicType': 'read'
|
||||
'id': '${content['id']}',
|
||||
'type': 'read',
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -463,12 +461,13 @@ class ChatItem extends StatelessWidget {
|
||||
case MsgType.article_card:
|
||||
return GestureDetector(
|
||||
onTap: () async {
|
||||
Get.toNamed('/htmlRender', parameters: {
|
||||
'url': "https://www.bilibili.com/read/cv${content['rid']}/",
|
||||
'title': content['title'] ?? "",
|
||||
'id': "cv${content['rid']}",
|
||||
'dynamicType': "read"
|
||||
});
|
||||
Get.toNamed(
|
||||
'/articlePage',
|
||||
parameters: {
|
||||
'id': '${content['rid']}',
|
||||
'type': "read",
|
||||
},
|
||||
);
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
Reference in New Issue
Block a user