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

use the thumbnail placeholder image in today widget #104

Merged
merged 1 commit into from
Jul 30, 2020
Merged
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
22 changes: 20 additions & 2 deletions BeeSwiftToday/TodayTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class TodayTableViewCell: UITableViewCell {
var pollTimer : Timer?
let graphImageView = UIImageView()

var thumbnailPlaceholder: UIImage? {
UIImage(named: "ThumbnailPlaceholder")
}

fileprivate

func configureCell() {
Expand All @@ -40,7 +44,8 @@ class TodayTableViewCell: UITableViewCell {
make.top.equalTo(20)
make.bottom.equalTo(-20)
})
self.graphImageView.af_setImage(withURL: URL(string: self.goalDictionary["thumbUrl"] as! String)!)
self.graphImageView.image = self.thumbnailPlaceholder
self.setGraphImage(urlStr: self.goalDictionary["thumbUrl"] as? String)

self.addSubview(self.limitLabel)
self.limitLabel.numberOfLines = 0
Expand Down Expand Up @@ -174,10 +179,23 @@ class TodayTableViewCell: UITableViewCell {
self.addDataButton.isUserInteractionEnabled = true
self.limitLabel.text = "\(slug): \(goalJSON["limsum"])"
let urlString = "\(goalJSON["thumb_url"])"
self.graphImageView.af_setImage(withURL: URL(string: urlString)!)
self.setGraphImage(urlStr: urlString)
}
}) { (responseError) in
//
}
}

/// updates the graph, setting a placeholder
/// and replacing it with the downloaded, updated image
/// provided via the urlStr
func setGraphImage(urlStr: String?) {
guard !CurrentUserManager.sharedManager.isDeadbeat(),
let thumbUrlStr = urlStr, let thumbUrl = URL(string: thumbUrlStr) else {
self.graphImageView.image = self.thumbnailPlaceholder
return
}

self.graphImageView.af_setImage(withURL: thumbUrl, placeholderImage: thumbnailPlaceholder, progressQueue: DispatchQueue.global(qos: .background), imageTransition: .crossDissolve(0.4), runImageTransitionIfCached: false)
}
}