1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 22:39:22 +00:00

Can change group visibility

This commit is contained in:
Pierre HUBERT 2020-05-01 20:52:24 +02:00
parent cc08ed0232
commit 2d86780f0b
3 changed files with 87 additions and 2 deletions

View File

@ -25,7 +25,7 @@ class Group {
final String iconURL;
final int numberMembers;
GroupMembershipLevel membershipLevel;
final GroupVisibilityLevel visibilityLevel;
GroupVisibilityLevel visibilityLevel;
final GroupRegistrationLevel registrationLevel;
final GroupPostCreationLevel postCreationLevel;
String virtualDirectory;

View File

@ -1,9 +1,12 @@
import 'package:comunic/helpers/groups_helper.dart';
import 'package:comunic/models/advanced_group_info.dart';
import 'package:comunic/models/group.dart';
import 'package:comunic/ui/dialogs/multi_choices_dialog.dart';
import 'package:comunic/ui/dialogs/virtual_directory_dialog.dart';
import 'package:comunic/ui/widgets/async_screen_widget.dart';
import 'package:comunic/ui/widgets/comunic_back_button_widget.dart';
import 'package:comunic/ui/widgets/safe_state.dart';
import 'package:comunic/ui/widgets/settings/multi_choices_settings_tile.dart';
import 'package:comunic/ui/widgets/settings/text_settings_edit_tile.dart';
import 'package:comunic/utils/input_utils.dart';
import 'package:comunic/utils/intl_utils.dart';
@ -69,7 +72,10 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
Widget _buildContent() {
return SettingsList(
sections: [_buildGeneralSection()],
sections: [
_buildGeneralSection(),
_buildAccessRestrictions(),
],
);
}
@ -137,4 +143,37 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
],
);
}
List<MultiChoiceEntry<GroupVisibilityLevel>> get _visibilityLevels => [
MultiChoiceEntry(
id: GroupVisibilityLevel.OPEN,
title: tr("Open group"),
subtitle:
tr("Group information & public posts are available to everyone."),
),
MultiChoiceEntry(
id: GroupVisibilityLevel.PRIVATE,
title: tr("Private groupe"),
subtitle: tr("The group is accessible to accepted members only."),
),
MultiChoiceEntry(
id: GroupVisibilityLevel.SECRETE,
title: tr("Secrete groupe"),
subtitle: tr("The group is visible only to invited members."),
),
];
Widget _buildAccessRestrictions() => SettingsSection(
title: tr("Access restrictions"),
tiles: [
MultiChoicesSettingsTile(
title: tr("Group visibility"),
choices: _visibilityLevels,
currentValue: _groupSettings.visibilityLevel,
onChanged: (v) {
_groupSettings.visibilityLevel = v;
_updateSettings();
})
],
);
}

View File

@ -0,0 +1,46 @@
import 'package:comunic/ui/dialogs/multi_choices_dialog.dart';
import 'package:flutter/material.dart';
import 'package:settings_ui/settings_ui.dart';
/// Multiple choices settings tile
///
/// @author Pierre Hubert
class MultiChoicesSettingsTile<T> extends SettingsTile {
final String title;
final List<MultiChoiceEntry<T>> choices;
final T currentValue;
final Function(T) onChanged;
const MultiChoicesSettingsTile({
Key key,
@required this.title,
@required this.choices,
@required this.currentValue,
@required this.onChanged,
}) : assert(title != null),
assert(choices != null),
assert(currentValue != null),
assert(onChanged != null);
@override
Widget build(BuildContext context) {
return SettingsTile(
title: title,
subtitle: choices.firstWhere((f) => f.id == currentValue).title,
onTap: () => _changeValue(context),
);
}
/// When the user request to change the current value
void _changeValue(BuildContext context) async {
final newChoice = await showMultiChoicesDialog(
context: context,
choices: choices,
defaultChoice: currentValue,
title: title,
);
if (newChoice == null) return;
onChanged(newChoice);
}
}