1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Can change account image visibility level

This commit is contained in:
Pierre HUBERT 2020-04-16 19:30:25 +02:00
parent 8feea380a4
commit 6e0f6d1d79
2 changed files with 69 additions and 1 deletions

View File

@ -35,4 +35,19 @@ class SettingsHelper {
.addFile("picture", newImage) .addFile("picture", newImage)
.execWithFiles()) .execWithFiles())
.isOK; .isOK;
/// Change account image visibility level
static Future<bool> setAccountImageVisibilityLevel(
AccountImageVisibilityLevels level) async =>
(await APIRequest(
uri: "settings/set_account_image_visibility", needLogin: true)
.addString(
"visibility",
// Find appropriate visibility level
_APIAccountImageVisibilityAPILevels.entries
.firstWhere((f) => f.value == level)
.key)
.exec())
.isOK;
} }

View File

@ -73,11 +73,26 @@ class __AccountImageSettingsBodyState extends State<_AccountImageSettingsBody> {
width: 40, width: 40,
), ),
), ),
// Upload new account image
SettingsTile( SettingsTile(
title: tr("Upload new account image"), title: tr("Upload new account image"),
onTap: () => _uploadAccountImage(), onTap: () => _uploadAccountImage(),
), ),
SettingsTile(title: tr("Change account image visibility")),
// Change account image visibility
SettingsTile(
title: tr("Change account image visibility"),
onTap: () => _chooseAccountImageVisibility(),
subtitle: tr("Current level: %level%", args: {
"level":
_settings.visibility == AccountImageVisibilityLevels.EVERYONE
? tr("Everyone")
: _settings.visibility ==
AccountImageVisibilityLevels.COMUNIC_USERS
? tr("Comunic users")
: tr("My friends only"),
})),
SettingsTile(title: tr("Delete account image")) SettingsTile(title: tr("Delete account image"))
]; ];
} }
@ -95,4 +110,42 @@ class __AccountImageSettingsBodyState extends State<_AccountImageSettingsBody> {
_key.currentState.refresh(); _key.currentState.refresh();
} }
/// Change account image visibility
void _chooseAccountImageVisibility() async {
final newLevel = await showDialog<AccountImageVisibilityLevels>(
context: context,
builder: (c) => AlertDialog(
title: Text(tr("Account image visiblity")),
content:
Text(tr("Please choose new account image visibility level:")),
actions: <Widget>[
MaterialButton(
child: Text(tr("Everyone")),
onPressed: () =>
Navigator.pop(c, AccountImageVisibilityLevels.EVERYONE),
),
MaterialButton(
child: Text(tr("Connected users")),
onPressed: () => Navigator.pop(
c, AccountImageVisibilityLevels.COMUNIC_USERS),
),
MaterialButton(
child: Text(tr("My friends")),
onPressed: () => Navigator.pop(
c, AccountImageVisibilityLevels.FRIENDS_ONLY),
)
],
));
if (newLevel == null) return;
if (!await SettingsHelper.setAccountImageVisibilityLevel(newLevel)) {
showSimpleSnack(
context, tr("Could not update account image visibility level!"));
return;
}
_key.currentState.refresh();
}
} }