forked from mirrors/linphone-iphone
Fix user avatar issue
This commit is contained in:
parent
f1fcb9129c
commit
a524d3c362
2 changed files with 53 additions and 49 deletions
|
|
@ -324,12 +324,15 @@ final class ContactsManager: ObservableObject {
|
||||||
if directory != nil {
|
if directory != nil {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
do {
|
do {
|
||||||
let urlName = URL(string: name + prefix)
|
if let urlName = URL(string: name + prefix) {
|
||||||
let imagePath = urlName != nil ? urlName!.absoluteString.replacingOccurrences(of: "%", with: "") : "ImageError"
|
let imagePath = urlName.absoluteString.replacingOccurrences(of: "%", with: "")
|
||||||
|
|
||||||
let decodedData: () = try data.write(to: directory!.appendingPathComponent(imagePath + ".png"))
|
let decodedData: () = try data.write(to: directory!.appendingPathComponent(imagePath + ".png"))
|
||||||
|
|
||||||
completion(decodedData, imagePath + ".png")
|
completion(decodedData, imagePath + ".png")
|
||||||
|
} else {
|
||||||
|
completion((), "")
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
print("Error: ", error)
|
print("Error: ", error)
|
||||||
completion((), "")
|
completion((), "")
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ struct ContentView: View {
|
||||||
@State private var isShowLoginFragment: Bool = false
|
@State private var isShowLoginFragment: Bool = false
|
||||||
|
|
||||||
private let avatarSize = 45.0
|
private let avatarSize = 45.0
|
||||||
|
@State private var imagePath: URL?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
let pub = NotificationCenter.default
|
let pub = NotificationCenter.default
|
||||||
|
|
@ -316,8 +317,7 @@ struct ContentView: View {
|
||||||
if searchIsActive == false {
|
if searchIsActive == false {
|
||||||
HStack {
|
HStack {
|
||||||
if (accountProfileViewModel.accountModelIndex ?? 0) < CoreContext.shared.accounts.count {
|
if (accountProfileViewModel.accountModelIndex ?? 0) < CoreContext.shared.accounts.count {
|
||||||
if sharedMainViewModel.defaultAvatar != nil {
|
AsyncImage(url: imagePath) { image in
|
||||||
AsyncImage(url: sharedMainViewModel.defaultAvatar) { image in
|
|
||||||
switch image {
|
switch image {
|
||||||
case .empty:
|
case .empty:
|
||||||
ProgressView()
|
ProgressView()
|
||||||
|
|
@ -342,30 +342,31 @@ struct ContentView: View {
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
openMenu()
|
openMenu()
|
||||||
}
|
}
|
||||||
|
.onAppear {
|
||||||
|
if let accountModelIndex = accountProfileViewModel.accountModelIndex,
|
||||||
|
accountModelIndex < CoreContext.shared.accounts.count {
|
||||||
|
let imagePathTmp = CoreContext.shared.accounts[accountModelIndex].getImagePath()
|
||||||
|
if !(imagePathTmp.lastPathComponent.isEmpty || imagePathTmp.lastPathComponent == "Error" || imagePathTmp.lastPathComponent == "ImageError.png") {
|
||||||
|
imagePath = imagePathTmp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
.onChange(of: CoreContext.shared.accounts[accountProfileViewModel.accountModelIndex ?? 0].usernaneAvatar) { _ in
|
.onChange(of: CoreContext.shared.accounts[accountProfileViewModel.accountModelIndex ?? 0].usernaneAvatar) { _ in
|
||||||
if let accountModelIndex = accountProfileViewModel.accountModelIndex,
|
if let accountModelIndex = accountProfileViewModel.accountModelIndex,
|
||||||
accountModelIndex < CoreContext.shared.accounts.count {
|
accountModelIndex < CoreContext.shared.accounts.count {
|
||||||
sharedMainViewModel.changeDefaultAvatar(defaultAvatarURL: CoreContext.shared.accounts[accountModelIndex].getImagePath())
|
let imagePathTmp = CoreContext.shared.accounts[accountModelIndex].getImagePath()
|
||||||
|
if !(imagePathTmp.lastPathComponent.isEmpty || imagePathTmp.lastPathComponent == "Error" || imagePathTmp.lastPathComponent == "ImageError.png") {
|
||||||
|
sharedMainViewModel.changeDefaultAvatar(defaultAvatarURL: imagePathTmp)
|
||||||
|
imagePath = imagePathTmp
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onReceive(imageChanged) { _ in
|
.onReceive(imageChanged) { _ in
|
||||||
if let accountModelIndex = accountProfileViewModel.accountModelIndex,
|
if let accountModelIndex = accountProfileViewModel.accountModelIndex,
|
||||||
accountModelIndex < CoreContext.shared.accounts.count {
|
accountModelIndex < CoreContext.shared.accounts.count {
|
||||||
sharedMainViewModel.changeDefaultAvatar(defaultAvatarURL: CoreContext.shared.accounts[accountModelIndex].getImagePath())
|
let imagePathTmp = CoreContext.shared.accounts[accountModelIndex].getImagePath()
|
||||||
}
|
sharedMainViewModel.changeDefaultAvatar(defaultAvatarURL: imagePathTmp)
|
||||||
}
|
imagePath = imagePathTmp
|
||||||
} else {
|
|
||||||
Image(uiImage: contactsManager.textToImage(
|
|
||||||
firstName: CoreContext.shared.accounts[accountProfileViewModel.accountModelIndex ?? 0].avatarModel?.name ?? "",
|
|
||||||
lastName: ""))
|
|
||||||
.resizable()
|
|
||||||
.frame(width: avatarSize, height: avatarSize)
|
|
||||||
.clipShape(Circle())
|
|
||||||
.onAppear {
|
|
||||||
if let accountModelIndex = accountProfileViewModel.accountModelIndex,
|
|
||||||
accountModelIndex < CoreContext.shared.accounts.count {
|
|
||||||
sharedMainViewModel.changeDefaultAvatar(defaultAvatarURL: CoreContext.shared.accounts[accountModelIndex].getImagePath())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue