FurryChat/lib/views/settings.dart

217 lines
7.1 KiB
Dart
Raw Normal View History

2020-10-06 19:59:36 +00:00
import 'package:furrychat/config/app_config.dart';
import 'package:furrychat/views/settings/settings_account.dart';
import 'package:furrychat/views/settings/settings_chat.dart';
import 'package:furrychat/views/settings/settings_devices.dart';
import 'package:furrychat/views/settings/settings_encryption.dart';
import 'package:furrychat/views/settings/settings_homeserver.dart';
2020-01-01 18:10:13 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:furrychat/views/settings/settings_themes.dart';
2020-01-04 08:40:38 +00:00
import 'package:url_launcher/url_launcher.dart';
2020-01-01 18:10:13 +00:00
import 'package:furrychat/components/adaptive_page_layout.dart';
import 'package:furrychat/components/matrix.dart';
import 'package:furrychat/utils/app_route.dart';
import 'package:furrychat/views/settings/settings_emotes.dart';
enum SettingsViews {
account,
homeserver,
themes,
chat,
emotes,
encryption,
devices,
}
2020-01-01 18:10:13 +00:00
class SettingsView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AdaptivePageLayout(
primaryPage: FocusPage.FIRST,
firstScaffold: Settings(
isInFocus: true,
),
secondScaffold: Scaffold(
body: Center(
child: Image.asset('assets/logo.png', width: 100, height: 100),
),
),
2020-01-01 18:10:13 +00:00
);
}
}
class Settings extends StatefulWidget {
final bool isInFocus;
final SettingsViews currentSetting;
const Settings({this.isInFocus = false, this.currentSetting, Key key})
: super(key: key);
2020-01-01 18:10:13 +00:00
@override
_SettingsState createState() => _SettingsState();
}
class _SettingsState extends State<Settings> {
Future<dynamic> profileFuture;
dynamic profile;
2020-04-03 18:24:25 +00:00
void _handleTap(Widget child) {
widget.isInFocus
? Navigator.of(context).push(
AppRoute.defaultRoute(
context,
child,
),
)
: Navigator.of(context).pushReplacement(
AppRoute.defaultRoute(
context,
child,
),
);
2020-06-25 14:29:06 +00:00
}
2020-01-01 18:10:13 +00:00
@override
Widget build(BuildContext context) {
2020-05-13 13:58:59 +00:00
final client = Matrix.of(context).client;
2020-06-25 14:29:06 +00:00
profileFuture ??= client.ownProfile.then((p) {
2020-01-08 13:19:15 +00:00
if (mounted) setState(() => profile = p);
2020-06-25 14:29:06 +00:00
return p;
});
2020-01-01 18:10:13 +00:00
return Scaffold(
2020-02-16 09:42:59 +00:00
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) =>
<Widget>[
SliverAppBar(
leading: !widget.isInFocus
? IconButton(
icon: Icon(Icons.close_outlined),
onPressed: () =>
{Navigator.of(context).popUntil((r) => r.isFirst)},
)
: null,
2020-02-16 09:42:59 +00:00
floating: true,
pinned: true,
backgroundColor: Theme.of(context).appBarTheme.color,
title: Text(L10n.of(context).settings),
2020-01-01 18:10:13 +00:00
),
2020-02-16 09:42:59 +00:00
],
body: ListView(
children: <Widget>[
2020-02-23 07:49:58 +00:00
ListTile(
leading: Icon(
Icons.person_outlined,
2020-05-09 11:36:41 +00:00
),
title: Text(profile?.displayname ?? L10n.of(context).account),
selected:
widget.currentSetting == SettingsViews.account ? true : false,
selectedTileColor: Theme.of(context).primaryColor.withAlpha(30),
subtitle: Text(client.userID),
onTap: () => _handleTap(AccountSettingsView()),
2020-05-09 11:36:41 +00:00
),
2020-05-12 07:02:33 +00:00
ListTile(
leading: Icon(
Icons.dns_outlined,
2020-05-12 07:02:33 +00:00
),
title: Text(L10n.of(context).homeserver),
selected: widget.currentSetting == SettingsViews.homeserver
? true
: false,
selectedTileColor: Theme.of(context).primaryColor.withAlpha(30),
subtitle: Text(client.homeserver.host),
onTap: () => _handleTap(HomeserverSettingsView()),
2020-05-12 07:02:33 +00:00
),
2020-02-16 09:42:59 +00:00
ListTile(
leading: Icon(
Icons.color_lens_outlined,
2020-01-04 08:40:38 +00:00
),
title: Text(L10n.of(context).changeTheme),
selected:
widget.currentSetting == SettingsViews.themes ? true : false,
selectedTileColor: Theme.of(context).primaryColor.withAlpha(30),
onTap: () => _handleTap(ThemesSettingsView()),
2020-01-04 08:40:38 +00:00
),
2020-02-16 09:42:59 +00:00
ListTile(
leading: Icon(
Icons.chat_outlined,
),
title: Text(L10n.of(context).chat),
selected:
widget.currentSetting == SettingsViews.chat ? true : false,
selectedTileColor: Theme.of(context).primaryColor.withAlpha(30),
onTap: () => _handleTap(ChatSettingsView()),
),
2020-09-19 13:29:12 +00:00
ListTile(
leading: Icon(
Icons.insert_emoticon_outlined,
2020-09-19 13:29:12 +00:00
),
title: Text(L10n.of(context).emoteSettings),
selected:
widget.currentSetting == SettingsViews.emotes ? true : false,
selectedTileColor: Theme.of(context).primaryColor.withAlpha(30),
onTap: () => _handleTap(EmotesSettingsView()),
2020-09-19 13:29:12 +00:00
),
2020-02-19 15:23:13 +00:00
ListTile(
leading: Icon(
Icons.lock_outline,
2020-09-21 15:50:01 +00:00
),
title: Text(L10n.of(context).encryption),
selected: widget.currentSetting == SettingsViews.encryption
? true
: false,
selectedTileColor: Theme.of(context).primaryColor.withAlpha(30),
onTap: () => _handleTap(EncryptionSettingsView()),
2020-09-21 15:50:01 +00:00
),
2020-06-25 14:29:06 +00:00
ListTile(
leading: Icon(
Icons.devices_other_outlined,
2020-06-25 14:29:06 +00:00
),
title: Text(L10n.of(context).devices),
selected:
widget.currentSetting == SettingsViews.devices ? true : false,
selectedTileColor: Theme.of(context).primaryColor.withAlpha(30),
onTap: () => _handleTap(DevicesSettingsView()),
2020-06-25 14:29:06 +00:00
),
Divider(thickness: 1),
2020-02-16 09:42:59 +00:00
ListTile(
leading: Icon(
Icons.help_outline_outlined,
2020-02-16 08:56:17 +00:00
),
2020-05-07 05:52:40 +00:00
title: Text(L10n.of(context).help),
2020-10-03 09:11:28 +00:00
onTap: () => launch(AppConfig.supportUrl),
),
ListTile(
leading: Icon(
Icons.privacy_tip_outlined,
),
2020-10-03 09:11:28 +00:00
title: Text(L10n.of(context).privacy),
onTap: () => launch(AppConfig.privacyUrl),
2020-02-16 09:42:59 +00:00
),
ListTile(
leading: Icon(
Icons.link_outlined,
),
2020-05-07 05:52:40 +00:00
title: Text(L10n.of(context).license),
2020-09-18 10:58:22 +00:00
onTap: () => showLicensePage(
context: context,
applicationIcon:
Image.asset('assets/logo.png', width: 100, height: 100),
applicationName: AppConfig.applicationName,
),
2020-02-16 09:42:59 +00:00
),
2020-10-02 09:24:19 +00:00
ListTile(
leading: Icon(
Icons.code_outlined,
),
2020-10-02 09:24:19 +00:00
title: Text(L10n.of(context).sourceCode),
2020-10-03 09:11:28 +00:00
onTap: () => launch(AppConfig.sourceCodeUrl),
2020-10-02 09:24:19 +00:00
),
2020-02-16 09:42:59 +00:00
],
),
2020-01-01 18:10:13 +00:00
),
);
}
}