chore: Redesign homeserver picker page

This commit is contained in:
Christian Pauly 2021-01-17 15:33:31 +01:00
parent 8477385853
commit 3c713518fb
5 changed files with 142 additions and 121 deletions

View File

@ -0,0 +1,29 @@
import 'package:fluffychat/utils/sentry_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
class SentrySwitchListTile extends StatefulWidget {
@override
_SentrySwitchListTileState createState() => _SentrySwitchListTileState();
}
class _SentrySwitchListTileState extends State<SentrySwitchListTile> {
bool _enabled = false;
@override
Widget build(BuildContext context) {
return FutureBuilder<bool>(
future: SentryController.getSentryStatus(),
builder: (context, snapshot) {
_enabled = snapshot.data ?? false;
return SwitchListTile(
title: Text(L10n.of(context).sendBugReports),
value: _enabled,
onChanged: (b) =>
SentryController.toggleSentryAction(context, b).then(
(_) => setState(() => null),
),
);
});
}
}

View File

@ -3,6 +3,7 @@ import 'dart:async';
import 'package:adaptive_theme/adaptive_theme.dart'; import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:adaptive_page_layout/adaptive_page_layout.dart'; import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/config/routes.dart'; import 'package:fluffychat/config/routes.dart';
import 'package:fluffychat/utils/sentry_controller.dart'; import 'package:fluffychat/utils/sentry_controller.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@ -56,9 +57,9 @@ class App extends StatelessWidget {
dividerColor: Theme.of(context).dividerColor, dividerColor: Theme.of(context).dividerColor,
columnWidth: FluffyThemes.columnWidth, columnWidth: FluffyThemes.columnWidth,
routeBuilder: (builder, settings) => routeBuilder: (builder, settings) =>
_apl.currentState.columnMode(context) Matrix.of(context).loginState == LoginState.logged
? FadeRoute(page: builder(context)) ? CupertinoPageRoute(builder: builder)
: CupertinoPageRoute(builder: builder), : FadeRoute(page: builder(context)),
), ),
), ),
), ),

View File

