Change download directory

This commit is contained in:
Benoit Martins 2024-06-07 15:03:57 +02:00
parent e91e722587
commit 0fff983b0a
5 changed files with 87 additions and 36 deletions

View file

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "image-broken.svg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="#000000" viewBox="0 0 256 256"><path d="M216,40H40A16,16,0,0,0,24,56V200a16,16,0,0,0,16,16h64a8,8,0,0,0,7.59-5.47l14.83-44.48L163,151.43a8.07,8.07,0,0,0,4.46-4.46l14.62-36.55,44.48-14.83A8,8,0,0,0,232,88V56A16,16,0,0,0,216,40ZM112.41,157.47,98.23,200H40V172l52-52,30.42,30.42L117,152.57A8,8,0,0,0,112.41,157.47ZM216,82.23,173.47,96.41a8,8,0,0,0-4.9,4.62l-14.72,36.82L138.58,144l-35.27-35.27a16,16,0,0,0-22.62,0L40,149.37V56H216Zm12.68,33a8,8,0,0,0-7.21-1.1l-23.8,7.94a8,8,0,0,0-4.9,4.61l-14.31,35.77-35.77,14.31a8,8,0,0,0-4.61,4.9l-7.94,23.8A8,8,0,0,0,137.73,216H216a16,16,0,0,0,16-16V121.73A8,8,0,0,0,228.68,115.24ZM216,200H148.83l3.25-9.75,35.51-14.2a8.07,8.07,0,0,0,4.46-4.46l14.2-35.51,9.75-3.25Z"></path></svg>

After

Width:  |  Height:  |  Size: 784 B

View file

