mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Can change account image visibility level
This commit is contained in:
		@@ -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;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user