@ -1,31 +1,18 @@
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:flushbar/flushbar_helper.dart';
import 'package:fluffychat/app_config.dart'; import 'package:fluffychat/app_config.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:sentry/sentry.dart'; import 'package:sentry/sentry.dart';
import 'famedlysdk_store.dart'; import 'famedlysdk_store.dart';
import '../config/setting_keys.dart'; import '../config/setting_keys.dart';
abstract class SentryController { abstract class SentryController {
static Future<void> toggleSentryAction(BuildContext context) async { static Future<void> toggleSentryAction(
BuildContext context, bool enableSentry) async {
if (!AppConfig.enableSentry) return; if (!AppConfig.enableSentry) return;
final enableSentry = await showOkCancelAlertDialog(
context: context,
title: L10n.of(context).sendBugReports,
message: L10n.of(context).sentryInfo,
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).no,
) ==
OkCancelResult.ok;
final storage = Store(); final storage = Store();
await storage.setItem(SettingKeys.sentry, enableSentry.toString()); await storage.setItem(SettingKeys.sentry, enableSentry.toString());
// ignore: unawaited_futures
FlushbarHelper.createSuccess(message: L10n.of(context).changesHaveBeenSaved)
.show(context);
return; return;
} }

View File

@ -1,100 +1,101 @@
import 'dart:math'; import 'dart:math';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:adaptive_page_layout/adaptive_page_layout.dart'; import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/app_config.dart'; import 'package:fluffychat/app_config.dart';
import 'package:fluffychat/components/sentry_switch_list_tile.dart';
import 'package:flushbar/flushbar_helper.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:fluffychat/utils/sentry_controller.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import '../utils/localized_exception_extension.dart';
class HomeserverPicker extends StatelessWidget { class HomeserverPicker extends StatefulWidget {
Future<void> _setHomeserverAction(BuildContext context) async { @override
const prefix = 'https://'; _HomeserverPickerState createState() => _HomeserverPickerState();
final homeserver = await showTextInputDialog( }
title: L10n.of(context).enterYourHomeserver,
context: context,
textFields: [
DialogTextField(
hintText: AppConfig.defaultHomeserver,
prefixText: prefix,
keyboardType: TextInputType.url,
)
],
);
if (homeserver?.single?.isEmpty ?? true) return;
_checkHomeserverAction(prefix + homeserver.single, context);
}
void _checkHomeserverAction(String homeserver, BuildContext context) async { class _HomeserverPickerState extends State<HomeserverPicker> {
if (await SentryController.getSentryStatus() == null || true) { final TextEditingController _controller =
await SentryController.toggleSentryAction(context); TextEditingController(text: AppConfig.defaultHomeserver);
}
bool _isLoading = false;
void _checkHomeserverAction(BuildContext context) async {
var homeserver = _controller.text;
if (!homeserver.startsWith('https://')) { if (!homeserver.startsWith('https://')) {
homeserver = 'https://$homeserver'; homeserver = 'https://$homeserver';
} }
final success = await showFutureLoadingDialog( setState(() => _isLoading = true);
context: context, try {
future: () => checkHomeserver(homeserver, Matrix.of(context).client)); await Matrix.of(context).client.checkHomeserver(homeserver);
if (success.result == true) {
await AdaptivePageLayout.of(context) await AdaptivePageLayout.of(context)
.pushNamed(AppConfig.enableRegistration ? '/signup' : '/login'); .pushNamed(AppConfig.enableRegistration ? '/signup' : '/login');
} catch (e) {
// ignore: unawaited_futures
FlushbarHelper.createError(
title: L10n.of(context).noConnectionToTheServer,
message: (e as Object).toLocalizedString(context))
.show(context);
} finally {
if (mounted) {
setState(() => _isLoading = false);
}
} }
} }
Future<bool> checkHomeserver(dynamic homeserver, Client client) async {
await client.checkHomeserver(homeserver);
return true;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar(
title: Container(
height: 40,
child: Material(
color: Theme.of(context).secondaryHeaderColor,
borderRadius: BorderRadius.circular(32),
child: TextField(
controller: _controller,
autocorrect: false,
readOnly: !AppConfig.allowOtherHomeservers,
decoration: InputDecoration(
prefixText: 'https://',
suffix: Icon(Icons.domain_outlined),
contentPadding: EdgeInsets.only(
left: 24,
right: 16,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(32),
),
labelText: L10n.of(context).changeTheHomeserver,
hintText: AppConfig.defaultHomeserver,
),
),
),
),
),
body: SafeArea( body: SafeArea(
child: Padding( child: Padding(
padding: EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
horizontal: horizontal:
max((MediaQuery.of(context).size.width - 600) / 2, 0)), max((MediaQuery.of(context).size.width - 600) / 2, 0)),
child: Column( child: ListView(
children: <Widget>[ children: [
Expanded( Hero(
child: ListView( tag: 'loginBanner',
children: [ child: Image.asset('assets/banner.png'),
Hero( ),
tag: 'loginBanner', Padding(
child: InkWell( padding: const EdgeInsets.all(16.0),
onTap: () => showAboutDialog( child: Text(
context: context, AppConfig.applicationWelcomeMessage ??
children: [ L10n.of(context).welcomeText,
RaisedButton( textAlign: TextAlign.center,
child: Text(L10n.of(context).privacy), style: TextStyle(
onPressed: () => launch(AppConfig.privacyUrl), fontSize: 22,
) ),
],
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,
),
),
),
],
), ),
), ),
SizedBox(height: 16), SizedBox(height: 16),
@ -110,42 +111,48 @@ class HomeserverPicker extends StatelessWidget {
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6), borderRadius: BorderRadius.circular(6),
), ),
child: Text( child: _isLoading
L10n.of(context).connect.toUpperCase(), ? LinearProgressIndicator()
style: TextStyle(color: Colors.white, fontSize: 16), : Text(
), L10n.of(context).connect.toUpperCase(),
onPressed: () => _checkHomeserverAction( style: TextStyle(color: Colors.white, fontSize: 16),
AppConfig.defaultHomeserver, context), ),
), onPressed: _isLoading
), ? null
), : () => _checkHomeserverAction(context),
Padding(
padding:
const EdgeInsets.only(left: 16.0, right: 16.0, top: 16.0),
child: Text(
L10n.of(context).byDefaultYouWillBeConnectedTo(
AppConfig.defaultHomeserver),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
), ),
), ),
), ),
SentrySwitchListTile(),
Wrap( Wrap(
alignment: WrapAlignment.center,
children: [ children: [
if (AppConfig.allowOtherHomeservers) FlatButton(
FlatButton( padding: EdgeInsets.all(8),
padding: EdgeInsets.all(8), child: Text(
child: Text( L10n.of(context).about,
L10n.of(context).changeTheHomeserver, style: TextStyle(
style: TextStyle( decoration: TextDecoration.underline,
decoration: TextDecoration.underline, fontSize: 16,
color: Theme.of(context).primaryColor,
fontSize: 16,
),
), ),
onPressed: () => _setHomeserverAction(context),
), ),
onPressed: () => showAboutDialog(
context: context,
children: [
RaisedButton(
child: Text(L10n.of(context).sourceCode),
onPressed: () => launch(AppConfig.sourceCodeUrl),
),
RaisedButton(
child: Text(L10n.of(context).help),
onPressed: () => launch(AppConfig.supportUrl),
),
],
applicationIcon: Image.asset('assets/logo.png',
width: 100, height: 100),
applicationName: AppConfig.applicationName,
),
),
FlatButton( FlatButton(
padding: EdgeInsets.all(8), padding: EdgeInsets.all(8),
child: Text( child: Text(

View File

@ -1,6 +1,7 @@
import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:adaptive_page_layout/adaptive_page_layout.dart'; import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:fluffychat/components/dialogs/bootstrap_dialog.dart'; import 'package:fluffychat/components/dialogs/bootstrap_dialog.dart';
import 'package:fluffychat/components/sentry_switch_list_tile.dart';
import 'package:flushbar/flushbar_helper.dart'; import 'package:flushbar/flushbar_helper.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:file_picker_cross/file_picker_cross.dart'; import 'package:file_picker_cross/file_picker_cross.dart';
@ -406,11 +407,7 @@ class _SettingsState extends State<Settings> {
onTap: () => onTap: () =>
AdaptivePageLayout.of(context).pushNamed('/settings/ignore'), AdaptivePageLayout.of(context).pushNamed('/settings/ignore'),
), ),
ListTile( SentrySwitchListTile(),
trailing: Icon(Icons.bug_report_outlined),
title: Text(L10n.of(context).sendBugReports),
onTap: () => SentryController.toggleSentryAction(context),
),
Divider(thickness: 1), Divider(thickness: 1),
ListTile( ListTile(
trailing: Icon(Icons.security_outlined), trailing: Icon(Icons.security_outlined),