Fix displayname in AccountProfileFragment

This commit is contained in:
Benoit Martins 2024-12-17 11:45:23 +01:00
parent e4b90b58e8
commit 5c71c34801
7 changed files with 294 additions and 183 deletions

View file

@ -321,7 +321,7 @@ struct ContentView: View {
.clipShape(Circle())
case .failure:
Image(uiImage: contactsManager.textToImage(
firstName: accountProfileViewModel.avatarModel?.name ?? "",
firstName: CoreContext.shared.accounts[accountProfileViewModel.accountModelIndex ?? 0].avatarModel?.name ?? "",
lastName: ""))
.resizable()
.frame(width: avatarSize, height: avatarSize)
@ -931,7 +931,7 @@ struct ContentView: View {
SideMenu(
accountProfileViewModel: accountProfileViewModel,
width: geometry.size.width / 5 * 4,
isOpen: self.sideMenuIsOpen,
isOpen: $sideMenuIsOpen,
menuClose: self.openMenu,
safeAreaInsets: geometry.safeAreaInsets,
isShowLoginFragment: $isShowLoginFragment,

View file

@ -47,6 +47,7 @@ struct ConversationInfoFragment: View {
@State private var participantListIsOpen = true
var body: some View {
let accountModel = CoreContext.shared.accounts[accountProfileViewModel.accountModelIndex ?? 0]
NavigationView {
GeometryReader { geometry in
if conversationViewModel.displayedConversation != nil {
@ -305,7 +306,7 @@ struct ConversationInfoFragment: View {
.clipShape(Circle())
case .failure:
Image(uiImage: contactsManager.textToImage(
firstName: accountProfileViewModel.avatarModel?.name ?? "",
firstName: accountModel.avatarModel?.name ?? "",
lastName: ""))
.resizable()
.frame(width: avatarSize, height: avatarSize)
@ -324,7 +325,7 @@ struct ConversationInfoFragment: View {
.frame(maxWidth: .infinity, alignment: .leading)
.lineLimit(1)
} else {
Text(accountProfileViewModel.displayName.isEmpty ? participantConversationModel.name : accountProfileViewModel.displayName)
Text(accountModel.displayName.isEmpty ? participantConversationModel.name : accountModel.displayName)
.foregroundStyle(Color.grayMain2c700)
.default_text_style(styleSize: 14)
.frame(maxWidth: .infinity, alignment: .leading)

View file

@ -26,7 +26,7 @@ struct SideMenu: View {
@ObservedObject var accountProfileViewModel: AccountProfileViewModel
let width: CGFloat
let isOpen: Bool
@Binding var isOpen: Bool
let menuClose: () -> Void
let safeAreaInsets: EdgeInsets
@Binding var isShowLoginFragment: Bool
@ -69,7 +69,7 @@ struct SideMenu: View {
List {
ForEach(0..<CoreContext.shared.accounts.count, id: \.self) { index in
SideMenuAccountRow( model: CoreContext.shared.accounts[index], accountProfileViewModel: accountProfileViewModel, isShowAccountProfileFragment: $isShowAccountProfileFragment)
SideMenuAccountRow( model: CoreContext.shared.accounts[index], accountProfileViewModel: accountProfileViewModel, isOpen: $isOpen, isShowAccountProfileFragment: $isShowAccountProfileFragment)
.background()
.listRowInsets(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16))
.listRowSeparator(.hidden)
@ -175,7 +175,7 @@ struct SideMenu: View {
SideMenu(
accountProfileViewModel: AccountProfileViewModel(),
width: geometry.size.width / 5 * 4,
isOpen: true,
isOpen: .constant(true),
menuClose: {},
safeAreaInsets: geometry.safeAreaInsets,
isShowLoginFragment: $triggerNavigateToLogin,

View file

@ -28,6 +28,7 @@ struct SideMenuAccountRow: View {
@ObservedObject var accountProfileViewModel: AccountProfileViewModel
@State private var navigateToOption = false
@Binding var isOpen: Bool
@Binding var isShowAccountProfileFragment: Bool
private let avatarSize = 45.0
@ -47,7 +48,7 @@ struct SideMenuAccountRow: View {
.clipShape(Circle())
case .failure:
Image(uiImage: contactsManager.textToImage(
firstName: accountProfileViewModel.avatarModel?.name ?? "",
firstName: model.avatarModel?.name ?? "",
lastName: ""))
.resizable()
.frame(width: avatarSize, height: avatarSize)
@ -97,6 +98,8 @@ struct SideMenuAccountRow: View {
Menu {
Button {
withAnimation {
isOpen = false
isShowAccountProfileFragment = true
}
} label: {

View file

@ -20,6 +20,7 @@
import SwiftUI
import UniformTypeIdentifiers
// swiftlint:disable type_body_length
struct AccountProfileFragment: View {
@ObservedObject var contactsManager = ContactsManager.shared
@ -35,6 +36,7 @@ struct AccountProfileFragment: View {
@State private var selectedImage: UIImage?
@State private var removedImage = false
@State private var isShowPopup = false
@State private var flag = true
@FocusState var isDisplayNameFocused: Bool
@ -82,18 +84,19 @@ struct AccountProfileFragment: View {
ScrollView {
VStack(spacing: 0) {
VStack(spacing: 0) {
if #unavailable(iOS 16.0) {
Rectangle()
.foregroundColor(Color.gray100)
.frame(height: 7)
}
if accountProfileViewModel.avatarModel != nil {
if accountProfileViewModel.accountModelIndex != nil {
let accountModel = CoreContext.shared.accounts[accountProfileViewModel.accountModelIndex!]
VStack(spacing: 0) {
if #unavailable(iOS 16.0) {
Rectangle()
.foregroundColor(Color.gray100)
.frame(height: 7)
}
VStack(spacing: 0) {
if accountProfileViewModel.avatarModel != nil
&& accountProfileViewModel.photoAvatarModel != nil
&& !accountProfileViewModel.photoAvatarModel!.isEmpty
if accountModel.avatarModel != nil
&& accountModel.photoAvatarModel != nil
&& !accountModel.photoAvatarModel!.isEmpty
&& selectedImage == nil && !removedImage {
AsyncImage(url: accountProfileViewModel.getImagePath()) { image in
@ -109,7 +112,7 @@ struct AccountProfileFragment: View {
.clipShape(Circle())
case .failure:
Image(uiImage: contactsManager.textToImage(
firstName: accountProfileViewModel.avatarModel?.name ?? "",
firstName: accountModel.avatarModel?.name ?? "",
lastName: ""))
.resizable()
.frame(width: avatarSize, height: avatarSize)
@ -120,7 +123,7 @@ struct AccountProfileFragment: View {
}
} else if selectedImage == nil {
Image(uiImage: contactsManager.textToImage(
firstName: accountProfileViewModel.avatarModel?.name ?? "",
firstName: accountModel.avatarModel?.name ?? "",
lastName: ""))
.resizable()
.frame(width: avatarSize, height: avatarSize)
@ -133,10 +136,10 @@ struct AccountProfileFragment: View {
.clipShape(Circle())
}
if accountProfileViewModel.avatarModel != nil
&& accountProfileViewModel.photoAvatarModel != nil
&& !accountProfileViewModel.photoAvatarModel!.isEmpty
&& (accountProfileViewModel.photoAvatarModel!.suffix(11) != "default.png" || selectedImage != nil)
if accountModel.avatarModel != nil
&& accountModel.photoAvatarModel != nil
&& !accountModel.photoAvatarModel!.isEmpty
&& (accountModel.photoAvatarModel!.suffix(11) != "default.png" || selectedImage != nil)
&& !removedImage {
HStack {
Spacer()
@ -236,140 +239,226 @@ struct AccountProfileFragment: View {
.padding(.top, 10)
.padding(.bottom, 2)
.background(Color.gray100)
}
HStack(alignment: .center) {
Text("manage_account_details_title")
.default_text_style_800(styleSize: 18)
.frame(maxWidth: .infinity, alignment: .leading)
Spacer()
Image(detailIsOpen ? "caret-up" : "caret-down")
.renderingMode(.template)
.resizable()
.foregroundStyle(Color.grayMain2c600)
.frame(width: 25, height: 25, alignment: .leading)
.padding(.all, 10)
}
.padding(.top, 30)
.padding(.bottom, 10)
.padding(.horizontal, 20)
.background(Color.gray100)
.onTapGesture {
withAnimation {
detailIsOpen.toggle()
HStack(alignment: .center) {
Text("manage_account_details_title")
.default_text_style_800(styleSize: 18)
.frame(maxWidth: .infinity, alignment: .leading)
Spacer()
Image(detailIsOpen ? "caret-up" : "caret-down")
.renderingMode(.template)
.resizable()
.foregroundStyle(Color.grayMain2c600)
.frame(width: 25, height: 25, alignment: .leading)
.padding(.all, 10)
}
}
if detailIsOpen {
VStack(spacing: 0) {
VStack(spacing: 30) {
HStack {
Text(String(localized: "sip_address") + ":")
.default_text_style_600(styleSize: 14)
Text(accountProfileViewModel.avatarModel!.address)
.foregroundStyle(Color.grayMain2c700)
.default_text_style(styleSize: 14)
.frame(maxWidth: .infinity, alignment: .leading)
.lineLimit(1)
Button(action: {
UIPasteboard.general.setValue(
accountProfileViewModel.avatarModel!.address,
forPasteboardType: UTType.plainText.identifier
)
ToastViewModel.shared.toastMessage = "Success_address_copied_into_clipboard"
ToastViewModel.shared.displayToast.toggle()
}, label: {
Image("copy")
.resizable()
.frame(width: 20, height: 20)
})
}
VStack(alignment: .leading) {
Text("sip_address_display_name")
.default_text_style_700(styleSize: 15)
.padding(.bottom, -5)
TextField(accountProfileViewModel.displayName, text: $accountProfileViewModel.displayName)
.default_text_style(styleSize: 15)
.frame(height: 25)
.padding(.horizontal, 20)
.padding(.vertical, 15)
.background(.white)
.cornerRadius(60)
.overlay(
RoundedRectangle(cornerRadius: 60)
.inset(by: 0.5)
.stroke(isDisplayNameFocused ? Color.orangeMain500 : Color.gray200, lineWidth: 1)
)
.focused($isDisplayNameFocused)
}
VStack(alignment: .leading) {
.padding(.top, 30)
.padding(.bottom, 10)
.padding(.horizontal, 20)
.background(Color.gray100)
.onTapGesture {
withAnimation {
detailIsOpen.toggle()
}
}
if detailIsOpen {
VStack(spacing: 0) {
VStack(spacing: 30) {
HStack {
Text("manage_account_international_prefix")
Text(String(localized: "sip_address") + ":")
.default_text_style_700(styleSize: 15)
.padding(.bottom, -5)
Text(accountModel.avatarModel!.address)
.foregroundStyle(Color.grayMain2c700)
.default_text_style(styleSize: 15)
.frame(maxWidth: .infinity, alignment: .leading)
.lineLimit(1)
Button(action: {
isShowPopup = true
UIPasteboard.general.setValue(
accountModel.avatarModel!.address,
forPasteboardType: UTType.plainText.identifier
)
ToastViewModel.shared.toastMessage = "Success_address_copied_into_clipboard"
ToastViewModel.shared.displayToast.toggle()
}, label: {
Image("question")
.renderingMode(.template)
Image("copy")
.resizable()
.foregroundStyle(Color.grayMain2c600)
.frame(width: 20, height: 20)
})
.padding(.bottom, -5)
}
Menu {
Picker("", selection: $accountProfileViewModel.dialPlanValueSelected) {
ForEach(registerViewModel.dialPlansLabelList, id: \.self) { dialPlan in
Text(dialPlan).tag(dialPlan)
}
}
.onChange(of: accountProfileViewModel.dialPlanValueSelected) { newValue in
accountProfileViewModel.updateDialPlan(newDialPlan: newValue)
}
} label: {
VStack(alignment: .leading) {
Text("sip_address_display_name")
.default_text_style_700(styleSize: 15)
.padding(.bottom, -5)
TextField(accountModel.displayNameAvatar, text: Binding(
get: { accountModel.displayNameAvatar },
set: { newValue in
accountModel.displayNameAvatar = newValue
}
))
.default_text_style(styleSize: 15)
.frame(height: 25)
.padding(.horizontal, 20)
.padding(.vertical, 15)
.background(.white)
.cornerRadius(60)
.overlay(
RoundedRectangle(cornerRadius: 60)
.inset(by: 0.5)
.stroke(isDisplayNameFocused ? Color.orangeMain500 : Color.gray200, lineWidth: 1)
)
.focused($isDisplayNameFocused)
}
VStack(alignment: .leading) {
HStack {
Text(accountProfileViewModel.dialPlanValueSelected)
.default_text_style(styleSize: 15)
.frame(maxWidth: .infinity, alignment: .leading)
Text("manage_account_international_prefix")
.default_text_style_700(styleSize: 15)
.padding(.bottom, -5)
.lineLimit(1)
Image("caret-down")
.resizable()
.frame(width: 20, height: 20)
Button(action: {
isShowPopup = true
}, label: {
Image("question")
.renderingMode(.template)
.resizable()
.foregroundStyle(Color.grayMain2c600)
.frame(width: 20, height: 20)
})
.padding(.bottom, -5)
}
Menu {
Picker("", selection: $accountProfileViewModel.dialPlanValueSelected) {
ForEach(registerViewModel.dialPlansLabelList, id: \.self) { dialPlan in
Text(dialPlan).tag(dialPlan)
}
}
.onChange(of: accountProfileViewModel.dialPlanValueSelected) { newValue in
accountProfileViewModel.updateDialPlan(newDialPlan: newValue)
}
} label: {
HStack {
Text(accountProfileViewModel.dialPlanValueSelected)
.default_text_style(styleSize: 15)
.frame(maxWidth: .infinity, alignment: .leading)
Image("caret-down")
.resizable()
.frame(width: 20, height: 20)
}
.frame(height: 25)
.padding(.horizontal, 20)
.padding(.vertical, 15)
.background(.white)
.cornerRadius(60)
.overlay(
RoundedRectangle(cornerRadius: 60)
.inset(by: 0.5)
.stroke(Color.gray200, lineWidth: 1)
)
}
.frame(height: 25)
.padding(.horizontal, 20)
.padding(.vertical, 15)
.background(.white)
.cornerRadius(60)
.overlay(
RoundedRectangle(cornerRadius: 60)
.inset(by: 0.5)
.stroke(Color.gray200, lineWidth: 1)
)
}
}
.padding(.vertical, 30)
.padding(.horizontal, 20)
}
.background(.white)
.cornerRadius(15)
.padding(.horizontal)
.zIndex(-1)
.transition(.move(edge: .top))
}
VStack(spacing: 0) {
VStack(spacing: 15) {
HStack(spacing: 20) {
Toggle("", isOn: $flag)
.labelsHidden()
Text("drawer_menu_account_connection_status_connected")
.default_text_style_700(styleSize: 15)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.bottom, -5)
.lineLimit(1)
}
Text("manage_account_international_prefix")
.default_text_style_700(styleSize: 15)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.bottom, -5)
.lineLimit(1)
}
.padding(.vertical, 30)
.padding(.horizontal, 20)
}
.background(.white)
.cornerRadius(15)
.padding(.horizontal)
.zIndex(-1)
.transition(.move(edge: .top))
.padding(.all)
HStack(alignment: .center) {
Text("manage_account_details_title")
.default_text_style_800(styleSize: 18)
.frame(maxWidth: .infinity, alignment: .leading)
Spacer()
Image(detailIsOpen ? "caret-up" : "caret-down")
.renderingMode(.template)
.resizable()
.foregroundStyle(Color.grayMain2c600)
.frame(width: 25, height: 25, alignment: .leading)
.padding(.all, 10)
}
.padding(.top, 10)
.padding(.bottom, 10)
.padding(.horizontal, 20)
.background(Color.gray100)
.onTapGesture {
withAnimation {
detailIsOpen.toggle()
}
}
if detailIsOpen {
VStack(spacing: 0) {
VStack(spacing: 30) {
Text("manage_account_dialog_international_prefix_help_message")
.default_text_style_700(styleSize: 15)
.frame(maxWidth: .infinity, alignment: .leading)
}
.padding(.vertical, 30)
.padding(.horizontal, 20)
}
.background(.white)
.cornerRadius(15)
.padding(.horizontal)
.zIndex(-1)
.transition(.move(edge: .top))
}
VStack(spacing: 0) {
VStack(spacing: 15) {
Text("manage_account_dialog_international_prefix_help_message")
.default_text_style_700(styleSize: 15)
.frame(maxWidth: .infinity, alignment: .leading)
}
.padding(.vertical, 30)
.padding(.horizontal, 20)
}
.background(.white)
.cornerRadius(15)
.padding(.all)
}
.frame(maxWidth: sharedMainViewModel.maxWidth)
}
.frame(maxWidth: sharedMainViewModel.maxWidth)
}
.frame(maxWidth: .infinity)
}
@ -397,11 +486,13 @@ struct AccountProfileFragment: View {
}
func saveImage() {
let accountModel = CoreContext.shared.accounts[accountProfileViewModel.accountModelIndex ?? 0]
accountProfileViewModel.saveImage(
image: selectedImage
?? ContactsManager.shared.textToImage(
firstName: accountProfileViewModel.avatarModel!.name, lastName: ""),
name: accountProfileViewModel.avatarModel!.name,
firstName: accountModel.avatarModel!.name, lastName: ""),
name: accountModel.avatarModel!.name,
prefix: ((selectedImage == nil) ? "-default" : ""))
}
}
// swiftlint:enable type_body_length

View file

@ -21,64 +21,64 @@ import linphonesw
class AccountProfileViewModel: ObservableObject {
let photoAvatarModelKey = "photo_avatar_model"
@Published var avatarModel: ContactAvatarModel?
@Published var photoAvatarModel: String?
@Published var displayName: String = ""
@Published var dialPlanValueSelected: String = "🇫🇷 France | +33"
var dialPlanSelected: DialPlan?
var dialPlansList: [DialPlan] = []
var accountModelIndex: Int? = 0
init() {}
func saveChangesWhenLeaving() {
CoreContext.shared.doOnCoreQueue { core in
let newParams = core.defaultAccount!.params?.clone()
if (self.displayName != newParams?.identityAddress?.displayName)
&& (newParams?.identityAddress?.displayName != nil || !self.displayName.isEmpty) {
if let newIdentityAddress = newParams?.identityAddress?.clone() {
try? newIdentityAddress.setDisplayname(newValue: self.displayName)
try? newParams?.setIdentityaddress(newValue: newIdentityAddress)
}
if self.getImagePath().lastPathComponent.contains("-default") || self.getImagePath().lastPathComponent == "Documents" {
DispatchQueue.main.async {
self.saveImage(
image: ContactsManager.shared.textToImage(
firstName: self.displayName.isEmpty ? core.defaultAccount!.displayName() : self.displayName, lastName: ""),
name: self.displayName.isEmpty ? core.defaultAccount!.displayName() : self.displayName,
prefix: "-default")
if accountModelIndex != nil {
CoreContext.shared.doOnCoreQueue { _ in
let displayNameAccountModel = CoreContext.shared.accounts[self.accountModelIndex!].displayNameAvatar
let newParams = CoreContext.shared.accounts[self.accountModelIndex!].account.params?.clone()
if (displayNameAccountModel != newParams?.identityAddress?.displayName)
&& (newParams?.identityAddress?.displayName != nil || !displayNameAccountModel.isEmpty) {
if let newIdentityAddress = newParams?.identityAddress?.clone() {
try? newIdentityAddress.setDisplayname(newValue: displayNameAccountModel)
try? newParams?.setIdentityaddress(newValue: newIdentityAddress)
}
if self.getImagePath().lastPathComponent.contains("-default") || self.getImagePath().lastPathComponent == "Documents" {
DispatchQueue.main.async {
self.saveImage(
image: ContactsManager.shared.textToImage(
firstName: displayNameAccountModel.isEmpty ? CoreContext.shared.accounts[self.accountModelIndex!].account.displayName() : displayNameAccountModel, lastName: ""),
name: displayNameAccountModel.isEmpty ? CoreContext.shared.accounts[self.accountModelIndex!].account.displayName() : displayNameAccountModel,
prefix: "-default")
}
}
}
if self.dialPlanSelected != nil
&& (self.dialPlanSelected!.countryCallingCode != newParams?.internationalPrefix || self.dialPlanSelected!.isoCountryCode != newParams?.internationalPrefixIsoCountryCode) {
newParams?.internationalPrefix = self.dialPlanSelected?.countryCallingCode
newParams?.internationalPrefixIsoCountryCode = self.dialPlanSelected?.isoCountryCode
newParams?.useInternationalPrefixForCallsAndChats = true
}
CoreContext.shared.accounts[self.accountModelIndex!].account.params = newParams
}
if self.dialPlanSelected != nil
&& (self.dialPlanSelected!.countryCallingCode != newParams?.internationalPrefix || self.dialPlanSelected!.isoCountryCode != newParams?.internationalPrefixIsoCountryCode) {
newParams?.internationalPrefix = self.dialPlanSelected?.countryCallingCode
newParams?.internationalPrefixIsoCountryCode = self.dialPlanSelected?.isoCountryCode
newParams?.useInternationalPrefixForCallsAndChats = true
}
core.defaultAccount!.params = newParams
}
}
func setAvatarModel() {
CoreContext.shared.doOnCoreQueue { core in
if core.defaultAccount != nil {
let displayNameTmp = core.defaultAccount!.params?.identityAddress?.displayName ?? ""
let contactAddressTmp = core.defaultAccount!.params?.identityAddress?.asStringUriOnly() ?? ""
if accountModelIndex != nil {
CoreContext.shared.doOnCoreQueue { _ in
let photoAvatarAccountModel = CoreContext.shared.accounts[self.accountModelIndex!].photoAvatarModel
let displayNameTmp = CoreContext.shared.accounts[self.accountModelIndex!].account.params?.identityAddress?.displayName ?? ""
let contactAddressTmp = CoreContext.shared.accounts[self.accountModelIndex!].account.params?.identityAddress?.asStringUriOnly() ?? ""
var photoAvatarModelTmp = ""
let prefix = core.defaultAccount!.params?.internationalPrefix ?? ""
let isoCountryCode = core.defaultAccount!.params?.internationalPrefixIsoCountryCode ?? ""
let prefix = CoreContext.shared.accounts[self.accountModelIndex!].account.params?.internationalPrefix ?? ""
let isoCountryCode = CoreContext.shared.accounts[self.accountModelIndex!].account.params?.internationalPrefixIsoCountryCode ?? ""
var dialPlanValueSelectedTmp = ""
if !prefix.isEmpty || !isoCountryCode.isEmpty {
Log.info(
"$TAG Account \(core.defaultAccount!.params?.identityAddress?.asStringUriOnly() ?? "") prefix is \(prefix) \(isoCountryCode)"
"$TAG Account \(CoreContext.shared.accounts[self.accountModelIndex!].account.params?.identityAddress?.asStringUriOnly() ?? "") prefix is \(prefix) \(isoCountryCode)"
)
self.dialPlansList = Factory.Instance.dialPlans
@ -90,16 +90,25 @@ class AccountProfileViewModel: ObservableObject {
let preferences = UserDefaults.standard
if preferences.object(forKey: self.photoAvatarModelKey) == nil {
preferences.set(self.photoAvatarModel ?? "", forKey: self.photoAvatarModelKey)
let accountDisplayName = CoreContext.shared.accounts[self.accountModelIndex!].account.displayName()
let photoAvatarModelKey = "photo_avatar_model" + CoreContext.shared.accounts[self.accountModelIndex!].address
if preferences.object(forKey: photoAvatarModelKey) == nil {
preferences.set(photoAvatarAccountModel ?? "", forKey: photoAvatarModelKey)
} else {
photoAvatarModelTmp = preferences.string(forKey: self.photoAvatarModelKey)!
photoAvatarModelTmp = preferences.string(forKey: photoAvatarModelKey)!
}
DispatchQueue.main.async {
self.avatarModel = ContactAvatarModel(friend: nil, name: displayNameTmp.isEmpty ? core.defaultAccount!.displayName() : displayNameTmp, address: contactAddressTmp, withPresence: false)
self.photoAvatarModel = photoAvatarModelTmp
self.displayName = displayNameTmp
CoreContext.shared.accounts[self.accountModelIndex!].avatarModel = ContactAvatarModel(
friend: nil,
name: displayNameTmp.isEmpty ? accountDisplayName : displayNameTmp,
address: contactAddressTmp,
withPresence: false
)
CoreContext.shared.accounts[self.accountModelIndex!].photoAvatarModel = photoAvatarModelTmp
CoreContext.shared.accounts[self.accountModelIndex!].displayNameAvatar = displayNameTmp
self.dialPlanValueSelected = dialPlanValueSelectedTmp
}
}
@ -118,14 +127,18 @@ class AccountProfileViewModel: ObservableObject {
return
}
let photoAvatarModelKey = "photo_avatar_model" + CoreContext.shared.accounts[self.accountModelIndex ?? 0].address
ContactsManager.shared.awaitDataWrite(data: data, name: name, prefix: prefix) { _, result in
UserDefaults.standard.set(result, forKey: self.photoAvatarModelKey)
self.photoAvatarModel = result
UserDefaults.standard.set(result, forKey: photoAvatarModelKey)
CoreContext.shared.accounts[self.accountModelIndex ?? 0].photoAvatarModel = result
}
}
func getImagePath() -> URL {
let imagePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent(self.photoAvatarModel ?? "Error")
let imagePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent(
CoreContext.shared.accounts[self.accountModelIndex ?? 0].photoAvatarModel ?? "Error"
)
return imagePath
}

View file

@ -30,6 +30,9 @@ class AccountModel: ObservableObject {
@Published var isDefaultAccount: Bool = false
@Published var displayName: String = ""
@Published var address: String = ""
@Published var avatarModel: ContactAvatarModel?
@Published var photoAvatarModel: String?
@Published var displayNameAvatar: String = ""
private var accountDelegate: AccountDelegate?
private var coreDelegate: CoreDelegate?