2020-04-12 10:35:45 +02:00
|
|
|
import 'dart:math';
|
|
|
|
|
2020-11-14 10:08:13 +01:00
|
|
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
2020-10-28 08:24:49 +01:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-04-12 10:35:45 +02:00
|
|
|
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
|
|
|
import 'package:fluffychat/components/matrix.dart';
|
2020-12-11 14:14:33 +01:00
|
|
|
import 'package:fluffychat/app_config.dart';
|
2020-10-03 11:11:28 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2020-04-12 10:35:45 +02:00
|
|
|
import 'package:fluffychat/utils/app_route.dart';
|
2020-09-08 10:55:32 +02:00
|
|
|
import 'package:fluffychat/utils/sentry_controller.dart';
|
2020-04-12 10:35:45 +02:00
|
|
|
import 'package:fluffychat/views/sign_up.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-10-03 11:11:28 +02:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2020-04-12 10:35:45 +02:00
|
|
|
|
2020-12-11 14:14:33 +01:00
|
|
|
import 'login.dart';
|
|
|
|
|
2020-04-12 10:35:45 +02:00
|
|
|
class HomeserverPicker extends StatelessWidget {
|
2020-05-13 15:58:59 +02:00
|
|
|
Future<void> _setHomeserverAction(BuildContext context) async {
|
2020-11-23 08:06:15 +01:00
|
|
|
const prefix = 'https://';
|
2020-11-14 10:08:13 +01:00
|
|
|
final homeserver = await showTextInputDialog(
|
|
|
|
title: L10n.of(context).enterYourHomeserver,
|
|
|
|
context: context,
|
|
|
|
textFields: [
|
|
|
|
DialogTextField(
|
|
|
|
hintText: AppConfig.defaultHomeserver,
|
2020-11-23 08:06:15 +01:00
|
|
|
prefixText: prefix,
|
|
|
|
keyboardType: TextInputType.url,
|
2020-11-14 10:08:13 +01:00
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
if (homeserver?.single?.isEmpty ?? true) return;
|
2020-11-23 08:06:15 +01:00
|
|
|
_checkHomeserverAction(prefix + homeserver.single, context);
|
2020-04-12 10:35:45 +02:00
|
|
|
}
|
|
|
|
|
2020-05-13 15:58:59 +02:00
|
|
|
void _checkHomeserverAction(String homeserver, BuildContext context) async {
|
2020-09-08 10:55:32 +02:00
|
|
|
if (await SentryController.getSentryStatus() == null || true) {
|
|
|
|
await SentryController.toggleSentryAction(context);
|
|
|
|
}
|
|
|
|
|
2020-04-12 10:35:45 +02:00
|
|
|
if (!homeserver.startsWith('https://')) {
|
|
|
|
homeserver = 'https://$homeserver';
|
|
|
|
}
|
2020-07-02 11:10:03 +02:00
|
|
|
|
2020-04-27 13:36:39 +02:00
|
|
|
final success = await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
2020-10-28 08:24:49 +01:00
|
|
|
checkHomeserver(homeserver, Matrix.of(context).client));
|
|
|
|
if (success == true) {
|
2020-12-11 14:14:33 +01:00
|
|
|
await Navigator.of(context)
|
|
|
|
.push(AppRoute(AppConfig.enableRegistration ? SignUp() : Login()));
|
2020-04-12 10:35:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 08:24:49 +01:00
|
|
|
Future<bool> checkHomeserver(dynamic homeserver, Client client) async {
|
|
|
|
await client.checkHomeserver(homeserver);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-12 10:35:45 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
body: SafeArea(
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
horizontal:
|
|
|
|
max((MediaQuery.of(context).size.width - 600) / 2, 0)),
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
2020-12-11 14:14:33 +01:00
|
|
|
Expanded(
|
|
|
|
child: ListView(
|
|
|
|
children: [
|
|
|
|
Hero(
|
|
|
|
tag: 'loginBanner',
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () => showAboutDialog(
|
|
|
|
context: context,
|
|
|
|
children: [
|
|
|
|
RaisedButton(
|
|
|
|
child: Text(L10n.of(context).privacy),
|
|
|
|
onPressed: () => launch(AppConfig.privacyUrl),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
applicationIcon: Image.asset('assets/logo.png',
|
|
|
|
width: 100, height: 100),
|
|
|
|
applicationName: AppConfig.applicationName,
|
|
|
|
),
|
|
|
|
child: Image.asset('assets/banner.png'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Text(
|
|
|
|
AppConfig.applicationWelcomeMessage ??
|
|
|
|
L10n.of(context).welcomeText,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 22,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2020-04-12 10:35:45 +02:00
|
|
|
),
|
|
|
|
),
|
2020-12-11 14:14:33 +01:00
|
|
|
SizedBox(height: 16),
|
2020-04-12 10:35:45 +02:00
|
|
|
Hero(
|
|
|
|
tag: 'loginButton',
|
|
|
|
child: Container(
|
|
|
|
width: double.infinity,
|
|
|
|
height: 50,
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12),
|
|
|
|
child: RaisedButton(
|
|
|
|
elevation: 7,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
),
|
|
|
|
child: Text(
|
2020-05-07 07:52:40 +02:00
|
|
|
L10n.of(context).connect.toUpperCase(),
|
2020-04-12 10:35:45 +02:00
|
|
|
style: TextStyle(color: Colors.white, fontSize: 16),
|
|
|
|
),
|
|
|
|
onPressed: () => _checkHomeserverAction(
|
2020-09-18 12:58:22 +02:00
|
|
|
AppConfig.defaultHomeserver, context),
|
2020-04-12 10:35:45 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding:
|
|
|
|
const EdgeInsets.only(left: 16.0, right: 16.0, top: 16.0),
|
2020-10-03 11:11:28 +02:00
|
|
|
child: Text(
|
|
|
|
L10n.of(context).byDefaultYouWillBeConnectedTo(
|
|
|
|
AppConfig.defaultHomeserver),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
2020-04-12 10:35:45 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-12-11 14:14:33 +01:00
|
|
|
Wrap(
|
|
|
|
children: [
|
|
|
|
if (AppConfig.allowOtherHomeservers)
|
|
|
|
FlatButton(
|
|
|
|
child: Text(
|
|
|
|
L10n.of(context).changeTheHomeserver,
|
|
|
|
style: TextStyle(
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
fontSize: 16,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: () => _setHomeserverAction(context),
|
|
|
|
),
|
|
|
|
FlatButton(
|
|
|
|
child: Text(
|
|
|
|
L10n.of(context).privacy,
|
|
|
|
style: TextStyle(
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
fontSize: 16,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: () => launch(AppConfig.privacyUrl),
|
2020-04-12 10:35:45 +02:00
|
|
|
),
|
2020-12-11 14:14:33 +01:00
|
|
|
],
|
2020-04-12 10:35:45 +02:00
|
|
|
),
|
|
|
|
SizedBox(height: 16),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|