@ -87,7 +87,7 @@ struct ContactsListFragment: View {
withAnimation {
contactViewModel.indexDisplayedFriend = index
}
if contactsManager.lastSearch[index].friend != nil && contactsManager.lastSearch[index].friend!.address != nil {
if index < contactsManager.lastSearch.count && contactsManager.lastSearch[index].friend != nil && contactsManager.lastSearch[index].friend!.address != nil {
startCallFunc(contactsManager.lastSearch[index].friend!.address!)
}
}

View file

@ -187,46 +187,62 @@ struct ChatBubbleView: View {
if message.attachments.first!.type == .image || message.attachments.first!.type == .video {
if #available(iOS 16.0, *) {
AsyncImage(url: message.attachments.first!.thumbnail) { image in
ZStack {
image
.resizable()
.interpolation(.medium)
.aspectRatio(contentMode: .fill)
if message.attachments.first!.type == .video {
Image("play-fill")
.renderingMode(.template)
AsyncImage(url: message.attachments.first!.thumbnail) { phase in
switch phase {
case .empty:
ProgressView()
case .success(let image):
ZStack {
image
.resizable()
.foregroundStyle(.white)
.frame(width: 40, height: 40, alignment: .leading)
.interpolation(.medium)
.aspectRatio(contentMode: .fill)
if message.attachments.first!.type == .video {
Image("play-fill")
.renderingMode(.template)
.resizable()
.foregroundStyle(.white)
.frame(width: 40, height: 40, alignment: .leading)
}
}
case .failure:
Image("image-broken")
@unknown default:
EmptyView()
}
} placeholder: {
ProgressView()
}
.layoutPriority(-1)
.clipShape(RoundedRectangle(cornerRadius: 4))
} else {
AsyncImage(url: message.attachments.first!.thumbnail) { image in
ZStack {
image
.resizable()
.interpolation(.medium)
.aspectRatio(contentMode: .fill)
if message.attachments.first!.type == .video {
Image("play-fill")
.renderingMode(.template)
AsyncImage(url: message.attachments.first!.thumbnail) { phase in
switch phase {
case .empty:
ProgressView()
case .success(let image):
ZStack {
image
.resizable()
.foregroundStyle(.white)
.frame(width: 40, height: 40, alignment: .leading)
.interpolation(.medium)
.aspectRatio(contentMode: .fill)
if message.attachments.first!.type == .video {
Image("play-fill")
.renderingMode(.template)
.resizable()
.foregroundStyle(.white)
.frame(width: 40, height: 40, alignment: .leading)
}
}
case .failure:
Image("image-broken")
@unknown default:
EmptyView()
}
} placeholder: {
ProgressView()
}
.id(UUID())
.layoutPriority(-1)
.clipShape(RoundedRectangle(cornerRadius: 4))
.id(UUID())
}
} else if message.attachments.first!.type == .gif {
if #available(iOS 16.0, *) {
@ -319,7 +335,7 @@ struct ChatBubbleView: View {
return orientation != nil && orientation == 6 ? (pixelHeight ?? 0, pixelWidth ?? 0) : (pixelWidth ?? 0, pixelHeight ?? 0)
}
}
return (0, 0)
return (100, 100)
}
}

View file

@ -139,6 +139,7 @@ class ConversationViewModel: ObservableObject {
} else {
if content.type != "video" {
let path = URL(string: self.getNewFilePath(name: content.name ?? ""))
if path != nil {
let attachment =
Attachment(
@ -151,6 +152,7 @@ class ConversationViewModel: ObservableObject {
} else if content.type == "video" {
let path = URL(string: self.getNewFilePath(name: content.name ?? ""))
let pathThumbnail = URL(string: self.generateThumbnail(name: content.name ?? ""))
if path != nil && pathThumbnail != nil {
let attachment =
Attachment(
@ -240,6 +242,7 @@ class ConversationViewModel: ObservableObject {
} else {
if content.type != "video" {
let path = URL(string: self.getNewFilePath(name: content.name ?? ""))
if path != nil {
let attachment =
Attachment(
@ -252,6 +255,7 @@ class ConversationViewModel: ObservableObject {
} else if content.type == "video" {
let path = URL(string: self.getNewFilePath(name: content.name ?? ""))
let pathThumbnail = URL(string: self.generateThumbnail(name: content.name ?? ""))
if path != nil && pathThumbnail != nil {
let attachment =
Attachment(
@ -339,6 +343,7 @@ class ConversationViewModel: ObservableObject {
} else if content.name != nil && !content.name!.isEmpty {
if content.type != "video" {
let path = URL(string: self.getNewFilePath(name: content.name ?? ""))
if path != nil {
let attachment =
Attachment(
@ -350,6 +355,7 @@ class ConversationViewModel: ObservableObject {
}
} else if content.type == "video" {
let path = URL(string: self.getNewFilePath(name: content.name ?? ""))
let pathThumbnail = URL(string: self.generateThumbnail(name: content.name ?? ""))
if path != nil && pathThumbnail != nil {
let attachment =
@ -512,7 +518,8 @@ class ConversationViewModel: ObservableObject {
if message != nil {
let path = FileManager.default.temporaryDirectory.appendingPathComponent((attachment.full.lastPathComponent.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? ""))
let newPath = URL(string: "file://" + Factory.Instance.getDownloadDir(context: nil) + (attachment.full.lastPathComponent.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? ""))
let newPath = URL(string: FileUtil.sharedContainerUrl().appendingPathComponent("Library/Images").absoluteString
+ (attachment.full.lastPathComponent.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? ""))
/*
let data = try Data(contentsOf: path)
let decodedData: () = try data.write(to: path)
@ -581,7 +588,7 @@ class ConversationViewModel: ObservableObject {
if contentName != nil {
let isImage = FileUtil.isExtensionImage(path: contentName!)
let file = FileUtil.getFileStoragePath(fileName: contentName ?? "", isImage: isImage)
content.filePath = file
content.filePath = String(file.dropFirst(7))
Log.info(
"[ConversationViewModel] File \(contentName) will be downloaded at \(content.filePath)"
)
@ -593,13 +600,14 @@ class ConversationViewModel: ObservableObject {
}
func getNewFilePath(name: String) -> String {
return "file://" + Factory.Instance.getDownloadDir(context: nil) + (name.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? "")
let groupName = "group.\(Bundle.main.bundleIdentifier ?? "").linphoneExtension"
return FileUtil.sharedContainerUrl().appendingPathComponent("Library/Images").absoluteString + (name.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? "")
}
func generateThumbnail(name: String, pathThumbnail: URL? = nil) -> String {
do {
let path = pathThumbnail == nil
? URL(string: "file://" + Factory.Instance.getDownloadDir(context: nil) + (name.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? ""))
? URL(string: "file://" + FileUtil.sharedContainerUrl().appendingPathComponent("Library/Images").absoluteString + (name.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? ""))
: pathThumbnail!.appendingPathComponent((name.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? ""))
let asset = AVURLAsset(url: path!, options: nil)
let imgGenerator = AVAssetImageGenerator(asset: asset)
@ -612,7 +620,12 @@ class ConversationViewModel: ObservableObject {
}
let urlName = pathThumbnail == nil
? URL(string: "file://" + Factory.Instance.getDownloadDir(context: nil) + "preview_" + (name.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? "") + ".png")
? URL(string: "file://"
+ FileUtil.sharedContainerUrl().appendingPathComponent("Library/Images").absoluteString
+ "preview_"
+ (name.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? "")
+ ".png"
)
: pathThumbnail!.appendingPathComponent("preview_" + (name.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? "") + ".png")
if urlName != nil {