Force well-known checks, updated welcome screen
This commit is contained in:
parent
d6379a9189
commit
d4d9a28067
|
@ -1,13 +1,20 @@
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:famedlysdk/matrix_api/model/well_known_informations.dart';
|
||||||
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
||||||
import 'package:fluffychat/components/matrix.dart';
|
import 'package:fluffychat/components/matrix.dart';
|
||||||
import 'package:fluffychat/l10n/l10n.dart';
|
import 'package:fluffychat/l10n/l10n.dart';
|
||||||
import 'package:fluffychat/utils/app_route.dart';
|
import 'package:fluffychat/utils/app_route.dart';
|
||||||
|
import 'package:fluffychat/views/login.dart';
|
||||||
import 'package:fluffychat/views/sign_up.dart';
|
import 'package:fluffychat/views/sign_up.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class HomeserverPicker extends StatelessWidget {
|
class HomeserverPicker extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_HomeserverPickerState createState() => _HomeserverPickerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HomeserverPickerState extends State<HomeserverPicker> {
|
||||||
Future<void> _setHomeserverAction(BuildContext context) async {
|
Future<void> _setHomeserverAction(BuildContext context) async {
|
||||||
final homeserver = await SimpleDialogs(context).enterText(
|
final homeserver = await SimpleDialogs(context).enterText(
|
||||||
titleText: L10n.of(context).enterYourHomeserver,
|
titleText: L10n.of(context).enterYourHomeserver,
|
||||||
|
@ -18,16 +25,70 @@ class HomeserverPicker extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _checkHomeserverAction(String homeserver, BuildContext context) async {
|
void _checkHomeserverAction(String homeserver, BuildContext context) async {
|
||||||
if (!homeserver.startsWith('https://')) {
|
if (!_isMXID && !homeserver.startsWith('https://')) {
|
||||||
homeserver = 'https://$homeserver';
|
homeserver = 'https://$homeserver';
|
||||||
}
|
}
|
||||||
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
WellKnownInformations wellknown;
|
||||||
Matrix.of(context).client.checkServer(homeserver));
|
if (_isMXID) {
|
||||||
if (success != false) {
|
if (!homeserver.startsWith('@')) {
|
||||||
await Navigator.of(context).push(AppRoute(SignUp()));
|
homeserver = '@$homeserver';
|
||||||
|
}
|
||||||
|
wellknown = await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||||
|
Matrix.of(context)
|
||||||
|
.client
|
||||||
|
.getWellKnownInformationsByUserId(homeserver));
|
||||||
|
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||||
|
Matrix.of(context).client.checkServer(wellknown.mHomeserver != null
|
||||||
|
? 'https://${Uri.parse(wellknown.mHomeserver.baseUrl).host}'
|
||||||
|
: homeserver));
|
||||||
|
if (success != false) {
|
||||||
|
await Navigator.of(context).push(AppRoute(Login(
|
||||||
|
username: homeserver,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wellknown = await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||||
|
Matrix.of(context)
|
||||||
|
.client
|
||||||
|
.getWellKnownInformationsByDomain(homeserver));
|
||||||
|
|
||||||
|
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||||
|
Matrix.of(context).client.checkServer(wellknown.mHomeserver != null
|
||||||
|
? 'https://${Uri.parse(wellknown.mHomeserver.baseUrl).host}'
|
||||||
|
: homeserver));
|
||||||
|
if (success != false) {
|
||||||
|
await Navigator.of(context).push(AppRoute(SignUp()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final textController = TextEditingController();
|
||||||
|
bool _isMXID = false;
|
||||||
|
|
||||||
|
void _checkInputType() {
|
||||||
|
if (textController.text.contains(':')) {
|
||||||
|
setState(() {
|
||||||
|
_isMXID = true;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
_isMXID = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
textController.addListener(_checkInputType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
textController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
@ -40,7 +101,15 @@ class HomeserverPicker extends StatelessWidget {
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Hero(
|
Hero(
|
||||||
tag: 'loginBanner',
|
tag: 'loginBanner',
|
||||||
child: Image.asset('assets/fluffychat-banner.png'),
|
child: Center(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(0.0, 32.0, 0.0, 18.0),
|
||||||
|
child: Text(
|
||||||
|
L10n.of(context).fluffychat,
|
||||||
|
style: TextStyle(fontSize: 28.0),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
@ -53,6 +122,23 @@ class HomeserverPicker extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Spacer(),
|
Spacer(),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: TextField(
|
||||||
|
controller: textController,
|
||||||
|
onSubmitted: (s) {
|
||||||
|
_checkHomeserverAction(s, context);
|
||||||
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
|
icon: (_isMXID
|
||||||
|
? Icon(Icons.person_outline)
|
||||||
|
: Icon(Icons.business)),
|
||||||
|
labelText: L10n.of(context).homeserverOrMXID,
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Spacer(),
|
||||||
Hero(
|
Hero(
|
||||||
tag: 'loginButton',
|
tag: 'loginButton',
|
||||||
child: Container(
|
child: Container(
|
||||||
|
@ -66,40 +152,14 @@ class HomeserverPicker extends StatelessWidget {
|
||||||
borderRadius: BorderRadius.circular(6),
|
borderRadius: BorderRadius.circular(6),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
L10n.of(context).connect.toUpperCase(),
|
(_isMXID ? L10n.of(context).login.toUpperCase() : L10n.of(context).connect.toUpperCase()),
|
||||||
style: TextStyle(color: Colors.white, fontSize: 16),
|
style: TextStyle(color: Colors.white, fontSize: 16),
|
||||||
),
|
),
|
||||||
onPressed: () => _checkHomeserverAction(
|
onPressed: () =>
|
||||||
Matrix.defaultHomeserver, context),
|
_checkHomeserverAction(textController.text, context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
|
||||||
padding:
|
|
||||||
const EdgeInsets.only(left: 16.0, right: 16.0, top: 16.0),
|
|
||||||
child: Opacity(
|
|
||||||
opacity: 0.75,
|
|
||||||
child: Text(
|
|
||||||
L10n.of(context).byDefaultYouWillBeConnectedTo(
|
|
||||||
Matrix.defaultHomeserver),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
FlatButton(
|
|
||||||
child: Text(
|
|
||||||
L10n.of(context).changeTheHomeserver,
|
|
||||||
style: TextStyle(
|
|
||||||
decoration: TextDecoration.underline,
|
|
||||||
color: Colors.blue,
|
|
||||||
fontSize: 16,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: () => _setHomeserverAction(context),
|
|
||||||
),
|
|
||||||
SizedBox(height: 16),
|
SizedBox(height: 16),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -13,6 +13,10 @@ import 'package:flutter/material.dart';
|
||||||
import 'chat_list.dart';
|
import 'chat_list.dart';
|
||||||
|
|
||||||
class Login extends StatefulWidget {
|
class Login extends StatefulWidget {
|
||||||
|
Login({Key key, String this.username: null}) : super(key:key);
|
||||||
|
|
||||||
|
final String username;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_LoginState createState() => _LoginState();
|
_LoginState createState() => _LoginState();
|
||||||
}
|
}
|
||||||
|
@ -101,6 +105,19 @@ class _LoginState extends State<Login> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
usernameController.text = widget?.username;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
usernameController.dispose();
|
||||||
|
passwordController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
@ -130,7 +147,7 @@ class _LoginState extends State<Login> {
|
||||||
title: TextField(
|
title: TextField(
|
||||||
readOnly: loading,
|
readOnly: loading,
|
||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
autofocus: true,
|
autofocus: widget.username != null ? false : true,
|
||||||
onChanged: (t) => _checkWellKnownWithCoolDown(t, context),
|
onChanged: (t) => _checkWellKnownWithCoolDown(t, context),
|
||||||
controller: usernameController,
|
controller: usernameController,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
|
@ -150,6 +167,7 @@ class _LoginState extends State<Login> {
|
||||||
title: TextField(
|
title: TextField(
|
||||||
readOnly: loading,
|
readOnly: loading,
|
||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
|
autofocus: widget.username != null ? true : false,
|
||||||
controller: passwordController,
|
controller: passwordController,
|
||||||
obscureText: !showPassword,
|
obscureText: !showPassword,
|
||||||
onSubmitted: (t) => login(context),
|
onSubmitted: (t) => login(context),
|
||||||
|
|
Loading…
Reference in a new issue