Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

@orta: Fixes crash on grid view #486

Merged
merged 1 commit into from
Jul 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ upcoming:
- Fixes problem manually entering in credit card info [ash]
- Disables bid buttons and marks them as "SOLD" for artworks that have been sold [ash]
- Adds support for new estimate field [ash]
- Fixes crash with images that have unspecified aspect ratios [ash]
releases:
- version: 3.5.2
date: June 19 2015
Expand Down
15 changes: 10 additions & 5 deletions Kiosk/App/Models/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ public class Image: JSONAble {
public let imageFormatString: String
public let imageVersions: [String]
public let imageSize: CGSize
public let aspectRatio: CGFloat
public let aspectRatio: CGFloat?

public let baseURL:String
public let baseURL: String
public let tileSize: Int
public let maxTiledHeight: Int
public let maxTiledWidth: Int
public let maxLevel: Int
public let isDefault: Bool

public init(id: String, imageFormatString: String, imageVersions: [String], imageSize: CGSize, aspectRatio: CGFloat, baseURL: String, tileSize: Int, maxTiledHeight: Int, maxTiledWidth: Int, maxLevel: Int, isDefault: Bool) {
public init(id: String, imageFormatString: String, imageVersions: [String], imageSize: CGSize, aspectRatio: CGFloat?, baseURL: String, tileSize: Int, maxTiledHeight: Int, maxTiledWidth: Int, maxLevel: Int, isDefault: Bool) {
self.id = id
self.imageFormatString = imageFormatString
self.imageVersions = imageVersions
Expand All @@ -36,7 +36,12 @@ public class Image: JSONAble {
let imageFormatString = json["image_url"].stringValue
let imageVersions = json["image_versions"].object as! [String]
let imageSize = CGSize(width: json["original_width"].int ?? 1, height: json["original_height"].int ?? 1)
let aspectRatio = CGFloat( json["aspect_ratio"].floatValue )
let aspectRatio = { () -> CGFloat? in
if let aspectRatio = json["aspect_ratio"].float {
return CGFloat(aspectRatio)
}
return nil
}()

let baseURL = json["tile_base_url"].stringValue
let tileSize = json["tile_size"].intValue
Expand All @@ -50,7 +55,7 @@ public class Image: JSONAble {

let maxLevel = Int( ceilf( logD / log2) )

return Image(id: id, imageFormatString: imageFormatString, imageVersions: imageVersions, imageSize: imageSize, aspectRatio:aspectRatio, baseURL: baseURL, tileSize: tileSize, maxTiledHeight: maxTiledHeight, maxTiledWidth: maxTiledWidth, maxLevel: maxLevel, isDefault: isDefault)
return Image(id: id, imageFormatString: imageFormatString, imageVersions: imageVersions, imageSize: imageSize, aspectRatio: aspectRatio, baseURL: baseURL, tileSize: tileSize, maxTiledHeight: maxTiledHeight, maxTiledWidth: maxTiledWidth, maxLevel: maxLevel, isDefault: isDefault)
}

public func thumbnailURL() -> NSURL? {
Expand Down
4 changes: 3 additions & 1 deletion Kiosk/Auction Listings/MasonryCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ extension MasonryCollectionViewCell {

private func heightForImageWithAspectRatio(aspectRatio: CGFloat?) -> CGFloat {
if let ratio = aspectRatio {
return CGFloat(MasonryCollectionViewCellWidth) / ratio
if ratio != 0 {
return CGFloat(MasonryCollectionViewCellWidth) / ratio
}
}
return CGFloat(MasonryCollectionViewCellWidth)
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,14 @@ public class SaleArtworkDetailsViewController: UIViewController {
return
})

let heightConstraintNumber = min(400, CGFloat(538) / image.aspectRatio)
let heightConstraintNumber = { () -> CGFloat in
if let aspectRatio = image.aspectRatio {
if aspectRatio != 0 {
return min(400, CGFloat(538) / aspectRatio)
}
}
return 400
}()
imageView.constrainHeight( "\(heightConstraintNumber)" )

imageView.contentMode = .ScaleAspectFit
Expand Down
2 changes: 1 addition & 1 deletion Kiosk/Stubbed Responses/AuctionListings.json

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.