Blame view

App/camera/board/Board.swift 3.54 KB
1341bf603   Trịnh Văn Quân   version 1.1
1
2
3
4
5
6
7
8
  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!
fbd62afcf   Trịnh Văn Quân   version 1.2.2
9
10
11
      @IBOutlet weak var tenCtruong: UILabel!
      @IBOutlet weak var tvShootItem: UILabel!
      @IBOutlet weak var tvCompanyName: UILabel!
1341bf603   Trịnh Văn Quân   version 1.1
12

fbd62afcf   Trịnh Văn Quân   version 1.2.2
13
14
      var shootItem: ShootItem?;
      var isReadOnly: Bool = false;
1341bf603   Trịnh Văn Quân   version 1.1
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
      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)
          }
      }
fbd62afcf   Trịnh Văn Quân   version 1.2.2
34
35
36
37
38
39
40
41
42
43
44
      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()
          }
1341bf603   Trịnh Văn Quân   version 1.1
45
          setDate(date: date)
fbd62afcf   Trịnh Văn Quân   version 1.2.2
46
47
48
49
50
51
52
  
          tenCtruong.text = ctruong.constructionName
          tvCompanyName.text = ctruong.companyName;
          tvShootItem.text = shootItem.name;
          if let note = imgObj?.note {
              tvNote.text = note;
          }
1341bf603   Trịnh Văn Quân   version 1.1
53
54
55
56
57
58
59
      }
  
      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)
fbd62afcf   Trịnh Văn Quân   version 1.2.2
60
          self.shootItem?.date = DataTypeUtils.getCurrentTimeSecond(date: date);
1341bf603   Trịnh Văn Quân   version 1.1
61
62
63
      }
  
      @IBAction func noteClick(_ sender: Any) {
fbd62afcf   Trịnh Văn Quân   version 1.2.2
64
65
66
          if isReadOnly {
              return;
          }
1341bf603   Trịnh Văn Quân   version 1.1
67
68
69
          let dialog = DialogUtils.builderDialog(showCloseButton: false, showTitle: false)
          let edt = dialog.addTextField()
          dialog.addButton(LocalizedString("OK"), action: {
fbd62afcf   Trịnh Văn Quân   version 1.2.2
70
71
72
              let node = (edt.text ?? "");
              self.shootItem?.note = node
              self.tvNote.text = " " + node;
1341bf603   Trịnh Văn Quân   version 1.1
73
74
          })
          dialog.showTitle("", subTitle: "備考", style: .edit)
289090880   Trịnh Văn Quân   version 1.2.2
75
          //edt.becomeFirstResponder()
1341bf603   Trịnh Văn Quân   version 1.1
76
77
78
      }
  
      @IBAction func dateClick(_ sender: Any) {
7b7581e89   Trịnh Văn Quân   Fixed: 2348, 2349
79
80
81
          if isReadOnly {
              return;
          }
1341bf603   Trịnh Văn Quân   version 1.1
82
          DatePickerDialog().show("撮影日", datePickerMode: .date, callback: { date in
fbd62afcf   Trịnh Văn Quân   version 1.2.2
83
84
85
86
              if let date = date {
                  self.setDate(date: date)
              }
          })
1341bf603   Trịnh Văn Quân   version 1.1
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
      }
  
      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)
      }
  }