UnbindViewController.swift 2.89 KB
//
//  UnbindViewController.swift
//  Twear
//
//  Created by yangbin on 2022/1/4.
//

import UIKit

class UnbindViewController: UIViewController {

    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var macLabel: UILabel!
    @IBOutlet weak var batteryLabel: UILabel!
    
    @IBOutlet weak var watchImageView: UIImageView!
    var unbindClosure: (() -> ())?
    
    let device = CurDevice
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.setNavigationBarHidden(false, animated: true)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = LocString("解绑设备")
        nameLabel.text = device.name
        macLabel.text = "mac:\(device.mac)"
        if DeviceIsCharging {
            batteryLabel.text = "\(LocString("充电中")):\(Battery)%"
        } else {
            batteryLabel.text = "\(LocString("电量")):\(Battery)%"
        }
       
        
        if device.name.contains("P8GT") {
            watchImageView.image = UIImage(named: "P8GT_icon")
        } else if device.name.contains("Watch 7") {
            watchImageView.image = UIImage(named: "Watch7_icon")
        } else if device.name.contains("S7 NO.1") {
            watchImageView.image = UIImage(named: "S7_NO.1_icon")
        } else if device.name.contains("hq7") {
            watchImageView.image = UIImage(named: "hq7_icon")
        } else {
            watchImageView.image = UIImage(named: "bracelet_icon")
        }
        // Do any additional setup after loading the view.
    }
    
    @IBAction func unbind(_ sender: Any) {
        let alertVC = UIAlertController(title: "", message: LocString("是否解除绑定?"), preferredStyle: .alert)
        let confirm = UIAlertAction(title: LocString("确定"), style: .destructive) { [weak self] (action) in
            BluetoothManager.shared.disconnect()
            BluetoothManager.shared.forgetPeripheral()
            self?.unbindClosure?()
//            self?.navigationController?.popViewController(animated: true)
            
            let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Setting", identifier: "UnbindRemindVC")
            self?.navigationController?.pushViewController(vc, animated: true)
            
//            self?.updateConnectView(false)
        }
        let cancel = UIAlertAction(title: LocString("取消"), style: .default, handler: nil)
        alertVC.addAction(cancel)
        alertVC.addAction(confirm)
        present(alertVC, animated: true, completion: nil)
    }
//
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}