open composer view when selected share file

This commit is contained in:
ManhNTX
2022-08-02 10:59:04 +07:00
committed by Dat H. Pham
parent 31afbdb60f
commit 7d33899aba
13 changed files with 115 additions and 98 deletions
-21
View File
@@ -82,27 +82,6 @@
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="video/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="video/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
<provider
@@ -0,0 +1,19 @@
# 12. change-app-group-id-in-receive-sharing-intent
Date: 2022-08-03
## Status
Accepted
## Context
Because this app group id not same app bundle id in iOS so i changed the code to get the app group id by bundle id with the app group id of this project.
## Decision
Required define APP_GROUP_ID in User-Defined at Build Setting
## Consequences
- Can share image like normal
+3
View File
@@ -460,6 +460,7 @@
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
APP_GROUP_ID = group.com.linagora.teammail;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
@@ -593,6 +594,7 @@
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
APP_GROUP_ID = group.com.linagora.teammail;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
@@ -620,6 +622,7 @@
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
APP_GROUP_ID = group.com.linagora.teammail;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
+2
View File
@@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AppGroupId</key>
<string>${APP_GROUP_ID}</string>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
-5
View File
@@ -26,12 +26,8 @@
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>15</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>15</integer>
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
<integer>15</integer>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
@@ -39,7 +35,6 @@
</dict>
<key>PHSupportedMediaTypes</key>
<array>
<string>Video</string>
<string>Image</string>
</array>
</dict>
@@ -5,15 +5,13 @@ import Photos
class ShareViewController: SLComposeServiceViewController {
var hostAppBundleIdentifier = ""
let appGroupId = "group.com.linagora.teammail"
var appGroupId = ""
let sharedKey = "ShareKey"
var sharedMedia: [SharedMediaFile] = []
var sharedText: [String] = []
let imageContentType = kUTTypeImage as String
let videoContentType = kUTTypeMovie as String
let textContentType = kUTTypeText as String
let urlContentType = kUTTypeURL as String
let fileURLType = kUTTypeFileURL as String;
override func isContentValid() -> Bool {
return true
@@ -30,6 +28,9 @@ class ShareViewController: SLComposeServiceViewController {
let lastIndexOfPoint = shareExtensionAppBundleIdentifier.lastIndex(of: ".");
hostAppBundleIdentifier = String(shareExtensionAppBundleIdentifier[..<lastIndexOfPoint!]);
// loading custom AppGroupId from Build Settings or use group.<hostAppBundleIdentifier>
appGroupId = (Bundle.main.object(forInfoDictionaryKey: "AppGroupId") as? String) ?? "group.\(hostAppBundleIdentifier)";
}
override func viewDidLoad() {
@@ -50,12 +51,8 @@ class ShareViewController: SLComposeServiceViewController {
handleImages(content: content, attachment: attachment, index: index)
} else if attachment.hasItemConformingToTypeIdentifier(textContentType) {
handleText(content: content, attachment: attachment, index: index)
} else if attachment.hasItemConformingToTypeIdentifier(fileURLType) {
handleFiles(content: content, attachment: attachment, index: index)
} else if attachment.hasItemConformingToTypeIdentifier(urlContentType) {
handleUrl(content: content, attachment: attachment, index: index)
} else if attachment.hasItemConformingToTypeIdentifier(videoContentType) {
handleVideos(content: content, attachment: attachment, index: index)
}
}
}
@@ -142,65 +139,6 @@ class ShareViewController: SLComposeServiceViewController {
}
}
private func handleVideos (content: NSExtensionItem, attachment: NSItemProvider, index: Int) {
attachment.loadItem(forTypeIdentifier: videoContentType, options: nil) { [weak self] data, error in
if error == nil, let url = data as? URL, let this = self {
// Always copy
let fileName = this.getFileName(from: url, type: .video)
let newPath = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: this.appGroupId)!
.appendingPathComponent(fileName)
let copied = this.copyFile(at: url, to: newPath)
if(copied) {
guard let sharedFile = this.getSharedMediaFile(forVideo: newPath) else {
return
}
this.sharedMedia.append(sharedFile)
}
// If this is the last item, save imagesData in userDefaults and redirect to host app
if index == (content.attachments?.count)! - 1 {
let userDefaults = UserDefaults(suiteName: this.appGroupId)
userDefaults?.set(this.toData(data: this.sharedMedia), forKey: this.sharedKey)
userDefaults?.synchronize()
this.redirectToHostApp(type: .media)
}
} else {
self?.dismissWithError()
}
}
}
private func handleFiles (content: NSExtensionItem, attachment: NSItemProvider, index: Int) {
attachment.loadItem(forTypeIdentifier: fileURLType, options: nil) { [weak self] data, error in
if error == nil, let url = data as? URL, let this = self {
// Always copy
let fileName = this.getFileName(from :url, type: .file)
let newPath = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: this.appGroupId)!
.appendingPathComponent(fileName)
let copied = this.copyFile(at: url, to: newPath)
if (copied) {
this.sharedMedia.append(SharedMediaFile(path: newPath.absoluteString, thumbnail: nil, duration: nil, type: .file))
}
if index == (content.attachments?.count)! - 1 {
let userDefaults = UserDefaults(suiteName: this.appGroupId)
userDefaults?.set(this.toData(data: this.sharedMedia), forKey: this.sharedKey)
userDefaults?.synchronize()
this.redirectToHostApp(type: .file)
}
} else {
self?.dismissWithError()
}
}
}
private func dismissWithError() {
print("[ERROR] Error loading data!")
@@ -25,6 +25,7 @@ import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:model/model.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:tmail_ui_user/features/base/base_controller.dart';
import 'package:tmail_ui_user/features/composer/domain/model/contact_suggestion_source.dart';
import 'package:tmail_ui_user/features/composer/domain/model/email_request.dart';
@@ -317,6 +318,7 @@ class ComposerController extends BaseController {
if (arguments.emailActionType == EmailActionType.edit) {
_getEmailContentAction(arguments);
}
_initEmailAddress(arguments);
_initSubjectEmail(arguments);
_initAttachments(arguments);
@@ -902,7 +904,40 @@ class ComposerController extends BaseController {
}
}
List<InlineImage> covertListSharedMediaFileToFile(List<SharedMediaFile> value) {
List<File> newFiles = List.empty(growable: true);
if (value.isNotEmpty) {
for (var element in value) {
newFiles.add(File(
Platform.isIOS
? element.type == SharedMediaType.FILE
? element.path.toString().replaceAll('file:/', '')
: element.path
: element.path,
));
}
}
final List<InlineImage> listInlineImage = newFiles.map(
(e) => InlineImage(
ImageSource.local,
fileInfo: FileInfo(
e.path.split('/').last,
e.path,
e.existsSync() ? e.lengthSync() : 0,
)
)
).toList();
return listInlineImage;
}
void _getEmailContentAction(ComposerArguments arguments) async {
if(arguments.listSharedMediaFile != null && arguments.listSharedMediaFile!.isNotEmpty){
final listInlineImage = covertListSharedMediaFileToFile(arguments.listSharedMediaFile!);
for (var e in listInlineImage) {
_uploadInlineAttachmentsAction(e.fileInfo!);
}
}
if(arguments.emailContents != null && arguments.emailContents!.isNotEmpty){
_emailContents = arguments.emailContents;
emailContentsViewState.value = Right(GetEmailContentSuccess(_emailContents!,[],[]));
@@ -1,12 +1,14 @@
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:model/model.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:tmail_ui_user/main/routes/router_arguments.dart';
class ComposerArguments extends RouterArguments {
final EmailActionType emailActionType;
final PresentationEmail? presentationEmail;
final List<EmailContent>? emailContents;
final List<SharedMediaFile>? listSharedMediaFile;
final EmailAddress? emailAddress;
final List<Attachment>? attachments;
final Role? mailboxRole;
@@ -18,6 +20,7 @@ class ComposerArguments extends RouterArguments {
this.attachments,
this.mailboxRole,
this.emailAddress,
this.listSharedMediaFile,
});
@override
@@ -28,5 +31,6 @@ class ComposerArguments extends RouterArguments {
attachments,
mailboxRole,
emailAddress,
listSharedMediaFile,
];
}
@@ -3,9 +3,7 @@ import 'package:dartz/dartz.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:model/account/account.dart';
import 'package:model/oidc/request/oidc_request.dart';
import 'package:model/oidc/token_oidc.dart';
import 'package:model/model.dart';
import 'package:tmail_ui_user/features/base/base_controller.dart';
import 'package:tmail_ui_user/features/caching/caching_manager.dart';
import 'package:tmail_ui_user/features/cleanup/domain/model/cleanup_rule.dart';
@@ -100,6 +98,11 @@ class HomeController extends BaseController {
_emailReceiveManager.setPendingEmailAddress(EmailAddress(null, uri.path));
}
});
_emailReceiveManager.receivingFileSharingStream.listen((listFile) {
log('HomeController::onInit(): SharedMediaFile: ${listFile.toString()}');
_emailReceiveManager.setPendingFileInfo(listFile);
});
}
void _goToLogin({LoginArguments? arguments}) {
@@ -89,6 +89,7 @@ class MailboxDashBoardController extends ReloadableController {
RouterArguments? routerArguments;
late StreamSubscription _connectivityStreamSubscription;
late StreamSubscription _emailReceiveManagerStreamSubscription;
late StreamSubscription _fileReceiveManagerStreamSubscription;
final StreamController<Either<Failure, Success>> _progressStateController =
StreamController<Either<Failure, Success>>.broadcast();
@@ -110,6 +111,7 @@ class MailboxDashBoardController extends ReloadableController {
void onInit() {
_registerNetworkConnectivityState();
_registerPendingEmailAddress();
_registerPendingFileInfo();
_initializeIsolateExecutor();
super.onInit();
}
@@ -239,6 +241,22 @@ class MailboxDashBoardController extends ReloadableController {
});
}
void _registerPendingFileInfo() {
_fileReceiveManagerStreamSubscription =
_emailReceiveManager.pendingFileInfo.stream.listen((listFile) {
log('MailboxDashBoardController::_registerPendingFileInfo(): ${listFile.length}');
if (listFile.isNotEmpty) {
_emailReceiveManager.clearPendingFileInfo();
final arguments = ComposerArguments(
emailActionType: EmailActionType.edit,
mailboxRole: selectedMailbox.value?.role,
listSharedMediaFile: listFile,
);
goToComposer(arguments);
}
});
}
void _initializeIsolateExecutor() async {
await _isolateExecutor.warmUp(log: BuildUtils.isDebugMode);
@@ -556,6 +574,7 @@ class MailboxDashBoardController extends ReloadableController {
void onClose() {
_emailReceiveManager.closeEmailReceiveManagerStream();
_emailReceiveManagerStreamSubscription.cancel();
_fileReceiveManagerStreamSubscription.cancel();
_connectivityStreamSubscription.cancel();
_progressStateController.close();
_isolateExecutor.dispose();
+1 -1
View File
@@ -1,5 +1,5 @@
{
"@@last_modified": "2022-07-27T12:01:37.344258",
"@@last_modified": "2022-08-03T00:27:26.944930",
"initializing_data": "Initializing data...",
"@initializing_data": {
"type": "text",
+21 -1
View File
@@ -8,13 +8,16 @@ class EmailReceiveManager {
BehaviorSubject<EmailAddress?> _pendingEmailAddressInfo = BehaviorSubject.seeded(null);
BehaviorSubject<EmailAddress?> get pendingEmailAddressInfo => _pendingEmailAddressInfo;
BehaviorSubject<List<SharedMediaFile>> _pendingFileInfo = BehaviorSubject.seeded(List.empty(growable: true));
BehaviorSubject<List<SharedMediaFile>> get pendingFileInfo => _pendingFileInfo;
Stream<Uri?> get receivingSharingStream {
return Rx.merge([
Stream.fromFuture(ReceiveSharingIntent.getInitialTextAsUri()),
ReceiveSharingIntent.getTextStreamAsUri()
]);
}
Stream<List<SharedMediaFile>> get receivingSharingStream2 {
Stream<List<SharedMediaFile>> get receivingFileSharingStream {
return Rx.merge([
Stream.fromFuture(ReceiveSharingIntent.getInitialMedia()),
ReceiveSharingIntent.getMediaStream()
@@ -37,4 +40,21 @@ class EmailReceiveManager {
void closeEmailReceiveManagerStream() {
_pendingEmailAddressInfo.close();
}
void setPendingFileInfo(List<SharedMediaFile> list) async {
clearPendingFileInfo();
_pendingFileInfo.add(list);
}
void clearPendingFileInfo() {
if(_pendingFileInfo.isClosed) {
_pendingFileInfo = BehaviorSubject.seeded(List.empty(growable: true));
} else {
_pendingFileInfo.add(List.empty(growable: true));
}
}
void closeFileSharingStream() {
_pendingFileInfo.close();
}
}
+1 -1
View File
@@ -146,7 +146,7 @@ dependencies:
receive_sharing_intent:
git:
url: https://github.com/ManhNTX/receive_sharing_intent.git
url: https://github.com/KasemJaffer/receive_sharing_intent.git
ref: master
dropdown_button2: 1.4.0