From e4ed3cc7efea2a5e4cb503a3f06eb0dbde05b49d Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 27 Jan 2020 10:59:03 +0100 Subject: [PATCH] Redesign login pages --- lib/components/dialogs/new_group_dialog.dart | 94 -------- .../dialogs/new_private_chat_dialog.dart | 210 ------------------ lib/components/list_items/message.dart | 4 +- lib/i18n/i18n.dart | 2 + lib/i18n/intl_de.arb | 2 +- lib/views/chat_details.dart | 2 +- lib/views/login.dart | 20 +- lib/views/sign_up.dart | 23 +- lib/views/sign_up_password.dart | 12 +- pubspec.lock | 4 +- pubspec.yaml | 1 + 11 files changed, 40 insertions(+), 334 deletions(-) delete mode 100644 lib/components/dialogs/new_group_dialog.dart delete mode 100644 lib/components/dialogs/new_private_chat_dialog.dart diff --git a/lib/components/dialogs/new_group_dialog.dart b/lib/components/dialogs/new_group_dialog.dart deleted file mode 100644 index cd629a1..0000000 --- a/lib/components/dialogs/new_group_dialog.dart +++ /dev/null @@ -1,94 +0,0 @@ -import 'package:fluffychat/i18n/i18n.dart'; -import 'package:fluffychat/views/chat.dart'; -import 'package:fluffychat/views/invitation_selection.dart'; -import 'package:flutter/material.dart'; -import 'package:pedantic/pedantic.dart'; - -import '../matrix.dart'; - -class NewGroupDialog extends StatefulWidget { - @override - _NewGroupDialogState createState() => _NewGroupDialogState(); -} - -class _NewGroupDialogState extends State { - TextEditingController controller = TextEditingController(); - bool publicGroup = false; - - void submitAction(BuildContext context) async { - final MatrixState matrix = Matrix.of(context); - Map params = {}; - if (publicGroup) { - params["preset"] = "public_chat"; - params["visibility"] = "public"; - if (controller.text.isNotEmpty) { - params["room_alias_name"] = controller.text; - } - } else { - params["preset"] = "private_chat"; - } - if (controller.text.isNotEmpty) params["name"] = controller.text; - final String roomID = await matrix.tryRequestWithLoadingDialog( - matrix.client.createRoom(params: params), - ); - Navigator.of(context).pop(); - if (roomID != null) { - unawaited( - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return ChatView(roomID); - }), - ), - ); - await Navigator.push( - context, - MaterialPageRoute( - builder: (context) => InvitationSelection( - matrix.client.getRoomById(roomID), - ), - ), - ); - } - } - - @override - Widget build(BuildContext context) { - return AlertDialog( - title: Text(I18n.of(context).createNewGroup), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - TextField( - controller: controller, - autocorrect: false, - textInputAction: TextInputAction.go, - onSubmitted: (s) => submitAction(context), - decoration: InputDecoration( - labelText: I18n.of(context).optionalGroupName, - icon: Icon(Icons.people), - hintText: I18n.of(context).enterAGroupName), - ), - SwitchListTile( - title: Text(I18n.of(context).groupIsPublic), - value: publicGroup, - onChanged: (bool b) => setState(() => publicGroup = b), - ), - ], - ), - actions: [ - FlatButton( - child: Text(I18n.of(context).close.toUpperCase(), - style: TextStyle(color: Colors.blueGrey)), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - FlatButton( - child: Text(I18n.of(context).create.toUpperCase()), - onPressed: () => submitAction(context), - ), - ], - ); - } -} diff --git a/lib/components/dialogs/new_private_chat_dialog.dart b/lib/components/dialogs/new_private_chat_dialog.dart deleted file mode 100644 index 5afdecc..0000000 --- a/lib/components/dialogs/new_private_chat_dialog.dart +++ /dev/null @@ -1,210 +0,0 @@ -import 'dart:async'; - -import 'package:famedlysdk/famedlysdk.dart'; -import 'package:fluffychat/components/avatar.dart'; -import 'package:fluffychat/i18n/i18n.dart'; -import 'package:fluffychat/views/chat.dart'; -import 'package:flutter/material.dart'; -import 'package:share/share.dart'; - -import '../matrix.dart'; - -class NewPrivateChatDialog extends StatefulWidget { - @override - _NewPrivateChatDialogState createState() => _NewPrivateChatDialogState(); -} - -class _NewPrivateChatDialogState extends State { - TextEditingController controller = TextEditingController(); - final _formKey = GlobalKey(); - bool loading = false; - String currentSearchTerm; - Map foundProfile; - Timer coolDown; - bool get correctMxId => - foundProfile != null && foundProfile["user_id"] == "@$currentSearchTerm"; - - void submitAction(BuildContext context) async { - if (controller.text.isEmpty) return; - if (!_formKey.currentState.validate()) return; - final MatrixState matrix = Matrix.of(context); - - if ("@" + controller.text.trim() == matrix.client.userID) return; - - final User user = User( - "@" + controller.text.trim(), - room: Room(id: "", client: matrix.client), - ); - final String roomID = - await matrix.tryRequestWithLoadingDialog(user.startDirectChat()); - Navigator.of(context).pop(); - - if (roomID != null) { - await Navigator.push( - context, - MaterialPageRoute(builder: (context) => ChatView(roomID)), - ); - } - } - - void searchUserWithCoolDown(BuildContext context, String text) async { - coolDown?.cancel(); - coolDown = Timer( - Duration(seconds: 1), - () => searchUser(context, text), - ); - } - - void searchUser(BuildContext context, String text) async { - if (text.isEmpty) { - setState(() { - foundProfile = null; - }); - } - currentSearchTerm = text; - if (currentSearchTerm.isEmpty) return; - if (loading) return; - setState(() => loading = true); - final MatrixState matrix = Matrix.of(context); - final response = await matrix.tryRequestWithErrorToast( - matrix.client.jsonRequest( - type: HTTPType.POST, - action: "/client/r0/user_directory/search", - data: { - "search_term": text, - "limit": 1, - }), - ); - setState(() => loading = false); - if (response == false || - !(response is Map) || - (response["results"]?.isEmpty ?? true)) return; - setState(() { - foundProfile = response["results"].first; - }); - } - - @override - Widget build(BuildContext context) { - final String defaultDomain = Matrix.of(context).client.userID.split(":")[1]; - return AlertDialog( - title: Text(I18n.of(context).newPrivateChat), - content: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Form( - key: _formKey, - child: TextFormField( - controller: controller, - autofocus: true, - autocorrect: false, - onChanged: (String text) => searchUserWithCoolDown(context, text), - textInputAction: TextInputAction.go, - onFieldSubmitted: (s) => submitAction(context), - validator: (value) { - if (value.isEmpty) { - return I18n.of(context).pleaseEnterAMatrixIdentifier; - } - final MatrixState matrix = Matrix.of(context); - String mxid = "@" + controller.text.trim(); - if (mxid == matrix.client.userID) { - return I18n.of(context).youCannotInviteYourself; - } - if (!mxid.contains("@")) { - return I18n.of(context).makeSureTheIdentifierIsValid; - } - if (!mxid.contains(":")) { - return I18n.of(context).makeSureTheIdentifierIsValid; - } - return null; - }, - decoration: InputDecoration( - labelText: I18n.of(context).enterAUsername, - icon: loading - ? Container( - width: 24, - height: 24, - child: CircularProgressIndicator(strokeWidth: 1), - ) - : correctMxId - ? Avatar( - MxContent(foundProfile["avatar_url"] ?? ""), - foundProfile["display_name"] ?? - foundProfile["user_id"], - size: 24, - ) - : Icon(Icons.account_circle), - prefixText: "@", - hintText: - "${I18n.of(context).username.toLowerCase()}:$defaultDomain", - ), - ), - ), - if (foundProfile != null && !correctMxId) - ListTile( - onTap: () { - setState(() { - controller.text = - currentSearchTerm = foundProfile["user_id"].substring(1); - }); - }, - leading: Avatar( - MxContent(foundProfile["avatar_url"] ?? ""), - foundProfile["display_name"] ?? foundProfile["user_id"], - //size: 24, - ), - contentPadding: EdgeInsets.all(0), - title: Text( - foundProfile["display_name"] ?? - foundProfile["user_id"].split(":").first.substring(1), - style: TextStyle(), - maxLines: 1, - ), - subtitle: Text( - foundProfile["user_id"], - maxLines: 1, - style: TextStyle( - fontSize: 12, - ), - ), - ), - if (foundProfile == null || correctMxId) - ListTile( - trailing: Icon( - Icons.share, - size: 16, - ), - contentPadding: EdgeInsets.all(0), - onTap: () => Share.share( - "https://matrix.to/#/${Matrix.of(context).client.userID}"), - title: Text( - "${I18n.of(context).yourOwnUsername}:", - style: TextStyle( - color: Colors.blueGrey, - fontSize: 12, - ), - ), - subtitle: Text( - Matrix.of(context).client.userID, - ), - ), - Divider(height: 1), - ], - ), - actions: [ - FlatButton( - child: Text(I18n.of(context).close.toUpperCase(), - style: TextStyle(color: Colors.blueGrey)), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - FlatButton( - child: Text(I18n.of(context).confirm.toUpperCase()), - onPressed: () => submitAction(context), - ), - ], - ); - } -} diff --git a/lib/components/list_items/message.dart b/lib/components/list_items/message.dart index 94e2332..0c51af8 100644 --- a/lib/components/list_items/message.dart +++ b/lib/components/list_items/message.dart @@ -67,9 +67,9 @@ class Message extends StatelessWidget { ].contains(event.messageType) && event.body.isNotEmpty) { popupMenuList.add( - const PopupMenuItem( + PopupMenuItem( value: "copy", - child: Text('Copy'), + child: Text(I18n.of(context).copy), ), ); } diff --git a/lib/i18n/i18n.dart b/lib/i18n/i18n.dart index 652352c..3769082 100644 --- a/lib/i18n/i18n.dart +++ b/lib/i18n/i18n.dart @@ -200,6 +200,8 @@ class I18n { String get copiedToClipboard => Intl.message("Copied to clipboard"); + String get copy => Intl.message("Copy"); + String get couldNotDecryptMessage => Intl.message("Could not decrypt message"); diff --git a/lib/i18n/intl_de.arb b/lib/i18n/intl_de.arb index c5c14b3..a33ad59 100644 --- a/lib/i18n/intl_de.arb +++ b/lib/i18n/intl_de.arb @@ -886,7 +886,7 @@ "targetName": {} } }, - "Unmute chat": "Nicht mehr stummschalten", + "Unmute chat": "Stumm aus", "@Unmute chat": { "type": "text", "placeholders": {} diff --git a/lib/views/chat_details.dart b/lib/views/chat_details.dart index 4fa7ac7..0ef73a0 100644 --- a/lib/views/chat_details.dart +++ b/lib/views/chat_details.dart @@ -215,7 +215,7 @@ class _ChatDetailsState extends State { child: Icon(Icons.edit), ) : null, - title: Text("Group description:", + title: Text("${I18n.of(context).groupDescription}:", style: TextStyle( color: Theme.of(context).primaryColor, fontWeight: FontWeight.bold)), diff --git a/lib/views/login.dart b/lib/views/login.dart index a9c36b4..0e42a9e 100644 --- a/lib/views/login.dart +++ b/lib/views/login.dart @@ -105,8 +105,7 @@ class _LoginState extends State { ), body: ListView( padding: EdgeInsets.symmetric( - vertical: 16, - horizontal: max((MediaQuery.of(context).size.width - 600) / 2, 16)), + horizontal: max((MediaQuery.of(context).size.width - 600) / 2, 0)), children: [ Container( height: 150, @@ -114,15 +113,15 @@ class _LoginState extends State { child: Center( child: Icon( Icons.vpn_key, - color: Theme.of(context).primaryColor, - size: 40, + size: 60, ), ), ), ListTile( leading: CircleAvatar( - backgroundColor: Colors.blue, - child: Icon(Icons.account_box), + backgroundColor: Colors.white, + child: Icon(Icons.account_box, + color: Theme.of(context).primaryColor), ), title: TextField( autocorrect: false, @@ -136,8 +135,8 @@ class _LoginState extends State { ), ListTile( leading: CircleAvatar( - backgroundColor: Colors.yellow, - child: Icon(Icons.lock), + backgroundColor: Colors.white, + child: Icon(Icons.lock, color: Theme.of(context).primaryColor), ), title: TextField( autocorrect: false, @@ -159,16 +158,17 @@ class _LoginState extends State { SizedBox(height: 20), Container( height: 50, + padding: EdgeInsets.symmetric(horizontal: 12), child: RaisedButton( elevation: 7, color: Theme.of(context).primaryColor, shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(50), + borderRadius: BorderRadius.circular(6), ), child: loading ? CircularProgressIndicator() : Text( - I18n.of(context).login, + I18n.of(context).login.toUpperCase(), style: TextStyle(color: Colors.white, fontSize: 16), ), onPressed: () => loading ? null : login(context), diff --git a/lib/views/sign_up.dart b/lib/views/sign_up.dart index 7f24dcd..c194dae 100644 --- a/lib/views/sign_up.dart +++ b/lib/views/sign_up.dart @@ -107,18 +107,20 @@ class _SignUpState extends State { ), body: ListView( padding: EdgeInsets.symmetric( - vertical: 16, horizontal: - max((MediaQuery.of(context).size.width - 600) / 2, 16)), + max((MediaQuery.of(context).size.width - 600) / 2, 0)), children: [ Image.asset("assets/fluffychat-banner.png"), ListTile( leading: CircleAvatar( backgroundImage: avatar == null ? null : FileImage(avatar), backgroundColor: avatar == null - ? Colors.green + ? Colors.white : Theme.of(context).secondaryHeaderColor, - child: avatar == null ? Icon(Icons.camera_alt) : null, + child: avatar == null + ? Icon(Icons.camera_alt, + color: Theme.of(context).primaryColor) + : null, ), trailing: avatar == null ? null @@ -135,8 +137,11 @@ class _SignUpState extends State { ), ListTile( leading: CircleAvatar( - backgroundColor: Colors.blue, - child: Icon(Icons.account_box), + backgroundColor: Colors.white, + child: Icon( + Icons.account_circle, + color: Theme.of(context).primaryColor, + ), ), title: TextField( autocorrect: false, @@ -151,16 +156,17 @@ class _SignUpState extends State { SizedBox(height: 20), Container( height: 50, + padding: EdgeInsets.symmetric(horizontal: 12), child: RaisedButton( elevation: 7, color: Theme.of(context).primaryColor, shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(50), + borderRadius: BorderRadius.circular(6), ), child: loading ? CircularProgressIndicator() : Text( - I18n.of(context).signUp, + I18n.of(context).signUp.toUpperCase(), style: TextStyle(color: Colors.white, fontSize: 16), ), onPressed: () => signUpAction(context), @@ -173,6 +179,7 @@ class _SignUpState extends State { style: TextStyle( decoration: TextDecoration.underline, color: Colors.blue, + fontSize: 16, ), ), onPressed: () => Navigator.of(context).push( diff --git a/lib/views/sign_up_password.dart b/lib/views/sign_up_password.dart index 6835342..b402d4d 100644 --- a/lib/views/sign_up_password.dart +++ b/lib/views/sign_up_password.dart @@ -125,8 +125,7 @@ class _SignUpPasswordState extends State { ), body: ListView( padding: EdgeInsets.symmetric( - vertical: 16, - horizontal: max((MediaQuery.of(context).size.width - 600) / 2, 16)), + horizontal: max((MediaQuery.of(context).size.width - 600) / 2, 0)), children: [ Container( height: 150, @@ -141,8 +140,8 @@ class _SignUpPasswordState extends State { ), ListTile( leading: CircleAvatar( - backgroundColor: Colors.yellow, - child: Icon(Icons.lock), + backgroundColor: Colors.white, + child: Icon(Icons.lock, color: Theme.of(context).primaryColor), ), title: TextField( controller: passwordController, @@ -165,16 +164,17 @@ class _SignUpPasswordState extends State { SizedBox(height: 20), Container( height: 50, + padding: EdgeInsets.symmetric(horizontal: 12), child: RaisedButton( elevation: 7, color: Theme.of(context).primaryColor, shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(50), + borderRadius: BorderRadius.circular(6), ), child: loading ? CircularProgressIndicator() : Text( - I18n.of(context).createAccountNow, + I18n.of(context).createAccountNow.toUpperCase(), style: TextStyle(color: Colors.white, fontSize: 16), ), onPressed: () => loading ? null : _signUpAction(context), diff --git a/pubspec.lock b/pubspec.lock index 998fa79..8f98b8a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -199,12 +199,12 @@ packages: source: hosted version: "0.14.0+3" http: - dependency: transitive + dependency: "direct main" description: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.12.0+3" + version: "0.12.0+4" http_parser: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 379fc5f..ee7f1a6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,6 +47,7 @@ dependencies: share: ^0.6.3+5 receive_sharing_intent: ^1.3.2 flutter_secure_storage: ^3.3.1+1 + http: ^0.12.0+4 intl: ^0.16.0 intl_translation: ^0.17.9