refactor: Pages folder structure
This commit is contained in:
parent
5fe495db94
commit
1abb7310f3
88 changed files with 188 additions and 250 deletions
167
lib/pages/settings_account/settings_account.dart
Normal file
167
lib/pages/settings_account/settings_account.dart
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/pages/settings_account/settings_account_view.dart';
|
||||
import 'package:fluffychat/widgets/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: [
|
||||
const 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,
|
||||
identifier: AuthenticationUserIdentifier(
|
||||
user: Matrix.of(context).client.userID),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void addAccountAction() => VRouter.of(context).to('add');
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
79
lib/pages/settings_account/settings_account_view.dart
Normal file
79
lib/pages/settings_account/settings_account_view.dart
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/utils/fluffy_share.dart';
|
||||
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||
import 'package:fluffychat/widgets/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: const Icon(Icons.add_box_outlined),
|
||||
title: Text(L10n.of(context).addAccount),
|
||||
subtitle: Text(L10n.of(context).enableMultiAccounts),
|
||||
onTap: controller.addAccountAction,
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
title: Text(L10n.of(context).yourUserId),
|
||||
subtitle: Text(Matrix.of(context).client.userID),
|
||||
trailing: const Icon(Icons.copy_outlined),
|
||||
onTap: () => FluffyShare.share(
|
||||
Matrix.of(context).client.userID,
|
||||
context,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
trailing: const 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: const Icon(Icons.phone_outlined),
|
||||
title: Text(L10n.of(context).editJitsiInstance),
|
||||
subtitle: Text(AppConfig.jitsiInstance),
|
||||
onTap: controller.setJitsiInstanceAction,
|
||||
),
|
||||
ListTile(
|
||||
trailing: const Icon(Icons.devices_other_outlined),
|
||||
title: Text(L10n.of(context).devices),
|
||||
onTap: () => VRouter.of(context).to('devices'),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
trailing: const Icon(Icons.exit_to_app_outlined),
|
||||
title: Text(L10n.of(context).logout),
|
||||
onTap: controller.logoutAction,
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
trailing: const Icon(Icons.delete_forever_outlined),
|
||||
title: Text(
|
||||
L10n.of(context).deleteAccount,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
onTap: controller.deleteAccountAction,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue