-
-
Notifications
You must be signed in to change notification settings - Fork 487
/
Copy pathSoundCell.swift
73 lines (64 loc) · 2.26 KB
/
SoundCell.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// SoundCell.swift
// Bark
//
// Created by huangfeng on 2020/9/14.
// Copyright © 2020 Fin. All rights reserved.
//
import AVKit
import Material
import UIKit
class SoundCell: BaseTableViewCell<SoundCellViewModel> {
let copyButton = IconButton(image: UIImage(named: "baseline_file_copy_white_24pt"), tintColor: BKColor.grey.base)
let nameLabel: UILabel = {
let label = UILabel()
label.fontSize = 14
label.textColor = BKColor.grey.darken4
return label
}()
let durationLabel: UILabel = {
let label = UILabel()
label.fontSize = 12
label.textColor = BKColor.grey.darken1
return label
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
self.backgroundColor = BKColor.background.secondary
self.contentView.addSubview(nameLabel)
self.contentView.addSubview(durationLabel)
self.contentView.addSubview(copyButton)
nameLabel.snp.makeConstraints { make in
make.left.top.equalToSuperview().offset(15)
}
durationLabel.snp.makeConstraints { make in
make.left.equalTo(nameLabel)
make.top.equalTo(nameLabel.snp.bottom).offset(5)
make.bottom.equalToSuperview().offset(-15)
}
copyButton.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-15)
make.centerY.equalToSuperview()
make.width.height.equalTo(40)
}
}
@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func bindViewModel(model: SoundCellViewModel) {
super.bindViewModel(model: model)
model.name
.bind(to: nameLabel.rx.text)
.disposed(by: rx.reuseBag)
model.duration
.map { String(format: "%.2g second(s)", CMTimeGetSeconds($0)) }
.bind(to: durationLabel.rx.text)
.disposed(by: rx.reuseBag)
copyButton.rx.tap
.map { model.name.value }
.bind(to: model.copyNameAction)
.disposed(by: rx.reuseBag)
}
}