-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2048 from acterglobal/kumar/pin-improvement
- Loading branch information
Showing
30 changed files
with
1,582 additions
and
496 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- [New] : Brand new UI-UX for Pin creation | ||
- [New] : Support for adding attachment while Pin Creation | ||
- [New] : Now you can add one or more Link as attachment for Pin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
app/lib/features/attachments/actions/handle_selected_attachments.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import 'dart:io'; | ||
import 'dart:typed_data'; | ||
import 'package:flutter_gen/gen_l10n/l10n.dart'; | ||
import 'package:acter/common/models/types.dart'; | ||
import 'package:acter/features/home/providers/client_providers.dart'; | ||
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart' | ||
show AttachmentDraft, AttachmentsManager; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_easyloading/flutter_easyloading.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:logging/logging.dart'; | ||
import 'package:mime/mime.dart'; | ||
|
||
final _log = Logger('a3::action::attachments'); | ||
|
||
// if generic attachment, send via manager | ||
Future<void> handleAttachmentSelected({ | ||
required BuildContext context, | ||
required WidgetRef ref, | ||
required AttachmentsManager manager, | ||
required List<File> attachments, | ||
String? title, | ||
String? link, | ||
required AttachmentType attachmentType, | ||
}) async { | ||
/// converts user selected media to attachment draft and sends state list. | ||
/// only supports image/video/audio/file. | ||
final lang = L10n.of(context); | ||
EasyLoading.show(status: lang.sendingAttachment); | ||
final client = ref.read(alwaysClientProvider); | ||
List<AttachmentDraft> drafts = []; | ||
try { | ||
for (var selected in attachments) { | ||
final file = selected; | ||
final mimeType = lookupMimeType(file.path); | ||
if (mimeType == null) throw lang.failedToDetectMimeType; | ||
if (attachmentType == AttachmentType.camera || | ||
attachmentType == AttachmentType.image) { | ||
Uint8List bytes = await file.readAsBytes(); | ||
final decodedImage = await decodeImageFromList(bytes); | ||
final imageDraft = client | ||
.imageDraft(file.path, mimeType) | ||
.size(bytes.length) | ||
.width(decodedImage.width) | ||
.height(decodedImage.height); | ||
final attachmentDraft = await manager.contentDraft(imageDraft); | ||
drafts.add(attachmentDraft); | ||
} else if (attachmentType == AttachmentType.audio) { | ||
Uint8List bytes = await file.readAsBytes(); | ||
final audioDraft = | ||
client.audioDraft(file.path, mimeType).size(bytes.length); | ||
final attachmentDraft = await manager.contentDraft(audioDraft); | ||
drafts.add(attachmentDraft); | ||
} else if (attachmentType == AttachmentType.video) { | ||
Uint8List bytes = await file.readAsBytes(); | ||
final videoDraft = | ||
client.videoDraft(file.path, mimeType).size(bytes.length); | ||
final attachmentDraft = await manager.contentDraft(videoDraft); | ||
drafts.add(attachmentDraft); | ||
} else { | ||
String fileName = file.path.split('/').last; | ||
final fileDraft = client | ||
.fileDraft(file.path, mimeType) | ||
.filename(fileName) | ||
.size(file.lengthSync()); | ||
final attachmentDraft = await manager.contentDraft(fileDraft); | ||
drafts.add(attachmentDraft); | ||
} | ||
} | ||
if (attachmentType == AttachmentType.link && link != null) { | ||
final attachmentDraft = await manager.linkDraft(link, title); | ||
drafts.add(attachmentDraft); | ||
} | ||
for (var draft in drafts) { | ||
final res = await draft.send(); | ||
_log.info('attachment sent: $res'); | ||
} | ||
EasyLoading.dismiss(); | ||
} catch (e) { | ||
_log.severe('Error sending attachments', e); | ||
if (!context.mounted) { | ||
EasyLoading.dismiss(); | ||
return; | ||
} | ||
EasyLoading.showError( | ||
lang.errorSendingAttachment(e), | ||
duration: const Duration(seconds: 3), | ||
); | ||
} | ||
} |
Oops, something went wrong.