diff --git a/assets/translations/en-US.json b/assets/translations/en-US.json index a55f58b..f2bf12a 100644 --- a/assets/translations/en-US.json +++ b/assets/translations/en-US.json @@ -282,6 +282,7 @@ "other": "{} attachments" }, "fieldAttachmentRandomId": "Random ID", + "fieldAttachmentAlt": "Alternative text", "addAttachmentFromAlbum": "Add from album", "addAttachmentFromClipboard": "Paste file", "addAttachmentFromCameraPhoto": "Take photo", @@ -293,6 +294,7 @@ "attachmentUnsetAsPostThumbnail": "Unset as post thumbnail", "attachmentCompressVideo": "Re-encode video", "attachmentSetThumbnail": "Set thumbnail", + "attachmentSetAlt": "Set alternative text", "attachmentCopyRandomId": "Copy RID", "attachmentUpload": "Upload", "attachmentInputDialog": "Upload attachments", diff --git a/assets/translations/zh-CN.json b/assets/translations/zh-CN.json index 4cfd3fb..0e434cf 100644 --- a/assets/translations/zh-CN.json +++ b/assets/translations/zh-CN.json @@ -280,6 +280,7 @@ "other": "{} 个附件" }, "fieldAttachmentRandomId": "访问 ID", + "fieldAttachmentAlt": "概述文字", "addAttachmentFromAlbum": "从相册中添加附件", "addAttachmentFromClipboard": "粘贴附件", "addAttachmentFromCameraPhoto": "拍摄照片", @@ -291,6 +292,7 @@ "attachmentUnsetAsPostThumbnail": "取消设置为帖子缩略图", "attachmentCompressVideo": "重新编码视频", "attachmentSetThumbnail": "设置缩略图", + "attachmentSetAlt": "设置概述文字", "attachmentCopyRandomId": "复制访问 ID", "attachmentUpload": "上传", "attachmentInputDialog": "上传附件", diff --git a/assets/translations/zh-HK.json b/assets/translations/zh-HK.json index b2eb7bc..cc61e04 100644 --- a/assets/translations/zh-HK.json +++ b/assets/translations/zh-HK.json @@ -280,6 +280,7 @@ "other": "{} 個附件" }, "fieldAttachmentRandomId": "訪問 ID", + "fieldAttachmentAlt": "概述文字", "addAttachmentFromAlbum": "從相冊中添加附件", "addAttachmentFromClipboard": "粘貼附件", "addAttachmentFromCameraPhoto": "拍攝照片", @@ -291,6 +292,7 @@ "attachmentUnsetAsPostThumbnail": "取消設置為帖子縮略圖", "attachmentCompressVideo": "重新編碼視頻", "attachmentSetThumbnail": "設置縮略圖", + "attachmentSetAlt": "設置概述文字", "attachmentCopyRandomId": "複製訪問 ID", "attachmentUpload": "上傳", "attachmentInputDialog": "上傳附件", diff --git a/assets/translations/zh-TW.json b/assets/translations/zh-TW.json index 9a90654..1f7d2af 100644 --- a/assets/translations/zh-TW.json +++ b/assets/translations/zh-TW.json @@ -280,6 +280,7 @@ "other": "{} 個附件" }, "fieldAttachmentRandomId": "訪問 ID", + "fieldAttachmentAlt": "概述文字", "addAttachmentFromAlbum": "從相冊中添加附件", "addAttachmentFromClipboard": "粘貼附件", "addAttachmentFromCameraPhoto": "拍攝照片", @@ -291,6 +292,7 @@ "attachmentUnsetAsPostThumbnail": "取消設置為帖子縮略圖", "attachmentCompressVideo": "重新編碼視頻", "attachmentSetThumbnail": "設置縮略圖", + "attachmentSetAlt": "設置概述文字", "attachmentCopyRandomId": "複製訪問 ID", "attachmentUpload": "上傳", "attachmentInputDialog": "上傳附件", diff --git a/lib/widgets/attachment/pending_attachment_alt.dart b/lib/widgets/attachment/pending_attachment_alt.dart new file mode 100644 index 0000000..038e662 --- /dev/null +++ b/lib/widgets/attachment/pending_attachment_alt.dart @@ -0,0 +1,87 @@ +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:gap/gap.dart'; +import 'package:provider/provider.dart'; +import 'package:surface/controllers/post_write_controller.dart'; +import 'package:surface/providers/sn_attachment.dart'; +import 'package:surface/widgets/dialog.dart'; + +class PendingAttachmentAltDialog extends StatefulWidget { + final PostWriteMedia media; + const PendingAttachmentAltDialog({super.key, required this.media}); + + @override + State createState() => _PendingAttachmentAltDialogState(); +} + +class _PendingAttachmentAltDialogState extends State { + final _contentController = TextEditingController(); + + @override + void initState() { + super.initState(); + _contentController.text = widget.media.attachment!.alt; + } + + bool _isBusy = false; + + Future _performAction() async { + if (_isBusy) return; + + setState(() => _isBusy = true); + + try { + final attach = context.read(); + final result = await attach.updateOne( + widget.media.attachment!, + alt: _contentController.text, + ); + if (!mounted) return; + attach.putCache([result]); + Navigator.pop(context, result); + } catch (err) { + if (!mounted) return; + context.showErrorDialog(err); + setState(() => _isBusy = false); + } + } + + @override + void dispose() { + _contentController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return AlertDialog( + title: Text('attachmentSetAlt').tr(), + content: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + TextField( + controller: _contentController, + decoration: InputDecoration( + labelText: 'fieldAttachmentAlt'.tr(), + border: const UnderlineInputBorder(), + ), + onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(), + ), + ], + ), + actions: [ + TextButton( + onPressed: _isBusy ? null : () { + Navigator.pop(context); + }, + child: Text('dialogDismiss'.tr()), + ), + TextButton( + onPressed: _isBusy ? null : () => _performAction(), + child: Text('dialogConfirm'.tr()), + ), + ], + ); + } +} diff --git a/lib/widgets/post/post_media_pending_list.dart b/lib/widgets/post/post_media_pending_list.dart index 0d4d0d8..999ff2d 100644 --- a/lib/widgets/post/post_media_pending_list.dart +++ b/lib/widgets/post/post_media_pending_list.dart @@ -21,6 +21,7 @@ import 'package:surface/providers/sn_network.dart'; import 'package:surface/types/attachment.dart'; import 'package:surface/widgets/attachment/attachment_input.dart'; import 'package:surface/widgets/attachment/attachment_zoom.dart'; +import 'package:surface/widgets/attachment/pending_attachment_alt.dart'; import 'package:surface/widgets/attachment/pending_attachment_boost.dart'; import 'package:surface/widgets/context_menu.dart'; import 'package:surface/widgets/dialog.dart'; @@ -157,6 +158,16 @@ class PostMediaPendingList extends StatelessWidget { onUpdate!(idx, result); } + Future _setAlt(BuildContext context, int idx) async { + final result = await showDialog( + context: context, + builder: (context) => PendingAttachmentAltDialog(media: attachments[idx]), + ); + if (result == null) return; + + onUpdate!(idx, PostWriteMedia(result)); + } + ContextMenu _createContextMenu(BuildContext context, int idx, PostWriteMedia media) { final canCompressVideo = !kIsWeb && (Platform.isAndroid || Platform.isIOS || Platform.isMacOS); return ContextMenu( @@ -169,6 +180,14 @@ class PostMediaPendingList extends StatelessWidget { _compressVideo(context, idx); }, ), + if (media.attachment != null) + MenuItem( + label: 'attachmentSetAlt'.tr(), + icon: Symbols.description, + onSelected: () { + _setAlt(context, idx); + }, + ), if (media.attachment != null) MenuItem( label: 'attachmentBoost'.tr(),