Blame view

Twear/Setting/DailSyncViewController.swift 6.07 KB
75d24c15   yangbin   123
1
2
3
4
5
6
7
8
9
10
11
12
  //
  //  DailSyncViewController.swift
  //  Twear
  //
  //  Created by yangbin on 2021/12/21.
  //
  
  import UIKit
  
  class DailSyncViewController: UIViewController {
      @IBOutlet weak var collectionView: UICollectionView!
      @IBOutlet weak var collectionViewFlowLayout: UICollectionViewFlowLayout!
582f536d   yangbin   common:2022.1.28
13
14
15
      var dialNum: Int = 9
      var identifierDic: [String: String] = [:]
  //    var isSyncing: Bool = false
75d24c15   yangbin   123
16
      
66e7e76d   yangbin   NFC
17
  
75d24c15   yangbin   123
18
      
582f536d   yangbin   common:2022.1.28
19
20
21
22
23
24
25
26
27
28
29
30
31
32
      
      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated)
        
      }
      override func viewWillDisappear(_ animated: Bool) {
          super.viewWillDisappear(animated)
          let navController = navigationController as? ZCNavigationController
          navController?.enableScreenEdgePanGestureRecognizer(true)
      }
      
      
    
      
75d24c15   yangbin   123
33
34
35
      override func viewDidLoad() {
          super.viewDidLoad()
          title = LocString("表盘推送")
66e7e76d   yangbin   NFC
36
          
75d24c15   yangbin   123
37
38
          collectionViewFlowLayout.minimumLineSpacing = 10
          collectionViewFlowLayout.minimumInteritemSpacing = 20
582f536d   yangbin   common:2022.1.28
39
40
          collectionViewFlowLayout.sectionInset = UIEdgeInsets(top: 5, left: 10, bottom: 10, right: 10)
          collectionViewFlowLayout.itemSize = CGSize(width: (SCREEN_WIDTH-60)/3.0, height: 130)
75d24c15   yangbin   123
41
42
43
44
45
46
47
48
49
50
51
          //        collectionView.bounces = false
          // Do any additional setup after loading the view.
  //        let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
  //        let fileURL = documentsURL.appendingPathComponent("update/v1.zip")
  //        print(fileURL.absoluteString)
  //        print(fileURL.path)
  //        print("\(Bundle.main.resourcePath!)/dial/Dialdata280/")
      }
      
      
      private func syncDail(_ indexPath: IndexPath) {
582f536d   yangbin   common:2022.1.28
52
          if IsDailSyncing { return }
75d24c15   yangbin   123
53
          let cell = self.collectionView.cellForItem(at: indexPath) as! DailCell
582f536d   yangbin   common:2022.1.28
54
55
          updateUserInteraction(true)
          cell.updateProgressView(0)
75d24c15   yangbin   123
56
57
58
59
60
          switch CurDevice.platform {
          case ._816:
              BluetoothManager.shared.syncDialWith(path: "\(Bundle.main.resourcePath!)/dial/Dialdata280/\(indexPath.row)") { progress in
                  cell.updateProgressView(progress)
              } completion: {[weak self] error in
582f536d   yangbin   common:2022.1.28
61
                  self?.updateUserInteraction(false)
75d24c15   yangbin   123
62
63
                  if error == nil {
                      cell.syncComplete()
582f536d   yangbin   common:2022.1.28
64
65
66
                  } else {
                      cell.initProgressView()
                      self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
75d24c15   yangbin   123
67
68
69
70
71
72
73
                  }
              }
              
          case ._818:
              BluetoothManager.shared.syncFileWith(path: "\(Bundle.main.resourcePath!)/dial/DialDataRtk/\(indexPath.row)/dial.bin") { progress in
                  cell.updateProgressView(progress)
              } completion: {[weak self] error in
582f536d   yangbin   common:2022.1.28
74
                  self?.updateUserInteraction(false)
75d24c15   yangbin   123
75
76
                  if error == nil {
                      cell.syncComplete()
582f536d   yangbin   common:2022.1.28
77
78
79
                  } else {
                      cell.initProgressView()
                      self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
75d24c15   yangbin   123
80
81
                  }
              }
582f536d   yangbin   common:2022.1.28
82
          case ._828:
75d24c15   yangbin   123
83
84
85
              BluetoothManager.shared.syncFileWith(path: "\(Bundle.main.resourcePath!)/dial/DialDataHQ7/\(indexPath.row)/dial.bin") { progress in
                  cell.updateProgressView(progress)
              } completion: {[weak self] error in
582f536d   yangbin   common:2022.1.28
86
                  self?.updateUserInteraction(false)
75d24c15   yangbin   123
87
88
                  if error == nil {
                      cell.syncComplete()
582f536d   yangbin   common:2022.1.28
89
90
91
92
                      
                  } else {
                      cell.initProgressView()
                      self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
75d24c15   yangbin   123
93
94
                  }
              }
75d24c15   yangbin   123
95
96
97
98
99
          default:
              break
          }
      }
      
582f536d   yangbin   common:2022.1.28
100
101
102
103
104
      func updateUserInteraction(_ isSyncing: Bool) {
  //        collectionView.isUserInteractionEnabled = !isSyncing
          IsDailSyncing = isSyncing
          let navController = navigationController as? ZCNavigationController
          navController?.enableScreenEdgePanGestureRecognizer(!isSyncing)
75d24c15   yangbin   123
105
106
      }
      
582f536d   yangbin   common:2022.1.28
107
108
109
      deinit {
          print("deinit\(NSStringFromClass(type(of: self)))!!!!!!!")
      } 
75d24c15   yangbin   123
110
111
112
113
114
115
      
  }
  
  
  extension DailSyncViewController: UICollectionViewDelegate, UICollectionViewDataSource {
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
582f536d   yangbin   common:2022.1.28
116
          return dialNum
75d24c15   yangbin   123
117
118
119
      }
      
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
582f536d   yangbin   common:2022.1.28
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
  //        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "DailCell", for: indexPath) as! DailCell
          let identifier: String = "DailCell\(indexPath.row)\(indexPath.section)"
          if identifierDic[identifier] == nil {
              collectionView.register(UINib(nibName: "DailCell", bundle: .main), forCellWithReuseIdentifier: identifier)
              identifierDic[identifier] = identifier
          }
          
  //        collectionView.register(DailCell.self, forCellWithReuseIdentifier: "DailCell")
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as! DailCell
          // 此处可起到防止重用的作用
  //        for view in cell.contentView.subviews {
  ////            if view != nil {
  //                view.removeFromSuperview()
  ////            }
  //
  //        }
             
          
75d24c15   yangbin   123
138
139
140
141
142
          switch CurDevice.platform {
          case ._816:
              cell.dailImageView.image = UIImage(contentsOfFile:  "\(Bundle.main.resourcePath!)/dial/dialpreview280/\(indexPath.row)/preview_0\(indexPath.row)@2x")
          case ._818:
              cell.dailImageView.image = UIImage(contentsOfFile:  "\(Bundle.main.resourcePath!)/dial/dialrtkpreview/\(indexPath.row)/preview@2x")
582f536d   yangbin   common:2022.1.28
143
          case ._828:
75d24c15   yangbin   123
144
145
146
147
148
149
              cell.dailImageView.image = UIImage(contentsOfFile:  "\(Bundle.main.resourcePath!)/dial/dialrtkpreviewHQ7/\(indexPath.row)/preview")
          default:
              break
          }
          
          cell.cellClickClosure = {[weak self] in
75d24c15   yangbin   123
150
151
152
153
154
155
156
              self?.syncDail(indexPath)
          }
          
          return cell
      }
      
  }