refactor: Update to new receive sharing intent package
This commit is contained in:
parent
625680ee2e
commit
9bd6399cd5
9 changed files with 119 additions and 368 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
@ -26,7 +25,6 @@ import 'package:fluffychat/widgets/avatar.dart';
|
|||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||
import '../../../utils/account_bundles.dart';
|
||||
import '../../config/setting_keys.dart';
|
||||
import '../../utils/matrix_sdk_extensions/matrix_file_extension.dart';
|
||||
import '../../utils/url_launcher.dart';
|
||||
import '../../utils/voip/callkeep_manager.dart';
|
||||
import '../../widgets/fluffy_chat_app.dart';
|
||||
|
|
@ -196,20 +194,14 @@ class ChatListController extends State<ChatList>
|
|||
// Share content into this room
|
||||
final shareContent = Matrix.of(context).shareContent;
|
||||
if (shareContent != null) {
|
||||
final shareFile = shareContent.tryGet<MatrixFile>('file');
|
||||
final shareFile = shareContent.tryGet<XFile>('file');
|
||||
if (shareContent.tryGet<String>('msgtype') == 'chat.fluffy.shared_file' &&
|
||||
shareFile != null) {
|
||||
await showDialog(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
builder: (c) => SendFileDialog(
|
||||
files: [
|
||||
XFile.fromData(
|
||||
shareFile.bytes,
|
||||
name: shareFile.name,
|
||||
mimeType: shareFile.mimeType,
|
||||
),
|
||||
],
|
||||
files: [shareFile],
|
||||
room: room,
|
||||
outerContext: context,
|
||||
),
|
||||
|
|
@ -432,16 +424,32 @@ class ChatListController extends State<ChatList>
|
|||
? SelectMode.share
|
||||
: SelectMode.normal;
|
||||
|
||||
void _processIncomingSharedFiles(List<SharedMediaFile> files) {
|
||||
void _processIncomingSharedMedia(List<SharedMediaFile> files) {
|
||||
if (files.isEmpty) return;
|
||||
final file = File(files.first.path.replaceFirst('file://', ''));
|
||||
|
||||
if (files.length > 1) {
|
||||
Logs().w(
|
||||
'Received ${files.length} incoming shared media but app can only handle the first one',
|
||||
);
|
||||
}
|
||||
|
||||
// We only handle the first file currently
|
||||
final sharedMedia = files.first;
|
||||
|
||||
// Handle URIs and Texts, which are also passed in path
|
||||
if (sharedMedia.type case SharedMediaType.text || SharedMediaType.url) {
|
||||
return _processIncomingSharedText(sharedMedia.path);
|
||||
}
|
||||
|
||||
final file = XFile(
|
||||
sharedMedia.path.replaceFirst('file://', ''),
|
||||
mimeType: sharedMedia.mimeType,
|
||||
);
|
||||
|
||||
Matrix.of(context).shareContent = {
|
||||
'msgtype': 'chat.fluffy.shared_file',
|
||||
'file': MatrixFile(
|
||||
bytes: file.readAsBytesSync(),
|
||||
name: file.path,
|
||||
).detectFileType,
|
||||
'file': file,
|
||||
if (sharedMedia.message != null) 'body': sharedMedia.message,
|
||||
};
|
||||
context.go('/rooms');
|
||||
}
|
||||
|
|
@ -473,18 +481,14 @@ class ChatListController extends State<ChatList>
|
|||
if (!PlatformInfos.isMobile) return;
|
||||
|
||||
// For sharing images coming from outside the app while the app is in the memory
|
||||
_intentFileStreamSubscription = ReceiveSharingIntent.getMediaStream()
|
||||
.listen(_processIncomingSharedFiles, onError: print);
|
||||
_intentFileStreamSubscription = ReceiveSharingIntent.instance
|
||||
.getMediaStream()
|
||||
.listen(_processIncomingSharedMedia, onError: print);
|
||||
|
||||
// For sharing images coming from outside the app while the app is closed
|
||||
ReceiveSharingIntent.getInitialMedia().then(_processIncomingSharedFiles);
|
||||
|
||||
// For sharing or opening urls/text coming from outside the app while the app is in the memory
|
||||
_intentDataStreamSubscription = ReceiveSharingIntent.getTextStream()
|
||||
.listen(_processIncomingSharedText, onError: print);
|
||||
|
||||
// For sharing or opening urls/text coming from outside the app while the app is closed
|
||||
ReceiveSharingIntent.getInitialText().then(_processIncomingSharedText);
|
||||
ReceiveSharingIntent.instance
|
||||
.getInitialMedia()
|
||||
.then(_processIncomingSharedMedia);
|
||||
|
||||
// For receiving shared Uris
|
||||
_intentUriStreamSubscription = linkStream.listen(_processIncomingUris);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue