Receive sharing intent
This commit is contained in:
parent
a0828535d5
commit
701c4d2757
11 changed files with 167 additions and 77 deletions
67
lib/components/image_bubble.dart
Normal file
67
lib/components/image_bubble.dart
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import 'package:bubble/bubble.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluffychat/utils/matrix_file_extension.dart';
|
||||
|
||||
class ImageBubble extends StatefulWidget {
|
||||
final Event event;
|
||||
|
||||
const ImageBubble(this.event, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ImageBubbleState createState() => _ImageBubbleState();
|
||||
}
|
||||
|
||||
class _ImageBubbleState extends State<ImageBubble> {
|
||||
MatrixFile _file;
|
||||
dynamic _error;
|
||||
|
||||
Future<MatrixFile> _getFile() async {
|
||||
if (_file != null) return _file;
|
||||
return widget.event.downloadAndDecryptAttachment();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final int size = 400;
|
||||
return Bubble(
|
||||
padding: BubbleEdges.all(0),
|
||||
radius: Radius.circular(10),
|
||||
elevation: 0,
|
||||
child: Container(
|
||||
height: size.toDouble(),
|
||||
width: size.toDouble(),
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
if (_error != null) {
|
||||
return Center(
|
||||
child: Text(
|
||||
_error.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (_file != null) {
|
||||
return InkWell(
|
||||
onTap: () => _file.open(),
|
||||
child: Image.memory(
|
||||
_file.bytes,
|
||||
width: size.toDouble(),
|
||||
height: size.toDouble(),
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
);
|
||||
}
|
||||
_getFile().then((MatrixFile file) {
|
||||
setState(() => _file = file);
|
||||
}, onError: (error) {
|
||||
setState(() => _error = error);
|
||||
});
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -77,7 +77,16 @@ class ChatListItem extends StatelessWidget {
|
|||
|
||||
if (room.membership == Membership.join) {
|
||||
if (Matrix.of(context).shareContent != null) {
|
||||
unawaited(room.sendEvent(Matrix.of(context).shareContent));
|
||||
if (Matrix.of(context).shareContent["msgtype"] ==
|
||||
"chat.fluffy.shared_file") {
|
||||
await Matrix.of(context).tryRequestWithErrorToast(
|
||||
room.sendFileEvent(
|
||||
Matrix.of(context).shareContent["file"],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
unawaited(room.sendEvent(Matrix.of(context).shareContent));
|
||||
}
|
||||
Matrix.of(context).shareContent = null;
|
||||
}
|
||||
await Navigator.pushAndRemoveUntil(
|
||||
|
|
|
|||
|
|
@ -394,7 +394,6 @@ class _InheritedMatrix extends InheritedWidget {
|
|||
bool update = old.data.client.accessToken != this.data.client.accessToken ||
|
||||
old.data.client.userID != this.data.client.userID ||
|
||||
old.data.client.matrixVersions != this.data.client.matrixVersions ||
|
||||
old.data.client.lazyLoadMembers != this.data.client.lazyLoadMembers ||
|
||||
old.data.client.deviceID != this.data.client.deviceID ||
|
||||
old.data.client.deviceName != this.data.client.deviceName ||
|
||||
old.data.client.homeserver != this.data.client.homeserver;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:bubble/bubble.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/audio_player.dart';
|
||||
import 'package:fluffychat/components/image_bubble.dart';
|
||||
import 'package:fluffychat/i18n/i18n.dart';
|
||||
import 'package:fluffychat/utils/event_extension.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
|
@ -26,37 +27,7 @@ class MessageContent extends StatelessWidget {
|
|||
switch (event.messageType) {
|
||||
case MessageTypes.Image:
|
||||
case MessageTypes.Sticker:
|
||||
final int size = 400;
|
||||
return Bubble(
|
||||
padding: BubbleEdges.all(0),
|
||||
radius: Radius.circular(10),
|
||||
elevation: 0,
|
||||
child: Container(
|
||||
height: size.toDouble(),
|
||||
width: size.toDouble(),
|
||||
child: FutureBuilder<MatrixFile>(
|
||||
future: event.downloadAndDecryptAttachment(),
|
||||
builder: (BuildContext context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(
|
||||
snapshot.error.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (snapshot.hasData) {
|
||||
return InkWell(
|
||||
onTap: () => snapshot.data.open(),
|
||||
child: Image.memory(snapshot.data.bytes),
|
||||
);
|
||||
}
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
return ImageBubble(event);
|
||||
case MessageTypes.Audio:
|
||||
return AudioPlayer(
|
||||
event,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue