-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hotfix/v3.4.2 #77
Hotfix/v3.4.2 #77
Changes from all commits
ed32f7a
bdc8be9
78b2687
f2e4aad
66efc2c
bfab946
5dc9816
1f941df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,57 +51,59 @@ struct ImageDownloader { | |
ImageDownloader.queue[view] = request | ||
ImageDownloader.stack.append(view) | ||
|
||
if ImageDownloader.queue.count <= 3 { | ||
if ImageDownloader.stack.count <= 3 { | ||
self.downloadNext() | ||
} | ||
} | ||
|
||
private func downloadNext() { | ||
guard let view = ImageDownloader.stack.popLast() else { return } | ||
guard let request = ImageDownloader.queue[view] else { | ||
self.downloadNext() | ||
return | ||
} | ||
|
||
request.fetch { response in | ||
switch response.status { | ||
|
||
case .success: | ||
DispatchQueue.global().async { | ||
if let image = try? response.image() { | ||
DispatchQueue.main.async { | ||
let width = view.width() * UIScreen.main.scale | ||
let height = view.height() * UIScreen.main.scale | ||
let resized = image.imageProportionally(with: CGSize(width: width, height: height)) | ||
ImageDownloader.images[request.baseURL] = resized | ||
if let image = try? response.image() { | ||
DispatchQueue(label: "com.gigigo.imagedownloader", qos: .background).async { | ||
var finalImage = image | ||
let width = view.width() * UIScreen.main.scale | ||
let height = view.height() * UIScreen.main.scale | ||
if let resized = image.imageProportionally(with: CGSize(width: width, height: height)) { | ||
finalImage = resized | ||
} | ||
ImageDownloader.images.updateValue(finalImage, forKey: request.baseURL) | ||
|
||
if let currentRequest = ImageDownloader.queue[view], request.baseURL == currentRequest.baseURL { | ||
self.setAnimated(image: resized, in: view) | ||
} | ||
|
||
if let index = ImageDownloader.queue.index(forKey: view) { | ||
ImageDownloader.queue.remove(at: index) | ||
} | ||
self.downloadNext() | ||
} | ||
} else if let imageGif = try? response.gif() { | ||
|
||
DispatchQueue.main.async { | ||
ImageDownloader.images[request.baseURL] = imageGif | ||
|
||
if let currentRequest = ImageDownloader.queue[view], request.baseURL == currentRequest.baseURL { | ||
self.setAnimated(image: imageGif, in: view) | ||
} | ||
|
||
self.setAnimated(image: finalImage, in: view) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace) |
||
if let index = ImageDownloader.queue.index(forKey: view) { | ||
ImageDownloader.queue.remove(at: index) | ||
} | ||
self.downloadNext() | ||
} | ||
} else { | ||
LogWarn("Al descargar la imagen,o se ha recibido un body vacio o no se se ha reconocido el tipo de imagen que es.") | ||
self.downloadNext() | ||
} | ||
} | ||
} | ||
} else if let imageGif = try? response.gif() { | ||
DispatchQueue.main.async { | ||
ImageDownloader.images.updateValue(imageGif, forKey: request.baseURL) | ||
|
||
if let currentRequest = ImageDownloader.queue[view], request.baseURL == currentRequest.baseURL { | ||
self.setAnimated(image: imageGif, in: view) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace) |
||
if let index = ImageDownloader.queue.index(forKey: view) { | ||
ImageDownloader.queue.remove(at: index) | ||
} | ||
self.downloadNext() | ||
} | ||
} else { | ||
LogWarn("Al descargar la imagen,o se ha recibido un body vacio o no se se ha reconocido el tipo de imagen que es.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line Length Violation: Line should be 120 characters or less: currently 135 characters (line_length) |
||
self.downloadNext() | ||
} | ||
|
||
default: | ||
LogError(response.error) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
Vertical Whitespace Violation: Limit vertical whitespace to a single empty line. Currently 2. (vertical_whitespace)