refactor: Switch to loading dialog
This commit is contained in:
parent
9521a93622
commit
75797a62b9
36 changed files with 461 additions and 350 deletions
|
|
@ -3,12 +3,12 @@ import 'dart:typed_data';
|
|||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/message_download_content.dart';
|
||||
import 'package:flushbar/flushbar_helper.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_sound/flutter_sound.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:universal_html/prefer_universal/html.dart' as html;
|
||||
import 'dialogs/simple_dialogs.dart';
|
||||
import '../utils/ui_fake.dart' if (dart.library.html) 'dart:ui' as ui;
|
||||
import 'matrix.dart';
|
||||
import '../utils/event_extension.dart';
|
||||
|
|
@ -68,13 +68,19 @@ class _AudioPlayerState extends State<AudioPlayer> {
|
|||
Future<void> _downloadAction() async {
|
||||
if (status != AudioPlayerStatus.NOT_DOWNLOADED) return;
|
||||
setState(() => status = AudioPlayerStatus.DOWNLOADING);
|
||||
final matrixFile = await SimpleDialogs(context).tryRequestWithErrorToast(
|
||||
widget.event.downloadAndDecryptAttachmentCached());
|
||||
setState(() {
|
||||
audioFile = matrixFile.bytes;
|
||||
status = AudioPlayerStatus.DOWNLOADED;
|
||||
});
|
||||
_playAction();
|
||||
try {
|
||||
final matrixFile =
|
||||
await widget.event.downloadAndDecryptAttachmentCached();
|
||||
setState(() {
|
||||
audioFile = matrixFile.bytes;
|
||||
status = AudioPlayerStatus.DOWNLOADED;
|
||||
});
|
||||
_playAction();
|
||||
} catch (e, s) {
|
||||
Logs().v('Could not download audio file', e, s);
|
||||
await FlushbarHelper.createError(message: e.toLocalizedString(context))
|
||||
.show(context);
|
||||
}
|
||||
}
|
||||
|
||||
void _playAction() async {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../app_config.dart';
|
||||
import 'dialogs/simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'matrix.dart';
|
||||
|
||||
class ChatSettingsPopupMenu extends StatefulWidget {
|
||||
|
|
@ -35,12 +35,13 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
void startCallAction(BuildContext context) async {
|
||||
final url =
|
||||
'${AppConfig.jitsiInstance}${Uri.encodeComponent(widget.room.id.localpart)}';
|
||||
final success = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(widget.room.sendEvent({
|
||||
'msgtype': Matrix.callNamespace,
|
||||
'body': url,
|
||||
}));
|
||||
if (success == false) return;
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => widget.room.sendEvent({
|
||||
'msgtype': Matrix.callNamespace,
|
||||
'body': url,
|
||||
}));
|
||||
if (success.error != null) return;
|
||||
await launch(url);
|
||||
}
|
||||
|
||||
|
|
@ -91,9 +92,9 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
title: L10n.of(context).areYouSure,
|
||||
);
|
||||
if (confirmed == OkCancelResult.ok) {
|
||||
final success = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(widget.room.leave());
|
||||
if (success != false) {
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context, future: () => widget.room.leave());
|
||||
if (success.error == null) {
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(context, ChatListView()),
|
||||
(Route r) => false);
|
||||
|
|
@ -101,12 +102,16 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
}
|
||||
break;
|
||||
case 'mute':
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
widget.room.setPushRuleState(PushRuleState.mentions_only));
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () =>
|
||||
widget.room.setPushRuleState(PushRuleState.mentions_only));
|
||||
break;
|
||||
case 'unmute':
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
widget.room.setPushRuleState(PushRuleState.notify));
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () =>
|
||||
widget.room.setPushRuleState(PushRuleState.notify));
|
||||
break;
|
||||
case 'call':
|
||||
startCallAction(context);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import 'package:fluffychat/views/settings.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import 'dialogs/simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'matrix.dart';
|
||||
|
||||
class DefaultDrawer extends StatelessWidget {
|
||||
|
|
@ -37,8 +37,9 @@ class DefaultDrawer extends StatelessWidget {
|
|||
);
|
||||
if (input == null || input.single.isEmpty) return;
|
||||
final client = Matrix.of(context).client;
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
client.sendPresence(
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => client.sendPresence(
|
||||
client.userID,
|
||||
PresenceType.online,
|
||||
statusMsg: input.single,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import 'package:adaptive_dialog/adaptive_dialog.dart';
|
|||
import 'package:famedlysdk/encryption.dart';
|
||||
import 'package:famedlysdk/encryption/utils/bootstrap.dart';
|
||||
import 'package:fluffychat/components/dialogs/adaptive_flat_button.dart';
|
||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
@ -119,11 +119,12 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
|
|||
)
|
||||
]);
|
||||
if (input?.isEmpty ?? true) return;
|
||||
final valid =
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
bootstrap.newSsssKey.unlock(keyOrPassphrase: input.single),
|
||||
final valid = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () =>
|
||||
bootstrap.newSsssKey.unlock(keyOrPassphrase: input.single),
|
||||
);
|
||||
if (valid != false) bootstrap.openExistingSsss();
|
||||
if (valid.error == null) bootstrap.openExistingSsss();
|
||||
}));
|
||||
break;
|
||||
case BootstrapState.askWipeCrossSigning:
|
||||
|
|
@ -237,9 +238,12 @@ class _AskUnlockOldSsssState extends State<_AskUnlockOldSsss> {
|
|||
return;
|
||||
}
|
||||
|
||||
valid = await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
widget.ssssKey.unlock(keyOrPassphrase: input),
|
||||
);
|
||||
valid = (await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => widget.ssssKey.unlock(keyOrPassphrase: input),
|
||||
))
|
||||
.error ==
|
||||
null;
|
||||
setState(() => null);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import '../avatar.dart';
|
||||
import 'adaptive_flat_button.dart';
|
||||
import 'simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import '../../utils/string_color.dart';
|
||||
|
||||
class KeyVerificationDialog extends StatefulWidget {
|
||||
|
|
@ -70,25 +70,26 @@ class _KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||
if (input == null) {
|
||||
return;
|
||||
}
|
||||
final valid = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(Future.microtask(() async {
|
||||
// make sure the loading spinner shows before we test the keys
|
||||
await Future.delayed(Duration(milliseconds: 100));
|
||||
var valid = false;
|
||||
try {
|
||||
await widget.request.openSSSS(recoveryKey: input);
|
||||
valid = true;
|
||||
} catch (_) {
|
||||
try {
|
||||
await widget.request.openSSSS(passphrase: input);
|
||||
valid = true;
|
||||
} catch (_) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}));
|
||||
if (valid == false) {
|
||||
final valid = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
// make sure the loading spinner shows before we test the keys
|
||||
await Future.delayed(Duration(milliseconds: 100));
|
||||
var valid = false;
|
||||
try {
|
||||
await widget.request.openSSSS(recoveryKey: input);
|
||||
valid = true;
|
||||
} catch (_) {
|
||||
try {
|
||||
await widget.request.openSSSS(passphrase: input);
|
||||
valid = true;
|
||||
} catch (_) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
});
|
||||
if (valid.error != null) {
|
||||
await showOkAlertDialog(
|
||||
context: context,
|
||||
message: L10n.of(context).incorrectPassphraseOrKey,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import 'package:famedlysdk/famedlysdk.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import '../../components/dialogs/simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import '../../utils/matrix_file_extension.dart';
|
||||
import '../../utils/room_send_file_extension.dart';
|
||||
import '../../utils/resize_image.dart';
|
||||
|
|
@ -88,8 +88,8 @@ class _SendFileDialogState extends State<SendFileDialog> {
|
|||
setState(() {
|
||||
_isSending = true;
|
||||
});
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(_send());
|
||||
await showFutureLoadingDialog(
|
||||
context: context, future: () => _send());
|
||||
await Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
import 'package:flushbar/flushbar_helper.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
class SimpleDialogs {
|
||||
final BuildContext context;
|
||||
|
||||
const SimpleDialogs(this.context);
|
||||
|
||||
Future<dynamic> tryRequestWithLoadingDialog(Future<dynamic> request,
|
||||
{Function(MatrixException) onAdditionalAuth}) async {
|
||||
final futureResult = tryRequestWithErrorToast(
|
||||
request,
|
||||
onAdditionalAuth: onAdditionalAuth,
|
||||
);
|
||||
return showDialog<dynamic>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
futureResult.then(
|
||||
(result) => Navigator.of(context).pop<dynamic>(result),
|
||||
);
|
||||
return AlertDialog(
|
||||
title: Text(L10n.of(context).loadingPleaseWait),
|
||||
content: LinearProgressIndicator(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
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 {
|
||||
await FlushbarHelper.createError(message: exception.errorMessage)
|
||||
.show(context);
|
||||
}
|
||||
} catch (exception) {
|
||||
await FlushbarHelper.createError(message: exception.toString())
|
||||
.show(context);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ import 'package:fluffychat/views/chat_encryption_settings.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import 'dialogs/simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'matrix.dart';
|
||||
|
||||
class EncryptionButton extends StatefulWidget {
|
||||
|
|
@ -46,8 +46,9 @@ class _EncryptionButtonState extends State<EncryptionButton> {
|
|||
okLabel: L10n.of(context).yes,
|
||||
) ==
|
||||
OkCancelResult.ok) {
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
widget.room.enableEncryption(),
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => widget.room.enableEncryption(),
|
||||
);
|
||||
// we want to enable the lock icon
|
||||
setState(() => null);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import '../../utils/date_time_extension.dart';
|
|||
import '../../views/chat.dart';
|
||||
import '../avatar.dart';
|
||||
import '../dialogs/send_file_dialog.dart';
|
||||
import '../dialogs/simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import '../matrix.dart';
|
||||
import '../mouse_over_builder.dart';
|
||||
import '../theme_switcher.dart';
|
||||
|
|
@ -41,9 +41,10 @@ class ChatListItem extends StatelessWidget {
|
|||
if (onTap != null) return onTap();
|
||||
if (!activeChat) {
|
||||
if (room.membership == Membership.invite &&
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(room.join()) ==
|
||||
false) {
|
||||
(await showFutureLoadingDialog(
|
||||
context: context, future: () => room.join()))
|
||||
.error !=
|
||||
null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -77,8 +78,10 @@ class ChatListItem extends StatelessWidget {
|
|||
await archiveAction(context);
|
||||
break;
|
||||
case ArchivedRoomAction.rejoin:
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(room.join());
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.join(),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -111,9 +114,11 @@ class ChatListItem extends StatelessWidget {
|
|||
Future<void> archiveAction(BuildContext context) async {
|
||||
{
|
||||
if ([Membership.leave, Membership.ban].contains(room.membership)) {
|
||||
final success = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(room.forget());
|
||||
if (success != false) {
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.forget(),
|
||||
);
|
||||
if (success.error == null) {
|
||||
if (onForget != null) onForget();
|
||||
}
|
||||
return success;
|
||||
|
|
@ -123,7 +128,8 @@ class ChatListItem extends StatelessWidget {
|
|||
title: L10n.of(context).areYouSure,
|
||||
);
|
||||
if (confirmed == OkCancelResult.cancel) return;
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(room.leave());
|
||||
await showFutureLoadingDialog(
|
||||
context: context, future: () => room.leave());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:famedlysdk/matrix_api.dart';
|
||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
|
|
@ -15,13 +15,15 @@ class PublicRoomListItem extends StatelessWidget {
|
|||
const PublicRoomListItem(this.publicRoomEntry, {Key key}) : super(key: key);
|
||||
|
||||
void joinAction(BuildContext context) async {
|
||||
final success = await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(_joinRoomAndWait(context));
|
||||
if (success != false) {
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => _joinRoomAndWait(context),
|
||||
);
|
||||
if (success.error == null) {
|
||||
await Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatView(success),
|
||||
ChatView(success.result),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:famedlysdk/encryption/utils/key_verification.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/audio_player.dart';
|
||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:fluffychat/components/image_bubble.dart';
|
||||
import 'package:fluffychat/utils/event_extension.dart';
|
||||
import 'package:fluffychat/utils/matrix_locals.dart';
|
||||
|
|
@ -54,10 +54,11 @@ class MessageContent extends StatelessWidget {
|
|||
};
|
||||
await KeyVerificationDialog(request: req).show(context);
|
||||
} else {
|
||||
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
event.requestKey(),
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => event.requestKey(),
|
||||
);
|
||||
if (success != false) {
|
||||
if (success.error == null) {
|
||||
await FlushbarHelper.createLoading(
|
||||
title: L10n.of(context).loadingPleaseWait,
|
||||
message: L10n.of(context).requestToReadOlderMessages,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import 'package:famedlysdk/famedlysdk.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
|
||||
import 'dialogs/simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'matrix.dart';
|
||||
|
||||
class MessageReactions extends StatelessWidget {
|
||||
|
|
@ -48,12 +48,16 @@ class MessageReactions extends StatelessWidget {
|
|||
e.content['m.relates_to']['key'] == r.key,
|
||||
orElse: () => null);
|
||||
if (evt != null) {
|
||||
SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(evt.redact());
|
||||
showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => evt.redact(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
event.room.sendReaction(event.eventId, r.key));
|
||||
showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () =>
|
||||
event.room.sendReaction(event.eventId, r.key));
|
||||
}
|
||||
},
|
||||
))
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import 'content_banner.dart';
|
|||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import '../utils/presence_extension.dart';
|
||||
import 'dialogs/simple_dialogs.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'matrix.dart';
|
||||
import 'dialogs/key_verification_dialog.dart';
|
||||
import '../utils/app_route.dart';
|
||||
|
|
@ -36,20 +36,28 @@ class UserBottomSheet extends StatelessWidget {
|
|||
break;
|
||||
case 'ban':
|
||||
if (await _askConfirmation()) {
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(user.ban());
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => user.ban(),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
break;
|
||||
case 'unban':
|
||||
if (await _askConfirmation()) {
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.unban());
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => user.unban(),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
break;
|
||||
case 'kick':
|
||||
if (await _askConfirmation()) {
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(user.kick());
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => user.kick(),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
break;
|
||||
|
|
@ -59,8 +67,10 @@ class UserBottomSheet extends StatelessWidget {
|
|||
.show(context);
|
||||
if (newPermission != null) {
|
||||
if (newPermission == 100 && await _askConfirmation() == false) break;
|
||||
await SimpleDialogs(context)
|
||||
.tryRequestWithLoadingDialog(user.setPower(newPermission));
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => user.setPower(newPermission),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue