From 9421135fac9af45a22e4dc806828f7c15ca676d9 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Thu, 5 Dec 2024 17:56:40 +0100 Subject: [PATCH] Change account photo --- Linphone/UI/Call/CallView.swift | 3 + Linphone/UI/Main/ContentView.swift | 35 +++++++++-- .../Fragments/ConversationFragment.swift | 2 + .../Fragments/ConversationInfoFragment.swift | 30 +++++++++- .../ViewModel/ConversationViewModel.swift | 22 +++---- Linphone/UI/Main/Fragments/SideMenu.swift | 5 +- .../Main/Fragments/SideMenuAccountRow.swift | 33 +++++++++-- .../Fragments/AccountProfileFragment.swift | 59 +++++++++++++++---- .../ViewModel/AccountProfileViewModel.swift | 30 ++++++++++ 9 files changed, 182 insertions(+), 37 deletions(-) diff --git a/Linphone/UI/Call/CallView.swift b/Linphone/UI/Call/CallView.swift index 365b4b12e..2674f9f68 100644 --- a/Linphone/UI/Call/CallView.swift +++ b/Linphone/UI/Call/CallView.swift @@ -40,6 +40,7 @@ struct CallView: View { @ObservedObject var contactViewModel: ContactViewModel @ObservedObject var editContactViewModel: EditContactViewModel @ObservedObject var meetingViewModel: MeetingViewModel + @ObservedObject var accountProfileViewModel: AccountProfileViewModel @State private var addParticipantsViewModel: AddParticipantsViewModel? @@ -211,6 +212,7 @@ struct CallView: View { contactViewModel: contactViewModel, editContactViewModel: editContactViewModel, meetingViewModel: meetingViewModel, + accountProfileViewModel: accountProfileViewModel, isShowConversationFragment: $isShowConversationFragment, isShowStartCallGroupPopup: $isShowStartCallGroupPopup, isShowEditContactFragment: $isShowEditContactFragment, @@ -2842,6 +2844,7 @@ struct PressedButtonStyle: ButtonStyle { contactViewModel: ContactViewModel(), editContactViewModel: EditContactViewModel(), meetingViewModel: MeetingViewModel(), + accountProfileViewModel: AccountProfileViewModel(), fullscreenVideo: .constant(false), isShowStartCallFragment: .constant(false), isShowConversationFragment: .constant(false), diff --git a/Linphone/UI/Main/ContentView.swift b/Linphone/UI/Main/ContentView.swift index 31c7e27d9..ab0f56d36 100644 --- a/Linphone/UI/Main/ContentView.swift +++ b/Linphone/UI/Main/ContentView.swift @@ -78,6 +78,8 @@ struct ContentView: View { @State var isShowScheduleMeetingFragment = false @State private var isShowLoginFragment: Bool = false + private let avatarSize = 45.0 + var body: some View { let pub = NotificationCenter.default .publisher(for: NSNotification.Name("ContactLoaded")) @@ -307,13 +309,31 @@ struct ContentView: View { VStack(spacing: 0) { if searchIsActive == false { HStack { - Image("profile-image-example") - .resizable() - .frame(width: 45, height: 45) - .clipShape(Circle()) - .onTapGesture { - openMenu() + AsyncImage(url: accountProfileViewModel.getImagePath()) { image in + switch image { + case .empty: + ProgressView() + .frame(width: avatarSize, height: avatarSize) + case .success(let image): + image + .resizable() + .aspectRatio(contentMode: .fill) + .frame(width: avatarSize, height: avatarSize) + .clipShape(Circle()) + case .failure: + Image(uiImage: contactsManager.textToImage( + firstName: accountProfileViewModel.avatarModel?.name ?? "", + lastName: "")) + .resizable() + .frame(width: avatarSize, height: avatarSize) + .clipShape(Circle()) + @unknown default: + EmptyView() } + } + .onTapGesture { + openMenu() + } Text(String(localized: index == 0 ? "bottom_navigation_contacts_label" : (index == 1 ? "bottom_navigation_calls_label" : (index == 2 ? "bottom_navigation_conversations_label" : "bottom_navigation_meetings_label")))) .default_text_style_white_800(styleSize: 20) @@ -867,6 +887,7 @@ struct ContentView: View { contactViewModel: contactViewModel, editContactViewModel: editContactViewModel, meetingViewModel: meetingViewModel, + accountProfileViewModel: accountProfileViewModel, isShowConversationFragment: $isShowConversationFragment, isShowStartCallGroupPopup: $isShowStartCallGroupPopup, isShowEditContactFragment: $isShowEditContactFragment, @@ -909,6 +930,7 @@ struct ContentView: View { } SideMenu( + accountProfileViewModel: accountProfileViewModel, width: geometry.size.width / 5 * 4, isOpen: self.sideMenuIsOpen, menuClose: self.openMenu, @@ -1253,6 +1275,7 @@ struct ContentView: View { contactViewModel: contactViewModel, editContactViewModel: editContactViewModel, meetingViewModel: meetingViewModel, + accountProfileViewModel: accountProfileViewModel, fullscreenVideo: $fullscreenVideo, isShowStartCallFragment: $isShowStartCallFragment, isShowConversationFragment: $isShowConversationFragment, diff --git a/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift b/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift index d1df79eb0..ad56cb146 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift @@ -36,6 +36,7 @@ struct ConversationFragment: View { @ObservedObject var contactViewModel: ContactViewModel @ObservedObject var editContactViewModel: EditContactViewModel @ObservedObject var meetingViewModel: MeetingViewModel + @ObservedObject var accountProfileViewModel: AccountProfileViewModel @State var isMenuOpen = false @State private var isMuted: Bool = false @@ -995,6 +996,7 @@ struct ConversationFragment: View { contactViewModel: contactViewModel, editContactViewModel: editContactViewModel, meetingViewModel: meetingViewModel, + accountProfileViewModel: accountProfileViewModel, isMuted: $isMuted, isShowEphemeralFragment: $isShowEphemeralFragment, isShowStartCallGroupPopup: $isShowStartCallGroupPopup, diff --git a/Linphone/UI/Main/Conversations/Fragments/ConversationInfoFragment.swift b/Linphone/UI/Main/Conversations/Fragments/ConversationInfoFragment.swift index 4e1127cfb..e33830faf 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ConversationInfoFragment.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ConversationInfoFragment.swift @@ -31,6 +31,7 @@ struct ConversationInfoFragment: View { @ObservedObject var contactViewModel: ContactViewModel @ObservedObject var editContactViewModel: EditContactViewModel @ObservedObject var meetingViewModel: MeetingViewModel + @ObservedObject var accountProfileViewModel: AccountProfileViewModel @State var addParticipantsViewModel = AddParticipantsViewModel() @@ -287,7 +288,33 @@ struct ConversationInfoFragment: View { VStack(spacing: 0) { ForEach(conversationViewModel.participantConversationModel) { participantConversationModel in HStack { - Avatar(contactAvatarModel: participantConversationModel, avatarSize: 50) + if conversationViewModel.myParticipantConversationModel != nil && conversationViewModel.myParticipantConversationModel!.address != participantConversationModel.address { + Avatar(contactAvatarModel: participantConversationModel, avatarSize: 50) + } else { + let avatarSize = 50.0 + AsyncImage(url: accountProfileViewModel.getImagePath()) { image in + switch image { + case .empty: + ProgressView() + .frame(width: avatarSize, height: avatarSize) + case .success(let image): + image + .resizable() + .aspectRatio(contentMode: .fill) + .frame(width: avatarSize, height: avatarSize) + .clipShape(Circle()) + case .failure: + Image(uiImage: contactsManager.textToImage( + firstName: accountProfileViewModel.avatarModel?.name ?? "", + lastName: "")) + .resizable() + .frame(width: avatarSize, height: avatarSize) + .clipShape(Circle()) + @unknown default: + EmptyView() + } + } + } VStack { Text(participantConversationModel.name) @@ -667,6 +694,7 @@ struct ConversationInfoFragment: View { contactViewModel: ContactViewModel(), editContactViewModel: EditContactViewModel(), meetingViewModel: MeetingViewModel(), + accountProfileViewModel: AccountProfileViewModel(), addParticipantsViewModel: AddParticipantsViewModel(), isMuted: .constant(false), isShowEphemeralFragment: .constant(false), diff --git a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift index c863b5748..4bccf1afe 100644 --- a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift +++ b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift @@ -469,17 +469,19 @@ class ConversationViewModel: ObservableObject { } } - if let currentUser = self.displayedConversation?.chatRoom.me, - let address = currentUser.address { - ContactAvatarModel.getAvatarModelFromAddress(address: address) { avatarResult in - let avatarModelTmp = avatarResult - DispatchQueue.main.async { - if currentUser.isAdmin { - self.isUserAdmin = true - self.participantConversationModelAdmin.append(avatarModelTmp) + if !self.displayedConversation!.isReadOnly { + if let currentUser = self.displayedConversation?.chatRoom.me, + let address = currentUser.address { + ContactAvatarModel.getAvatarModelFromAddress(address: address) { avatarResult in + let avatarModelTmp = avatarResult + DispatchQueue.main.async { + if currentUser.isAdmin { + self.isUserAdmin = true + self.participantConversationModelAdmin.append(avatarModelTmp) + } + self.participantConversationModel.append(avatarModelTmp) + self.myParticipantConversationModel = avatarModelTmp } - self.participantConversationModel.append(avatarModelTmp) - self.myParticipantConversationModel = avatarModelTmp } } } diff --git a/Linphone/UI/Main/Fragments/SideMenu.swift b/Linphone/UI/Main/Fragments/SideMenu.swift index 97b41835e..537c17d6c 100644 --- a/Linphone/UI/Main/Fragments/SideMenu.swift +++ b/Linphone/UI/Main/Fragments/SideMenu.swift @@ -23,6 +23,8 @@ import UniformTypeIdentifiers struct SideMenu: View { + @ObservedObject var accountProfileViewModel: AccountProfileViewModel + let width: CGFloat let isOpen: Bool let menuClose: () -> Void @@ -67,7 +69,7 @@ struct SideMenu: View { List { ForEach(0.. URL { + let imagePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent(self.photoAvatarModel ?? "Error") + + return imagePath + } }