LockOptionViewViewController.swift 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //
  2. // LockOptionViewViewControllerSwift.swift
  3. // MCPlus
  4. //
  5. // Created by seo ha on 14/02/2019.
  6. // Copyright © 2019 KangSH. All rights reserved.
  7. //
  8. import Foundation
  9. import UIKit
  10. class LockOptionViewViewController: UIViewController {
  11. @IBOutlet weak var tableview:UITableView!{
  12. didSet{
  13. tableview.delegate = self
  14. tableview.dataSource = self
  15. let nib = UINib(nibName: cellIdentifier, bundle: nil)
  16. tableview.register(nib, forCellReuseIdentifier: cellIdentifier)
  17. }
  18. }
  19. @IBOutlet weak var navigationbar:UINavigationBar!{
  20. didSet{
  21. navigationbar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
  22. navigationbar.barTintColor = UIColor(red: 71/255.0, green: 112/255.0, blue: 178/255.0, alpha: 1.0)
  23. navigationbar.isTranslucent = false
  24. let backButton = UIBarButtonItem(title: "", style: .plain, target: navigationController, action: nil)
  25. let rightButton = UIBarButtonItem(barButtonSystemItem: .stop, target: nil, action: #selector(closeOption))
  26. rightButton.tintColor = UIColor.white
  27. let previousItem = UINavigationItem(title: "암호 잠금")
  28. previousItem.leftBarButtonItem = backButton
  29. previousItem.rightBarButtonItem = rightButton
  30. navigationbar.pushItem(previousItem, animated: true)
  31. }
  32. }
  33. @IBOutlet weak var naviTitle:UINavigationItem!
  34. let userDefaults = UserDefaults.standard
  35. var str_desc:String = "암호를 분실했을 경우 앱을 삭제하고 재설치 해야하며, 재설치 후 암호를 새로 설정하시기 바랍니다."
  36. var itemsInfo:[String:[String]] = {
  37. var itemsInfo = [String:[String]]()
  38. itemsInfo["1"] = ["암호잠금(필수)"]
  39. itemsInfo["2"] = ["생체인증(지문)"]
  40. itemsInfo["3"] = ["암호 변경"]
  41. return itemsInfo
  42. }()
  43. let cellIdentifier = "LockOptionCell"
  44. deinit {
  45. Notification.removeNotification(observer: self)
  46. }
  47. }
  48. extension LockOptionViewViewController{
  49. func appWillEnterBackground(notification:Notification){
  50. let lockScreenDao = LockScreenDAO.sharedInstance
  51. self.dismiss(animated: false, completion: nil)
  52. }
  53. override func viewDidLoad() {
  54. Notification.registerNotification(name: UIApplication.didEnterBackgroundNotification, queue: .main, block: appWillEnterBackground)
  55. }
  56. override func didReceiveMemoryWarning() {
  57. super.didReceiveMemoryWarning()
  58. // Dispose of any resources that can be recreated.
  59. }
  60. @objc func closeOption(){
  61. print("close.......")
  62. self.dismiss(animated: false, completion: nil)
  63. }
  64. @objc func switchChanged(sender:UISwitch?){
  65. print("The tag is \(sender?.tag)")
  66. print("The switch is \(sender?.isOn == true ? "ON" : "OFF")")
  67. // 어차피 현재 스위치 태그는 다 0임.
  68. userDefaults.set(sender?.isOn == true ? "ON" : "OFF", forKey: "fingerprint")
  69. }
  70. }
  71. //MARK: - UITableview delegate & datasource
  72. extension LockOptionViewViewController:UITableViewDelegate, UITableViewDataSource{
  73. func numberOfSections(in tableView: UITableView) -> Int {
  74. // Return the number of sections.
  75. return itemsInfo.map({$0.key}).count
  76. }
  77. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
  78. let key = itemsInfo.map({$0.key})[section]
  79. return itemsInfo[key]?.count ?? 0
  80. }
  81. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
  82. let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! LockOptionCell
  83. cell.selectionStyle = .none
  84. let key = itemsInfo.map({$0.key})[indexPath.section]
  85. cell.label.text = itemsInfo[key]?[indexPath.row] ?? ""
  86. cell.switchButton.tag = indexPath.row
  87. cell.switchButton.addTarget(self, action: #selector(switchChanged(sender:)), for: .valueChanged)
  88. cell.switchButton.isEnabled = false
  89. switch indexPath.section {
  90. case 1:
  91. cell.switchButton.isEnabled = true
  92. if let temp = userDefaults.object(forKey: "fingerprint") as? String{
  93. cell.switchButton.isOn = temp == "ON"
  94. }else{
  95. cell.switchButton.isOn = true
  96. }
  97. case 2:
  98. cell.switchButton.isHidden = true
  99. default:
  100. break
  101. }
  102. return cell
  103. }
  104. func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
  105. return "" //[[itemsInfo allKeys] objectAtIndex:section];
  106. }
  107. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  108. return 44
  109. }
  110. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  111. // calculate height of UILabel
  112. let lblSectionName = UILabel()
  113. lblSectionName.text = self.str_desc
  114. lblSectionName.textColor = UIColor.lightGray
  115. lblSectionName.numberOfLines = 0
  116. lblSectionName.lineBreakMode = .byWordWrapping
  117. lblSectionName.backgroundColor = UIColor.lightGray
  118. lblSectionName.frame = CGRect(x: 20, y: 15, width: Constants.kScreenWidth-30, height: lblSectionName.frame.width)
  119. lblSectionName.sizeToFit()
  120. //푸터 설정
  121. if section == 2 {
  122. return lblSectionName.frame.size.height + 30
  123. }
  124. return 0
  125. }
  126. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  127. let footerView = UIView()
  128. let lblSectionName = UILabel()
  129. lblSectionName.text = self.str_desc
  130. lblSectionName.textColor = UIColor.red
  131. lblSectionName.numberOfLines = 0
  132. lblSectionName.lineBreakMode = .byWordWrapping;
  133. lblSectionName.frame = CGRect(x: 20, y: 15, width: Constants.kScreenWidth-30, height: lblSectionName.frame.width)
  134. lblSectionName.sizeToFit()
  135. footerView.addSubview(lblSectionName)
  136. footerView.frame = CGRect(x: 0, y: 0, width: tableView.bounds.width, height: lblSectionName.frame.height)
  137. footerView.backgroundColor = UIColor(red: 247/255.0, green: 247/255.0, blue: 247/255.0, alpha: 1.0)
  138. if section == 2 {
  139. return footerView
  140. }
  141. return nil
  142. }
  143. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  144. print("selected cell is (\(indexPath.section), \(indexPath.row))")
  145. if indexPath.section == 2 {
  146. // 암호변경화면 호출.
  147. let lockScreenDao = LockScreenDAO.sharedInstance
  148. lockScreenDao.pwInputType = LockScreenDAO.PASSWORD_INPUT_TYPE.FIRST_INPUT
  149. lockScreenDao.saveOptionValuesWithoutPassword()
  150. let VC = ScreenLockViewController()
  151. self.present(VC, animated: true, completion: nil)
  152. }
  153. }
  154. }