mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-15 13:50:14 +08:00
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPlus/common/widgets/scroll_physics.dart' show ReloadMixin;
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/reply.dart';
|
||||
@@ -7,7 +8,7 @@ import 'package:PiliPlus/utils/id_utils.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class DynamicDetailController extends CommonDynController {
|
||||
class DynamicDetailController extends CommonDynController with ReloadMixin {
|
||||
@override
|
||||
late int oid;
|
||||
@override
|
||||
@@ -73,4 +74,10 @@ class DynamicDetailController extends CommonDynController {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onReload() {
|
||||
reload = true;
|
||||
return super.onReload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/common/style.dart';
|
||||
import 'package:PiliPlus/common/widgets/custom_icon.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/controller.dart';
|
||||
import 'package:PiliPlus/common/widgets/pair.dart';
|
||||
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
|
||||
import 'package:PiliPlus/common/widgets/sliver/sliver_floating_header.dart';
|
||||
import 'package:PiliPlus/common/widgets/sliver/sliver_to_box_adapter.dart';
|
||||
import 'package:PiliPlus/http/constants.dart';
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/common/reply/reply_option_type.dart';
|
||||
import 'package:PiliPlus/models/dynamics/result.dart';
|
||||
import 'package:PiliPlus/pages/common/dyn/common_dyn_page.dart';
|
||||
import 'package:PiliPlus/pages/common/dyn/reaction/controller.dart';
|
||||
import 'package:PiliPlus/pages/common/dyn/reaction/view.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/widgets/author_panel.dart';
|
||||
import 'package:PiliPlus/pages/dynamics/widgets/dynamic_panel.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_create/view.dart';
|
||||
@@ -32,32 +38,71 @@ class DynamicDetailPage extends StatefulWidget {
|
||||
State<DynamicDetailPage> createState() => _DynamicDetailPageState();
|
||||
}
|
||||
|
||||
class _DynamicDetailPageState extends CommonDynPageState<DynamicDetailPage> {
|
||||
class _DynamicDetailPageState
|
||||
extends CommonDynPageMultiState<DynamicDetailPage> {
|
||||
@override
|
||||
final DynamicDetailController controller = Get.putOrFind(
|
||||
DynamicDetailController.new,
|
||||
tag: (Get.arguments['item'] as DynamicItemModel).idStr.toString(),
|
||||
);
|
||||
late final DynamicDetailController controller;
|
||||
late final DynReactController _reactController;
|
||||
|
||||
late final RxBool _isRefreshing = false.obs;
|
||||
|
||||
void _startRefresh() {
|
||||
_isRefreshing.value = true;
|
||||
_refreshController.repeat();
|
||||
}
|
||||
|
||||
void _stopRefresh() {
|
||||
if (!mounted) return;
|
||||
_isRefreshing.value = false;
|
||||
_refreshController.stop();
|
||||
}
|
||||
|
||||
void _onRefresh(Future<void> future) {
|
||||
_startRefresh();
|
||||
future.whenComplete(_stopRefresh);
|
||||
// Future.delayed(
|
||||
// const Duration(milliseconds: 800),
|
||||
// ).whenComplete(_stopRefresh);
|
||||
}
|
||||
|
||||
late final AnimationController _refreshController;
|
||||
|
||||
@override
|
||||
dynamic get arguments => {
|
||||
'item': controller.dynItem,
|
||||
};
|
||||
dynamic get arguments => {'item': controller.dynItem};
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (scrollController.hasClients) {
|
||||
controller.showTitle.value =
|
||||
scrollController.positions.first.pixels > 55;
|
||||
}
|
||||
});
|
||||
void initState() {
|
||||
super.initState();
|
||||
final args = Get.arguments;
|
||||
final item = args['item'] as DynamicItemModel;
|
||||
final id = item.idStr.toString();
|
||||
if (args['viewComment'] ?? false) {
|
||||
WidgetsBinding.instance.addPostFrameCallback(_jumpToComment);
|
||||
}
|
||||
controller = Get.putOrFind(DynamicDetailController.new, tag: id);
|
||||
final stat = item.modules.moduleStat;
|
||||
controller.count.value = stat?.comment?.count ?? -1;
|
||||
_reactController = Get.put(
|
||||
DynReactController(
|
||||
id,
|
||||
count: (stat?.like?.count ?? -1) + (stat?.forward?.count ?? -1),
|
||||
),
|
||||
tag: id,
|
||||
);
|
||||
_refreshController = AnimationController(
|
||||
vsync: this,
|
||||
duration: CircularProgressIndicator.defaultAnimationDuration,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_refreshController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
appBar: _buildAppBar(),
|
||||
@@ -66,14 +111,14 @@ class _DynamicDetailPageState extends CommonDynPageState<DynamicDetailPage> {
|
||||
child: isPortrait
|
||||
? refreshIndicator(
|
||||
onRefresh: controller.onRefresh,
|
||||
child: _buildBody(theme),
|
||||
child: _buildBody(),
|
||||
)
|
||||
: _buildBody(theme),
|
||||
: _buildBody(),
|
||||
),
|
||||
floatingActionButtonLocation: floatingActionButtonLocation,
|
||||
floatingActionButton: SlideTransition(
|
||||
position: fabAnimation,
|
||||
child: _buildBottom(theme),
|
||||
child: _buildBottom(),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -242,17 +287,126 @@ class _DynamicDetailPageState extends CommonDynPageState<DynamicDetailPage> {
|
||||
: [ratioWidget(maxWidth), const SizedBox(width: 16)],
|
||||
);
|
||||
|
||||
Widget _buildBody(ThemeData theme) {
|
||||
double padding = max(maxWidth / 2 - Grid.smallCardWidth, 0);
|
||||
Widget child;
|
||||
if (isPortrait) {
|
||||
child = Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: padding),
|
||||
child: CustomScrollView(
|
||||
controller: scrollController,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
Widget _buildTabBar() {
|
||||
return SizedBox(
|
||||
height: 40,
|
||||
child: TabBar(
|
||||
padding: .zero,
|
||||
isScrollable: true,
|
||||
indicatorSize: .tab,
|
||||
tabAlignment: .start,
|
||||
controller: tabController,
|
||||
labelPadding: const .symmetric(horizontal: 12),
|
||||
dividerColor: theme.colorScheme.outline.withValues(alpha: 0.1),
|
||||
onTap: (value) {
|
||||
if (!tabController.indexIsChanging) {
|
||||
final positions = PrimaryScrollController.of(context).positions;
|
||||
if (positions.length == 1) {
|
||||
final postion = positions.single;
|
||||
if (postion.pixels >= postion.maxScrollExtent) {
|
||||
postion.jumpTo(postion.pixels);
|
||||
}
|
||||
}
|
||||
switch (value) {
|
||||
case 0:
|
||||
_onRefresh(controller.onRefresh());
|
||||
case 1:
|
||||
_onRefresh(_reactController.onRefresh());
|
||||
}
|
||||
}
|
||||
},
|
||||
tabs: [
|
||||
Tab(
|
||||
child: Obx(() {
|
||||
final count = controller.count.value;
|
||||
return Text(
|
||||
'${DynType.reply.label}${count < 0 ? '' : ' ${NumUtils.numFormat(count)}'}',
|
||||
);
|
||||
}),
|
||||
),
|
||||
Tab(
|
||||
child: Obx(() {
|
||||
final count = _reactController.count.value;
|
||||
return Text(
|
||||
'${DynType.reaction.label}${count < 0 ? '' : ' ${NumUtils.numFormat(count)}'}',
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabBody([bool isPortrait = true]) {
|
||||
final reply = CustomScrollView(
|
||||
key: const PageStorageKey(DynType.reply),
|
||||
physics: ReloadScrollPhysics(controller: controller),
|
||||
slivers: [
|
||||
buildReplyHeader(isPortrait),
|
||||
Obx(() => replyList(controller.loadingState.value)),
|
||||
],
|
||||
);
|
||||
return Stack(
|
||||
clipBehavior: .none,
|
||||
children: [
|
||||
tabBarView(
|
||||
controller: tabController,
|
||||
children: [
|
||||
isPortrait
|
||||
? reply
|
||||
: refreshIndicator(
|
||||
onRefresh: controller.onRefresh,
|
||||
child: reply,
|
||||
),
|
||||
DynReactPage(
|
||||
isPortrait: isPortrait,
|
||||
id: controller.dynItem.idStr,
|
||||
controller: _reactController,
|
||||
),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: displacement,
|
||||
child: Obx(() {
|
||||
final isRefreshing = _isRefreshing.value;
|
||||
return AnimatedScale(
|
||||
scale: isRefreshing ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: Center(
|
||||
child: SizedBox.fromSize(
|
||||
size: const .square(40),
|
||||
child: Material(
|
||||
type: .circle,
|
||||
color: theme.colorScheme.onSecondary,
|
||||
elevation: 2.0,
|
||||
child: Padding(
|
||||
padding: const .all(6),
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2.5,
|
||||
controller: _refreshController,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPortrait(double padding) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: padding),
|
||||
child: NestedScrollView(
|
||||
headerSliverBuilder: (context, innerBoxIsScrolled) {
|
||||
return [
|
||||
SliverToBoxWithOffsetAdapter(
|
||||
offset: 55,
|
||||
onVisibilityChanged: controller.showTitle.call,
|
||||
child: DynamicPanel(
|
||||
item: controller.dynItem,
|
||||
isDetail: true,
|
||||
@@ -262,72 +416,81 @@ class _DynamicDetailPageState extends CommonDynPageState<DynamicDetailPage> {
|
||||
onSetReplySubject: controller.onSetReplySubject,
|
||||
),
|
||||
),
|
||||
buildReplyHeader(theme),
|
||||
Obx(() => replyList(theme, controller.loadingState.value)),
|
||||
];
|
||||
},
|
||||
body: Column(
|
||||
children: [
|
||||
_buildTabBar(),
|
||||
Expanded(child: _buildTabBody()),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
padding = padding / 4;
|
||||
final flex = controller.ratio[0].toInt();
|
||||
final flex1 = controller.ratio[1].toInt();
|
||||
child = Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: flex,
|
||||
child: CustomScrollView(
|
||||
controller: scrollController,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
left: padding,
|
||||
bottom: this.padding.bottom + 100,
|
||||
),
|
||||
sliver: SliverToBoxAdapter(
|
||||
child: DynamicPanel(
|
||||
item: controller.dynItem,
|
||||
isDetail: true,
|
||||
isDetailPortraitW: isPortrait,
|
||||
onSetPubSetting: controller.onSetPubSetting,
|
||||
onEdit: _onEdit,
|
||||
onSetReplySubject: controller.onSetReplySubject,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHorizontal(double padding) {
|
||||
padding = padding / 4;
|
||||
final flex = controller.ratio[0].toInt();
|
||||
final flex1 = controller.ratio[1].toInt();
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: flex,
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: .only(
|
||||
left: padding,
|
||||
bottom: this.padding.bottom + 100,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: flex1,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(right: padding),
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: refreshIndicator(
|
||||
onRefresh: controller.onRefresh,
|
||||
child: CustomScrollView(
|
||||
controller: scrollController,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
buildReplyHeader(theme),
|
||||
Obx(
|
||||
() => replyList(theme, controller.loadingState.value),
|
||||
),
|
||||
],
|
||||
sliver: SliverToBoxWithOffsetAdapter(
|
||||
offset: 55,
|
||||
onVisibilityChanged: controller.showTitle.call,
|
||||
child: DynamicPanel(
|
||||
item: controller.dynItem,
|
||||
isDetail: true,
|
||||
isDetailPortraitW: isPortrait,
|
||||
onSetPubSetting: controller.onSetPubSetting,
|
||||
onEdit: _onEdit,
|
||||
onSetReplySubject: controller.onSetReplySubject,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: flex1,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(right: padding),
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: Column(
|
||||
children: [
|
||||
_buildTabBar(),
|
||||
Expanded(child: _buildTabBody(false)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return child;
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBottom(ThemeData theme) {
|
||||
Widget _buildBody() {
|
||||
double padding = max(maxWidth / 2 - Grid.smallCardWidth, 0);
|
||||
Widget child;
|
||||
if (isPortrait) {
|
||||
child = _buildPortrait(padding);
|
||||
} else {
|
||||
child = _buildHorizontal(padding);
|
||||
}
|
||||
return fabAnimWrapper(child);
|
||||
}
|
||||
|
||||
Widget _buildBottom() {
|
||||
if (!controller.showDynActionBar) {
|
||||
return fabButton;
|
||||
}
|
||||
@@ -432,6 +595,14 @@ class _DynamicDetailPageState extends CommonDynPageState<DynamicDetailPage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: textIconButton(
|
||||
icon: FontAwesomeIcons.comment,
|
||||
text: '评论',
|
||||
stat: moduleStat?.comment,
|
||||
onPressed: _jumpToComment,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
@@ -460,4 +631,44 @@ class _DynamicDetailPageState extends CommonDynPageState<DynamicDetailPage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildReplyHeader([bool isPortrait = true]) {
|
||||
final secondary = theme.colorScheme.secondary;
|
||||
final child = Padding(
|
||||
padding: const .fromLTRB(12, 2.5, 6, 2.5),
|
||||
child: Obx(
|
||||
() {
|
||||
final sortType = controller.sortType.value;
|
||||
return Row(
|
||||
mainAxisAlignment: .spaceBetween,
|
||||
children: [
|
||||
Text(sortType.title),
|
||||
TextButton.icon(
|
||||
style: Style.buttonStyle,
|
||||
onPressed: controller.queryBySort,
|
||||
icon: Icon(Icons.sort, size: 16, color: secondary),
|
||||
label: Text(
|
||||
sortType.label,
|
||||
style: TextStyle(fontSize: 13, color: secondary),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
return SliverFloatingHeaderWidget(
|
||||
backgroundColor: theme.colorScheme.surface,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
void _jumpToComment([_]) {
|
||||
if (!isPortrait) return;
|
||||
try {
|
||||
final position = PrimaryScrollController.of(context).position;
|
||||
position.jumpTo(position.maxScrollExtent);
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user