1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-26 23:09:21 +00:00
comunicmobile/lib/ui/routes/settings/account_settings_route.dart

208 lines
6.2 KiB
Dart
Raw Normal View History

2021-04-18 12:09:48 +00:00
import 'package:comunic/ui/routes/TourRoute.dart';
2020-05-12 16:42:33 +00:00
import 'package:comunic/ui/routes/settings/account_image_settings.dart';
import 'package:comunic/ui/routes/settings/account_privacy_settings.dart';
import 'package:comunic/ui/routes/settings/account_security_settings.dart';
import 'package:comunic/ui/routes/settings/application_settings.dart';
import 'package:comunic/ui/routes/settings/custom_emojies_account_settings.dart';
import 'package:comunic/ui/routes/settings/general_account_settings.dart';
import 'package:comunic/ui/routes/settings/notifications_settings.dart';
2021-02-12 21:36:22 +00:00
import 'package:comunic/ui/widgets/settings/header_spacer_section.dart';
2020-04-16 14:33:44 +00:00
import 'package:comunic/utils/intl_utils.dart';
2020-05-13 16:12:45 +00:00
import 'package:comunic/utils/ui_utils.dart';
2020-04-16 14:33:44 +00:00
import 'package:flutter/material.dart';
import 'package:settings_ui/settings_ui.dart';
2021-04-18 12:09:48 +00:00
enum _MainMenuActions { SHOW_TOUR }
2020-04-16 14:33:44 +00:00
/// Account settings route
///
/// @author Pierre HUBERT
2020-05-13 16:12:45 +00:00
class _SettingsSection {
final String title;
final String subtitle;
final IconData icon;
final Widget Function() onBuild;
const _SettingsSection({
@required this.title,
@required this.subtitle,
@required this.icon,
@required this.onBuild,
}) : assert(title != null),
assert(subtitle != null),
assert(icon != null),
assert(onBuild != null);
}
2020-04-16 14:33:44 +00:00
class AccountSettingsRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2020-05-12 16:42:33 +00:00
title: Text(tr("Settings")),
2021-04-18 12:09:48 +00:00
actions: [
PopupMenuButton<_MainMenuActions>(
onSelected: (v) => _doPopupMenuAction(context, v),
itemBuilder: (c) => [
PopupMenuItem(
value: _MainMenuActions.SHOW_TOUR,
child: Text(tr("See the tour again")),
),
]),
],
2020-04-16 14:33:44 +00:00
),
body: _AccountSettingsBody(),
);
}
2021-04-18 12:09:48 +00:00
void _doPopupMenuAction(BuildContext context, _MainMenuActions value) async {
switch (value) {
case _MainMenuActions.SHOW_TOUR:
Navigator.of(context)
.push(MaterialPageRoute(builder: (c) => TourRoute()));
break;
}
}
2020-04-16 14:33:44 +00:00
}
class _AccountSettingsBody extends StatefulWidget {
@override
__AccountSettingsBodyState createState() => __AccountSettingsBodyState();
}
class __AccountSettingsBodyState extends State<_AccountSettingsBody> {
2020-05-13 16:12:45 +00:00
_SettingsSection _currentSection;
2020-04-16 14:33:44 +00:00
@override
2020-05-13 16:12:45 +00:00
void initState() {
super.initState();
2020-04-27 11:27:37 +00:00
2020-05-13 16:12:45 +00:00
/// Choose first section by default
_currentSection = _sections[0];
}
2020-04-28 17:03:23 +00:00
2020-05-13 16:12:45 +00:00
/// The list of settings sections
List<_SettingsSection> get _sections => [
_SettingsSection(
title: tr("General settings"),
subtitle: tr("Configure the main settings of your account"),
icon: Icons.settings,
onBuild: () => GeneralAccountSettingsScreen(),
),
2020-04-29 15:28:47 +00:00
2020-05-13 16:12:45 +00:00
// Emoticons
_SettingsSection(
title: tr("Custom emojis"),
subtitle: tr("Set your own emoticon shorcuts"),
icon: Icons.insert_emoticon,
onBuild: () => CustomEmojisAccountSettings(),
),
2020-05-01 08:52:53 +00:00
2020-05-13 16:12:45 +00:00
// Account image
_SettingsSection(
title: tr("Account image"),
subtitle: tr("Customize your account image"),
icon: Icons.account_circle,
onBuild: () => AccountImageSettingsScreen(),
),
// Notifications settings
_SettingsSection(
title: tr("Notifications"),
2021-04-11 12:33:19 +00:00
subtitle: tr("Choose the notifications you receive on your phone"),
icon: Icons.notifications,
onBuild: () => NotificationsSettingsScreen(),
),
2020-05-13 16:12:45 +00:00
// Security settings
_SettingsSection(
title: tr("Security"),
subtitle: tr("Manage security options of your account"),
icon: Icons.lock,
onBuild: () => AccountSecuritySettingsScreen(),
),
2020-05-12 15:50:05 +00:00
2020-05-13 16:12:45 +00:00
// Privacy settings
_SettingsSection(
title: tr("Privacy"),
subtitle: tr("Here you can make actions to protect your privacy"),
icon: Icons.security,
onBuild: () => AccountPrivacySettings(),
),
// Privacy settings
_SettingsSection(
title: tr("Application settings"),
subtitle: tr("Manage local application settings"),
icon: Icons.smartphone,
onBuild: () => ApplicationSettings(),
),
];
@override
Widget build(BuildContext context) =>
isTablet(context) ? _buildTabletMode() : _buildMobileMode();
/// Tablet mode
Widget _buildTabletMode() => Row(
children: <Widget>[
Container(width: 400, child: _buildTabletLeftPane()),
Expanded(child: _currentSection.onBuild())
],
);
Widget _buildTabletLeftPane() => ListView.builder(
itemBuilder: (c, i) {
final section = _sections[i];
return Container(
color: section.title == _currentSection.title
? Colors.black.withAlpha(50)
: null,
child: ListTile(
title: Text(section.title),
subtitle: Text(section.subtitle),
leading: Icon(section.icon),
onTap: () => _openSectionTablet(section),
2020-05-12 15:50:05 +00:00
),
2020-05-13 16:12:45 +00:00
);
},
itemCount: _sections.length,
);
void _openSectionTablet(_SettingsSection s) =>
setState(() => _currentSection = s);
2020-04-16 14:33:44 +00:00
2020-05-13 16:12:45 +00:00
/// Mobile mode
Widget _buildMobileMode() => SettingsList(
sections: [
2021-02-12 21:36:22 +00:00
HeadSpacerSection(),
2020-05-13 16:12:45 +00:00
SettingsSection(
title: tr("Settings"),
tiles: _sections
.map((f) => SettingsTile(
title: f.title,
leading: Icon(f.icon),
subtitle: f.subtitle,
2021-02-07 16:09:08 +00:00
onPressed: (_) => _openSectionsAsNewRoute(f),
2021-04-17 06:40:33 +00:00
subtitleMaxLines: 3,
2020-05-13 16:12:45 +00:00
))
.toList(),
)
],
);
/// Push a new route with the settings section
_openSectionsAsNewRoute(_SettingsSection f) {
Navigator.of(context).push(MaterialPageRoute(
builder: (c) => Scaffold(
appBar: AppBar(
title: Text(f.title),
),
body: f.onBuild(),
),
));
2020-04-16 14:33:44 +00:00
}
}