change: Chat backup dialog as a banner

This commit is contained in:
Krille Fear 2021-11-19 09:12:47 +01:00
parent 213339678c
commit dcfd717c6c
4 changed files with 50 additions and 29 deletions

View File

@ -2615,5 +2615,7 @@
"openGallery": "Open gallery", "openGallery": "Open gallery",
"removeFromSpace": "Remove from space", "removeFromSpace": "Remove from space",
"removeFromSpaceDescription": "This removes this chat from the current space. It will then still be visible under \"All chats\".", "removeFromSpaceDescription": "This removes this chat from the current space. It will then still be visible under \"All chats\".",
"addToSpaceDescription": "Select a space to add this chat to it." "addToSpaceDescription": "Select a space to add this chat to it.",
"start": "Start",
"setupChatBackupNow": "Set up your chat backup now"
} }

View File

@ -57,14 +57,18 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
bool _wipe; bool _wipe;
@override
void initState() {
_createBootstrap(widget.wipe);
super.initState();
}
void _createBootstrap(bool wipe) { void _createBootstrap(bool wipe) {
setState(() { _wipe = wipe;
_wipe = wipe; titleText = null;
titleText = null; _recoveryKeyStored = false;
_recoveryKeyStored = false; bootstrap = widget.client.encryption
bootstrap = widget.client.encryption .bootstrap(onUpdate: () => setState(() => null));
.bootstrap(onUpdate: () => setState(() => null));
});
} }
@override @override
@ -76,20 +80,7 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
: const LinearProgressIndicator(); : const LinearProgressIndicator();
titleText = L10n.of(context).loadingPleaseWait; titleText = L10n.of(context).loadingPleaseWait;
if (bootstrap == null) { if (bootstrap.newSsssKey?.recoveryKey != null &&
titleText = L10n.of(context).setupChatBackup;
body = Column(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset('assets/backup.png', fit: BoxFit.contain),
Text(L10n.of(context).setupChatBackupDescription),
],
);
buttons.add(AdaptiveFlatButton(
label: L10n.of(context).next,
onPressed: () => _createBootstrap(false),
));
} else if (bootstrap.newSsssKey?.recoveryKey != null &&
_recoveryKeyStored == false) { _recoveryKeyStored == false) {
final key = bootstrap.newSsssKey.recoveryKey; final key = bootstrap.newSsssKey.recoveryKey;
titleText = L10n.of(context).securityKey; titleText = L10n.of(context).securityKey;
@ -183,6 +174,11 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
child: ListView( child: ListView(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
children: [ children: [
Text(
L10n.of(context).setupChatBackupDescription,
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
TextField( TextField(
minLines: 4, minLines: 4,
maxLines: 4, maxLines: 4,
@ -275,7 +271,7 @@ class _BootstrapDialogState extends State<BootstrapDialog> {
cancelLabel: L10n.of(context).cancel, cancelLabel: L10n.of(context).cancel,
isDestructiveAction: true, isDestructiveAction: true,
)) { )) {
_createBootstrap(true); setState(() => _createBootstrap(true));
} }
}, },
) )

View File

@ -79,13 +79,13 @@ class ChatListController extends State<ChatList> {
final selectedRoomIds = <String>{}; final selectedRoomIds = <String>{};
bool crossSigningCached; bool crossSigningCached;
bool hideChatBackupBanner = false; bool showChatBackupBanner = false;
void hideChatBackupBannerAction() =>
setState(() => hideChatBackupBanner = true);
void firstRunBootstrapAction() async { void firstRunBootstrapAction() async {
hideChatBackupBannerAction(); setState(() {
showChatBackupBanner = false;
});
await BootstrapDialog( await BootstrapDialog(
client: Matrix.of(context).client, client: Matrix.of(context).client,
).show(context); ).show(context);
@ -181,7 +181,9 @@ class ChatListController extends State<ChatList> {
crossSigning == false; crossSigning == false;
final isUnknownSession = Matrix.of(context).client.isUnknownSession; final isUnknownSession = Matrix.of(context).client.isUnknownSession;
if (needsBootstrap || isUnknownSession) { if (needsBootstrap || isUnknownSession) {
firstRunBootstrapAction(); setState(() {
showChatBackupBanner = true;
});
} }
} }

View File

@ -182,6 +182,27 @@ class ChatListView extends StatelessWidget {
), ),
body: Column(children: [ body: Column(children: [
const ConnectionStatusHeader(), const ConnectionStatusHeader(),
AnimatedContainer(
height: controller.showChatBackupBanner ? 54 : 0,
duration: const Duration(milliseconds: 300),
clipBehavior: Clip.hardEdge,
curve: Curves.bounceInOut,
decoration: const BoxDecoration(),
child: MaterialBanner(
leading: Image.asset(
'assets/backup.png',
fit: BoxFit.contain,
width: 44,
),
content: Text(L10n.of(context).setupChatBackupNow),
actions: [
TextButton(
onPressed: controller.firstRunBootstrapAction,
child: Text(L10n.of(context).start),
),
],
),
),
Expanded(child: _ChatListViewBody(controller)), Expanded(child: _ChatListViewBody(controller)),
]), ]),
floatingActionButton: selectMode == SelectMode.normal floatingActionButton: selectMode == SelectMode.normal