Skip to content
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

Bug 1344783 - Make the highlight cells have similar favicons to TopSites #2496

Merged
merged 1 commit into from Mar 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 8 additions & 20 deletions Client/Frontend/Widgets/AlternateSimpleHighlightCell.swift
Expand Up @@ -14,6 +14,7 @@ struct AlternateSimpleHighlightCellUX {
static let CellTopBottomOffset = 12
static let SiteImageViewSize: CGSize = CGSize(width: 99, height: 76)
static let StatusIconSize = 12
static let FaviconSize = CGSize(width: 32, height: 32)
static let DescriptionLabelColor = UIColor(colorString: "919191")
static let SelectedOverlayColor = UIColor(white: 0.0, alpha: 0.25)
static let CornerRadius: CGFloat = 3
Expand Down Expand Up @@ -137,32 +138,19 @@ class AlternateSimpleHighlightCell: UITableViewCell {
fatalError("init(coder:) has not been implemented")
}

func setImageWithURL(_ url: URL) {
siteImageView.sd_setImage(with: url) { (img, err, type, url) -> Void in
guard let img = img else {
return
}
// Resize an Image to a specfic size to make sure that it doesnt appear bigger than it needs to (32px) inside a larger frame (48px).
self.siteImageView.image = img.createScaled(CGSize(width: 32, height: 32))
self.siteImageView.image?.getColors(scaleDownSize: CGSize(width: 25, height: 25)) { colors in
self.siteImageView.backgroundColor = colors.backgroundColor ?? UIColor.lightGray
}
}
}

override func prepareForReuse() {
super.prepareForReuse()
self.siteImageView.image = nil
contentView.backgroundColor = UIColor.clear
siteImageView.backgroundColor = UIColor.clear
}

func configureWithSite(_ site: Site) {
if let icon = site.icon, let url = URL(string:icon.url) {
self.setImageWithURL(url)
} else {
let url = site.url.asURL!
self.siteImageView.image = FaviconFetcher.getDefaultFavicon(url)
self.siteImageView.backgroundColor = FaviconFetcher.getDefaultColor(url)
}
self.siteImageView.setFavicon(forSite: site, onCompletion: { [weak self] (color, url) in
self?.siteImageView.image = self?.siteImageView.image?.createScaled(AlternateSimpleHighlightCellUX.FaviconSize)
})
self.siteImageView.contentMode = .center

self.domainLabel.text = site.tileURL.hostSLD
self.titleLabel.text = site.title.characters.count <= 1 ? site.url : site.title

Expand Down