mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
180 lines
5.2 KiB
Dart
180 lines
5.2 KiB
Dart
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';
|
|
import 'package:comunic/utils/ui_utils.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:settings_ui/settings_ui.dart';
|
|
|
|
/// Groups settings screen
|
|
///
|
|
/// @author Pierre Hubert
|
|
|
|
class GroupSettingsScreen extends StatefulWidget {
|
|
final int groupID;
|
|
|
|
const GroupSettingsScreen({Key key, @required this.groupID})
|
|
: assert(groupID != null),
|
|
super(key: key);
|
|
|
|
@override
|
|
_GroupSettingsScreenState createState() => _GroupSettingsScreenState();
|
|
}
|
|
|
|
class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
|
|
AdvancedGroupInfo _groupSettings;
|
|
|
|
final _key = GlobalKey<AsyncScreenWidgetState>();
|
|
|
|
Future<void> _refresh() async {
|
|
_groupSettings = await GroupsHelper().getSettings(widget.groupID);
|
|
}
|
|
|
|
Future<void> _updateSettings() async {
|
|
try {
|
|
await GroupsHelper.setSettings(_groupSettings);
|
|
} catch (e, stack) {
|
|
print("Could not update group settings! $e\n$stack");
|
|
showSimpleSnack(context, tr("Could not update group settings!"));
|
|
}
|
|
|
|
_key.currentState.refresh();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
leading: ComunicBackButton(),
|
|
title: Text(tr("Group settings")),
|
|
),
|
|
body: _buildBody(),
|
|
);
|
|
}
|
|
|
|
Widget _buildBody() {
|
|
return AsyncScreenWidget(
|
|
key: _key,
|
|
onReload: _refresh,
|
|
onBuild: _buildContent,
|
|
errorMessage: tr("Could not get group settings!"),
|
|
showOldDataWhileUpdating: true,
|
|
);
|
|
}
|
|
|
|
Widget _buildContent() {
|
|
return SettingsList(
|
|
sections: [
|
|
_buildGeneralSection(),
|
|
_buildAccessRestrictions(),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildGeneralSection() {
|
|
return SettingsSection(
|
|
title: tr("General information"),
|
|
tiles: [
|
|
// Group ID
|
|
SettingsTile(
|
|
title: tr("Group ID"),
|
|
subtitle: _groupSettings.id.toString(),
|
|
),
|
|
|
|
// Group name
|
|
TextEditSettingsTile(
|
|
title: tr("Group name"),
|
|
currValue: _groupSettings.name,
|
|
onChanged: (s) {
|
|
_groupSettings.name = s;
|
|
_updateSettings();
|
|
}),
|
|
|
|
// Group virtual directory
|
|
SettingsTile(
|
|
title: tr("Virtual directory (optional)"),
|
|
subtitle: _groupSettings.virtualDirectory,
|
|
onTap: () async {
|
|
final newDir = await showVirtualDirectoryDialog(
|
|
context: context,
|
|
initialDirectory: _groupSettings.virtualDirectory,
|
|
id: _groupSettings.id,
|
|
type: VirtualDirectoryTargetType.GROUP,
|
|
);
|
|
|
|
if (newDir == null) return;
|
|
|
|
_groupSettings.virtualDirectory = newDir;
|
|
_updateSettings();
|
|
},
|
|
),
|
|
|
|
// Group URL
|
|
TextEditSettingsTile(
|
|
title: tr("Group URL (optional)"),
|
|
currValue: _groupSettings.url,
|
|
checkInput: validateUrl,
|
|
allowEmptyValues: true,
|
|
onChanged: (s) {
|
|
_groupSettings.url = s;
|
|
_updateSettings();
|
|
},
|
|
),
|
|
|
|
// Group description
|
|
TextEditSettingsTile(
|
|
title: tr("Group description (optional)"),
|
|
currValue: _groupSettings.description,
|
|
maxLines: 3,
|
|
maxLength: 255,
|
|
allowEmptyValues: true,
|
|
onChanged: (s) {
|
|
_groupSettings.description = s;
|
|
_updateSettings();
|
|
}),
|
|
],
|
|
);
|
|
}
|
|
|
|
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();
|
|
})
|
|
],
|
|
);
|
|
}
|