mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
Use saveImage on core queue
This commit is contained in:
parent
c5cef9119a
commit
af981603ab
4 changed files with 63 additions and 100 deletions
|
|
@ -154,25 +154,22 @@ final class ContactsManager: ObservableObject {
|
|||
|
||||
let imageThumbnail = UIImage(data: contact.thumbnailImageData ?? Data())
|
||||
if let image = imageThumbnail {
|
||||
DispatchQueue.main.async {
|
||||
self.saveImage(
|
||||
image: image,
|
||||
name: contact.givenName + contact.familyName,
|
||||
prefix: "",
|
||||
contact: newContact, linphoneFriend: self.nativeAddressBookFriendList, existingFriend: nil) {
|
||||
dispatchGroup.leave()
|
||||
}
|
||||
}
|
||||
self.saveImage(
|
||||
image: image,
|
||||
name: contact.givenName + contact.familyName,
|
||||
prefix: "",
|
||||
contact: newContact, linphoneFriend: self.nativeAddressBookFriendList, existingFriend: nil) {
|
||||
dispatchGroup.leave()
|
||||
}
|
||||
} else {
|
||||
self.textToImageInMainThread(firstName: contact.givenName, lastName: contact.familyName) { image in
|
||||
self.saveImage(
|
||||
image: image,
|
||||
name: contact.givenName + contact.familyName,
|
||||
prefix: "-default",
|
||||
contact: newContact, linphoneFriend: self.nativeAddressBookFriendList, existingFriend: nil) {
|
||||
dispatchGroup.leave()
|
||||
}
|
||||
}
|
||||
let image = self.textToImage(firstName: contact.givenName, lastName: contact.familyName)
|
||||
self.saveImage(
|
||||
image: image,
|
||||
name: contact.givenName + contact.familyName,
|
||||
prefix: "-default",
|
||||
contact: newContact, linphoneFriend: self.nativeAddressBookFriendList, existingFriend: nil) {
|
||||
dispatchGroup.leave()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -197,33 +194,6 @@ final class ContactsManager: ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
func textToImageInMainThread(firstName: String?, lastName: String?, completion: @escaping (UIImage) -> Void) {
|
||||
DispatchQueue.main.async {
|
||||
let lblNameInitialize = UILabel()
|
||||
lblNameInitialize.frame.size = CGSize(width: 200.0, height: 200.0)
|
||||
lblNameInitialize.font = UIFont(name: "NotoSans-ExtraBold", size: 80) ?? UIFont.boldSystemFont(ofSize: 80)
|
||||
lblNameInitialize.textColor = UIColor(Color.grayMain2c600)
|
||||
|
||||
let textToDisplay = (firstName?.first.map { String($0) } ?? "") + (lastName?.first.map { String($0) } ?? "")
|
||||
lblNameInitialize.text = textToDisplay.uppercased()
|
||||
lblNameInitialize.textAlignment = .center
|
||||
lblNameInitialize.backgroundColor = UIColor(Color.grayMain2c200)
|
||||
lblNameInitialize.layer.cornerRadius = 10.0
|
||||
lblNameInitialize.clipsToBounds = true
|
||||
|
||||
UIGraphicsBeginImageContextWithOptions(lblNameInitialize.frame.size, false, 0)
|
||||
defer { UIGraphicsEndImageContext() }
|
||||
|
||||
if let context = UIGraphicsGetCurrentContext() {
|
||||
lblNameInitialize.layer.render(in: context)
|
||||
let image = UIGraphicsGetImageFromCurrentImageContext() ?? UIImage()
|
||||
completion(image)
|
||||
} else {
|
||||
completion(UIImage())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func textToImage(firstName: String?, lastName: String?) -> UIImage {
|
||||
let firstInitial = firstName?.first.map { String($0) } ?? ""
|
||||
let lastInitial = lastName?.first.map { String($0) } ?? ""
|
||||
|
|
@ -468,15 +438,14 @@ final class ContactsManager: ObservableObject {
|
|||
imageData: ""
|
||||
)
|
||||
|
||||
self.textToImageInMainThread(firstName: friend.name ?? addressTmp, lastName: "") { image in
|
||||
self.saveImage(
|
||||
image: image,
|
||||
name: friend.name ?? addressTmp,
|
||||
prefix: "-default",
|
||||
contact: newContact, linphoneFriend: friendList.displayName ?? "No Display Name", existingFriend: nil) {
|
||||
dispatchGroup.leave()
|
||||
}
|
||||
}
|
||||
let image = self.textToImage(firstName: friend.name ?? addressTmp, lastName: "")
|
||||
self.saveImage(
|
||||
image: image,
|
||||
name: friend.name ?? addressTmp,
|
||||
prefix: "-default",
|
||||
contact: newContact, linphoneFriend: friendList.displayName ?? "No Display Name", existingFriend: nil) {
|
||||
dispatchGroup.leave()
|
||||
}
|
||||
}
|
||||
|
||||
dispatchGroup.notify(queue: .main) {
|
||||
|
|
|
|||
|
|
@ -52,13 +52,11 @@ class AccountProfileViewModel: ObservableObject {
|
|||
if self.getImagePath().lastPathComponent.contains("-default") || self.getImagePath().lastPathComponent == "Documents" {
|
||||
let usernameTmp = CoreContext.shared.accounts[self.accountModelIndex!].usernaneAvatar
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.saveImage(
|
||||
image: ContactsManager.shared.textToImage(
|
||||
firstName: displayNameAccountModel.isEmpty ? usernameTmp : displayNameAccountModel, lastName: ""),
|
||||
name: usernameTmp,
|
||||
prefix: "-default")
|
||||
}
|
||||
self.saveImage(
|
||||
image: ContactsManager.shared.textToImage(
|
||||
firstName: displayNameAccountModel.isEmpty ? usernameTmp : displayNameAccountModel, lastName: ""),
|
||||
name: usernameTmp,
|
||||
prefix: "-default")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,13 +105,11 @@ class AccountModel: ObservableObject {
|
|||
|
||||
if !photoAvatarModelKey.isEmpty {
|
||||
if preferences.object(forKey: photoAvatarModelKey) == nil {
|
||||
DispatchQueue.main.async {
|
||||
self.saveImage(
|
||||
image: ContactsManager.shared.textToImage(
|
||||
firstName: usernaneAvatarTmp, lastName: ""),
|
||||
name: usernaneAvatarTmp,
|
||||
prefix: "-default")
|
||||
}
|
||||
self.saveImage(
|
||||
image: ContactsManager.shared.textToImage(
|
||||
firstName: usernaneAvatarTmp, lastName: ""),
|
||||
name: usernaneAvatarTmp,
|
||||
prefix: "-default")
|
||||
} else {
|
||||
photoAvatarModelTmp = preferences.string(forKey: photoAvatarModelKey)!
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,38 +26,36 @@ struct EditContactView: UIViewControllerRepresentable {
|
|||
class Coordinator: NSObject, CNContactViewControllerDelegate, UINavigationControllerDelegate {
|
||||
func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) {
|
||||
if let cnc = contact {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
self.parent.contact = cnc
|
||||
|
||||
let newContact = Contact(
|
||||
identifier: cnc.identifier,
|
||||
firstName: cnc.givenName,
|
||||
lastName: cnc.familyName,
|
||||
organizationName: cnc.organizationName,
|
||||
jobTitle: "",
|
||||
displayName: cnc.nickname,
|
||||
sipAddresses: cnc.instantMessageAddresses.map { $0.value.service == "SIP" ? $0.value.username : "" },
|
||||
phoneNumbers: cnc.phoneNumbers.map { PhoneNumber(numLabel: $0.label ?? "", num: $0.value.stringValue)},
|
||||
imageData: ""
|
||||
)
|
||||
|
||||
let imageThumbnail = UIImage(data: contact!.thumbnailImageData ?? Data())
|
||||
ContactsManager.shared.saveImage(
|
||||
image: imageThumbnail
|
||||
?? ContactsManager.shared.textToImage(
|
||||
firstName: cnc.givenName.isEmpty
|
||||
&& cnc.familyName.isEmpty
|
||||
&& cnc.phoneNumbers.first?.value.stringValue != nil
|
||||
? cnc.phoneNumbers.first!.value.stringValue
|
||||
: cnc.givenName, lastName: cnc.familyName),
|
||||
name: cnc.givenName + cnc.familyName,
|
||||
prefix: ((imageThumbnail == nil) ? "-default" : ""),
|
||||
contact: newContact,
|
||||
linphoneFriend: "Native address-book",
|
||||
existingFriend: ContactsManager.shared.getFriendWithContact(contact: newContact)) {
|
||||
MagicSearchSingleton.shared.searchForContacts()
|
||||
}
|
||||
}
|
||||
self.parent.contact = cnc
|
||||
|
||||
let newContact = Contact(
|
||||
identifier: cnc.identifier,
|
||||
firstName: cnc.givenName,
|
||||
lastName: cnc.familyName,
|
||||
organizationName: cnc.organizationName,
|
||||
jobTitle: "",
|
||||
displayName: cnc.nickname,
|
||||
sipAddresses: cnc.instantMessageAddresses.map { $0.value.service == "SIP" ? $0.value.username : "" },
|
||||
phoneNumbers: cnc.phoneNumbers.map { PhoneNumber(numLabel: $0.label ?? "", num: $0.value.stringValue)},
|
||||
imageData: ""
|
||||
)
|
||||
|
||||
let imageThumbnail = UIImage(data: contact!.thumbnailImageData ?? Data())
|
||||
ContactsManager.shared.saveImage(
|
||||
image: imageThumbnail
|
||||
?? ContactsManager.shared.textToImage(
|
||||
firstName: cnc.givenName.isEmpty
|
||||
&& cnc.familyName.isEmpty
|
||||
&& cnc.phoneNumbers.first?.value.stringValue != nil
|
||||
? cnc.phoneNumbers.first!.value.stringValue
|
||||
: cnc.givenName, lastName: cnc.familyName),
|
||||
name: cnc.givenName + cnc.familyName,
|
||||
prefix: ((imageThumbnail == nil) ? "-default" : ""),
|
||||
contact: newContact,
|
||||
linphoneFriend: "Native address-book",
|
||||
existingFriend: ContactsManager.shared.getFriendWithContact(contact: newContact)) {
|
||||
MagicSearchSingleton.shared.searchForContacts()
|
||||
}
|
||||
}
|
||||
viewController.dismiss(animated: true, completion: {})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue