Skip to content

Commit

Permalink
Merge pull request #77 from gigigoapps/hotfix/v3.4.2
Browse files Browse the repository at this point in the history
Hotfix/v3.4.2
  • Loading branch information
radaloda authored Nov 12, 2019
2 parents cc81ec7 + 1f941df commit 8cb198f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
4 changes: 2 additions & 2 deletions GiGLibrary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2698,7 +2698,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 3.4;
MARKETING_VERSION = 3.4.1;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.gigigo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -2727,7 +2727,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 3.4;
MARKETING_VERSION = 3.4.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.gigigo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Build Status](https://travis-ci.org/gigigoapps/gigigo-ios-lib.svg?branch=master)](https://travis-ci.org/gigigoapps/gigigo-ios-lib)
![Language](https://img.shields.io/badge/Language-Objective--C-orange.svg)
![Language](https://img.shields.io/badge/Language-Swift-orange.svg)
![Version](https://img.shields.io/badge/version-3.3.1-blue.svg)
![Version](https://img.shields.io/badge/version-3.4.1-blue.svg)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)


Expand Down
60 changes: 31 additions & 29 deletions Source/GIGUtils/Image/ImageDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
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)
}

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()
}

default:
LogError(response.error)
Expand Down

0 comments on commit 8cb198f

Please sign in to comment.