Board.swift
3.54 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import Foundation
import UIKit
import GeneralUtils
@IBDesignable class Board: UIView {
@IBOutlet weak var vRoot: UIView!
@IBOutlet weak var tvDate: UILabel!
@IBOutlet weak var tvNote: UILabel!
@IBOutlet weak var tenCtruong: UILabel!
@IBOutlet weak var tvShootItem: UILabel!
@IBOutlet weak var tvCompanyName: UILabel!
var shootItem: ShootItem?;
var isReadOnly: Bool = false;
override init(frame: CGRect) {
super.init(frame: frame)
xibSetup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
xibSetup()
}
func xibSetup() {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: "Board", bundle: bundle)
if let view = nib.instantiate(withOwner: self, options: nil)[0] as? UIView {
view.frame = bounds
view.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]
addSubview(view)
}
}
func initData(ctruong: CongTruong, shootItem: ShootItem, imgObj: ImgObj? = nil) {
self.shootItem = shootItem;
if imgObj != nil {
isReadOnly = true;
}
var date: Date!;
if let dateSave = imgObj?.date, dateSave > 0 {
date = DataTypeUtils.getDateFromTimeSecond(timeSeconds: Double(dateSave));
} else {
date = Date()
}
setDate(date: date)
tenCtruong.text = ctruong.constructionName
tvCompanyName.text = ctruong.companyName;
tvShootItem.text = shootItem.name;
if let note = imgObj?.note {
tvNote.text = note;
}
}
private func setDate(date: Date) {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM d, yyyy"
dateFormatter.locale = Locale(identifier: "ja_JP")
tvDate.text = dateFormatter.string(from: date)
self.shootItem?.date = DataTypeUtils.getCurrentTimeSecond(date: date);
}
@IBAction func noteClick(_ sender: Any) {
if isReadOnly {
return;
}
let dialog = DialogUtils.builderDialog(showCloseButton: false, showTitle: false)
let edt = dialog.addTextField()
dialog.addButton(LocalizedString("OK"), action: {
let node = (edt.text ?? "");
self.shootItem?.note = node
self.tvNote.text = " " + node;
})
dialog.showTitle("", subTitle: "備考", style: .edit)
//edt.becomeFirstResponder()
}
@IBAction func dateClick(_ sender: Any) {
if isReadOnly {
return;
}
DatePickerDialog().show("撮影日", datePickerMode: .date, callback: { date in
if let date = date {
self.setDate(date: date)
}
})
}
func scale() {
delayExcute(1, block: {
print("Scale")
UIView.animate(withDuration: 5, animations: {
self.vRoot.transform = CGAffineTransform.identity.scaledBy(x: 0.3, y: 0.3)
self.vRoot.frame.origin.x = 0
self.vRoot.frame.origin.y = 0
})
})
}
func delayExcute(_ delay: TimeInterval, queueParam: DispatchQueue? = nil, block: @escaping () -> ()) {
var queue: DispatchQueue!
if queueParam == nil {
queue = DispatchQueue.main
} else {
queue = queueParam
}
let time = DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
queue.asyncAfter(deadline: time, execute: block)
}
}