Skip to content

Commit

Permalink
Improve tom bootstrap dialog (#979)
Browse files Browse the repository at this point in the history
* Create init client dialog on mobile

* Implement new bootstrap dialog for mobile

* Implement new on auth screen for web

* Prevent back button and back android during loading in homeserver picker

* Fix dialog overlap when resizing screen

* Fix dialog overlap when resizing screen

* Handle error for `_getRecoveryWords`

* Handle error for Twake welcome screen
  • Loading branch information
nqhhdev authored Jun 17, 2024
1 parent 3642616 commit 1a47da0
Show file tree
Hide file tree
Showing 17 changed files with 642 additions and 303 deletions.
5 changes: 5 additions & 0 deletions assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3031,6 +3031,11 @@
}
},
"downloading": "Downloading",
"settingUpYourTwake": "Setting up your Twake\nIt could take a while",
"performingAutomaticalLogin": "Performing automatical login via SSO",
"backingUpYourMessage": "Preparing server environment for backing up your messages",
"recoveringYourEncryptedChats": "Recovering your encrypted chats",
"configureDataEncryption": "Configure data encryption",
"configurationNotFound": "The configuration data not found",
"fileSavedToGallery": "File saved to Gallery",
"saveFileToGalleryError": "Failed to save file to Gallery",
Expand Down
2 changes: 2 additions & 0 deletions assets/twake_loading.json

Large diffs are not rendered by default.

32 changes: 19 additions & 13 deletions lib/pages/bootstrap/bootstrap_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
centerTitle: true,
leading: IconButton(
icon: const Icon(Icons.close),
onPressed: Navigator.of(context).pop,
onPressed: () => Navigator.of(context).pop(false),
),
title: Text(L10n.of(context)!.recoveryKey),
),
Expand Down Expand Up @@ -233,7 +233,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
centerTitle: true,
leading: IconButton(
icon: const Icon(Icons.close),
onPressed: Navigator.of(context).pop,
onPressed: () => Navigator.of(context).pop(false),
),
title: Text(L10n.of(context)!.chatBackup),
),
Expand Down Expand Up @@ -372,8 +372,6 @@ class BootstrapDialogState extends State<BootstrapDialog> {
isDestructiveAction: true,
)) {
await TomBootstrapDialog(
wipe: true,
wipeRecovery: true,
client: widget.client,
).show().then(
(value) => Navigator.of(
Expand Down Expand Up @@ -426,12 +424,17 @@ class BootstrapDialogState extends State<BootstrapDialog> {
);
break;
case BootstrapState.done:
titleText = L10n.of(context)!.everythingReady;
titleText = null;
body = Column(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset('assets/backup.png', fit: BoxFit.contain),
Text(L10n.of(context)!.yourChatBackupHasBeenSetUp),
Flexible(
child: Text(
L10n.of(context)!.yourChatBackupHasBeenSetUp,
textAlign: TextAlign.center,
),
),
],
);
buttons.add(
Expand All @@ -448,16 +451,19 @@ class BootstrapDialogState extends State<BootstrapDialog> {
return AlertDialog(
content: Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 16.0),
child: body,
),
Expanded(
child: Text(
titleText!,
overflow: TextOverflow.ellipsis,
child: Padding(
padding: const EdgeInsets.only(right: 16.0),
child: body,
),
),
if (titleText != null)
Expanded(
child: Text(
titleText!,
overflow: TextOverflow.ellipsis,
),
),
],
),
actions: buttons.isNotEmpty ? buttons : null,
Expand Down
137 changes: 137 additions & 0 deletions lib/pages/bootstrap/init_client_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import 'dart:async';
import 'package:fluffychat/presentation/model/client_login_state_event.dart';
import 'package:fluffychat/widgets/layouts/agruments/logged_in_body_args.dart';
import 'package:fluffychat/widgets/layouts/agruments/logged_in_other_account_body_args.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:fluffychat/widgets/twake_app.dart';
import 'package:flutter/material.dart';
import 'package:matrix/matrix.dart';

class InitClientDialog extends StatefulWidget {
final Future Function() future;

const InitClientDialog({
super.key,
required this.future,
});

@override
State<InitClientDialog> createState() => _InitClientDialogState();
}

class _InitClientDialogState extends State<InitClientDialog>
with TickerProviderStateMixin {
late AnimationController loginSSOProgressController;

Client? _clientFirstLoggedIn;

Client? _clientAddAnotherAccount;

StreamSubscription? _clientLoginStateChangedSubscription;

@override
void initState() {
_initial();
_clientLoginStateChangedSubscription =
Matrix.of(context).onClientLoginStateChanged.stream.listen(
_listenClientLoginStateChanged,
);
WidgetsBinding.instance.addPostFrameCallback(
(_) async {
_startLoginSSOProgress();
await widget
.future()
.then(
(_) => _handleFunctionOnDone(),
)
.onError(
(error, _) => _handleFunctionOnError(error),
);
},
);

super.initState();
}

void _listenClientLoginStateChanged(ClientLoginStateEvent event) {
Logs().i(
'StreamDialogBuilder::_listenClientLoginStateChanged - ${event.multipleAccountLoginType}',
);
if (event.multipleAccountLoginType ==
MultipleAccountLoginType.firstLoggedIn) {
_clientFirstLoggedIn = event.client;
return;
}

if (event.multipleAccountLoginType ==
MultipleAccountLoginType.otherAccountLoggedIn) {
_clientAddAnotherAccount = event.client;
return;
}
}

void _handleFunctionOnDone() async {
Logs().i('StreamDialogBuilder::_handleFunctionOnDone');
Navigator.of(context, rootNavigator: false).pop();
if (_clientFirstLoggedIn != null) {
_handleFirstLoggedIn(_clientFirstLoggedIn!);
return;
}

if (_clientAddAnotherAccount != null) {
_handleAddAnotherAccount(_clientAddAnotherAccount!);
return;
}
}

void _handleFunctionOnError(Object? error) {
Logs().e('StreamDialogBuilder::_handleFunctionOnError - $error');
Navigator.pop(context);
}

void _handleFirstLoggedIn(Client client) {
TwakeApp.router.go(
'/rooms',
extra: LoggedInBodyArgs(
newActiveClient: client,
),
);
}

void _handleAddAnotherAccount(Client client) {
TwakeApp.router.go(
'/rooms',
extra: LoggedInOtherAccountBodyArgs(
newActiveClient: client,
),
);
}

void _initial() {
loginSSOProgressController = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
);
}

void _startLoginSSOProgress() {
loginSSOProgressController.addListener(() {
setState(() {});
});
loginSSOProgressController.repeat();
}

@override
void dispose() {
loginSSOProgressController.dispose();
_clientLoginStateChangedSubscription?.cancel();
super.dispose();
}

@override
Widget build(BuildContext context) {
return const Scaffold(
backgroundColor: Colors.transparent,
);
}
}
Loading

0 comments on commit 1a47da0

Please sign in to comment.