Skip to content

Commit

Permalink
TW-1699: change avatar updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Te-Z committed May 3, 2024
1 parent 400fda4 commit 5e783c0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
15 changes: 12 additions & 3 deletions lib/domain/model/extensions/xfile_extension.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:file_picker/file_picker.dart';
import 'package:file_selector/file_selector.dart';
import 'package:matrix/matrix.dart';

extension XFileExtension on XFile {

Future<MatrixFile> toMatrixFile() async{
Future<MatrixFile> toMatrixFile() async {
return MatrixFile.fromMimeType(
bytes: await readAsBytes(),
mimeType: mimeType,
Expand All @@ -12,4 +12,13 @@ extension XFileExtension on XFile {
sizeInBytes: await length(),
);
}
}

Future<PlatformFile> toPlatformFile() async {
return PlatformFile.fromMap({
'name': name,
'path': path,
'bytes': await readAsBytes(),
'size': await length(),
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/domain/app_state/room/upload_content_state.dart';
import 'package:fluffychat/domain/app_state/settings/update_profile_failure.dart';
import 'package:fluffychat/domain/app_state/settings/update_profile_success.dart';
import 'package:fluffychat/domain/model/extensions/xfile_extension.dart';
import 'package:fluffychat/domain/usecase/room/upload_content_for_web_interactor.dart';
import 'package:fluffychat/domain/usecase/room/upload_content_interactor.dart';
import 'package:fluffychat/domain/usecase/settings/update_profile_interactor.dart';
Expand All @@ -33,6 +34,8 @@ import 'package:linagora_design_flutter/images_picker/asset_counter.dart';
import 'package:linagora_design_flutter/linagora_design_flutter.dart';
import 'package:matrix/matrix.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:file_selector/file_selector.dart';
import 'package:path_provider/path_provider.dart';
import 'package:wechat_camera_picker/wechat_camera_picker.dart';

class SettingsProfile extends StatefulWidget {
Expand Down Expand Up @@ -180,7 +183,43 @@ class SettingsProfileController extends State<SettingsProfile>
),
);
Logs().d(
'SettingsProfile::_getImageOnWeb(): AvatarWebNotifier - $result',
'SettingsProfile::_getImageOnWeb(): AvatarNotifier - $result',
);
}
}

void _getImageOnDesktop(
BuildContext context,
) async {
const XTypeGroup typeGroup = XTypeGroup(
label: 'images',
extensions: <String>['jpg', 'png'],
);
final String initialDirectory =
(await getApplicationDocumentsDirectory()).path;

final XFile? result = await openFile(
initialDirectory: initialDirectory,
acceptedTypeGroups: [typeGroup],
);

Logs().d(
'SettingsProfile::_getImageOnDesktop(): FilePickerResult - ${result?.path}',
);

if (result == null) {
return;
} else {
if (!isEditedProfileNotifier.value) {
isEditedProfileNotifier.toggle();
}
settingsProfileUIState.value = Right<Failure, Success>(
GetAvatarInBytesUIStateSuccess(
filePickerResult: FilePickerResult([await result.toPlatformFile()]),
),
);
Logs().d(
'SettingsProfile::_getImageOnDesktop(): AvatarNotifier - $result',
);
}
}
Expand All @@ -190,6 +229,10 @@ class SettingsProfileController extends State<SettingsProfile>
_getImageOnWeb(context);
return;
}
if (PlatformInfos.isDesktop) {
_getImageOnDesktop(context);
return;
}
final currentPermissionPhotos = await getCurrentMediaPermission();
if (currentPermissionPhotos != null) {
final imagePickerController = createImagePickerController();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class SettingsProfileViewMobile extends StatelessWidget {
);
}
if (success is GetAvatarInBytesUIStateSuccess &&
PlatformInfos.isWeb) {
PlatformInfos.isWebOrDesktop) {
if (success.filePickerResult == null ||
success.filePickerResult?.files.single.bytes ==
null) {
Expand Down Expand Up @@ -160,7 +160,7 @@ class SettingsProfileViewMobile extends StatelessWidget {
) {
return GestureDetector(
onTap: () {
if (PlatformInfos.isWeb) {
if (PlatformInfos.isWebOrDesktop) {
menuController.isOpen
? menuController.close()
: menuController.open();
Expand Down

0 comments on commit 5e783c0

Please sign in to comment.