Use SimpleDialogs
This commit is contained in:
parent
d154adf517
commit
547aace85c
21 changed files with 119 additions and 111 deletions
|
|
@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_sound/flutter_sound.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'matrix.dart';
|
||||
import 'dialogs/simple_dialogs.dart';
|
||||
|
||||
class AudioPlayer extends StatefulWidget {
|
||||
final Color color;
|
||||
|
|
@ -48,7 +48,7 @@ class _AudioPlayerState extends State<AudioPlayer> {
|
|||
_downloadAction() async {
|
||||
if (status != AudioPlayerStatus.NOT_DOWNLOADED) return;
|
||||
setState(() => status = AudioPlayerStatus.DOWNLOADING);
|
||||
final matrixFile = await Matrix.of(context)
|
||||
final matrixFile = await SimpleDialogs(context)
|
||||
.tryRequestWithErrorToast(widget.event.downloadAndDecryptAttachment());
|
||||
setState(() {
|
||||
audioFile = matrixFile.bytes;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
void startCallAction(BuildContext context) async {
|
||||
final url =
|
||||
'${Matrix.of(context).jitsiInstance}${Uri.encodeComponent(widget.room.id.localpart)}';
|
||||
final success = await Matrix.of(context)
|
||||
final success = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(widget.room.sendEvent({
|
||||
'msgtype': Matrix.callNamespace,
|
||||
'body': url,
|
||||
|
|
@ -86,7 +86,7 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
case "leave":
|
||||
bool confirmed = await SimpleDialogs(context).askConfirmation();
|
||||
if (confirmed) {
|
||||
final success = await Matrix.of(context)
|
||||
final success = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(widget.room.leave());
|
||||
if (success != false) {
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
|
|
@ -96,11 +96,11 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
}
|
||||
break;
|
||||
case "mute":
|
||||
await Matrix.of(context).tryRequestWithLoadingDialog(
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
widget.room.setPushRuleState(PushRuleState.mentions_only));
|
||||
break;
|
||||
case "unmute":
|
||||
await Matrix.of(context).tryRequestWithLoadingDialog(
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
widget.room.setPushRuleState(PushRuleState.notify));
|
||||
break;
|
||||
case "call":
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import 'package:fluffychat/i18n/i18n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:flutter_styled_toast/flutter_styled_toast.dart';
|
||||
|
||||
class SimpleDialogs {
|
||||
final BuildContext context;
|
||||
|
|
@ -22,7 +24,7 @@ class SimpleDialogs {
|
|||
await showDialog(
|
||||
context: context,
|
||||
builder: (c) => AlertDialog(
|
||||
title: Text(titleText ?? I18n.of(context).enterAUsername),
|
||||
title: Text(titleText ?? 'Please enter a text'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
|
|
@ -104,4 +106,46 @@ class SimpleDialogs {
|
|||
);
|
||||
return confirmed;
|
||||
}
|
||||
|
||||
Future<dynamic> tryRequestWithLoadingDialog(Future<dynamic> request,
|
||||
{Function(MatrixException) onAdditionalAuth}) async {
|
||||
showLoadingDialog(context);
|
||||
final dynamic = await tryRequestWithErrorToast(request,
|
||||
onAdditionalAuth: onAdditionalAuth);
|
||||
Navigator.of(context)?.pop();
|
||||
return dynamic;
|
||||
}
|
||||
|
||||
Future<dynamic> tryRequestWithErrorToast(Future<dynamic> request,
|
||||
{Function(MatrixException) onAdditionalAuth}) async {
|
||||
try {
|
||||
return await request;
|
||||
} on MatrixException catch (exception) {
|
||||
if (exception.requireAdditionalAuthentication &&
|
||||
onAdditionalAuth != null) {
|
||||
return await tryRequestWithErrorToast(onAdditionalAuth(exception));
|
||||
} else {
|
||||
showToast(exception.errorMessage);
|
||||
}
|
||||
} catch (exception) {
|
||||
showToast(exception.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
showLoadingDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
content: Row(
|
||||
children: <Widget>[
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(width: 16),
|
||||
Text(I18n.of(context).loadingPleaseWait),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class _EncryptionButtonState extends State<EncryptionButton> {
|
|||
confirmText: I18n.of(context).yes,
|
||||
) ==
|
||||
true) {
|
||||
await Matrix.of(context).tryRequestWithLoadingDialog(
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
widget.room.enableEncryption(),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ class ChatListItem extends StatelessWidget {
|
|||
void clickAction(BuildContext context) async {
|
||||
if (!activeChat) {
|
||||
if (room.membership == Membership.invite &&
|
||||
await Matrix.of(context).tryRequestWithLoadingDialog(room.join()) ==
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(room.join()) ==
|
||||
false) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -60,7 +61,7 @@ class ChatListItem extends StatelessWidget {
|
|||
child: Text(I18n.of(context).rejoin.toUpperCase(),
|
||||
style: TextStyle(color: Colors.blue)),
|
||||
onPressed: () async {
|
||||
await Matrix.of(context)
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(room.join());
|
||||
await Navigator.of(context).pop();
|
||||
},
|
||||
|
|
@ -74,7 +75,7 @@ class ChatListItem extends StatelessWidget {
|
|||
if (Matrix.of(context).shareContent != null) {
|
||||
if (Matrix.of(context).shareContent["msgtype"] ==
|
||||
"chat.fluffy.shared_file") {
|
||||
await Matrix.of(context).tryRequestWithErrorToast(
|
||||
await SimpleDialogs(context).tryRequestWithErrorToast(
|
||||
room.sendFileEvent(
|
||||
Matrix.of(context).shareContent["file"],
|
||||
),
|
||||
|
|
@ -96,8 +97,8 @@ class ChatListItem extends StatelessWidget {
|
|||
Future<bool> archiveAction(BuildContext context) async {
|
||||
{
|
||||
if ([Membership.leave, Membership.ban].contains(room.membership)) {
|
||||
final success =
|
||||
await Matrix.of(context).tryRequestWithLoadingDialog(room.forget());
|
||||
final success = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(room.forget());
|
||||
if (success != false) {
|
||||
if (this.onForget != null) this.onForget();
|
||||
}
|
||||
|
|
@ -107,8 +108,8 @@ class ChatListItem extends StatelessWidget {
|
|||
if (!confirmed) {
|
||||
return false;
|
||||
}
|
||||
final success =
|
||||
await Matrix.of(context).tryRequestWithLoadingDialog(room.leave());
|
||||
final success = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(room.leave());
|
||||
if (success == false) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:bubble/bubble.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:fluffychat/components/message_content.dart';
|
||||
import 'package:fluffychat/components/reply_content.dart';
|
||||
import 'package:fluffychat/i18n/i18n.dart';
|
||||
|
|
@ -116,7 +117,7 @@ class Message extends StatelessWidget {
|
|||
I18n.of(context).requestPermission,
|
||||
style: TextStyle(color: textColor),
|
||||
),
|
||||
onPressed: () => Matrix.of(context)
|
||||
onPressed: () => SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(event.requestKey()),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
|
|
|
|||
|
|
@ -14,36 +14,39 @@ class ParticipantListItem extends StatelessWidget {
|
|||
const ParticipantListItem(this.user);
|
||||
|
||||
participantAction(BuildContext context, String action) async {
|
||||
final MatrixState matrix = Matrix.of(context);
|
||||
switch (action) {
|
||||
case "ban":
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
await matrix.tryRequestWithLoadingDialog(user.ban());
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(user.ban());
|
||||
}
|
||||
break;
|
||||
case "unban":
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
await matrix.tryRequestWithLoadingDialog(user.unban());
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.unban());
|
||||
}
|
||||
break;
|
||||
case "kick":
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
await matrix.tryRequestWithLoadingDialog(user.kick());
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(user.kick());
|
||||
}
|
||||
break;
|
||||
case "admin":
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
await matrix.tryRequestWithLoadingDialog(user.setPower(100));
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.setPower(100));
|
||||
}
|
||||
break;
|
||||
case "moderator":
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
await matrix.tryRequestWithLoadingDialog(user.setPower(50));
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.setPower(50));
|
||||
}
|
||||
break;
|
||||
case "user":
|
||||
if (await SimpleDialogs(context).askConfirmation()) {
|
||||
await matrix.tryRequestWithLoadingDialog(user.setPower(0));
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.setPower(0));
|
||||
}
|
||||
break;
|
||||
case "message":
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class PresenceListItem extends StatelessWidget {
|
|||
width: 80,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
SizedBox(height: 6),
|
||||
SizedBox(height: 9),
|
||||
Avatar(avatarUrl, displayname),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../i18n/i18n.dart';
|
||||
import '../../utils/app_route.dart';
|
||||
import '../../views/chat.dart';
|
||||
import '../avatar.dart';
|
||||
import '../matrix.dart';
|
||||
|
||||
class PublicRoomListItem extends StatelessWidget {
|
||||
final PublicRoomEntry publicRoomEntry;
|
||||
|
|
@ -13,7 +13,7 @@ class PublicRoomListItem extends StatelessWidget {
|
|||
const PublicRoomListItem(this.publicRoomEntry, {Key key}) : super(key: key);
|
||||
|
||||
void joinAction(BuildContext context) async {
|
||||
final success = await Matrix.of(context)
|
||||
final success = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(publicRoomEntry.join());
|
||||
if (success != false) {
|
||||
await Navigator.of(context).push(
|
||||
|
|
|
|||
|
|
@ -77,53 +77,6 @@ class MatrixState extends State<Matrix> {
|
|||
await storage.deleteItem(widget.clientName);
|
||||
}
|
||||
|
||||
BuildContext _loadingDialogContext;
|
||||
|
||||
Future<dynamic> tryRequestWithLoadingDialog(Future<dynamic> request,
|
||||
{Function(MatrixException) onAdditionalAuth}) async {
|
||||
showLoadingDialog(context);
|
||||
final dynamic = await tryRequestWithErrorToast(request,
|
||||
onAdditionalAuth: onAdditionalAuth);
|
||||
hideLoadingDialog();
|
||||
return dynamic;
|
||||
}
|
||||
|
||||
Future<dynamic> tryRequestWithErrorToast(Future<dynamic> request,
|
||||
{Function(MatrixException) onAdditionalAuth}) async {
|
||||
try {
|
||||
return await request;
|
||||
} on MatrixException catch (exception) {
|
||||
if (exception.requireAdditionalAuthentication &&
|
||||
onAdditionalAuth != null) {
|
||||
return await tryRequestWithErrorToast(onAdditionalAuth(exception));
|
||||
} else {
|
||||
showToast(exception.errorMessage);
|
||||
}
|
||||
} catch (exception) {
|
||||
showToast(exception.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
showLoadingDialog(BuildContext context) {
|
||||
_loadingDialogContext = context;
|
||||
showDialog(
|
||||
context: _loadingDialogContext,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
content: Row(
|
||||
children: <Widget>[
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(width: 16),
|
||||
Text(I18n.of(context).loadingPleaseWait),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
hideLoadingDialog() => Navigator.of(_loadingDialogContext)?.pop();
|
||||
|
||||
Future<String> downloadAndSaveContent(MxContent content,
|
||||
{int width, int height, ThumbnailMethod method}) async {
|
||||
final bool thumbnail = width == null && height == null ? false : true;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import 'package:link_text/link_text.dart';
|
|||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:fluffychat/utils/matrix_file_extension.dart';
|
||||
|
||||
import 'dialogs/simple_dialogs.dart';
|
||||
import 'matrix.dart';
|
||||
|
||||
class MessageContent extends StatelessWidget {
|
||||
|
|
@ -60,8 +61,9 @@ class MessageContent extends StatelessWidget {
|
|||
);
|
||||
return;
|
||||
}
|
||||
final MatrixFile matrixFile = await Matrix.of(context)
|
||||
.tryRequestWithLoadingDialog(
|
||||
final MatrixFile matrixFile =
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(
|
||||
event.downloadAndDecryptAttachment(),
|
||||
);
|
||||
matrixFile.open();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue