Enhanced UX and clean up

This commit is contained in:
Christian Pauly 2020-02-16 11:36:18 +01:00
parent 7b2f4c0163
commit e665f4adc3
6 changed files with 41 additions and 89 deletions

View file

@ -7,6 +7,7 @@ import 'package:fluffychat/views/chat_details.dart';
import 'package:fluffychat/views/chat_list.dart'; import 'package:fluffychat/views/chat_list.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'dialogs/simple_dialogs.dart';
import 'matrix.dart'; import 'matrix.dart';
class ChatSettingsPopupMenu extends StatefulWidget { class ChatSettingsPopupMenu extends StatefulWidget {
@ -66,11 +67,16 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
onSelected: (String choice) async { onSelected: (String choice) async {
switch (choice) { switch (choice) {
case "leave": case "leave":
await Matrix.of(context) bool confirmed = await SimpleDialogs(context).askConfirmation();
if (confirmed) {
final success = await Matrix.of(context)
.tryRequestWithLoadingDialog(widget.room.leave()); .tryRequestWithLoadingDialog(widget.room.leave());
if (success != false) {
await Navigator.of(context).pushAndRemoveUntil( await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(context, ChatListView()), AppRoute.defaultRoute(context, ChatListView()),
(Route r) => false); (Route r) => false);
}
}
break; break;
case "mute": case "mute":
await Matrix.of(context).tryRequestWithLoadingDialog( await Matrix.of(context).tryRequestWithLoadingDialog(

View file

@ -1,36 +0,0 @@
import 'package:fluffychat/i18n/i18n.dart';
import 'package:flutter/material.dart';
class ConfirmDialog extends StatelessWidget {
const ConfirmDialog(
this.text,
this.confirmText,
this.onConfirmed,
);
final String text;
final String confirmText;
final Function(BuildContext) onConfirmed;
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(text),
actions: <Widget>[
FlatButton(
child: Text(I18n.of(context).close.toUpperCase(),
style: TextStyle(color: Colors.blueGrey)),
onPressed: () => Navigator.of(context).pop(),
),
FlatButton(
child: Text(
confirmText.toUpperCase(),
),
onPressed: () {
Navigator.of(context).pop();
onConfirmed(context);
},
),
],
);
}
}

View file

@ -37,18 +37,23 @@ class SimpleDialogs {
labelText: labelText, labelText: labelText,
prefixText: prefixText, prefixText: prefixText,
suffixText: suffixText, suffixText: suffixText,
prefixStyle: TextStyle(color: Theme.of(context).primaryColor),
suffixStyle: TextStyle(color: Theme.of(context).primaryColor),
border: OutlineInputBorder(), border: OutlineInputBorder(),
), ),
), ),
actions: <Widget>[ actions: <Widget>[
FlatButton( FlatButton(
child: Text(cancelText ?? I18n.of(context).close.toUpperCase(), child: Text(
cancelText?.toUpperCase() ??
I18n.of(context).close.toUpperCase(),
style: TextStyle(color: Colors.blueGrey)), style: TextStyle(color: Colors.blueGrey)),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
), ),
FlatButton( FlatButton(
child: Text( child: Text(
confirmText ?? I18n.of(context).confirm.toUpperCase(), confirmText?.toUpperCase() ??
I18n.of(context).confirm.toUpperCase(),
), ),
onPressed: () { onPressed: () {
input = controller.text; input = controller.text;
@ -70,16 +75,19 @@ class SimpleDialogs {
await showDialog( await showDialog(
context: context, context: context,
builder: (c) => AlertDialog( builder: (c) => AlertDialog(
title: Text(I18n.of(context).areYouSure ?? titleText), title: Text(titleText ?? I18n.of(context).areYouSure),
actions: <Widget>[ actions: <Widget>[
FlatButton( FlatButton(
child: Text(cancelText ?? I18n.of(context).close.toUpperCase(), child: Text(
cancelText?.toUpperCase() ??
I18n.of(context).close.toUpperCase(),
style: TextStyle(color: Colors.blueGrey)), style: TextStyle(color: Colors.blueGrey)),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
), ),
FlatButton( FlatButton(
child: Text( child: Text(
confirmText ?? I18n.of(context).confirm.toUpperCase(), confirmText?.toUpperCase() ??
I18n.of(context).confirm.toUpperCase(),
), ),
onPressed: () { onPressed: () {
confirmed = true; confirmed = true;

View file

@ -5,7 +5,7 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart'; import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/chat_settings_popup_menu.dart'; import 'package:fluffychat/components/chat_settings_popup_menu.dart';
import 'package:fluffychat/components/dialogs/confirm_dialog.dart'; import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
import 'package:fluffychat/components/list_items/message.dart'; import 'package:fluffychat/components/list_items/message.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/components/reply_content.dart'; import 'package:fluffychat/components/reply_content.dart';
@ -234,13 +234,9 @@ class _ChatState extends State<_Chat> {
} }
void redactEventsAction(BuildContext context) async { void redactEventsAction(BuildContext context) async {
bool confirmed = false; bool confirmed = await SimpleDialogs(context).askConfirmation(
await showDialog( titleText: I18n.of(context).messageWillBeRemovedWarning,
context: context, confirmText: I18n.of(context).remove,
builder: (context) => ConfirmDialog(
I18n.of(context).messageWillBeRemovedWarning,
I18n.of(context).remove,
(c) => confirmed = true),
); );
if (!confirmed) return; if (!confirmed) return;
for (Event event in selectedEvents) { for (Event event in selectedEvents) {
@ -280,6 +276,7 @@ class _ChatState extends State<_Chat> {
replyEvent = selectedEvents.first; replyEvent = selectedEvents.first;
selectedEvents.clear(); selectedEvents.clear();
}); });
inputFocus.requestFocus();
} }
@override @override
@ -400,28 +397,7 @@ class _ChatState extends State<_Chat> {
SafeArea( SafeArea(
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Material( if (_loadingHistory) LinearProgressIndicator(),
elevation: 1,
color: Theme.of(context).scaffoldBackgroundColor,
child: AnimatedContainer(
duration: Duration(milliseconds: 300),
height: _loadingHistory ? 40 : 0,
child: Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
height: 20,
width: 20,
child: CircularProgressIndicator(strokeWidth: 2),
),
SizedBox(width: 8),
Text(I18n.of(context).loadingPleaseWait),
],
),
),
),
),
Expanded( Expanded(
child: FutureBuilder<bool>( child: FutureBuilder<bool>(
future: getTimeline(), future: getTimeline(),

View file

@ -58,7 +58,7 @@ class _ChatDetailsState extends State<ChatDetails> {
labelText: I18n.of(context).setInvitationLink, labelText: I18n.of(context).setInvitationLink,
hintText: I18n.of(context).alias.toLowerCase(), hintText: I18n.of(context).alias.toLowerCase(),
prefixText: "#", prefixText: "#",
suffixText: widget.room.client.userID.domain, suffixText: ":" + widget.room.client.userID.domain,
); );
if (s == null) return; if (s == null) return;
final String domain = widget.room.client.userID.domain; final String domain = widget.room.client.userID.domain;

View file

@ -2,7 +2,7 @@ import 'dart:async';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart'; import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/dialogs/confirm_dialog.dart'; import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/utils/beautify_string_extension.dart'; import 'package:fluffychat/utils/beautify_string_extension.dart';
import 'package:fluffychat/i18n/i18n.dart'; import 'package:fluffychat/i18n/i18n.dart';
@ -62,23 +62,21 @@ class _ChatEncryptionSettingsState extends State<ChatEncryptionSettings> {
subtitle: Text(room.encryptionAlgorithm ?? I18n.of(context).none), subtitle: Text(room.encryptionAlgorithm ?? I18n.of(context).none),
trailing: Icon(room.encrypted ? Icons.lock : Icons.lock_open, trailing: Icon(room.encrypted ? Icons.lock : Icons.lock_open,
color: room.encrypted ? Colors.green : Colors.red), color: room.encrypted ? Colors.green : Colors.red),
onTap: () { onTap: () async {
if (room.encrypted) return; if (room.encrypted) return;
if (!room.client.encryptionEnabled) { if (!room.client.encryptionEnabled) {
Toast.show(I18n.of(context).needPantalaimonWarning, context, Toast.show(I18n.of(context).needPantalaimonWarning, context,
duration: 8); duration: 8);
return; return;
} }
showDialog( if (await SimpleDialogs(context).askConfirmation(
context: context, titleText: I18n.of(context).enableEncryptionWarning,
builder: (BuildContext context) => ConfirmDialog( confirmText: I18n.of(context).yes) ==
I18n.of(context).enableEncryptionWarning, true) {
I18n.of(context).yes, await Matrix.of(context).tryRequestWithLoadingDialog(
(context) => Matrix.of(context).tryRequestWithLoadingDialog(
room.enableEncryption(), room.enableEncryption(),
),
),
); );
}
}, },
), ),
ListTile( ListTile(