opt pub page

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-07-08 21:42:35 +08:00
parent 8bf55ec95a
commit 05153fda72
27 changed files with 1374 additions and 288 deletions

View File

@@ -1,4 +1,6 @@
import 'dart:async';
import 'dart:io';
import 'dart:math' show max;
import 'package:PiliPlus/common/widgets/button/toolbar_icon_button.dart';
import 'package:PiliPlus/common/widgets/text_field/controller.dart'
@@ -12,10 +14,16 @@ import 'package:PiliPlus/models/common/publish_panel_type.dart';
import 'package:PiliPlus/pages/common/publish/common_rich_text_pub_page.dart';
import 'package:PiliPlus/pages/dynamics_mention/controller.dart';
import 'package:PiliPlus/pages/emote/view.dart';
import 'package:PiliPlus/pages/video/controller.dart';
import 'package:PiliPlus/pages/video/reply_search_item/view.dart';
import 'package:PiliPlus/utils/duration_util.dart';
import 'package:PiliPlus/utils/grid.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
import 'package:PiliPlus/utils/utils.dart';
import 'package:flutter/material.dart' hide TextField;
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:path_provider/path_provider.dart';
class ReplyPage extends CommonRichTextPubPage {
final int oid;
@@ -44,31 +52,7 @@ class ReplyPage extends CommonRichTextPubPage {
class _ReplyPageState extends CommonRichTextPubPageState<ReplyPage> {
final RxBool _syncToDynamic = false.obs;
Widget get child => SafeArea(
bottom: false,
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
constraints: const BoxConstraints(maxWidth: 640),
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(12),
topRight: Radius.circular(12),
),
color: themeData.colorScheme.surface,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
...buildInputView(),
buildImagePreview(),
buildPanelContainer(Colors.transparent),
],
),
),
),
);
final heroTag = Get.arguments?['heroTag'];
@override
void dispose() {
@@ -90,6 +74,30 @@ class _ReplyPageState extends CommonRichTextPubPageState<ReplyPage> {
@override
Widget build(BuildContext context) {
Widget child = SafeArea(
bottom: false,
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
constraints: const BoxConstraints(maxWidth: 640),
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(12),
topRight: Radius.circular(12),
),
color: themeData.colorScheme.surface,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
...buildInputView(),
buildImagePreview(),
buildPanelContainer(themeData, Colors.transparent),
],
),
),
),
);
return darkVideoPage ? Theme(data: themeData, child: child) : child;
}
@@ -167,31 +175,7 @@ class _ReplyPageState extends CommonRichTextPubPageState<ReplyPage> {
padding: const EdgeInsets.only(left: 12, right: 12),
child: Row(
children: [
Obx(
() => ToolbarIconButton(
tooltip: '输入',
onPressed: () {
if (panelType.value != PanelType.keyboard) {
updatePanelType(PanelType.keyboard);
}
},
icon: const Icon(Icons.keyboard, size: 22),
selected: panelType.value == PanelType.keyboard,
),
),
const SizedBox(width: 8),
Obx(
() => ToolbarIconButton(
tooltip: '表情',
onPressed: () {
if (panelType.value != PanelType.emoji) {
updatePanelType(PanelType.emoji);
}
},
icon: const Icon(Icons.emoji_emotions, size: 22),
selected: panelType.value == PanelType.emoji,
),
),
emojiBtn,
if (widget.root == 0) ...[
const SizedBox(width: 8),
ToolbarIconButton(
@@ -202,12 +186,9 @@ class _ReplyPageState extends CommonRichTextPubPageState<ReplyPage> {
),
],
const SizedBox(width: 8),
ToolbarIconButton(
onPressed: () => onMention(true),
icon: const Icon(Icons.alternate_email, size: 22),
tooltip: '@',
selected: false,
),
atBtn,
const SizedBox(width: 8),
moreBtn,
Expanded(
child: Center(
child: Obx(
@@ -264,6 +245,144 @@ class _ReplyPageState extends CommonRichTextPubPageState<ReplyPage> {
];
}
@override
Widget buildMorePanel(ThemeData theme) {
double height = context.isTablet ? 300 : 170;
final keyboardHeight = controller.keyboardHeight;
if (keyboardHeight != 0) {
height = max(height, keyboardHeight);
}
Widget item({
required VoidCallback onTap,
required Icon icon,
required String title,
}) {
return GestureDetector(
onTap: onTap,
child: Column(
spacing: 5,
mainAxisSize: MainAxisSize.min,
children: [
AspectRatio(
aspectRatio: 1,
child: Container(
decoration: BoxDecoration(
color: themeData.colorScheme.onInverseSurface,
borderRadius: const BorderRadius.all(Radius.circular(6)),
),
alignment: Alignment.center,
child: icon,
),
),
Text(
title,
maxLines: 1,
style: const TextStyle(fontSize: 13),
),
],
),
);
}
final isRoot = widget.root == 0;
final color = themeData.colorScheme.onSurfaceVariant;
return SizedBox(
height: height,
child: GridView(
padding: const EdgeInsets.only(left: 12, bottom: 12, right: 12),
gridDelegate: const SliverGridDelegateWithExtentAndRatio(
maxCrossAxisExtent: 65,
mainAxisSpacing: 12,
crossAxisSpacing: 12,
mainAxisExtent: 25,
),
children: [
item(
onTap: () async {
controller.keepChatPanel();
({String title, String url})? res = await Get.to(
ReplySearchPage(type: widget.replyType, oid: widget.oid));
if (res != null) {
onInsertText(
'${res.title} ',
RichTextType.common,
rawText: '${res.url} ',
);
}
controller.restoreChatPanel();
},
icon: Icon(Icons.post_add, size: 28, color: color),
title: '插入内容',
),
if (heroTag != null) ...[
// if (isRoot)
// item(
// onTap: () {
// Get.back();
// try {
// Get.find<VideoDetailController>(tag: heroTag)
// .showNoteList(context);
// } catch (e) {
// debugPrint(e.toString());
// }
// },
// icon: Icon(Icons.edit_note, size: 28, color: color),
// title: '笔记',
// ),
item(
onTap: () {
try {
final plPlayerController =
Get.find<VideoDetailController>(tag: heroTag);
onInsertText(
' ${DurationUtil.formatDuration((plPlayerController.playedTime ?? Duration.zero).inSeconds)} ',
RichTextType.common,
);
} catch (e) {
debugPrint(e.toString());
}
},
icon: Icon(Icons.my_location, size: 28, color: color),
title: '视频进度',
),
if (isRoot)
item(
onTap: () async {
if (pathList.length >= limit) {
SmartDialog.showToast('最多选择$limit张图片');
return;
}
try {
final plPlayerController =
Get.find<VideoDetailController>(tag: heroTag);
final res = await plPlayerController
.plPlayerController.videoPlayerController
?.screenshot(format: 'image/png');
if (res != null) {
final tempDir = await getTemporaryDirectory();
File file = File(
'${tempDir.path}/${Utils.generateRandomString(8)}.png');
await file.writeAsBytes(res);
pathList.add(file.path);
} else {
debugPrint('null screenshot');
}
} catch (e) {
debugPrint(e.toString());
}
},
icon: Icon(Icons.enhance_photo_translate_outlined,
size: 28, color: color),
title: '视频截图',
),
],
],
),
);
}
@override
Future<void> onCustomPublish({List? pictures}) async {
Map<String, int> atNameToMid = {};