mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-26 04:48:51 +00:00
Can upload a new logo for the group
This commit is contained in:
parent
f450a46e99
commit
1a53a26f39
@ -1,3 +1,5 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:comunic/lists/groups_list.dart';
|
||||
import 'package:comunic/models/advanced_group_info.dart';
|
||||
import 'package:comunic/models/api_request.dart';
|
||||
@ -226,6 +228,15 @@ class GroupsHelper {
|
||||
.execWithThrow();
|
||||
}
|
||||
|
||||
/// Upload a new logo
|
||||
///
|
||||
/// Throws in case of failure
|
||||
static Future<void> uploadNewLogo(int groupID, Uint8List bytes) async =>
|
||||
await APIRequest(uri: "groups/upload_logo", needLogin: true)
|
||||
.addInt("id", groupID)
|
||||
.addBytesFile("logo", BytesFile("logo.png", bytes))
|
||||
.execWithFilesAndThrow();
|
||||
|
||||
/// Turn an API entry into a group object
|
||||
Group _getGroupFromAPI(Map<String, dynamic> map) {
|
||||
return Group(
|
||||
|
@ -71,4 +71,8 @@ class APIRequest {
|
||||
|
||||
/// Execute the request with files
|
||||
Future<APIResponse> execWithFiles() async => APIHelper().execWithFiles(this);
|
||||
|
||||
/// Execute the request with files to send & throws in case of failure
|
||||
Future<APIResponse> execWithFilesAndThrow() async =>
|
||||
(await execWithFiles()).assertOk();
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:comunic/helpers/groups_helper.dart';
|
||||
import 'package:comunic/models/advanced_group_info.dart';
|
||||
import 'package:comunic/models/group.dart';
|
||||
@ -5,9 +7,11 @@ 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/group_icon_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/files_utils.dart';
|
||||
import 'package:comunic/utils/input_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
@ -75,6 +79,7 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
|
||||
sections: [
|
||||
_buildGeneralSection(),
|
||||
_buildAccessRestrictions(),
|
||||
_buildGroupLogoArea()
|
||||
],
|
||||
);
|
||||
}
|
||||
@ -233,4 +238,40 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
|
||||
}),
|
||||
],
|
||||
);
|
||||
|
||||
Widget _buildGroupLogoArea() {
|
||||
return SettingsSection(
|
||||
title: tr("Group logo"),
|
||||
tiles: [
|
||||
// Current logo
|
||||
SettingsTile(
|
||||
title: tr("Current logo"),
|
||||
leading: GroupIcon(group: _groupSettings),
|
||||
),
|
||||
|
||||
// Upload a new logo
|
||||
SettingsTile(
|
||||
title: tr("Upload a new logo"),
|
||||
onTap: _uploadNewLogo,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// Upload a new logo for the group
|
||||
void _uploadNewLogo() async {
|
||||
try {
|
||||
final logo = await pickImage(context);
|
||||
final bytes = logo.readAsBytesSync();
|
||||
await _doUploadLogo(bytes);
|
||||
} catch (e, stack) {
|
||||
print("Could not upload new logo! $e\n$stack");
|
||||
showSimpleSnack(context, tr("Could not upload new logo!"));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _doUploadLogo(Uint8List bytes) async {
|
||||
await GroupsHelper.uploadNewLogo(_groupSettings.id, bytes);
|
||||
_key.currentState.refresh();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user