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
|
|
be19e595
yangbin
9
|
17
18
19
20
|
// var tempIndex: Int = -1
// var syncIndex = UserInfo.dailIndex
// var isSynced: Bool = UserInfo.isDailSync
var user = UserInfo
|
582f536d
yangbin
common:2022.1.28
|
21
22
23
|
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
|
be19e595
yangbin
9
|
24
|
|
582f536d
yangbin
common:2022.1.28
|
25
26
27
28
29
30
31
|
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
let navController = navigationController as? ZCNavigationController
navController?.enableScreenEdgePanGestureRecognizer(true)
}
|
be19e595
yangbin
9
|
32
33
34
35
36
37
38
39
40
|
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if user.isDailSync {
if user.dailIndex >= 0 && user.dailIndex <= dialNum-1 {
let cell = collectionView.cellForItem(at: IndexPath(row: user.dailIndex, section: 0)) as! DailCell
cell.syncComplete()
}
}
}
|
582f536d
yangbin
common:2022.1.28
|
41
42
|
|
75d24c15
yangbin
123
|
43
44
45
|
override func viewDidLoad() {
super.viewDidLoad()
title = LocString("表盘推送")
|
66e7e76d
yangbin
NFC
|
46
|
|
75d24c15
yangbin
123
|
47
48
|
collectionViewFlowLayout.minimumLineSpacing = 10
collectionViewFlowLayout.minimumInteritemSpacing = 20
|
be19e595
yangbin
9
|
49
|
collectionViewFlowLayout.sectionInset = UIEdgeInsets(top: 5, left: 10, bottom: 10+NAVBAR_HEIGHT+10, right: 10)
|
582f536d
yangbin
common:2022.1.28
|
50
|
collectionViewFlowLayout.itemSize = CGSize(width: (SCREEN_WIDTH-60)/3.0, height: 130)
|
be19e595
yangbin
9
|
51
52
|
|
75d24c15
yangbin
123
|
53
54
55
56
57
58
59
60
61
62
63
|
// 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
|
64
|
if IsDailSyncing { return }
|
75d24c15
yangbin
123
|
65
|
let cell = self.collectionView.cellForItem(at: indexPath) as! DailCell
|
be19e595
yangbin
9
|
66
|
if cell.progressView.label.text == LocString("已同步") { return }
|
582f536d
yangbin
common:2022.1.28
|
67
68
|
updateUserInteraction(true)
cell.updateProgressView(0)
|
75d24c15
yangbin
123
|
69
70
71
72
73
|
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
|
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
82
83
84
85
86
|
}
}
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
|
87
|
self?.updateUserInteraction(false)
|
75d24c15
yangbin
123
|
88
|
if error == nil {
|
be19e595
yangbin
9
|
89
|
self?.syncComplete(index: indexPath.row)
|
75d24c15
yangbin
123
|
90
|
cell.syncComplete()
|
582f536d
yangbin
common:2022.1.28
|
91
92
93
|
} else {
cell.initProgressView()
self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
|
75d24c15
yangbin
123
|
94
95
|
}
}
|
582f536d
yangbin
common:2022.1.28
|
96
|
case ._828:
|
75d24c15
yangbin
123
|
97
98
99
|
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
|
100
|
self?.updateUserInteraction(false)
|
75d24c15
yangbin
123
|
101
|
if error == nil {
|
be19e595
yangbin
9
|
102
|
self?.syncComplete(index: indexPath.row)
|
75d24c15
yangbin
123
|
103
|
cell.syncComplete()
|
582f536d
yangbin
common:2022.1.28
|
104
105
106
|
} else {
cell.initProgressView()
self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
|
75d24c15
yangbin
123
|
107
108
|
}
}
|
75d24c15
yangbin
123
|
109
110
111
112
113
|
default:
break
}
}
|
be19e595
yangbin
9
|
114
115
116
117
118
119
120
121
122
123
|
func syncComplete(index: Int) {
if user.dailIndex >= 0 {
let cell = collectionView.cellForItem(at: IndexPath(row: user.dailIndex, section: 0)) as! DailCell
cell.initProgressView()
}
user.isDailSync = true
user.dailIndex = index
AdminHelper.shared.updateUser(user)
}
|
582f536d
yangbin
common:2022.1.28
|
124
125
126
127
128
|
func updateUserInteraction(_ isSyncing: Bool) {
// collectionView.isUserInteractionEnabled = !isSyncing
IsDailSyncing = isSyncing
let navController = navigationController as? ZCNavigationController
navController?.enableScreenEdgePanGestureRecognizer(!isSyncing)
|
75d24c15
yangbin
123
|
129
130
|
}
|
582f536d
yangbin
common:2022.1.28
|
131
132
133
|
deinit {
print("deinit\(NSStringFromClass(type(of: self)))!!!!!!!")
}
|
75d24c15
yangbin
123
|
134
135
136
137
138
139
|
}
extension DailSyncViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
582f536d
yangbin
common:2022.1.28
|
140
|
return dialNum
|
75d24c15
yangbin
123
|
141
142
143
|
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
582f536d
yangbin
common:2022.1.28
|
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
// 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
|
162
163
164
165
166
|
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
|
167
|
case ._828:
|
75d24c15
yangbin
123
|
168
169
170
171
172
173
|
cell.dailImageView.image = UIImage(contentsOfFile: "\(Bundle.main.resourcePath!)/dial/dialrtkpreviewHQ7/\(indexPath.row)/preview")
default:
break
}
cell.cellClickClosure = {[weak self] in
|
75d24c15
yangbin
123
|
174
175
176
177
178
179
180
|
self?.syncDail(indexPath)
}
return cell
}
}
|