-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlockedCell.swift
57 lines (48 loc) · 2.28 KB
/
BlockedCell.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Copyright (c) 2020 Related Code - http://relatedcode.com
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import UIKit
//-------------------------------------------------------------------------------------------------------------------------------------------------
class BlockedCell: UITableViewCell {
@IBOutlet var imageUser: UIImageView!
@IBOutlet var labelInitials: UILabel!
@IBOutlet var labelName: UILabel!
//---------------------------------------------------------------------------------------------------------------------------------------------
func bindData(person: Person) {
labelName.text = person.fullname
}
//---------------------------------------------------------------------------------------------------------------------------------------------
func loadImage(person: Person, tableView: UITableView, indexPath: IndexPath) {
if let path = MediaDownload.pathUser(person.objectId) {
imageUser.image = UIImage.image(path, size: 40)
labelInitials.text = nil
} else {
imageUser.image = nil
labelInitials.text = person.initials()
downloadImage(person: person, tableView: tableView, indexPath: indexPath)
}
}
//---------------------------------------------------------------------------------------------------------------------------------------------
func downloadImage(person: Person, tableView: UITableView, indexPath: IndexPath) {
MediaDownload.startUser(person.objectId, pictureAt: person.pictureAt) { image, error in
let indexSelf = tableView.indexPath(for: self)
if ((indexSelf == nil) || (indexSelf == indexPath)) {
if (error == nil) {
self.imageUser.image = image?.square(to: 40)
self.labelInitials.text = nil
} else if (error!.code() == 102) {
DispatchQueue.main.async(after: 0.5) {
self.downloadImage(person: person, tableView: tableView, indexPath: indexPath)
}
}
}
}
}
}