|
|
|
//
|
|
|
|
// DialPushViewControllers.swift
|
|
|
|
// Lookfit
|
|
|
|
//
|
|
|
|
// Created by lemo. on 2020/4/29.
|
|
|
|
// Copyright © 2020 Sheldon. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
// MARK:- 复用
|
|
|
|
fileprivate enum Resuable {
|
|
|
|
static let dialCell = ReusableCell<DialPushCell>(nibName: "DialPushCell")
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK:- 常量
|
|
|
|
fileprivate struct Metric {
|
|
|
|
static let itemW = (kScreenW - (kNavBarItemMargin * 4)) / 3.0
|
|
|
|
static let itemSize: CGSize = CGSize(width: itemW, height: itemW)
|
|
|
|
}
|
|
|
|
|
|
|
|
class DialPushViewControllers: ViewController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lazy var rxDataSource: RxCollectionViewSectionedReloadDataSource = {
|
|
|
|
return RxCollectionViewSectionedReloadDataSource
|
|
|
|
<SectionModel<String, DialModel>>(
|
|
|
|
configureCell: { (dataSource, collectionView, indexPath, element) in
|
|
|
|
let cell = collectionView.dequeue(Resuable.dialCell, for: indexPath)
|
|
|
|
|
|
|
|
let path = element.icon.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)
|
|
|
|
let url = URL.init(string: path!)
|
|
|
|
print(url as Any);
|
|
|
|
cell.dilaImageView.kf.setImage(with: url)
|
|
|
|
return cell
|
|
|
|
})
|
|
|
|
}()
|
|
|
|
private lazy var collectionView: UICollectionView = {
|
|
|
|
let flowLayout = UICollectionViewFlowLayout()
|
|
|
|
flowLayout.headerReferenceSize = CGSize(width: kScreenW, height: 34)
|
|
|
|
flowLayout.minimumInteritemSpacing = kNavBarItemMargin
|
|
|
|
flowLayout.itemSize = Metric.itemSize
|
|
|
|
flowLayout.sectionInset = UIEdgeInsets(top: 0, left: kNavBarItemMargin, bottom: kNavBarItemMargin, right: kNavBarItemMargin)
|
|
|
|
let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: flowLayout).then {
|
|
|
|
$0.backgroundColor = .white
|
|
|
|
$0.showsVerticalScrollIndicator = false
|
|
|
|
$0.register(Resuable.dialCell)
|
|
|
|
view.addSubview($0)
|
|
|
|
}
|
|
|
|
return collectionView
|
|
|
|
}()
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
|
|
|
|
if let deviceInfo = UserDefaultsManager.getDeviceInfo() {
|
|
|
|
switch deviceInfo.otaPlan {
|
|
|
|
case .jerry:
|
|
|
|
BluetoothFireBoltt.shareInstance()?.openDialFile()
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// override func viewDidDisappear(_ animated: Bool) {
|
|
|
|
// super.viewDidDisappear(animated)
|
|
|
|
// if Bluetooth.shareInstance()!.isConnected == false {
|
|
|
|
// Bluetooth.shareInstance()?.startAndStopReconnect(true)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
override func makeUI() {
|
|
|
|
super.makeUI()
|
|
|
|
collectionView.snp.makeConstraints { (make) in
|
|
|
|
make.edges.equalToSuperview()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override func bindViewModel() {
|
|
|
|
super.bindViewModel()
|
|
|
|
guard let viewModel = viewModel as? DialPushViewModels else { return }
|
|
|
|
viewModel.relay
|
|
|
|
.bind(to: collectionView.rx.items(dataSource: rxDataSource))
|
|
|
|
.disposed(by: rx.disposeBag)
|
|
|
|
let _ = viewModel.transform(input: DialPushViewModels.Input(selection: collectionView.rx.modelSelected(DialModel.self).asObservable()))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|