DailSyncViewController.swift
4.24 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
//
// 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!
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
UIApplication.shared.isIdleTimerDisabled = false
}
override func viewDidLoad() {
super.viewDidLoad()
title = LocString("表盘推送")
UIApplication.shared.isIdleTimerDisabled = true
collectionViewFlowLayout.minimumLineSpacing = 10
collectionViewFlowLayout.minimumInteritemSpacing = 20
collectionViewFlowLayout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
collectionViewFlowLayout.itemSize = CGSize(width: (SCREEN_WIDTH-60)/3.0, height: 140)
// 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) {
let cell = self.collectionView.cellForItem(at: indexPath) as! DailCell
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
if error == nil {
cell.syncComplete()
self?.collectionView.isUserInteractionEnabled = true
}
}
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
if error == nil {
cell.syncComplete()
self?.collectionView.isUserInteractionEnabled = true
}
}
case ._818_hq7:
BluetoothManager.shared.syncFileWith(path: "\(Bundle.main.resourcePath!)/dial/DialDataHQ7/\(indexPath.row)/dial.bin") { progress in
cell.updateProgressView(progress)
} completion: {[weak self] error in
if error == nil {
cell.syncComplete()
self?.collectionView.isUserInteractionEnabled = true
}
}
default:
break
}
}
deinit {
print("deinit\(NSStringFromClass(type(of: self)))!!!!!!!")
}
}
extension DailSyncViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 9
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "DailCell", for: indexPath) as! DailCell
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")
case ._818_hq7:
cell.dailImageView.image = UIImage(contentsOfFile: "\(Bundle.main.resourcePath!)/dial/dialrtkpreviewHQ7/\(indexPath.row)/preview")
default:
break
}
cell.cellClickClosure = {[weak self] in
self?.collectionView.isUserInteractionEnabled = false
self?.syncDail(indexPath)
}
return cell
}
}