Compare commits
No commits in common. "8b3c45ab294d091116346c44d5328bb2e3b1ce14" and "9765b200b98d53fd0ceb88df40fdd7747d793f7f" have entirely different histories.
8b3c45ab29
...
9765b200b9
@ -112,14 +112,13 @@ class PostEditorController extends GetxController {
|
|||||||
Future<void> editAttachment(BuildContext context) {
|
Future<void> editAttachment(BuildContext context) {
|
||||||
return showModalBottomSheet(
|
return showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
|
isScrollControlled: true,
|
||||||
builder: (context) => AttachmentEditorPopup(
|
builder: (context) => AttachmentEditorPopup(
|
||||||
usage: 'i.attachment',
|
usage: 'i.attachment',
|
||||||
initialAttachments: attachments,
|
current: attachments,
|
||||||
onAdd: (value) {
|
onUpdate: (value) {
|
||||||
attachments.add(value);
|
attachments.value = value;
|
||||||
},
|
attachments.refresh();
|
||||||
onRemove: (value) {
|
|
||||||
attachments.remove(value);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -165,8 +164,6 @@ class PostEditorController extends GetxController {
|
|||||||
visibleUsers.clear();
|
visibleUsers.clear();
|
||||||
invisibleUsers.clear();
|
invisibleUsers.clear();
|
||||||
visibility.value = 0;
|
visibility.value = 0;
|
||||||
publishedAt.value = null;
|
|
||||||
publishedUntil.value = null;
|
|
||||||
isDraft.value = false;
|
isDraft.value = false;
|
||||||
isRestoreFromLocal.value = false;
|
isRestoreFromLocal.value = false;
|
||||||
lastSaveTime.value = null;
|
lastSaveTime.value = null;
|
||||||
|
@ -10,7 +10,6 @@ import 'package:sentry_flutter/sentry_flutter.dart';
|
|||||||
import 'package:solian/bootstrapper.dart';
|
import 'package:solian/bootstrapper.dart';
|
||||||
import 'package:solian/firebase_options.dart';
|
import 'package:solian/firebase_options.dart';
|
||||||
import 'package:solian/platform.dart';
|
import 'package:solian/platform.dart';
|
||||||
import 'package:solian/providers/attachment_uploader.dart';
|
|
||||||
import 'package:solian/providers/theme_switcher.dart';
|
import 'package:solian/providers/theme_switcher.dart';
|
||||||
import 'package:solian/providers/websocket.dart';
|
import 'package:solian/providers/websocket.dart';
|
||||||
import 'package:solian/providers/auth.dart';
|
import 'package:solian/providers/auth.dart';
|
||||||
@ -126,6 +125,5 @@ class SolianApp extends StatelessWidget {
|
|||||||
Get.lazyPut(() => ChannelProvider());
|
Get.lazyPut(() => ChannelProvider());
|
||||||
Get.lazyPut(() => RealmProvider());
|
Get.lazyPut(() => RealmProvider());
|
||||||
Get.lazyPut(() => ChatCallProvider());
|
Get.lazyPut(() => ChatCallProvider());
|
||||||
Get.lazyPut(() => AttachmentUploaderController());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,165 +0,0 @@
|
|||||||
import 'dart:io';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:get/get.dart';
|
|
||||||
import 'package:solian/models/attachment.dart';
|
|
||||||
import 'package:solian/providers/content/attachment.dart';
|
|
||||||
|
|
||||||
class AttachmentUploadTask {
|
|
||||||
File file;
|
|
||||||
String usage;
|
|
||||||
Map<String, dynamic>? metadata;
|
|
||||||
|
|
||||||
double progress = 0;
|
|
||||||
bool isUploading = false;
|
|
||||||
bool isCompleted = false;
|
|
||||||
|
|
||||||
AttachmentUploadTask({
|
|
||||||
required this.file,
|
|
||||||
required this.usage,
|
|
||||||
this.metadata,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
class AttachmentUploaderController extends GetxController {
|
|
||||||
RxBool isUploading = false.obs;
|
|
||||||
RxDouble progressOfUpload = 0.0.obs;
|
|
||||||
RxList<AttachmentUploadTask> queueOfUpload = RxList.empty(growable: true);
|
|
||||||
|
|
||||||
void enqueueTask(AttachmentUploadTask task) {
|
|
||||||
if (isUploading.value) throw Exception('uploading blocked');
|
|
||||||
queueOfUpload.add(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
void dequeueTask(AttachmentUploadTask task) {
|
|
||||||
if (isUploading.value) throw Exception('uploading blocked');
|
|
||||||
queueOfUpload.remove(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Attachment> performSingleTask(int queueIndex) async {
|
|
||||||
isUploading.value = true;
|
|
||||||
progressOfUpload.value = 0;
|
|
||||||
|
|
||||||
queueOfUpload[queueIndex].isUploading = true;
|
|
||||||
queueOfUpload.refresh();
|
|
||||||
|
|
||||||
final task = queueOfUpload[queueIndex];
|
|
||||||
final result = await _rawUploadAttachment(
|
|
||||||
await task.file.readAsBytes(),
|
|
||||||
task.file.path,
|
|
||||||
task.usage,
|
|
||||||
null,
|
|
||||||
onProgress: (value) {
|
|
||||||
queueOfUpload[queueIndex].progress = value;
|
|
||||||
queueOfUpload.refresh();
|
|
||||||
progressOfUpload.value = value;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
queueOfUpload.removeAt(queueIndex);
|
|
||||||
queueOfUpload.refresh();
|
|
||||||
|
|
||||||
isUploading.value = false;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> performUploadQueue({
|
|
||||||
required Function(Attachment item) onData,
|
|
||||||
}) async {
|
|
||||||
isUploading.value = true;
|
|
||||||
progressOfUpload.value = 0;
|
|
||||||
|
|
||||||
for (var idx = 0; idx < queueOfUpload.length; idx++) {
|
|
||||||
queueOfUpload[idx].isUploading = true;
|
|
||||||
queueOfUpload.refresh();
|
|
||||||
|
|
||||||
final task = queueOfUpload[idx];
|
|
||||||
final result = await _rawUploadAttachment(
|
|
||||||
await task.file.readAsBytes(),
|
|
||||||
task.file.path,
|
|
||||||
task.usage,
|
|
||||||
null,
|
|
||||||
onProgress: (value) {
|
|
||||||
queueOfUpload[idx].progress = value;
|
|
||||||
queueOfUpload.refresh();
|
|
||||||
progressOfUpload.value = (idx + value) / queueOfUpload.length;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
progressOfUpload.value = (idx + 1) / queueOfUpload.length;
|
|
||||||
onData(result);
|
|
||||||
|
|
||||||
queueOfUpload[idx].isUploading = false;
|
|
||||||
queueOfUpload[idx].isCompleted = false;
|
|
||||||
queueOfUpload.refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
queueOfUpload.clear();
|
|
||||||
queueOfUpload.refresh();
|
|
||||||
isUploading.value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> uploadAttachmentWithCallback(
|
|
||||||
Uint8List data,
|
|
||||||
String path,
|
|
||||||
String usage,
|
|
||||||
Map<String, dynamic>? metadata,
|
|
||||||
Function(Attachment) callback,
|
|
||||||
) async {
|
|
||||||
if (isUploading.value) throw Exception('uploading blocked');
|
|
||||||
|
|
||||||
isUploading.value = true;
|
|
||||||
final result = await _rawUploadAttachment(
|
|
||||||
data,
|
|
||||||
path,
|
|
||||||
usage,
|
|
||||||
metadata,
|
|
||||||
onProgress: (progress) {
|
|
||||||
progressOfUpload.value = progress;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
isUploading.value = false;
|
|
||||||
callback(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Attachment> uploadAttachment(
|
|
||||||
Uint8List data,
|
|
||||||
String path,
|
|
||||||
String usage,
|
|
||||||
Map<String, dynamic>? metadata,
|
|
||||||
) async {
|
|
||||||
if (isUploading.value) throw Exception('uploading blocked');
|
|
||||||
|
|
||||||
isUploading.value = true;
|
|
||||||
final result = await _rawUploadAttachment(
|
|
||||||
data,
|
|
||||||
path,
|
|
||||||
usage,
|
|
||||||
metadata,
|
|
||||||
onProgress: (progress) {
|
|
||||||
progressOfUpload.value = progress;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
isUploading.value = false;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Attachment> _rawUploadAttachment(
|
|
||||||
Uint8List data, String path, String usage, Map<String, dynamic>? metadata,
|
|
||||||
{Function(double)? onProgress}) async {
|
|
||||||
final AttachmentProvider provider = Get.find();
|
|
||||||
try {
|
|
||||||
final resp = await provider.createAttachment(
|
|
||||||
data,
|
|
||||||
path,
|
|
||||||
usage,
|
|
||||||
metadata,
|
|
||||||
onProgress: onProgress,
|
|
||||||
);
|
|
||||||
var result = Attachment.fromJson(resp.body);
|
|
||||||
return result;
|
|
||||||
} catch (err) {
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -38,8 +38,11 @@ class AttachmentProvider extends GetConnect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Response> createAttachment(
|
Future<Response> createAttachment(
|
||||||
Uint8List data, String path, String usage, Map<String, dynamic>? metadata,
|
Uint8List data,
|
||||||
{Function(double)? onProgress}) async {
|
String path,
|
||||||
|
String usage,
|
||||||
|
Map<String, dynamic>? metadata,
|
||||||
|
) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
if (auth.isAuthorized.isFalse) throw Exception('unauthorized');
|
||||||
|
|
||||||
@ -68,13 +71,7 @@ class AttachmentProvider extends GetConnect {
|
|||||||
if (mimetypeOverride != null) 'mimetype': mimetypeOverride,
|
if (mimetypeOverride != null) 'mimetype': mimetypeOverride,
|
||||||
'metadata': jsonEncode(metadata),
|
'metadata': jsonEncode(metadata),
|
||||||
});
|
});
|
||||||
final resp = await client.post(
|
final resp = await client.post('/attachments', payload);
|
||||||
'/attachments',
|
|
||||||
payload,
|
|
||||||
uploadProgress: (progress) {
|
|
||||||
if (onProgress != null) onProgress(progress);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (resp.statusCode != 200) {
|
if (resp.statusCode != 200) {
|
||||||
throw Exception(resp.bodyString);
|
throw Exception(resp.bodyString);
|
||||||
}
|
}
|
||||||
|
@ -157,11 +157,6 @@ const i18nEnglish = {
|
|||||||
'reactCompleted': 'Your reaction has been added',
|
'reactCompleted': 'Your reaction has been added',
|
||||||
'reactUncompleted': 'Your reaction has been removed',
|
'reactUncompleted': 'Your reaction has been removed',
|
||||||
'attachmentUploadBy': 'Upload by',
|
'attachmentUploadBy': 'Upload by',
|
||||||
'attachmentAutoUpload': 'Auto Upload',
|
|
||||||
'attachmentUploadQueue': 'Upload Queue',
|
|
||||||
'attachmentUploadQueueStart': 'Start All',
|
|
||||||
'attachmentAttached': 'Exists Files',
|
|
||||||
'attachmentUploadBlocked': 'Upload blocked, there is currently a task in progress...',
|
|
||||||
'attachmentAdd': 'Attach attachments',
|
'attachmentAdd': 'Attach attachments',
|
||||||
'attachmentAddGalleryPhoto': 'Gallery photo',
|
'attachmentAddGalleryPhoto': 'Gallery photo',
|
||||||
'attachmentAddGalleryVideo': 'Gallery video',
|
'attachmentAddGalleryVideo': 'Gallery video',
|
||||||
|
@ -146,11 +146,6 @@ const i18nSimplifiedChinese = {
|
|||||||
'reactCompleted': '你的反应已被添加',
|
'reactCompleted': '你的反应已被添加',
|
||||||
'reactUncompleted': '你的反应已被移除',
|
'reactUncompleted': '你的反应已被移除',
|
||||||
'attachmentUploadBy': '由上传',
|
'attachmentUploadBy': '由上传',
|
||||||
'attachmentAutoUpload': '自动上传',
|
|
||||||
'attachmentUploadQueue': '上传队列',
|
|
||||||
'attachmentUploadQueueStart': '整队上传',
|
|
||||||
'attachmentAttached': '已附附件',
|
|
||||||
'attachmentUploadBlocked': '上传受阻,当前已有任务进行中……',
|
|
||||||
'attachmentAdd': '附加附件',
|
'attachmentAdd': '附加附件',
|
||||||
'attachmentAddGalleryPhoto': '相册照片',
|
'attachmentAddGalleryPhoto': '相册照片',
|
||||||
'attachmentAddGalleryVideo': '相册视频',
|
'attachmentAddGalleryVideo': '相册视频',
|
||||||
|
@ -1,132 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_animate/flutter_animate.dart';
|
|
||||||
import 'package:get/get.dart';
|
|
||||||
import 'package:solian/exts.dart';
|
|
||||||
import 'package:solian/models/attachment.dart';
|
|
||||||
import 'package:solian/providers/content/attachment.dart';
|
|
||||||
|
|
||||||
class AttachmentAttrEditorDialog extends StatefulWidget {
|
|
||||||
final Attachment item;
|
|
||||||
final Function(Attachment item) onUpdate;
|
|
||||||
|
|
||||||
const AttachmentAttrEditorDialog({
|
|
||||||
super.key,
|
|
||||||
required this.item,
|
|
||||||
required this.onUpdate,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<AttachmentAttrEditorDialog> createState() => _AttachmentAttrEditorDialogState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _AttachmentAttrEditorDialogState extends State<AttachmentAttrEditorDialog> {
|
|
||||||
final _altController = TextEditingController();
|
|
||||||
|
|
||||||
bool _isBusy = false;
|
|
||||||
bool _isMature = false;
|
|
||||||
|
|
||||||
Future<Attachment?> _updateAttachment() async {
|
|
||||||
final AttachmentProvider provider = Get.find();
|
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
|
||||||
try {
|
|
||||||
final resp = await provider.updateAttachment(
|
|
||||||
widget.item.id,
|
|
||||||
_altController.value.text,
|
|
||||||
widget.item.usage,
|
|
||||||
isMature: _isMature,
|
|
||||||
);
|
|
||||||
|
|
||||||
Get.find<AttachmentProvider>().clearCache(id: widget.item.id);
|
|
||||||
|
|
||||||
setState(() => _isBusy = false);
|
|
||||||
return Attachment.fromJson(resp.body);
|
|
||||||
} catch (e) {
|
|
||||||
context.showErrorDialog(e);
|
|
||||||
setState(() => _isBusy = false);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncWidget() {
|
|
||||||
_isMature = widget.item.isMature;
|
|
||||||
_altController.text = widget.item.alt;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
syncWidget();
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: Text('attachmentSetting'.tr),
|
|
||||||
content: Container(
|
|
||||||
constraints: const BoxConstraints(minWidth: 400),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
if (_isBusy)
|
|
||||||
ClipRRect(
|
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
||||||
child: const LinearProgressIndicator().animate().scaleX(),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 18),
|
|
||||||
TextField(
|
|
||||||
controller: _altController,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
isDense: true,
|
|
||||||
prefixIcon: const Icon(Icons.image_not_supported),
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
labelText: 'attachmentAlt'.tr,
|
|
||||||
),
|
|
||||||
onTapOutside: (_) =>
|
|
||||||
FocusManager.instance.primaryFocus?.unfocus(),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
CheckboxListTile(
|
|
||||||
contentPadding: const EdgeInsets.only(left: 4, right: 18),
|
|
||||||
shape: const RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.all(Radius.circular(10))),
|
|
||||||
title: Text('matureContent'.tr),
|
|
||||||
secondary: const Icon(Icons.visibility_off),
|
|
||||||
value: _isMature,
|
|
||||||
onChanged: (newValue) {
|
|
||||||
setState(() => _isMature = newValue ?? false);
|
|
||||||
},
|
|
||||||
controlAffinity: ListTileControlAffinity.leading,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actionsAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
actions: <Widget>[
|
|
||||||
Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
TextButton(
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
foregroundColor:
|
|
||||||
Theme.of(context).colorScheme.onSurfaceVariant),
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
child: Text('cancel'.tr),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
child: Text('apply'.tr),
|
|
||||||
onPressed: () {
|
|
||||||
_updateAttachment().then((value) {
|
|
||||||
if (value != null) {
|
|
||||||
widget.onUpdate(value);
|
|
||||||
Navigator.pop(context);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +1,9 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:desktop_drop/desktop_drop.dart';
|
import 'package:desktop_drop/desktop_drop.dart';
|
||||||
import 'package:dismissible_page/dismissible_page.dart';
|
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_animate/flutter_animate.dart';
|
import 'package:flutter_animate/flutter_animate.dart';
|
||||||
@ -14,24 +14,20 @@ import 'package:path/path.dart' show basename;
|
|||||||
import 'package:solian/exts.dart';
|
import 'package:solian/exts.dart';
|
||||||
import 'package:solian/models/attachment.dart';
|
import 'package:solian/models/attachment.dart';
|
||||||
import 'package:solian/platform.dart';
|
import 'package:solian/platform.dart';
|
||||||
import 'package:solian/providers/attachment_uploader.dart';
|
|
||||||
import 'package:solian/providers/auth.dart';
|
import 'package:solian/providers/auth.dart';
|
||||||
import 'package:solian/providers/content/attachment.dart';
|
import 'package:solian/providers/content/attachment.dart';
|
||||||
import 'package:solian/widgets/attachments/attachment_attr_editor.dart';
|
import 'package:solian/widgets/attachments/attachment_item.dart';
|
||||||
import 'package:solian/widgets/attachments/attachment_fullscreen.dart';
|
|
||||||
|
|
||||||
class AttachmentEditorPopup extends StatefulWidget {
|
class AttachmentEditorPopup extends StatefulWidget {
|
||||||
final String usage;
|
final String usage;
|
||||||
final List<int> initialAttachments;
|
final List<int> current;
|
||||||
final void Function(int) onAdd;
|
final void Function(List<int> data) onUpdate;
|
||||||
final void Function(int) onRemove;
|
|
||||||
|
|
||||||
const AttachmentEditorPopup({
|
const AttachmentEditorPopup({
|
||||||
super.key,
|
super.key,
|
||||||
required this.usage,
|
required this.usage,
|
||||||
required this.initialAttachments,
|
required this.current,
|
||||||
required this.onAdd,
|
required this.onUpdate,
|
||||||
required this.onRemove,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -40,44 +36,58 @@ class AttachmentEditorPopup extends StatefulWidget {
|
|||||||
|
|
||||||
class _AttachmentEditorPopupState extends State<AttachmentEditorPopup> {
|
class _AttachmentEditorPopupState extends State<AttachmentEditorPopup> {
|
||||||
final _imagePicker = ImagePicker();
|
final _imagePicker = ImagePicker();
|
||||||
final AttachmentUploaderController _uploadController = Get.find();
|
|
||||||
|
|
||||||
bool _isAutoUpload = false;
|
|
||||||
|
|
||||||
bool _isBusy = false;
|
bool _isBusy = false;
|
||||||
bool _isFirstTimeBusy = true;
|
bool _isFirstTimeBusy = true;
|
||||||
|
|
||||||
List<Attachment?> _attachments = List.empty(growable: true);
|
List<Attachment?> _attachments = List.empty(growable: true);
|
||||||
|
|
||||||
Future<void> _pickPhotoToUpload() async {
|
Future<void> pickPhotoToUpload() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (auth.isAuthorized.isFalse) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final medias = await _imagePicker.pickMultiImage();
|
final medias = await _imagePicker.pickMultiImage();
|
||||||
if (medias.isEmpty) return;
|
if (medias.isEmpty) return;
|
||||||
|
|
||||||
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
for (final media in medias) {
|
for (final media in medias) {
|
||||||
final file = File(media.path);
|
final file = File(media.path);
|
||||||
_enqueueTask(
|
try {
|
||||||
AttachmentUploadTask(file: file, usage: widget.usage),
|
await uploadAttachment(
|
||||||
|
await file.readAsBytes(),
|
||||||
|
file.path,
|
||||||
|
null,
|
||||||
);
|
);
|
||||||
|
} catch (err) {
|
||||||
|
context.showErrorDialog(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _pickVideoToUpload() async {
|
setState(() => _isBusy = false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> pickVideoToUpload() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (auth.isAuthorized.isFalse) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
final media = await _imagePicker.pickVideo(source: ImageSource.gallery);
|
final media = await _imagePicker.pickVideo(source: ImageSource.gallery);
|
||||||
if (media == null) return;
|
if (media == null) return;
|
||||||
|
|
||||||
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
final file = File(media.path);
|
final file = File(media.path);
|
||||||
_enqueueTask(
|
|
||||||
AttachmentUploadTask(file: file, usage: widget.usage),
|
try {
|
||||||
);
|
await uploadAttachment(await file.readAsBytes(), file.path, null);
|
||||||
|
} catch (err) {
|
||||||
|
context.showErrorDialog(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _pickFileToUpload() async {
|
setState(() => _isBusy = false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> pickFileToUpload() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (auth.isAuthorized.isFalse) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
@ -86,16 +96,22 @@ class _AttachmentEditorPopupState extends State<AttachmentEditorPopup> {
|
|||||||
);
|
);
|
||||||
if (result == null) return;
|
if (result == null) return;
|
||||||
|
|
||||||
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
List<File> files = result.paths.map((path) => File(path!)).toList();
|
List<File> files = result.paths.map((path) => File(path!)).toList();
|
||||||
|
|
||||||
for (final file in files) {
|
for (final file in files) {
|
||||||
_enqueueTask(
|
try {
|
||||||
AttachmentUploadTask(file: file, usage: widget.usage),
|
await uploadAttachment(await file.readAsBytes(), file.path, null);
|
||||||
);
|
} catch (err) {
|
||||||
|
context.showErrorDialog(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _takeMediaToUpload(bool isVideo) async {
|
setState(() => _isBusy = false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> takeMediaToUpload(bool isVideo) async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (auth.isAuthorized.isFalse) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
@ -107,30 +123,50 @@ class _AttachmentEditorPopupState extends State<AttachmentEditorPopup> {
|
|||||||
}
|
}
|
||||||
if (media == null) return;
|
if (media == null) return;
|
||||||
|
|
||||||
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
final file = File(media.path);
|
final file = File(media.path);
|
||||||
_enqueueTask(
|
try {
|
||||||
AttachmentUploadTask(file: file, usage: widget.usage),
|
await uploadAttachment(await file.readAsBytes(), file.path, null);
|
||||||
);
|
} catch (err) {
|
||||||
|
context.showErrorDialog(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _pasteFileToUpload() async {
|
setState(() => _isBusy = false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pasteFileToUpload() async {
|
||||||
final data = await Pasteboard.image;
|
final data = await Pasteboard.image;
|
||||||
if (data == null) return;
|
if (data == null) return;
|
||||||
|
|
||||||
if (_uploadController.isUploading.value) return;
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
_uploadController.uploadAttachmentWithCallback(
|
uploadAttachment(data, 'Pasted Image', null);
|
||||||
data,
|
|
||||||
'Pasted Image',
|
setState(() => _isBusy = false);
|
||||||
widget.usage,
|
|
||||||
null,
|
|
||||||
(item) {
|
|
||||||
widget.onAdd(item.id);
|
|
||||||
if (mounted) {
|
|
||||||
setState(() => _attachments.add(item));
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
Future<void> uploadAttachment(
|
||||||
|
Uint8List data, String path, Map<String, dynamic>? metadata) async {
|
||||||
|
final AttachmentProvider provider = Get.find();
|
||||||
|
try {
|
||||||
|
context.showSnackbar((PlatformInfo.isWeb
|
||||||
|
? 'attachmentUploadingWebMode'
|
||||||
|
: 'attachmentUploading')
|
||||||
|
.trParams({'name': basename(path)}));
|
||||||
|
final resp = await provider.createAttachment(
|
||||||
|
data,
|
||||||
|
path,
|
||||||
|
widget.usage,
|
||||||
|
metadata,
|
||||||
);
|
);
|
||||||
|
var result = Attachment.fromJson(resp.body);
|
||||||
|
setState(() => _attachments.add(result));
|
||||||
|
widget.onUpdate(_attachments.map((e) => e!.id).toList());
|
||||||
|
context.clearSnackbar();
|
||||||
|
} catch (err) {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _formatBytes(int bytes, {int decimals = 2}) {
|
String _formatBytes(int bytes, {int decimals = 2}) {
|
||||||
@ -152,24 +188,24 @@ class _AttachmentEditorPopupState extends State<AttachmentEditorPopup> {
|
|||||||
return '${(bytes / math.pow(k, i)).toStringAsFixed(dm)} ${sizes[i]}';
|
return '${(bytes / math.pow(k, i)).toStringAsFixed(dm)} ${sizes[i]}';
|
||||||
}
|
}
|
||||||
|
|
||||||
void _revertMetadataList() {
|
void revertMetadataList() {
|
||||||
final AttachmentProvider provider = Get.find();
|
final AttachmentProvider provider = Get.find();
|
||||||
|
|
||||||
if (widget.initialAttachments.isEmpty) {
|
if (widget.current.isEmpty) {
|
||||||
_isFirstTimeBusy = false;
|
_isFirstTimeBusy = false;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
_attachments = List.filled(widget.initialAttachments.length, null);
|
_attachments = List.filled(widget.current.length, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
int progress = 0;
|
int progress = 0;
|
||||||
for (var idx = 0; idx < widget.initialAttachments.length; idx++) {
|
for (var idx = 0; idx < widget.current.length; idx++) {
|
||||||
provider.getMetadata(widget.initialAttachments[idx]).then((resp) {
|
provider.getMetadata(widget.current[idx]).then((resp) {
|
||||||
progress++;
|
progress++;
|
||||||
_attachments[idx] = resp;
|
_attachments[idx] = resp;
|
||||||
if (progress == widget.initialAttachments.length) {
|
if (progress == widget.current.length) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isBusy = false;
|
_isBusy = false;
|
||||||
_isFirstTimeBusy = false;
|
_isFirstTimeBusy = false;
|
||||||
@ -179,250 +215,34 @@ class _AttachmentEditorPopupState extends State<AttachmentEditorPopup> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showAttachmentPreview(Attachment element) {
|
void showEdit(Attachment element, int index) {
|
||||||
context.pushTransparentRoute(
|
|
||||||
AttachmentFullScreen(
|
|
||||||
parentId: 'attachment-editor-preview',
|
|
||||||
item: element,
|
|
||||||
),
|
|
||||||
rootNavigator: true,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showEdit(Attachment element, int index) {
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return AttachmentAttrEditorDialog(
|
return AttachmentEditorDialog(
|
||||||
item: element,
|
item: element,
|
||||||
|
onDelete: () {
|
||||||
|
setState(() => _attachments.removeAt(index));
|
||||||
|
widget.onUpdate(_attachments.map((e) => e!.id).toList());
|
||||||
|
},
|
||||||
onUpdate: (item) {
|
onUpdate: (item) {
|
||||||
setState(() => _attachments[index] = item);
|
setState(() => _attachments[index] = item);
|
||||||
|
widget.onUpdate(_attachments.map((e) => e!.id).toList());
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _deleteAttachment(Attachment element) async {
|
|
||||||
setState(() => _isBusy = true);
|
|
||||||
try {
|
|
||||||
final AttachmentProvider provider = Get.find();
|
|
||||||
await provider.deleteAttachment(element.id);
|
|
||||||
} catch (e) {
|
|
||||||
context.showErrorDialog(e);
|
|
||||||
} finally {
|
|
||||||
setState(() => _isBusy = false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildQueueEntry(AttachmentUploadTask element, int index) {
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.only(left: 16, right: 8, bottom: 16),
|
|
||||||
child: Card(
|
|
||||||
color: Theme.of(context).colorScheme.surface,
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
height: 54,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
basename(element.file.path),
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
maxLines: 1,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
fontFamily: 'monospace',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
FutureBuilder(
|
|
||||||
future: element.file.length(),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
if (!snapshot.hasData) {
|
|
||||||
return const Text(
|
|
||||||
'- Bytes',
|
|
||||||
style: TextStyle(fontSize: 12),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return Text(
|
|
||||||
_formatBytes(snapshot.data!),
|
|
||||||
style: const TextStyle(fontSize: 12),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (element.isUploading)
|
|
||||||
SizedBox(
|
|
||||||
width: 40,
|
|
||||||
height: 38,
|
|
||||||
child: Center(
|
|
||||||
child: SizedBox(
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
strokeWidth: 2.5,
|
|
||||||
value: element.progress,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (element.isCompleted)
|
|
||||||
const SizedBox(
|
|
||||||
width: 40,
|
|
||||||
height: 38,
|
|
||||||
child: Center(
|
|
||||||
child: Icon(Icons.check),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (!element.isCompleted && !element.isUploading)
|
|
||||||
IconButton(
|
|
||||||
color: Colors.green,
|
|
||||||
icon: const Icon(Icons.play_arrow),
|
|
||||||
visualDensity: const VisualDensity(horizontal: -4),
|
|
||||||
onPressed: _uploadController.isUploading.value
|
|
||||||
? null
|
|
||||||
: () {
|
|
||||||
_uploadController
|
|
||||||
.performSingleTask(index)
|
|
||||||
.then((r) {
|
|
||||||
widget.onAdd(r.id);
|
|
||||||
if (mounted) {
|
|
||||||
setState(() => _attachments.add(r));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
if (!element.isCompleted && !element.isUploading)
|
|
||||||
IconButton(
|
|
||||||
color: Colors.red,
|
|
||||||
icon: const Icon(Icons.remove_circle),
|
|
||||||
visualDensity: const VisualDensity(horizontal: -4),
|
|
||||||
onPressed: () {
|
|
||||||
_uploadController.dequeueTask(element);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
).paddingSymmetric(vertical: 8, horizontal: 16),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildListEntry(Attachment element, int index) {
|
|
||||||
var fileType = element.mimetype.split('/').firstOrNull;
|
|
||||||
fileType ??= 'unknown';
|
|
||||||
|
|
||||||
final canBePreview = fileType.toLowerCase() == 'image';
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.only(left: 16, right: 8, bottom: 16),
|
|
||||||
child: Card(
|
|
||||||
color: Theme.of(context).colorScheme.surface,
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
height: 54,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
element.alt,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
maxLines: 1,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
fontFamily: 'monospace',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
'${fileType[0].toUpperCase()}${fileType.substring(1)} · ${_formatBytes(element.size)}',
|
|
||||||
style: const TextStyle(fontSize: 12),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
color: Colors.teal,
|
|
||||||
icon: const Icon(Icons.preview),
|
|
||||||
visualDensity: const VisualDensity(horizontal: -4),
|
|
||||||
onPressed: canBePreview
|
|
||||||
? () => _showAttachmentPreview(element)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
PopupMenuButton(
|
|
||||||
icon: const Icon(Icons.more_horiz),
|
|
||||||
iconColor: Theme.of(context).colorScheme.primary,
|
|
||||||
style: const ButtonStyle(
|
|
||||||
visualDensity: VisualDensity(horizontal: -4),
|
|
||||||
),
|
|
||||||
itemBuilder: (BuildContext context) => [
|
|
||||||
PopupMenuItem(
|
|
||||||
child: ListTile(
|
|
||||||
title: Text('edit'.tr),
|
|
||||||
leading: const Icon(Icons.edit),
|
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 8,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onTap: () => _showEdit(element, index),
|
|
||||||
),
|
|
||||||
PopupMenuItem(
|
|
||||||
child: ListTile(
|
|
||||||
title: Text('delete'.tr),
|
|
||||||
leading: const Icon(Icons.delete),
|
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 8,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onTap: () {
|
|
||||||
_deleteAttachment(element).then((_) {
|
|
||||||
widget.onRemove(element.id);
|
|
||||||
setState(() => _attachments.removeAt(index));
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
).paddingSymmetric(vertical: 8, horizontal: 16),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _enqueueTask(AttachmentUploadTask task) {
|
|
||||||
_uploadController.enqueueTask(task);
|
|
||||||
if (_isAutoUpload) {
|
|
||||||
_startUploading();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _startUploading() {
|
|
||||||
_uploadController.performUploadQueue(onData: (r) {
|
|
||||||
widget.onAdd(r.id);
|
|
||||||
if (mounted) {
|
|
||||||
setState(() => _attachments.add(r));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_revertMetadataList();
|
revertMetadataList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -430,150 +250,109 @@ class _AttachmentEditorPopupState extends State<AttachmentEditorPopup> {
|
|||||||
const density = VisualDensity(horizontal: 0, vertical: 0);
|
const density = VisualDensity(horizontal: 0, vertical: 0);
|
||||||
|
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
|
child: SizedBox(
|
||||||
|
height: MediaQuery.of(context).size.height * 0.85,
|
||||||
child: DropTarget(
|
child: DropTarget(
|
||||||
onDragDone: (detail) async {
|
onDragDone: (detail) async {
|
||||||
if (_uploadController.isUploading.value) return;
|
setState(() => _isBusy = true);
|
||||||
for (final file in detail.files) {
|
for (final file in detail.files) {
|
||||||
_enqueueTask(
|
final data = await file.readAsBytes();
|
||||||
AttachmentUploadTask(file: File(file.path), usage: widget.usage),
|
uploadAttachment(data, file.path, null);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
setState(() => _isBusy = false);
|
||||||
},
|
},
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'attachmentAdd'.tr,
|
'attachmentAdd'.tr,
|
||||||
style: Theme.of(context).textTheme.headlineSmall,
|
style: Theme.of(context).textTheme.headlineSmall,
|
||||||
),
|
|
||||||
const SizedBox(width: 10),
|
|
||||||
Obx(() {
|
|
||||||
if (_uploadController.isUploading.value) {
|
|
||||||
return const SizedBox(
|
|
||||||
width: 18,
|
|
||||||
height: 18,
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
strokeWidth: 2.5,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return const SizedBox();
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text('attachmentAutoUpload'.tr),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Switch(
|
|
||||||
value: _isAutoUpload,
|
|
||||||
onChanged: (bool? value) {
|
|
||||||
if (value != null) {
|
|
||||||
setState(() => _isAutoUpload = value);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
).paddingOnly(left: 24, right: 24, top: 32, bottom: 16),
|
).paddingOnly(left: 24, right: 24, top: 32, bottom: 16),
|
||||||
if (_isBusy) const LinearProgressIndicator().animate().scaleX(),
|
if (_isBusy) const LinearProgressIndicator().animate().scaleX(),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: CustomScrollView(
|
child: Builder(builder: (context) {
|
||||||
slivers: [
|
|
||||||
Obx(() {
|
|
||||||
if (_uploadController.queueOfUpload.isNotEmpty) {
|
|
||||||
return SliverPadding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 8),
|
|
||||||
sliver: SliverToBoxAdapter(
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'attachmentUploadQueue'.tr,
|
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
|
||||||
),
|
|
||||||
Obx(() {
|
|
||||||
if (_uploadController.isUploading.value) {
|
|
||||||
return const SizedBox();
|
|
||||||
}
|
|
||||||
return TextButton(
|
|
||||||
child: Text('attachmentUploadQueueStart'.tr),
|
|
||||||
onPressed: () {
|
|
||||||
_startUploading();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
).paddingOnly(left: 24, right: 24),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return const SliverToBoxAdapter(child: SizedBox());
|
|
||||||
}),
|
|
||||||
Obx(() {
|
|
||||||
if (_uploadController.queueOfUpload.isNotEmpty) {
|
|
||||||
return SliverPadding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 8),
|
|
||||||
sliver: SliverList.builder(
|
|
||||||
itemCount: _uploadController.queueOfUpload.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final element =
|
|
||||||
_uploadController.queueOfUpload[index];
|
|
||||||
return _buildQueueEntry(element, index);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return const SliverToBoxAdapter(child: SizedBox());
|
|
||||||
}),
|
|
||||||
if (_attachments.isNotEmpty)
|
|
||||||
SliverPadding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 8),
|
|
||||||
sliver: SliverToBoxAdapter(
|
|
||||||
child: Text(
|
|
||||||
'attachmentAttached'.tr,
|
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
|
||||||
).paddingOnly(left: 24, right: 24),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (_attachments.isNotEmpty)
|
|
||||||
Builder(builder: (context) {
|
|
||||||
if (_isFirstTimeBusy && _isBusy) {
|
if (_isFirstTimeBusy && _isBusy) {
|
||||||
return const SliverFillRemaining(
|
return const Center(
|
||||||
child: Center(
|
|
||||||
child: CircularProgressIndicator(),
|
child: CircularProgressIndicator(),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SliverList.builder(
|
return ListView.builder(
|
||||||
itemCount: _attachments.length,
|
itemCount: _attachments.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final element = _attachments[index];
|
final element = _attachments[index];
|
||||||
return _buildListEntry(element!, index);
|
var fileType = element!.mimetype.split('/').firstOrNull;
|
||||||
},
|
fileType ??= 'unknown';
|
||||||
);
|
return Container(
|
||||||
}),
|
padding: const EdgeInsets.only(
|
||||||
|
left: 16, right: 8, bottom: 16),
|
||||||
|
child: Card(
|
||||||
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
height: 280,
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: const BorderRadius.only(
|
||||||
|
topLeft: Radius.circular(8),
|
||||||
|
topRight: Radius.circular(8),
|
||||||
|
),
|
||||||
|
child: AttachmentItem(
|
||||||
|
parentId: 'attachment-editor',
|
||||||
|
item: element,
|
||||||
|
showBadge: false,
|
||||||
|
showHideButton: false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 54,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment:
|
||||||
|
CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
element.alt,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
maxLines: 1,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontFamily: 'monospace'),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'${fileType[0].toUpperCase()}${fileType.substring(1)} · ${_formatBytes(element.size)}',
|
||||||
|
style:
|
||||||
|
const TextStyle(fontSize: 12),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Obx(() {
|
IconButton(
|
||||||
return IgnorePointer(
|
style: TextButton.styleFrom(
|
||||||
ignoring: _uploadController.isUploading.value,
|
shape: const CircleBorder(),
|
||||||
child: Container(
|
foregroundColor:
|
||||||
|
Theme.of(context).primaryColor,
|
||||||
|
),
|
||||||
|
icon: const Icon(Icons.more_horiz),
|
||||||
|
onPressed: () => showEdit(element, index),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).paddingSymmetric(vertical: 8, horizontal: 16),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
const Divider(thickness: 0.3, height: 0.3),
|
||||||
|
SizedBox(
|
||||||
height: 64,
|
height: 64,
|
||||||
decoration: BoxDecoration(
|
|
||||||
border: Border(
|
|
||||||
top: BorderSide(
|
|
||||||
color: Theme.of(context).dividerColor,
|
|
||||||
width: 0.3,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
child: Wrap(
|
child: Wrap(
|
||||||
@ -582,58 +361,202 @@ class _AttachmentEditorPopupState extends State<AttachmentEditorPopup> {
|
|||||||
alignment: WrapAlignment.center,
|
alignment: WrapAlignment.center,
|
||||||
runAlignment: WrapAlignment.center,
|
runAlignment: WrapAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
if (PlatformInfo.isDesktop ||
|
if (PlatformInfo.isDesktop || PlatformInfo.isIOS || PlatformInfo.isWeb)
|
||||||
PlatformInfo.isIOS ||
|
|
||||||
PlatformInfo.isWeb)
|
|
||||||
ElevatedButton.icon(
|
ElevatedButton.icon(
|
||||||
icon: const Icon(Icons.paste),
|
icon: const Icon(Icons.paste),
|
||||||
label: Text('attachmentAddClipboard'.tr),
|
label: Text('attachmentAddClipboard'.tr),
|
||||||
style: const ButtonStyle(visualDensity: density),
|
style: const ButtonStyle(visualDensity: density),
|
||||||
onPressed: () => _pasteFileToUpload(),
|
onPressed: () => pasteFileToUpload(),
|
||||||
),
|
),
|
||||||
ElevatedButton.icon(
|
ElevatedButton.icon(
|
||||||
icon: const Icon(Icons.add_photo_alternate),
|
icon: const Icon(Icons.add_photo_alternate),
|
||||||
label: Text('attachmentAddGalleryPhoto'.tr),
|
label: Text('attachmentAddGalleryPhoto'.tr),
|
||||||
style: const ButtonStyle(visualDensity: density),
|
style: const ButtonStyle(visualDensity: density),
|
||||||
onPressed: () => _pickPhotoToUpload(),
|
onPressed: () => pickPhotoToUpload(),
|
||||||
),
|
),
|
||||||
ElevatedButton.icon(
|
ElevatedButton.icon(
|
||||||
icon: const Icon(Icons.add_road),
|
icon: const Icon(Icons.add_road),
|
||||||
label: Text('attachmentAddGalleryVideo'.tr),
|
label: Text('attachmentAddGalleryVideo'.tr),
|
||||||
style: const ButtonStyle(visualDensity: density),
|
style: const ButtonStyle(visualDensity: density),
|
||||||
onPressed: () => _pickVideoToUpload(),
|
onPressed: () => pickVideoToUpload(),
|
||||||
),
|
),
|
||||||
ElevatedButton.icon(
|
ElevatedButton.icon(
|
||||||
icon: const Icon(Icons.photo_camera_back),
|
icon: const Icon(Icons.photo_camera_back),
|
||||||
label: Text('attachmentAddCameraPhoto'.tr),
|
label: Text('attachmentAddCameraPhoto'.tr),
|
||||||
style: const ButtonStyle(visualDensity: density),
|
style: const ButtonStyle(visualDensity: density),
|
||||||
onPressed: () => _takeMediaToUpload(false),
|
onPressed: () => takeMediaToUpload(false),
|
||||||
),
|
),
|
||||||
ElevatedButton.icon(
|
ElevatedButton.icon(
|
||||||
icon: const Icon(Icons.video_camera_back_outlined),
|
icon: const Icon(Icons.video_camera_back_outlined),
|
||||||
label: Text('attachmentAddCameraVideo'.tr),
|
label: Text('attachmentAddCameraVideo'.tr),
|
||||||
style: const ButtonStyle(visualDensity: density),
|
style: const ButtonStyle(visualDensity: density),
|
||||||
onPressed: () => _takeMediaToUpload(true),
|
onPressed: () => takeMediaToUpload(true),
|
||||||
),
|
),
|
||||||
ElevatedButton.icon(
|
ElevatedButton.icon(
|
||||||
icon: const Icon(Icons.file_present_rounded),
|
icon: const Icon(Icons.file_present_rounded),
|
||||||
label: Text('attachmentAddFile'.tr),
|
label: Text('attachmentAddFile'.tr),
|
||||||
style: const ButtonStyle(visualDensity: density),
|
style: const ButtonStyle(visualDensity: density),
|
||||||
onPressed: () => _pickFileToUpload(),
|
onPressed: () => pickFileToUpload(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
).paddingSymmetric(horizontal: 12),
|
).paddingSymmetric(horizontal: 12),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.animate(
|
|
||||||
target: _uploadController.isUploading.value ? 0 : 1,
|
|
||||||
)
|
|
||||||
.fade(duration: 100.ms),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AttachmentEditorDialog extends StatefulWidget {
|
||||||
|
final Attachment item;
|
||||||
|
final Function onDelete;
|
||||||
|
final Function(Attachment item) onUpdate;
|
||||||
|
|
||||||
|
const AttachmentEditorDialog(
|
||||||
|
{super.key,
|
||||||
|
required this.item,
|
||||||
|
required this.onDelete,
|
||||||
|
required this.onUpdate});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<AttachmentEditorDialog> createState() => _AttachmentEditorDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AttachmentEditorDialogState extends State<AttachmentEditorDialog> {
|
||||||
|
final _altController = TextEditingController();
|
||||||
|
|
||||||
|
bool _isBusy = false;
|
||||||
|
bool _isMature = false;
|
||||||
|
|
||||||
|
Future<Attachment?> updateAttachment() async {
|
||||||
|
final AttachmentProvider provider = Get.find();
|
||||||
|
|
||||||
|
setState(() => _isBusy = true);
|
||||||
|
try {
|
||||||
|
final resp = await provider.updateAttachment(
|
||||||
|
widget.item.id,
|
||||||
|
_altController.value.text,
|
||||||
|
widget.item.usage,
|
||||||
|
isMature: _isMature,
|
||||||
|
);
|
||||||
|
|
||||||
|
Get.find<AttachmentProvider>().clearCache(id: widget.item.id);
|
||||||
|
|
||||||
|
setState(() => _isBusy = false);
|
||||||
|
return Attachment.fromJson(resp.body);
|
||||||
|
} catch (e) {
|
||||||
|
context.showErrorDialog(e);
|
||||||
|
|
||||||
|
setState(() => _isBusy = false);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> deleteAttachment() async {
|
||||||
|
setState(() => _isBusy = true);
|
||||||
|
try {
|
||||||
|
final AttachmentProvider provider = Get.find();
|
||||||
|
await provider.deleteAttachment(widget.item.id);
|
||||||
|
widget.onDelete();
|
||||||
|
} catch (e) {
|
||||||
|
context.showErrorDialog(e);
|
||||||
|
} finally {
|
||||||
|
setState(() => _isBusy = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncWidget() {
|
||||||
|
_isMature = widget.item.isMature;
|
||||||
|
_altController.text = widget.item.alt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
syncWidget();
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text('attachmentSetting'.tr),
|
||||||
|
content: Container(
|
||||||
|
constraints: const BoxConstraints(minWidth: 400),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
if (_isBusy)
|
||||||
|
ClipRRect(
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||||
|
child: const LinearProgressIndicator().animate().scaleX(),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 18),
|
||||||
|
TextField(
|
||||||
|
controller: _altController,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
isDense: true,
|
||||||
|
prefixIcon: const Icon(Icons.image_not_supported),
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
labelText: 'attachmentAlt'.tr,
|
||||||
|
),
|
||||||
|
onTapOutside: (_) =>
|
||||||
|
FocusManager.instance.primaryFocus?.unfocus(),
|
||||||
|
),
|
||||||
|
Card(
|
||||||
|
child: CheckboxListTile(
|
||||||
|
shape: const RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular(10))),
|
||||||
|
title: Text('matureContent'.tr),
|
||||||
|
secondary: const Icon(Icons.visibility_off),
|
||||||
|
value: _isMature,
|
||||||
|
onChanged: (newValue) {
|
||||||
|
setState(() => _isMature = newValue ?? false);
|
||||||
|
},
|
||||||
|
controlAffinity: ListTileControlAffinity.leading,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actionsAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
actions: <Widget>[
|
||||||
|
TextButton(
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
foregroundColor: Theme.of(context).colorScheme.error),
|
||||||
|
onPressed: () {
|
||||||
|
deleteAttachment().then((_) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: Text('delete'.tr),
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
TextButton(
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
foregroundColor:
|
||||||
|
Theme.of(context).colorScheme.onSurfaceVariant),
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: Text('cancel'.tr),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
child: Text('apply'.tr),
|
||||||
|
onPressed: () {
|
||||||
|
updateAttachment().then((value) {
|
||||||
|
if (value != null) {
|
||||||
|
widget.onUpdate(value);
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import 'package:get/get.dart';
|
|||||||
import 'package:solian/models/attachment.dart';
|
import 'package:solian/models/attachment.dart';
|
||||||
import 'package:solian/widgets/attachments/attachment_item.dart';
|
import 'package:solian/widgets/attachments/attachment_item.dart';
|
||||||
import 'package:solian/providers/content/attachment.dart';
|
import 'package:solian/providers/content/attachment.dart';
|
||||||
import 'package:solian/widgets/attachments/attachment_fullscreen.dart';
|
import 'package:solian/widgets/attachments/attachment_list_fullscreen.dart';
|
||||||
|
|
||||||
class AttachmentList extends StatefulWidget {
|
class AttachmentList extends StatefulWidget {
|
||||||
final String parentId;
|
final String parentId;
|
||||||
@ -320,7 +320,7 @@ class AttachmentListEntry extends StatelessWidget {
|
|||||||
onReveal(true);
|
onReveal(true);
|
||||||
} else if (['image'].contains(item!.mimetype.split('/').first)) {
|
} else if (['image'].contains(item!.mimetype.split('/').first)) {
|
||||||
context.pushTransparentRoute(
|
context.pushTransparentRoute(
|
||||||
AttachmentFullScreen(
|
AttachmentListFullScreen(
|
||||||
parentId: parentId,
|
parentId: parentId,
|
||||||
item: item!,
|
item: item!,
|
||||||
),
|
),
|
||||||
|
@ -16,18 +16,19 @@ import 'package:solian/widgets/attachments/attachment_item.dart';
|
|||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
import 'package:path/path.dart' show extension;
|
import 'package:path/path.dart' show extension;
|
||||||
|
|
||||||
class AttachmentFullScreen extends StatefulWidget {
|
class AttachmentListFullScreen extends StatefulWidget {
|
||||||
final String parentId;
|
final String parentId;
|
||||||
final Attachment item;
|
final Attachment item;
|
||||||
|
|
||||||
const AttachmentFullScreen(
|
const AttachmentListFullScreen(
|
||||||
{super.key, required this.parentId, required this.item});
|
{super.key, required this.parentId, required this.item});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AttachmentFullScreen> createState() => _AttachmentFullScreenState();
|
State<AttachmentListFullScreen> createState() =>
|
||||||
|
_AttachmentListFullScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AttachmentFullScreenState extends State<AttachmentFullScreen> {
|
class _AttachmentListFullScreenState extends State<AttachmentListFullScreen> {
|
||||||
bool _showDetails = true;
|
bool _showDetails = true;
|
||||||
|
|
||||||
bool _isDownloading = false;
|
bool _isDownloading = false;
|
||||||
@ -82,7 +83,7 @@ class _AttachmentFullScreenState extends State<AttachmentFullScreen> {
|
|||||||
setState(() => _isDownloading = true);
|
setState(() => _isDownloading = true);
|
||||||
|
|
||||||
var extName = extension(widget.item.name);
|
var extName = extension(widget.item.name);
|
||||||
if (extName.isEmpty) extName = '.png';
|
if(extName.isEmpty) extName = '.png';
|
||||||
final imagePath =
|
final imagePath =
|
||||||
'${Directory.systemTemp.path}/${widget.item.uuid}$extName';
|
'${Directory.systemTemp.path}/${widget.item.uuid}$extName';
|
||||||
await Dio().download(
|
await Dio().download(
|
@ -112,9 +112,7 @@ class ChatEvent extends StatelessWidget {
|
|||||||
case 'messages.edit':
|
case 'messages.edit':
|
||||||
return ChatEventMessageActionLog(
|
return ChatEventMessageActionLog(
|
||||||
icon: const Icon(Icons.edit_note, size: 16),
|
icon: const Icon(Icons.edit_note, size: 16),
|
||||||
text: 'messageEditDesc'.trParams({
|
text: 'messageEditDesc'.trParams({'id': '#${item.id}'}),
|
||||||
'id': '#${item.body['related_event']}',
|
|
||||||
}),
|
|
||||||
isMerged: isMerged,
|
isMerged: isMerged,
|
||||||
isHasMerged: isHasMerged,
|
isHasMerged: isHasMerged,
|
||||||
isQuote: isQuote,
|
isQuote: isQuote,
|
||||||
@ -122,9 +120,7 @@ class ChatEvent extends StatelessWidget {
|
|||||||
case 'messages.delete':
|
case 'messages.delete':
|
||||||
return ChatEventMessageActionLog(
|
return ChatEventMessageActionLog(
|
||||||
icon: const Icon(Icons.cancel_schedule_send, size: 16),
|
icon: const Icon(Icons.cancel_schedule_send, size: 16),
|
||||||
text: 'messageDeleteDesc'.trParams({
|
text: 'messageDeleteDesc'.trParams({'id': '#${item.id}'}),
|
||||||
'id': '#${item.body['related_event']}',
|
|
||||||
}),
|
|
||||||
isMerged: isMerged,
|
isMerged: isMerged,
|
||||||
isHasMerged: isHasMerged,
|
isHasMerged: isHasMerged,
|
||||||
isQuote: isQuote,
|
isQuote: isQuote,
|
||||||
|
@ -38,7 +38,7 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
|
|||||||
final TextEditingController _textController = TextEditingController();
|
final TextEditingController _textController = TextEditingController();
|
||||||
final FocusNode _focusNode = FocusNode();
|
final FocusNode _focusNode = FocusNode();
|
||||||
|
|
||||||
final List<int> _attachments = List.empty(growable: true);
|
List<int> _attachments = List.empty(growable: true);
|
||||||
|
|
||||||
Event? _editTo;
|
Event? _editTo;
|
||||||
Event? _replyTo;
|
Event? _replyTo;
|
||||||
@ -46,19 +46,11 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
|
|||||||
void _editAttachments() {
|
void _editAttachments() {
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
|
isScrollControlled: true,
|
||||||
builder: (context) => AttachmentEditorPopup(
|
builder: (context) => AttachmentEditorPopup(
|
||||||
usage: 'm.attachment',
|
usage: 'm.attachment',
|
||||||
initialAttachments: _attachments,
|
current: _attachments,
|
||||||
onAdd: (value) {
|
onUpdate: (value) => _attachments = value,
|
||||||
setState(() {
|
|
||||||
_attachments.add(value);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onRemove: (value) {
|
|
||||||
setState(() {
|
|
||||||
_attachments.remove(value);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user