design: Sort settings routes
parent
324adbeba6
commit
bc912f48f7
@ -0,0 +1,163 @@
|
|||||||
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||||
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
|
import 'package:fluffychat/config/setting_keys.dart';
|
||||||
|
import 'package:fluffychat/pages/views/settings_account_view.dart';
|
||||||
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
|
class SettingsAccount extends StatefulWidget {
|
||||||
|
const SettingsAccount({Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
SettingsAccountController createState() => SettingsAccountController();
|
||||||
|
}
|
||||||
|
|
||||||
|
class SettingsAccountController extends State<SettingsAccount> {
|
||||||
|
Future<dynamic> profileFuture;
|
||||||
|
Profile profile;
|
||||||
|
bool profileUpdated = false;
|
||||||
|
|
||||||
|
void updateProfile() => setState(() {
|
||||||
|
profileUpdated = true;
|
||||||
|
profile = profileFuture = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
void setDisplaynameAction() async {
|
||||||
|
final input = await showTextInputDialog(
|
||||||
|
useRootNavigator: false,
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).editDisplayname,
|
||||||
|
okLabel: L10n.of(context).ok,
|
||||||
|
cancelLabel: L10n.of(context).cancel,
|
||||||
|
textFields: [
|
||||||
|
DialogTextField(
|
||||||
|
initialText: profile?.displayname ??
|
||||||
|
Matrix.of(context).client.userID.localpart,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
if (input == null) return;
|
||||||
|
final matrix = Matrix.of(context);
|
||||||
|
final success = await showFutureLoadingDialog(
|
||||||
|
context: context,
|
||||||
|
future: () =>
|
||||||
|
matrix.client.setDisplayName(matrix.client.userID, input.single),
|
||||||
|
);
|
||||||
|
if (success.error == null) {
|
||||||
|
updateProfile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setJitsiInstanceAction() async {
|
||||||
|
const prefix = 'https://';
|
||||||
|
final input = await showTextInputDialog(
|
||||||
|
useRootNavigator: false,
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).editJitsiInstance,
|
||||||
|
okLabel: L10n.of(context).ok,
|
||||||
|
cancelLabel: L10n.of(context).cancel,
|
||||||
|
textFields: [
|
||||||
|
DialogTextField(
|
||||||
|
initialText: AppConfig.jitsiInstance.replaceFirst(prefix, ''),
|
||||||
|
prefixText: prefix,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
if (input == null) return;
|
||||||
|
var jitsi = prefix + input.single;
|
||||||
|
if (!jitsi.endsWith('/')) {
|
||||||
|
jitsi += '/';
|
||||||
|
}
|
||||||
|
final matrix = Matrix.of(context);
|
||||||
|
await matrix.store.setItem(SettingKeys.jitsiInstance, jitsi);
|
||||||
|
AppConfig.jitsiInstance = jitsi;
|
||||||
|
}
|
||||||
|
|
||||||
|
void logoutAction() async {
|
||||||
|
if (await showOkCancelAlertDialog(
|
||||||
|
useRootNavigator: false,
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).areYouSureYouWantToLogout,
|
||||||
|
okLabel: L10n.of(context).yes,
|
||||||
|
cancelLabel: L10n.of(context).cancel,
|
||||||
|
) ==
|
||||||
|
OkCancelResult.cancel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final matrix = Matrix.of(context);
|
||||||
|
await showFutureLoadingDialog(
|
||||||
|
context: context,
|
||||||
|
future: () => matrix.client.logout(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteAccountAction() async {
|
||||||
|
if (await showOkCancelAlertDialog(
|
||||||
|
useRootNavigator: false,
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).warning,
|
||||||
|
message: L10n.of(context).deactivateAccountWarning,
|
||||||
|
okLabel: L10n.of(context).ok,
|
||||||
|
cancelLabel: L10n.of(context).cancel,
|
||||||
|
) ==
|
||||||
|
OkCancelResult.cancel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (await showOkCancelAlertDialog(
|
||||||
|
useRootNavigator: false,
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).areYouSure,
|
||||||
|
okLabel: L10n.of(context).yes,
|
||||||
|
cancelLabel: L10n.of(context).cancel,
|
||||||
|
) ==
|
||||||
|
OkCancelResult.cancel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final input = await showTextInputDialog(
|
||||||
|
useRootNavigator: false,
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).pleaseEnterYourPassword,
|
||||||
|
okLabel: L10n.of(context).ok,
|
||||||
|
cancelLabel: L10n.of(context).cancel,
|
||||||
|
textFields: [
|
||||||
|
DialogTextField(
|
||||||
|
obscureText: true,
|
||||||
|
hintText: '******',
|
||||||
|
minLines: 1,
|
||||||
|
maxLines: 1,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
if (input == null) return;
|
||||||
|
await showFutureLoadingDialog(
|
||||||
|
context: context,
|
||||||
|
future: () => Matrix.of(context).client.deactivateAccount(
|
||||||
|
auth: AuthenticationPassword(
|
||||||
|
password: input.single,
|
||||||
|
user: Matrix.of(context).client.userID,
|
||||||
|
identifier: AuthenticationUserIdentifier(
|
||||||
|
user: Matrix.of(context).client.userID),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final client = Matrix.of(context).client;
|
||||||
|
profileFuture ??= client
|
||||||
|
.getProfileFromUserId(
|
||||||
|
client.userID,
|
||||||
|
cache: !profileUpdated,
|
||||||
|
getFromRooms: !profileUpdated,
|
||||||
|
)
|
||||||
|
.then((p) {
|
||||||
|
if (mounted) setState(() => profile = p);
|
||||||
|
return p;
|
||||||
|
});
|
||||||
|
return SettingsAccountView(this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'views/settings_chat_view.dart';
|
||||||
|
|
||||||
|
class SettingsChat extends StatefulWidget {
|
||||||
|
const SettingsChat({Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
SettingsChatController createState() => SettingsChatController();
|
||||||
|
}
|
||||||
|
|
||||||
|
class SettingsChatController extends State<SettingsChat> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => SettingsChatView(this);
|
||||||
|
}
|
@ -0,0 +1,120 @@
|
|||||||
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||||
|
import 'package:fluffychat/config/setting_keys.dart';
|
||||||
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_app_lock/flutter_app_lock.dart';
|
||||||
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
|
||||||
|
import 'bootstrap_dialog.dart';
|
||||||
|
import 'views/settings_security_view.dart';
|
||||||
|
|
||||||
|
class SettingsSecurity extends StatefulWidget {
|
||||||
|
const SettingsSecurity({Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
SettingsSecurityController createState() => SettingsSecurityController();
|
||||||
|
}
|
||||||
|
|
||||||
|
class SettingsSecurityController extends State<SettingsSecurity> {
|
||||||
|
void changePasswordAccountAction() async {
|
||||||
|
final input = await showTextInputDialog(
|
||||||
|
useRootNavigator: false,
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).changePassword,
|
||||||
|
okLabel: L10n.of(context).ok,
|
||||||
|
cancelLabel: L10n.of(context).cancel,
|
||||||
|
textFields: [
|
||||||
|
DialogTextField(
|
||||||
|
hintText: L10n.of(context).pleaseEnterYourPassword,
|
||||||
|
obscureText: true,
|
||||||
|
minLines: 1,
|
||||||
|
maxLines: 1,
|
||||||
|
),
|
||||||
|
DialogTextField(
|
||||||
|
hintText: L10n.of(context).chooseAStrongPassword,
|
||||||
|
obscureText: true,
|
||||||
|
minLines: 1,
|
||||||
|
maxLines: 1,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
if (input == null) return;
|
||||||
|
final success = await showFutureLoadingDialog(
|
||||||
|
context: context,
|
||||||
|
future: () => Matrix.of(context)
|
||||||
|
.client
|
||||||
|
.changePassword(input.last, oldPassword: input.first),
|
||||||
|
);
|
||||||
|
if (success.error == null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(L10n.of(context).passwordHasBeenChanged)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setAppLockAction() async {
|
||||||
|
final currentLock =
|
||||||
|
await FlutterSecureStorage().read(key: SettingKeys.appLockKey);
|
||||||
|
if (currentLock?.isNotEmpty ?? false) {
|
||||||
|
await AppLock.of(context).showLockScreen();
|
||||||
|
}
|
||||||
|
final newLock = await showTextInputDialog(
|
||||||
|
useRootNavigator: false,
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).pleaseChooseAPasscode,
|
||||||
|
message: L10n.of(context).pleaseEnter4Digits,
|
||||||
|
cancelLabel: L10n.of(context).cancel,
|
||||||
|
textFields: [
|
||||||
|
DialogTextField(
|
||||||
|
validator: (text) {
|
||||||
|
if (text.isEmpty || (text.length == 4 && int.tryParse(text) >= 0)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return L10n.of(context).pleaseEnter4Digits;
|
||||||
|
},
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
obscureText: true,
|
||||||
|
maxLines: 1,
|
||||||
|
minLines: 1,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
if (newLock != null) {
|
||||||
|
await FlutterSecureStorage()
|
||||||
|
.write(key: SettingKeys.appLockKey, value: newLock.single);
|
||||||
|
if (newLock.single.isEmpty) {
|
||||||
|
AppLock.of(context).disable();
|
||||||
|
} else {
|
||||||
|
AppLock.of(context).enable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void bootstrapSettingsAction() async {
|
||||||
|
if (await Matrix.of(context).client.encryption.keyManager.isCached()) {
|
||||||
|
if (OkCancelResult.ok ==
|
||||||
|
await showOkCancelAlertDialog(
|
||||||
|
useRootNavigator: false,
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).keysCached,
|
||||||
|
message: L10n.of(context).wipeChatBackup,
|
||||||
|
isDestructiveAction: true,
|
||||||
|
okLabel: L10n.of(context).ok,
|
||||||
|
cancelLabel: L10n.of(context).cancel,
|
||||||
|
)) {
|
||||||
|
await BootstrapDialog(
|
||||||
|
client: Matrix.of(context).client,
|
||||||
|
wipe: true,
|
||||||
|
).show(context);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await BootstrapDialog(
|
||||||
|
client: Matrix.of(context).client,
|
||||||
|
).show(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => SettingsSecurityView(this);
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
|
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||||
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
import 'package:vrouter/vrouter.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
|
import '../settings_account.dart';
|
||||||
|
|
||||||
|
class SettingsAccountView extends StatelessWidget {
|
||||||
|
final SettingsAccountController controller;
|
||||||
|
const SettingsAccountView(this.controller, {Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(title: Text(L10n.of(context).account)),
|
||||||
|
body: MaxWidthBody(
|
||||||
|
withScrolling: true,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
ListTile(
|
||||||
|
trailing: Icon(Icons.edit_outlined),
|
||||||
|
title: Text(L10n.of(context).editDisplayname),
|
||||||
|
subtitle: Text(controller.profile?.displayname ??
|
||||||
|
Matrix.of(context).client.userID.localpart),
|
||||||
|
onTap: controller.setDisplaynameAction,
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
trailing: Icon(Icons.phone_outlined),
|
||||||
|
title: Text(L10n.of(context).editJitsiInstance),
|
||||||
|
subtitle: Text(AppConfig.jitsiInstance),
|
||||||
|
onTap: controller.setJitsiInstanceAction,
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
trailing: Icon(Icons.devices_other_outlined),
|
||||||
|
title: Text(L10n.of(context).devices),
|
||||||
|
onTap: () => VRouter.of(context).push('devices'),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
trailing: Icon(Icons.exit_to_app_outlined),
|
||||||
|
title: Text(L10n.of(context).logout),
|
||||||
|
onTap: controller.logoutAction,
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
trailing: Icon(Icons.delete_forever_outlined),
|
||||||
|
title: Text(
|
||||||
|
L10n.of(context).deleteAccount,
|
||||||
|
style: TextStyle(color: Colors.red),
|
||||||
|
),
|
||||||
|
onTap: controller.deleteAccountAction,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
|
import 'package:fluffychat/config/setting_keys.dart';
|
||||||
|
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||||
|
import 'package:fluffychat/widgets/settings_switch_list_tile.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:vrouter/vrouter.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
|
||||||
|
import '../settings_chat.dart';
|
||||||
|
|
||||||
|
class SettingsChatView extends StatelessWidget {
|
||||||
|
final SettingsChatController controller;
|
||||||
|
const SettingsChatView(this.controller, {Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(title: Text(L10n.of(context).chat)),
|
||||||
|
body: MaxWidthBody(
|
||||||
|
withScrolling: true,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
ListTile(
|
||||||
|
title: Text(L10n.of(context).changeTheme),
|
||||||
|
onTap: () => VRouter.of(context).push('style'),
|
||||||
|
trailing: Icon(Icons.style_outlined),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
title: Text(L10n.of(context).emoteSettings),
|
||||||
|
onTap: () => VRouter.of(context).push('emotes'),
|
||||||
|
trailing: Icon(Icons.insert_emoticon_outlined),
|
||||||
|
),
|
||||||
|
Divider(height: 1),
|
||||||
|
SettingsSwitchListTile(
|
||||||
|
title: L10n.of(context).renderRichContent,
|
||||||
|
onChanged: (b) => AppConfig.renderHtml = b,
|
||||||
|
storeKey: SettingKeys.renderHtml,
|
||||||
|
defaultValue: AppConfig.renderHtml,
|
||||||
|
),
|
||||||
|
SettingsSwitchListTile(
|
||||||
|
title: L10n.of(context).hideRedactedEvents,
|
||||||
|
onChanged: (b) => AppConfig.hideRedactedEvents = b,
|
||||||
|
storeKey: SettingKeys.hideRedactedEvents,
|
||||||
|
defaultValue: AppConfig.hideRedactedEvents,
|
||||||
|
),
|
||||||
|
SettingsSwitchListTile(
|
||||||
|
title: L10n.of(context).hideUnknownEvents,
|
||||||
|
onChanged: (b) => AppConfig.hideUnknownEvents = b,
|
||||||
|
storeKey: SettingKeys.hideUnknownEvents,
|
||||||
|
defaultValue: AppConfig.hideUnknownEvents,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||||
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
|
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||||
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
import 'package:vrouter/vrouter.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/utils/beautify_string_extension.dart';
|
||||||
|
import '../settings_security.dart';
|
||||||
|
|
||||||
|
class SettingsSecurityView extends StatelessWidget {
|
||||||
|
final SettingsSecurityController controller;
|
||||||
|
const SettingsSecurityView(this.controller, {Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(title: Text(L10n.of(context).security)),
|
||||||
|
body: MaxWidthBody(
|
||||||
|
withScrolling: true,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
ListTile(
|
||||||
|
trailing: Icon(Icons.block_outlined),
|
||||||
|
title: Text(L10n.of(context).ignoredUsers),
|
||||||
|
onTap: () => VRouter.of(context).push('ignorelist'),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
trailing: Icon(Icons.security_outlined),
|
||||||
|
title: Text(
|
||||||
|
L10n.of(context).changePassword,
|
||||||
|
),
|
||||||
|
onTap: controller.changePasswordAccountAction,
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
trailing: Icon(Icons.email_outlined),
|
||||||
|
title: Text(L10n.of(context).passwordRecovery),
|
||||||
|
onTap: () => VRouter.of(context).push('3pid'),
|
||||||
|
),
|
||||||
|
if (Matrix.of(context).client.encryption != null) ...{
|
||||||
|
Divider(thickness: 1),
|
||||||
|
if (PlatformInfos.isMobile)
|
||||||
|
ListTile(
|
||||||
|
trailing: Icon(Icons.lock_outlined),
|
||||||
|
title: Text(L10n.of(context).appLock),
|
||||||
|
onTap: controller.setAppLockAction,
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
title: Text(L10n.of(context).yourPublicKey),
|
||||||
|
onTap: () => showOkAlertDialog(
|
||||||
|
useRootNavigator: false,
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).yourPublicKey,
|
||||||
|
message: Matrix.of(context).client.fingerprintKey.beautified,
|
||||||
|
okLabel: L10n.of(context).ok,
|
||||||
|
),
|
||||||
|
trailing: Icon(Icons.vpn_key_outlined),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
title: Text(L10n.of(context).cachedKeys),
|
||||||
|
trailing: Icon(Icons.wb_cloudy_outlined),
|
||||||
|
subtitle: Text(
|
||||||
|
'${Matrix.of(context).client.encryption.keyManager.enabled ? L10n.of(context).onlineKeyBackupEnabled : L10n.of(context).onlineKeyBackupDisabled}\n${Matrix.of(context).client.encryption.crossSigning.enabled ? L10n.of(context).crossSigningEnabled : L10n.of(context).crossSigningDisabled}'),
|
||||||
|
onTap: controller.bootstrapSettingsAction,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue