1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-26 06:49:22 +00:00

Can update page visibility settings

This commit is contained in:
Pierre HUBERT 2020-04-27 18:44:41 +02:00
parent 991d7ec1ab
commit cf0708cd3b
4 changed files with 154 additions and 2 deletions

View File

@ -48,7 +48,7 @@ class SettingsHelper {
"firstName": settings.firstName, "firstName": settings.firstName,
"lastName": settings.lastName, "lastName": settings.lastName,
"allow_comunic_mails": settings.allowComunicEmails ? "true" : "false", "allow_comunic_mails": settings.allowComunicEmails ? "true" : "false",
"isPublic": settings.pageVisibility == UserPageVisibility.PUBLIC "isPublic": settings.pageVisibility != UserPageVisibility.PRIVATE
? "true" ? "true"
: "false", : "false",
"isOpen": "isOpen":

View File

@ -9,7 +9,7 @@ class GeneralSettings {
final String email; final String email;
String firstName; String firstName;
String lastName; String lastName;
final UserPageVisibility pageVisibility; UserPageVisibility pageVisibility;
final bool allowComments; final bool allowComments;
final bool allowPostsFromFriends; final bool allowPostsFromFriends;
bool allowComunicEmails; bool allowComunicEmails;

View File

@ -0,0 +1,104 @@
import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// Build and show a dialog to offer to the user to choose between several
/// options
///
/// @author Pierre HUBERT
class MultiChoiceEntry<T> {
final T id;
final String title;
final String subtitle;
const MultiChoiceEntry({
@required this.id,
@required this.title,
this.subtitle,
}) : assert(id != null),
assert(title != null);
}
/// Show multiple choices dialog
Future<T> showMultiChoicesDialog<T>({
@required BuildContext context,
@required List<MultiChoiceEntry<T>> choices,
@required T defaultChoice,
@required String title,
}) async {
return await showDialog<T>(
context: context,
builder: (c) => _MultiChoicesEntryDialog(
title: title,
defaultChoice: defaultChoice,
choices: choices,
));
}
class _MultiChoicesEntryDialog<T> extends StatefulWidget {
final String title;
final T defaultChoice;
final List<MultiChoiceEntry<T>> choices;
const _MultiChoicesEntryDialog({
Key key,
@required this.title,
@required this.defaultChoice,
@required this.choices,
}) : assert(title != null),
assert(defaultChoice != null),
assert(choices != null),
super(key: key);
@override
__MultiChoicesEntryDialogState createState() =>
__MultiChoicesEntryDialogState();
}
class __MultiChoicesEntryDialogState<T>
extends State<_MultiChoicesEntryDialog<T>> {
T _currChoice;
@override
void initState() {
super.initState();
_currChoice = widget.defaultChoice;
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(widget.title),
content: SingleChildScrollView(
child: IntrinsicHeight(
child: Column(
children: widget.choices
.map((f) => ListTile(
leading: Radio<T>(
groupValue: _currChoice,
value: f.id,
onChanged: (v) => setState(() => _currChoice = v),
),
title: Text(f.title),
subtitle: Text(f.subtitle),
))
.toList(),
),
),
),
actions: <Widget>[
MaterialButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(tr("Cancel").toUpperCase()),
textColor: Colors.red,
),
MaterialButton(
onPressed: () => Navigator.of(context).pop(_currChoice),
child: Text(tr("Confirm").toUpperCase()),
textColor: Colors.green,
),
],
);
}
}

View File

@ -1,6 +1,8 @@
import 'package:comunic/enums/user_page_visibility.dart';
import 'package:comunic/helpers/database/users_database_helper.dart'; import 'package:comunic/helpers/database/users_database_helper.dart';
import 'package:comunic/helpers/settings_helper.dart'; import 'package:comunic/helpers/settings_helper.dart';
import 'package:comunic/models/general_settings.dart'; import 'package:comunic/models/general_settings.dart';
import 'package:comunic/ui/dialogs/multi_choices_dialog.dart';
import 'package:comunic/ui/widgets/async_screen_widget.dart'; import 'package:comunic/ui/widgets/async_screen_widget.dart';
import 'package:comunic/ui/widgets/settings/text_settings_edit_tile.dart'; import 'package:comunic/ui/widgets/settings/text_settings_edit_tile.dart';
import 'package:comunic/utils/account_utils.dart'; import 'package:comunic/utils/account_utils.dart';
@ -61,6 +63,10 @@ class __GeneralAccountSettingsBodyState
SettingsSection( SettingsSection(
title: tr("Main account information"), title: tr("Main account information"),
tiles: _mainInformationTiles(), tiles: _mainInformationTiles(),
),
SettingsSection(
title: tr("Your page settings"),
tiles: _pageSettingsTiles(),
) )
], ],
); );
@ -111,6 +117,48 @@ class __GeneralAccountSettingsBodyState
]; ];
} }
List<MultiChoiceEntry> get _visibilityChoices => [
MultiChoiceEntry(
id: UserPageVisibility.PRIVATE,
title: tr("Private"),
subtitle: tr("Private, accessible only to your friends")),
MultiChoiceEntry(
id: UserPageVisibility.PUBLIC,
title: tr("Public"),
subtitle: tr("Public, accessible to all Comunic members")),
MultiChoiceEntry(
id: UserPageVisibility.OPEN,
title: tr("Open"),
subtitle:
tr("Accessible to everyone, including non-Comunic users")),
];
/// Build page settings tile
List<SettingsTile> _pageSettingsTiles() {
return [
// Page visibility
SettingsTile(
title: tr("Page visibility"),
subtitle: _visibilityChoices
.firstWhere((f) => f.id == _settings.pageVisibility)
.subtitle,
onTap: () async {
final choice = await showMultiChoicesDialog(
context: context,
choices: _visibilityChoices,
defaultChoice: _settings.pageVisibility,
title: tr("Change your page visibility"),
);
if (choice == null) return;
_settings.pageVisibility = choice;
_updateSettings();
},
),
];
}
/// Apply new settings /// Apply new settings
Future<void> _updateSettings() async { Future<void> _updateSettings() async {
try { try {