fluffychat/lib/pages/views/settings_view.dart

262 lines
10 KiB
Dart
Raw Normal View History

2020-11-14 09:08:13 +00:00
import 'package:adaptive_dialog/adaptive_dialog.dart';
2021-01-16 11:46:38 +00:00
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
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
2020-01-01 18:10:13 +00:00
import 'package:famedlysdk/famedlysdk.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';
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(
2021-02-25 12:24:07 +00:00
leading: IconButton(
icon: Icon(Icons.close_outlined),
onPressed: () => AdaptivePageLayout.of(context).popUntilIsFirst(),
),
2021-02-13 10:55:22 +00:00
expandedHeight: 300.0,
floating: true,
pinned: true,
2021-05-16 09:29:18 +00:00
title: Text(L10n.of(context).settings),
2021-02-27 08:10:08 +00:00
actions: [
FutureBuilder(
2021-04-24 06:22:42 +00:00
future: controller.crossSigningCachedFuture,
2021-02-27 08:10:08 +00:00
builder: (context, snapshot) {
final needsBootstrap = Matrix.of(context)
.client
.encryption
2021-04-09 18:16:56 +00:00
?.crossSigning
?.enabled ==
2021-02-27 08:10:08 +00:00
false ||
snapshot.data == false;
final isUnknownSession =
Matrix.of(context).client.isUnknownSession;
final displayHeader = needsBootstrap || isUnknownSession;
if (!displayHeader) return Container();
return TextButton.icon(
icon: Icon(Icons.cloud, color: Colors.red),
label: Text(
L10n.of(context).chatBackup,
style: TextStyle(color: Colors.red),
),
2021-04-24 06:22:42 +00:00
onPressed: controller.firstRunBootstrapAction,
2021-02-27 08:10:08 +00:00
);
}),
],
2021-02-13 10:55:22 +00:00
backgroundColor: Theme.of(context).appBarTheme.color,
flexibleSpace: FlexibleSpaceBar(
2021-04-24 06:22:42 +00:00
background: ContentBanner(controller.profile?.avatarUrl,
onEdit: controller.setAvatarAction),
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(
color: Theme.of(context).accentColor,
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),
onTap: () => AdaptivePageLayout.of(context)
.pushNamed('/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(
color: Theme.of(context).accentColor,
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),
onTap: () =>
AdaptivePageLayout.of(context).pushNamed('/settings/style'),
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),
onTap: () =>
AdaptivePageLayout.of(context).pushNamed('/settings/emotes'),
trailing: Icon(Icons.insert_emoticon_outlined),
),
Divider(thickness: 1),
ListTile(
title: Text(
L10n.of(context).account,
style: TextStyle(
color: Theme.of(context).accentColor,
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),
onTap: () =>
AdaptivePageLayout.of(context).pushNamed('/settings/devices'),
),
ListTile(
trailing: Icon(Icons.block_outlined),
title: Text(L10n.of(context).ignoredUsers),
onTap: () =>
AdaptivePageLayout.of(context).pushNamed('/settings/ignore'),
),
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),
onTap: () =>
AdaptivePageLayout.of(context).pushNamed('/settings/3pid'),
),
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(
color: Theme.of(context).accentColor,
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(
context: context,
title: L10n.of(context).yourPublicKey,
message: client.fingerprintKey.beautified,
2021-02-24 11:17:23 +00:00
okLabel: L10n.of(context).ok,
useRootNavigator: false,
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(
color: Theme.of(context).accentColor,
fontWeight: FontWeight.bold,
),
),
onTap: () => AdaptivePageLayout.of(context).pushNamed('/logs'),
),
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
);
}
}