mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Improve account image settings
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
import 'package:comunic/helpers/database/users_database_helper.dart';
|
||||
import 'package:comunic/helpers/settings_helper.dart';
|
||||
import 'package:comunic/models/account_image_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/network_image_widget.dart';
|
||||
import 'package:comunic/ui/widgets/settings/header_spacer_section.dart';
|
||||
import 'package:comunic/ui/widgets/settings/multi_choices_settings_tile.dart';
|
||||
import 'package:comunic/utils/account_utils.dart';
|
||||
import 'package:comunic/utils/files_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
@ -87,6 +89,27 @@ class _AccountImageSettingsScreenState
|
||||
];
|
||||
}
|
||||
|
||||
List<MultiChoiceEntry<AccountImageVisibilityLevels>> get _visibilityLevels =>
|
||||
[
|
||||
MultiChoiceEntry(
|
||||
id: AccountImageVisibilityLevels.EVERYONE,
|
||||
title: tr("Everyone"),
|
||||
subtitle: tr(
|
||||
"Your account image is visible by everyone, including users external to Comunic."),
|
||||
),
|
||||
MultiChoiceEntry(
|
||||
id: AccountImageVisibilityLevels.COMUNIC_USERS,
|
||||
title: tr("Connected users"),
|
||||
subtitle: tr(
|
||||
"Your account image is visible only to connected Comunic users."),
|
||||
),
|
||||
MultiChoiceEntry(
|
||||
id: AccountImageVisibilityLevels.FRIENDS_ONLY,
|
||||
title: tr("My friends"),
|
||||
subtitle: tr("Your account image is visible only by your friends."),
|
||||
),
|
||||
];
|
||||
|
||||
/// When the user has an account image
|
||||
List<SettingsTile> _buildHasAccountImageTiles() {
|
||||
return [
|
||||
@ -112,18 +135,16 @@ class _AccountImageSettingsScreenState
|
||||
),
|
||||
|
||||
// Change account image visibility
|
||||
SettingsTile(
|
||||
title: tr("Change account image visibility"),
|
||||
onPressed: (_) => _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"),
|
||||
})),
|
||||
MultiChoicesSettingsTile(
|
||||
title: tr("Account image visibility"),
|
||||
choices: _visibilityLevels,
|
||||
currentValue: _settings.visibility,
|
||||
onChanged: (newLevel) async {
|
||||
if (!await SettingsHelper.setAccountImageVisibilityLevel(newLevel))
|
||||
showSimpleSnack(context,
|
||||
tr("Could not update account image visibility level!"));
|
||||
_key.currentState.refresh();
|
||||
}),
|
||||
|
||||
// Delete account image
|
||||
SettingsTile(
|
||||
@ -161,44 +182,6 @@ class _AccountImageSettingsScreenState
|
||||
_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();
|
||||
}
|
||||
|
||||
/// Delete user account image
|
||||
void _deleteAccountImage() async {
|
||||
if (!await showConfirmDialog(
|
||||
|
Reference in New Issue
Block a user