// // ChangePasswordViewController.swift // Akamu_iOS // // Created by Maurice Kraus on 19.07.20. // Copyright © 2020 Akamu e.V. All rights reserved. // import AkamuUIKit import UIKit import Logger class ChangePasswordViewController: UITableViewController { var firstPasswordCell: UITableViewCell = UITableViewCell() var secondPasswordCell: UITableViewCell = UITableViewCell() var firstPasswordField: UITextField = UITextField() var secondPasswordField: UITextField = UITextField() override func viewDidLoad() { super.viewDidLoad() logger.event("User visited \(String(describing: ChangePasswordViewController.self))") tableView = UITableView(frame: tableView.frame, style: .grouped) } override func loadView() { super.loadView() // construct first name cell, section 0, row 0 firstPasswordCell.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.5) firstPasswordField = UITextField(frame: firstPasswordCell.contentView.bounds.insetBy(dx: 15, dy: 0)) firstPasswordField.placeholder = "New Password" firstPasswordField.isSecureTextEntry = true firstPasswordCell.addSubview(firstPasswordField) // construct last name cell, section 0, row 1 secondPasswordCell.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.5) secondPasswordField = UITextField(frame: secondPasswordCell.contentView.bounds.insetBy(dx: 15, dy: 0)) secondPasswordField.placeholder = "Retype New Password" secondPasswordField.isSecureTextEntry = true secondPasswordCell.addSubview(secondPasswordField) } override func numberOfSections(in tableView: UITableView) -> Int { return 2 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 1 } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { switch indexPath.section { case 0: switch indexPath.row { case 0: return firstPasswordCell // section 0, row 0 is the first name default: fatalError("Unknown row in section 0") } case 1: switch indexPath.row { case 0: return secondPasswordCell // section 1, row 0 is the share option default: fatalError("Unknown row in section 1") } default: fatalError("Unknown section") } } override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { if section == 1 { return 100 } else { return 0 } } override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { guard section != 0 else { return nil } let footerView = UIView() footerView.backgroundColor = .clear let button = UIButton() button.setTitle("Update Password", for: .normal) button.setTitleColor(Colors.akamuBlue, for: .normal) button.layer.borderWidth = 1 button.layer.borderColor = Colors.akamuBlue.cgColor button.layer.cornerRadius = 5 footerView.addSubview(button) button.translatesAutoresizingMaskIntoConstraints = false button.centerInSuperview() button.heightAnchor.constraint(equalToConstant: 50).isActive = true button.titleEdgeInsets = .init(top: 0, left: 10, bottom: 0, right: 10) button.widthAnchor.constraint(greaterThanOrEqualToConstant: 200).isActive = true return footerView } override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { switch section { case 0: return "New Password" case 1: return "Retype Password" default: fatalError("Unknown section") } } } #if canImport(SwiftUI) && PREVIEW import SwiftUI import Swinject @available(iOS 13, *) struct ChangePasswordViewControllerPreview: PreviewProvider { static var previews: some View { ForEach(Devices.all, id: \.identity) { deviceName in NavigationView { ChangePasswordViewController().toPreview() .navigationBarTitle(Text("Change Password")) } .previewDevice(PreviewDevice(rawValue: deviceName)).previewDisplayName(deviceName) } } } #endif