RemindViewController.swift 4.52 KB
//
//  RemindViewController.swift
//  Twear
//
//  Created by yangbin on 2021/12/24.
//

import UIKit

class RemindViewController: UIViewController {
    
    @IBOutlet weak var tableView: UITableView!

    var device = CurDevice
    private let remindArray: [String] = ["来电提醒", "短信提醒", "健康提醒", "应用提醒", "闹钟提醒"]
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        device = CurDevice
        tableView.reloadData()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = LocString("提醒功能")
        
        tableView.register(UINib.init(nibName: "SettingCell3", bundle: Bundle.main), forCellReuseIdentifier: "SettingCell3")
        tableView.tableFooterView = UIView(frame: CGRect.zero)
        
        // Do any additional setup after loading the view.
    }
}

extension RemindViewController: UITableViewDelegate, UITableViewDataSource {
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 5
    }

    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView()
        view.backgroundColor = UIColor.rgbColorFromHex(0xF2F2F2)
        return view
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.5
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 50
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return remindArray.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "SettingCell3", for: indexPath) as! SettingCell3
        
        let remindText = remindArray[indexPath.section]
        cell.titleLabel.text = LocString(remindText)
        cell.setImageView.image = UIImage(named: remindText)
        cell.lineView.isHidden = true
        
        switch remindText {
        case "闹钟提醒":
            var isOn: Bool = false
            for alarmClock in device.alarmClocks {
                if alarmClock.isOn {
                    isOn = true
                }
            }
            cell.detailLabel.text = isOn ? LocString("已开启") : LocString("未开启")
        case "来电提醒":
            cell.detailLabel.text = device.push.call ? LocString("已开启") : LocString("未开启")
        case "短信提醒":
            cell.detailLabel.text = device.push.sms ? LocString("已开启") : LocString("未开启")
        case "应用提醒":
            cell.detailLabel.text = device.push.app ? LocString("已开启") : LocString("未开启")
        case "健康提醒":
            cell.detailLabel.text = (device.drink.isOn || device.sedentary.isOn) ? LocString("已开启") : LocString("未开启")
        default:
            break
        }

        
        return cell
    }
    

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let cell = tableView.cellForRow(at: indexPath) as! SettingCell3
        cell.isSelected = false
//        let device = CurDevice
        switch remindArray[indexPath.section] {
        case "来电提醒":
            let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Setting", identifier: "CallRemindVC")
            navigationController?.pushViewController(vc, animated: true)
        case "短信提醒":
            let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Setting", identifier: "SMSRemindVC")
            navigationController?.pushViewController(vc, animated: true)
        case "应用提醒":
            let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Setting", identifier: "APPRemindVC")
            navigationController?.pushViewController(vc, animated: true)
        case "健康提醒":
            let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Setting", identifier: "HealthRemindVC")
            navigationController?.pushViewController(vc, animated: true)
        case "闹钟提醒":
            let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Setting", identifier: "AlarmClockVC")
            navigationController?.pushViewController(vc, animated: true)
        default:
            break
        }
    }
}