Commit 1fe884ac authored by gabrieso's avatar gabrieso
Browse files

Further UI Improvements in Settings:

- Each Cell can be easily customized now
- Subviews are interactive
parent 8fde3adf
......@@ -15,6 +15,7 @@
7F996B2821716B1600FCC28F /* FoodPreferenceModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F996B2721716B1600FCC28F /* FoodPreferenceModel.swift */; };
7F996B2B2171D5D800FCC28F /* FoodPreferenceDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F996B2A2171D5D800FCC28F /* FoodPreferenceDelegate.swift */; };
7F996B2D2171EDD300FCC28F /* FoodPreferencesSectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F996B2C2171EDD300FCC28F /* FoodPreferencesSectionModel.swift */; };
7F996B3321723D5B00FCC28F /* CustomTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F996B3221723D5B00FCC28F /* CustomTableViewCell.swift */; };
B048377E21582D4E00AFA689 /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B048377D21582D4E00AFA689 /* String+Extension.swift */; };
B050E120215169230090CB79 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B050E11F215169230090CB79 /* AppDelegate.swift */; };
B050E127215169250090CB79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B050E126215169250090CB79 /* Assets.xcassets */; };
......@@ -119,6 +120,7 @@
7F996B2721716B1600FCC28F /* FoodPreferenceModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodPreferenceModel.swift; sourceTree = "<group>"; };
7F996B2A2171D5D800FCC28F /* FoodPreferenceDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodPreferenceDelegate.swift; sourceTree = "<group>"; };
7F996B2C2171EDD300FCC28F /* FoodPreferencesSectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodPreferencesSectionModel.swift; sourceTree = "<group>"; };
7F996B3221723D5B00FCC28F /* CustomTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTableViewCell.swift; sourceTree = "<group>"; };
B048377D21582D4E00AFA689 /* String+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = "<group>"; };
B050E11C215169230090CB79 /* Amiv.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Amiv.app; sourceTree = BUILT_PRODUCTS_DIR; };
B050E11F215169230090CB79 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
......@@ -521,6 +523,7 @@
7F996B2E2171FA8C00FCC28F /* FoodPreference */,
B050E1842151A3700090CB79 /* SettingsViewController.swift */,
B050E1862151A3C40090CB79 /* SettingsViewControllerDelegate.swift */,
7F996B3221723D5B00FCC28F /* CustomTableViewCell.swift */,
);
path = Settings;
sourceTree = "<group>";
......@@ -865,6 +868,7 @@
files = (
B0FE2F1421550C4400F3D073 /* EventsViewControllerDelegate.swift in Sources */,
B0AF91422157D192008F3B80 /* KeychainKey.swift in Sources */,
7F996B3321723D5B00FCC28F /* CustomTableViewCell.swift in Sources */,
B0FE2F16215514E600F3D073 /* QuickLookDataSource.swift in Sources */,
B050E17821517EF50090CB79 /* AmivMicroAppModel.swift in Sources */,
B0AF91452157D34E008F3B80 /* JobsResponse.swift in Sources */,
......
......@@ -30,8 +30,9 @@ extension FoodPreferenceModel{
public static func createFoodPreferenceSection() -> FoodPreferenceSectionModel {
let vegetarisch = FoodPreferencesCellModel(text: "vegetarisch", action: .changeFoodPreference, cellType: .normal)
let Nichts = FoodPreferencesCellModel(text: "Keine Vorlieben", action: .changeFoodPreference, cellType: .normal)
let Other = FoodPreferencesCellModel(text: "Other Food", action: .changeFoodPreference, cellType: .normal)
return FoodPreferenceSectionModel(headerText: "Your Choice", footerText: "FooterText", cellModels: [vegetarisch, Nichts])
return FoodPreferenceSectionModel(headerText: "Your Choice", footerText: "FooterText", cellModels: [vegetarisch, Nichts, Other])
}
}
......@@ -14,6 +14,7 @@ public enum SettingsCellType {
case normal
case login
case changeValue
case custom
public func reuseIdentifier() -> String {
switch self {
......@@ -23,6 +24,8 @@ public enum SettingsCellType {
return "login"
case .changeValue:
return "changeValue"
case .custom:
return "custom"
}
}
......@@ -34,6 +37,8 @@ public enum SettingsCellType {
return .subtitle
case .login:
return .subtitle
case .custom:
return .default
}
}
}
......@@ -40,10 +40,13 @@ extension SettingsModel {
private static func createValueSection() -> SettingsSectionModel{
let food = SettingsCellModel(text: "Food Preference", detailText: "All", action: .changeValue("food"), cellType: .changeValue)
let SpecialFoodRequierements = SettingsCellModel(text: "Special Food Requierement", detailText: "Special FoodRequirement", action: .none, cellType: .custom)
let publicTransport = SettingsCellModel(text: "Public Transport", detailText: "GA", action: .changeValue("pubTrans"), cellType: .changeValue)
let pushNotification = SettingsCellModel(text: "Enabled", detailText: "Tap to disable Push Notifications", action: .changeValue("pushNotification"), cellType: .changeValue)
return SettingsSectionModel(headerText: "Settings", footerText: nil, cellModels: [food, publicTransport, pushNotification])
return SettingsSectionModel(headerText: "Settings", footerText: nil, cellModels: [food,SpecialFoodRequierements, publicTransport, pushNotification])
}
private static func createDisclosureSection() -> SettingsSectionModel {
......
//
// CustomTableViewCell.swift
// Amiv
//
// Created by Gabriel Sonderegger on 13.10.18.
// Copyright © 2018 Amiv an der ETH. All rights reserved.
//
import UIKit
class CustomTableViewCell: UITableViewCell {
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.createTextField()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func createTextField(){
let Label = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 20))
Label.text = "Food Requierement"
let sampleTextField = UITextField(frame: CGRect(x: 0, y: 0, width: 300, height: 40))
sampleTextField.textAlignment = .center
sampleTextField.placeholder = "Enter text here"
sampleTextField.font = UIFont.systemFont(ofSize: 15)
sampleTextField.borderStyle = UITextField.BorderStyle.roundedRect
sampleTextField.autocorrectionType = UITextAutocorrectionType.no
sampleTextField.keyboardType = UIKeyboardType.default
sampleTextField.returnKeyType = UIReturnKeyType.done
sampleTextField.clearButtonMode = UITextField.ViewMode.whileEditing;
sampleTextField.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center
contentView.addSubview(sampleTextField)
sampleTextField.widthAnchor.constraint(equalToConstant: 400).isActive = true
sampleTextField.heightAnchor.constraint(equalToConstant: 40).isActive = true
debugPrint(self.contentView.centerXAnchor)
sampleTextField.centerXAnchor.constraint(equalTo: self.contentView.centerXAnchor).isActive = true
sampleTextField.centerYAnchor.constraint(equalTo: self.contentView.centerYAnchor).isActive = true
}
}
......@@ -39,6 +39,10 @@ class FoodPreferenceViewController: UITableViewController {
extension FoodPreferenceViewController {
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 85
}
public override func numberOfSections(in tableView: UITableView) -> Int {
return self.model.sectionModels.count
}
......@@ -54,20 +58,21 @@ extension FoodPreferenceViewController {
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellModel = self.model.sectionModels[indexPath.section].cellModels[indexPath.row]
let cell: UITableViewCell = {
guard let cell = tableView.dequeueReusableCell(withIdentifier: cellModel.cellType.reuseIdentifier()) else {
return UITableViewCell(style: cellModel.cellType.style(), reuseIdentifier: cellModel.cellType.reuseIdentifier())
}
return cell
}()
cell.tintColor = UIColor(named: "lightBlue")
cell.textLabel?.text = cellModel.text
cell.textLabel?.textAlignment = .center
cell.textLabel?.font = UIFont(name:"Avenir", size:22)
cell.selectionStyle = cellModel.action.selectionStyle()
cell.accessoryType = cellModel.action.indicator()
return cell
}
public override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cellModel = self.model.sectionModels[indexPath.section].cellModels[indexPath.row]
......@@ -78,8 +83,6 @@ extension FoodPreferenceViewController {
case .none:
break
case .changeFoodPreference:
debugPrint("This Works")
debugPrint(self.delegate)
self.delegate?.changeFoodPreference()
}
}
......
......@@ -16,7 +16,7 @@ public class SettingsViewController: UITableViewController {
// MARK: - Variables
private var model: SettingsModel
private var CustomIdentifier = "customIdentifier"
public var delegate: SettingsViewControllerDelegate?
// MARK: - Initializers
......@@ -25,6 +25,8 @@ public class SettingsViewController: UITableViewController {
self.model = model
super.init(style: .grouped)
self.title = "Settings"
self.tableView.register(CustomTableViewCell.self, forCellReuseIdentifier: CustomIdentifier)
}
required init?(coder aDecoder: NSCoder) {
......@@ -73,25 +75,41 @@ extension SettingsViewController {
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellModel = self.model.sectionModels[indexPath.section].cellModels[indexPath.row]
var cell = UITableViewCell()
switch cellModel.cellType {
case .custom:
cell = tableView.dequeueReusableCell(withIdentifier: CustomIdentifier, for: indexPath) as! CustomTableViewCell
return cell
case .changeValue:
cell = UITableViewCell(style: cellModel.cellType.style(), reuseIdentifier: cellModel.cellType.reuseIdentifier())
populateNormalCell(cell: cell, cellModel: cellModel)
return cell
case .login:
cell = UITableViewCell(style: cellModel.cellType.style(), reuseIdentifier: cellModel.cellType.reuseIdentifier())
populateNormalCell(cell: cell, cellModel: cellModel)
return cell
case .normal:
cell = UITableViewCell(style: cellModel.cellType.style(), reuseIdentifier: cellModel.cellType.reuseIdentifier())
populateNormalCell(cell: cell, cellModel: cellModel)
return cell
}
/*
let cellModel = self.model.sectionModels[indexPath.section].cellModels[indexPath.row]
let cell: UITableViewCell = {
guard let cell = tableView.dequeueReusableCell(withIdentifier: cellModel.cellType.reuseIdentifier()) else {
return UITableViewCell(style: cellModel.cellType.style(), reuseIdentifier: cellModel.cellType.reuseIdentifier())
}
return cell
}()
*/
cell.textLabel?.text = cellModel.text
cell.detailTextLabel?.text = cellModel.detailText
cell.textLabel?.numberOfLines = 0
cell.accessoryType = cellModel.action.indicator()
cell.tintColor = UIColor(named: "lightBlue")
cell.selectionStyle = cellModel.action.selectionStyle()
return cell
}
//Was passiert wenn eine Zelle geklickt wird
public override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cellModel = self.model.sectionModels[indexPath.section].cellModels[indexPath.row]
......@@ -108,6 +126,14 @@ extension SettingsViewController {
}
}
private func populateNormalCell(cell : UITableViewCell, cellModel : SettingsCellModel){
cell.textLabel?.text = cellModel.text
cell.detailTextLabel?.text = cellModel.detailText
cell.textLabel?.numberOfLines = 0
cell.accessoryType = cellModel.action.indicator()
cell.tintColor = UIColor(named: "lightBlue")
cell.selectionStyle = cellModel.action.selectionStyle()
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment