fluffychat/lib/pages/views/settings_view.dart

231 lines
8.7 KiB
Dart
Raw Normal View History

2020-11-14 09:08:13 +00:00
import 'package:adaptive_dialog/adaptive_dialog.dart';
2021-05-23 11:11:55 +00:00
2021-05-22 06:53:52 +00:00
import 'package:fluffychat/widgets/sentry_switch_list_tile.dart';
import 'package:fluffychat/widgets/settings_switch_list_tile.dart';
2021-04-03 11:09:20 +00:00
import 'package:matrix/matrix.dart';
2020-12-19 12:06:31 +00:00
import 'package:fluffychat/utils/beautify_string_extension.dart';
2020-10-04 15:01:54 +00:00
2021-04-09 14:29:48 +00:00
import 'package:fluffychat/config/app_config.dart';
2020-10-04 15:01:54 +00:00
import 'package:fluffychat/utils/platform_infos.dart';
2020-01-01 18:10:13 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2020-01-04 08:40:38 +00:00
import 'package:url_launcher/url_launcher.dart';
2021-05-23 11:11:55 +00:00
import 'package:vrouter/vrouter.dart';
2020-01-01 18:10:13 +00:00
2021-05-22 06:53:52 +00:00
import '../../widgets/content_banner.dart';
import '../../widgets/matrix.dart';
import '../../config/app_config.dart';
import '../../config/setting_keys.dart';
2021-04-24 06:22:42 +00:00
import '../settings.dart';
2020-01-01 18:10:13 +00:00
2021-05-22 07:13:47 +00:00
class SettingsView extends StatelessWidget {
2021-04-24 06:22:42 +00:00
final SettingsController controller;
2020-06-25 14:29:06 +00:00
2021-05-22 07:13:47 +00:00
const SettingsView(this.controller, {Key key}) : super(key: key);
2021-01-18 07:38:19 +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;
2021-02-13 10:55:22 +00:00
return Scaffold(
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) =>
<Widget>[
SliverAppBar(
expandedHeight: 300.0,
floating: true,
pinned: true,
2021-05-16 09:29:18 +00:00
title: Text(L10n.of(context).settings),
2021-02-13 10:55:22 +00:00
backgroundColor: Theme.of(context).appBarTheme.color,
flexibleSpace: FlexibleSpaceBar(
2021-05-31 17:33:40 +00:00
background: ContentBanner(
controller.profile?.avatarUrl,
onEdit: controller.setAvatarAction,
defaultIcon: Icons.account_circle_outlined,
),
2020-01-01 18:10:13 +00:00
),
),
2021-02-13 10:55:22 +00:00
],
body: ListView(
children: <Widget>[
ListTile(
title: Text(
L10n.of(context).notifications,
style: TextStyle(
2021-05-24 08:59:00 +00:00
color: Theme.of(context).colorScheme.secondary,
2021-02-13 10:55:22 +00:00
fontWeight: FontWeight.bold,
),
),
2020-02-16 09:42:59 +00:00
),
2021-02-13 10:55:22 +00:00
ListTile(
trailing: Icon(Icons.notifications_outlined),
title: Text(L10n.of(context).notifications),
2021-05-23 11:11:55 +00:00
onTap: () => VRouter.of(context).push('/settings/notifications'),
2020-09-21 15:50:01 +00:00
),
2021-02-13 10:55:22 +00:00
Divider(thickness: 1),
ListTile(
title: Text(
L10n.of(context).chat,
style: TextStyle(
2021-05-24 08:59:00 +00:00
color: Theme.of(context).colorScheme.secondary,
2021-02-13 10:55:22 +00:00
fontWeight: FontWeight.bold,
),
2020-02-16 08:56:17 +00:00
),
),
2020-02-16 09:42:59 +00:00
ListTile(
2021-02-13 10:55:22 +00:00
title: Text(L10n.of(context).changeTheme),
2021-05-23 11:11:55 +00:00
onTap: () => VRouter.of(context).push('/settings/style'),
2021-02-13 10:55:22 +00:00
trailing: Icon(Icons.style_outlined),
2020-10-03 09:11:28 +00:00
),
2021-02-13 10:55:22 +00:00
SettingsSwitchListTile(
title: L10n.of(context).renderRichContent,
onChanged: (b) => AppConfig.renderHtml = b,
storeKey: SettingKeys.renderHtml,
defaultValue: AppConfig.renderHtml,
2020-02-16 09:42:59 +00:00
),
2021-02-13 10:55:22 +00:00
SettingsSwitchListTile(
title: L10n.of(context).hideRedactedEvents,
onChanged: (b) => AppConfig.hideRedactedEvents = b,
storeKey: SettingKeys.hideRedactedEvents,
defaultValue: AppConfig.hideRedactedEvents,
2021-01-17 14:43:38 +00:00
),
2021-02-13 10:55:22 +00:00
SettingsSwitchListTile(
title: L10n.of(context).hideUnknownEvents,
onChanged: (b) => AppConfig.hideUnknownEvents = b,
storeKey: SettingKeys.hideUnknownEvents,
defaultValue: AppConfig.hideUnknownEvents,
),
ListTile(
title: Text(L10n.of(context).emoteSettings),
2021-05-23 11:11:55 +00:00
onTap: () => VRouter.of(context).push('/settings/emotes'),
2021-02-13 10:55:22 +00:00
trailing: Icon(Icons.insert_emoticon_outlined),
),
Divider(thickness: 1),
ListTile(
title: Text(
L10n.of(context).account,
style: TextStyle(
2021-05-24 08:59:00 +00:00
color: Theme.of(context).colorScheme.secondary,
2021-02-13 10:55:22 +00:00
fontWeight: FontWeight.bold,
),
),
),
ListTile(
trailing: Icon(Icons.edit_outlined),
title: Text(L10n.of(context).editDisplayname),
2021-04-24 06:22:42 +00:00
subtitle: Text(
controller.profile?.displayname ?? client.userID.localpart),
onTap: controller.setDisplaynameAction,
2021-02-13 10:55:22 +00:00
),
ListTile(
trailing: Icon(Icons.phone_outlined),
title: Text(L10n.of(context).editJitsiInstance),
subtitle: Text(AppConfig.jitsiInstance),
2021-04-24 06:22:42 +00:00
onTap: controller.setJitsiInstanceAction,
2021-02-13 10:55:22 +00:00
),
ListTile(
trailing: Icon(Icons.devices_other_outlined),
title: Text(L10n.of(context).devices),
2021-05-23 11:11:55 +00:00
onTap: () => VRouter.of(context).push('/settings/devices'),
2021-02-13 10:55:22 +00:00
),
ListTile(
trailing: Icon(Icons.block_outlined),
title: Text(L10n.of(context).ignoredUsers),
2021-05-23 11:11:55 +00:00
onTap: () => VRouter.of(context).push('/settings/ignorelist'),
2021-02-13 10:55:22 +00:00
),
SentrySwitchListTile(),
Divider(thickness: 1),
ListTile(
trailing: Icon(Icons.security_outlined),
title: Text(
L10n.of(context).changePassword,
),
2021-04-24 06:22:42 +00:00
onTap: controller.changePasswordAccountAction,
2021-02-13 10:55:22 +00:00
),
ListTile(
trailing: Icon(Icons.email_outlined),
title: Text(L10n.of(context).passwordRecovery),
2021-05-23 11:11:55 +00:00
onTap: () => VRouter.of(context).push('/settings/3pid'),
2021-02-13 10:55:22 +00:00
),
ListTile(
trailing: Icon(Icons.exit_to_app_outlined),
title: Text(L10n.of(context).logout),
2021-04-24 06:22:42 +00:00
onTap: controller.logoutAction,
2021-02-13 10:55:22 +00:00
),
ListTile(
trailing: Icon(Icons.delete_forever_outlined),
title: Text(
L10n.of(context).deleteAccount,
style: TextStyle(color: Colors.red),
),
2021-04-24 06:22:42 +00:00
onTap: controller.deleteAccountAction,
2021-02-13 10:55:22 +00:00
),
if (client.encryption != null) ...{
Divider(thickness: 1),
ListTile(
title: Text(
L10n.of(context).security,
style: TextStyle(
2021-05-24 08:59:00 +00:00
color: Theme.of(context).colorScheme.secondary,
2021-02-13 10:55:22 +00:00
fontWeight: FontWeight.bold,
),
),
),
if (PlatformInfos.isMobile)
ListTile(
trailing: Icon(Icons.lock_outlined),
title: Text(L10n.of(context).appLock),
2021-04-24 06:22:42 +00:00
onTap: controller.setAppLockAction,
2021-02-13 10:55:22 +00:00
),
ListTile(
title: Text(L10n.of(context).yourPublicKey),
onTap: () => showOkAlertDialog(
2021-05-23 13:02:36 +00:00
useRootNavigator: false,
2021-02-13 10:55:22 +00:00
context: context,
title: L10n.of(context).yourPublicKey,
message: client.fingerprintKey.beautified,
2021-02-24 11:17:23 +00:00
okLabel: L10n.of(context).ok,
2021-02-13 10:55:22 +00:00
),
trailing: Icon(Icons.vpn_key_outlined),
),
ListTile(
title: Text(L10n.of(context).cachedKeys),
trailing: Icon(Icons.wb_cloudy_outlined),
subtitle: Text(
'${client.encryption.keyManager.enabled ? L10n.of(context).onlineKeyBackupEnabled : L10n.of(context).onlineKeyBackupDisabled}\n${client.encryption.crossSigning.enabled ? L10n.of(context).crossSigningEnabled : L10n.of(context).crossSigningDisabled}'),
2021-04-24 06:22:42 +00:00
onTap: controller.bootstrapSettingsAction,
2021-02-13 10:55:22 +00:00
),
},
Divider(thickness: 1),
ListTile(
title: Text(
L10n.of(context).about,
style: TextStyle(
2021-05-24 08:59:00 +00:00
color: Theme.of(context).colorScheme.secondary,
2021-02-13 10:55:22 +00:00
fontWeight: FontWeight.bold,
),
),
2021-05-23 11:11:55 +00:00
onTap: () => VRouter.of(context).push('/logs'),
2021-02-13 10:55:22 +00:00
),
ListTile(
trailing: Icon(Icons.help_outlined),
title: Text(L10n.of(context).help),
onTap: () => launch(AppConfig.supportUrl),
),
ListTile(
trailing: Icon(Icons.privacy_tip_outlined),
title: Text(L10n.of(context).privacy),
onTap: () => launch(AppConfig.privacyUrl),
),
ListTile(
trailing: Icon(Icons.link_outlined),
title: Text(L10n.of(context).about),
onTap: () => PlatformInfos.showDialog(context),
),
],
2021-02-03 14:47:51 +00:00
),
2021-02-13 10:55:22 +00:00
),
2020-01-01 18:10:13 +00:00
);
}
}