Verified Commit 99faaa35 authored by Geoff Pado's avatar Geoff Pado

Clean up settings view controller classes

parent 8824cec6
......@@ -37,6 +37,10 @@
043CD9D62275316E0012F5AE /* PhotoEditingScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043CD9D52275316E0012F5AE /* PhotoEditingScrollView.swift */; };
043CD9D8227531DF0012F5AE /* PhotoEditingObservationVisualizationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043CD9D7227531DF0012F5AE /* PhotoEditingObservationVisualizationView.swift */; };
043CD9DB22753D510012F5AE /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043CD9DA22753D510012F5AE /* SettingsViewController.swift */; };
043CD9DD227548C20012F5AE /* SettingsTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043CD9DC227548C20012F5AE /* SettingsTableView.swift */; };
043CD9DF227548F30012F5AE /* SettingsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043CD9DE227548F30012F5AE /* SettingsTableViewCell.swift */; };
043CD9E12275490E0012F5AE /* SettingsContentProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043CD9E02275490E0012F5AE /* SettingsContentProvider.swift */; };
043CD9E3227549330012F5AE /* SettingsTableViewDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043CD9E2227549330012F5AE /* SettingsTableViewDataSource.swift */; };
047072932268134500FF20B6 /* PhotoEditingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047072922268134500FF20B6 /* PhotoEditingView.swift */; };
047072952268137900FF20B6 /* PhotoEditingImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047072942268137900FF20B6 /* PhotoEditingImageView.swift */; };
048909F2226571AB0048E203 /* PhotoEditingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048909F1226571AB0048E203 /* PhotoEditingViewController.swift */; };
......@@ -94,6 +98,10 @@
043CD9D52275316E0012F5AE /* PhotoEditingScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoEditingScrollView.swift; sourceTree = "<group>"; };
043CD9D7227531DF0012F5AE /* PhotoEditingObservationVisualizationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoEditingObservationVisualizationView.swift; sourceTree = "<group>"; };
043CD9DA22753D510012F5AE /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
043CD9DC227548C20012F5AE /* SettingsTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsTableView.swift; sourceTree = "<group>"; };
043CD9DE227548F30012F5AE /* SettingsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsTableViewCell.swift; sourceTree = "<group>"; };
043CD9E02275490E0012F5AE /* SettingsContentProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsContentProvider.swift; sourceTree = "<group>"; };
043CD9E2227549330012F5AE /* SettingsTableViewDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsTableViewDataSource.swift; sourceTree = "<group>"; };
047072922268134500FF20B6 /* PhotoEditingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoEditingView.swift; sourceTree = "<group>"; };
047072942268137900FF20B6 /* PhotoEditingImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoEditingImageView.swift; sourceTree = "<group>"; };
048909F1226571AB0048E203 /* PhotoEditingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoEditingViewController.swift; sourceTree = "<group>"; };
......@@ -226,6 +234,10 @@
isa = PBXGroup;
children = (
043CD9DA22753D510012F5AE /* SettingsViewController.swift */,
043CD9DC227548C20012F5AE /* SettingsTableView.swift */,
043CD9DE227548F30012F5AE /* SettingsTableViewCell.swift */,
043CD9E02275490E0012F5AE /* SettingsContentProvider.swift */,
043CD9E2227549330012F5AE /* SettingsTableViewDataSource.swift */,
);
path = Settings;
sourceTree = "<group>";
......@@ -414,11 +426,13 @@
buildActionMask = 2147483647;
files = (
043CD9D8227531DF0012F5AE /* PhotoEditingObservationVisualizationView.swift in Sources */,
043CD9E3227549330012F5AE /* SettingsTableViewDataSource.swift in Sources */,
041EFF5D2255A85F0058D8EE /* NavigationController.swift in Sources */,
041EFF492252FAF50058D8EE /* IntroViewController.swift in Sources */,
047072952268137900FF20B6 /* PhotoEditingImageView.swift in Sources */,
043CD9CF226EB0C70012F5AE /* DetectedTextObservation.swift in Sources */,
047072932268134500FF20B6 /* PhotoEditingView.swift in Sources */,
043CD9E12275490E0012F5AE /* SettingsContentProvider.swift in Sources */,
041EFF6B225C36350058D8EE /* PhotoLibraryViewController.swift in Sources */,
043CD9DB22753D510012F5AE /* SettingsViewController.swift in Sources */,
041EFF70225C3D830058D8EE /* PhotoLibraryView.swift in Sources */,
......@@ -435,11 +449,13 @@
041EFF192251AAFE0058D8EE /* UIViewControllerExtensions.swift in Sources */,
041EFF52225303430058D8EE /* PromptButton.swift in Sources */,
041EFEF92251A9F30058D8EE /* AppDelegate.swift in Sources */,
043CD9DD227548C20012F5AE /* SettingsTableView.swift in Sources */,
041EFF76225C3DF10058D8EE /* PhotoLibraryViewLayout.swift in Sources */,
04D68BC7225EE2FD00D09BBD /* PhotoLibraryViewCellImageView.swift in Sources */,
041EFF5B2255A39D0058D8EE /* Fonts.swift in Sources */,
041EFF50225303120058D8EE /* PromptLabel.swift in Sources */,
043CD9D1226EB0F60012F5AE /* UIImageExtensions.swift in Sources */,
043CD9DF227548F30012F5AE /* SettingsTableViewCell.swift in Sources */,
041EFF1B2251AB8D0058D8EE /* AppWindow.swift in Sources */,
041EFF4E225302CC0058D8EE /* IntroView.swift in Sources */,
041EFF74225C3DD20058D8EE /* PhotoLibraryViewCell.swift in Sources */,
......
// Created by Geoff Pado on 4/27/19.
// Copyright © 2019 Cocoatype, LLC. All rights reserved.
import Foundation
class SettingsContentProvider: NSObject {
enum Section: Equatable {
case about, otherApps
var items: [Item] {
switch self {
case .about: return [.about, .privacy, .acknowledgements, .contact]
case .otherApps: return []
}
}
var header: String? { return nil }
}
enum Item: Equatable {
case about, acknowledgements, contact, otherApp, privacy
var title: String {
switch self {
case .about: return NSLocalizedString("SettingsContentProvider.Item.about", comment: "Title for the about settings item")
case .acknowledgements: return NSLocalizedString("SettingsContentProvider.Item.acknowledgements", comment: "Title for the acknowledgements settings item")
case .contact: return NSLocalizedString("SettingsContentProvider.Item.contact", comment: "Title for the contact settings item")
case .otherApp: return ""
case .privacy: return NSLocalizedString("SettingsContentProvider.Item.privacy", comment: "Title for the privacy policy settings item")
}
}
}
private var sections: [Section] { return [.about, .otherApps] }
// MARK: Data
func sectionIndex(for section: Section) -> Int? {
return sections.firstIndex(where: { $0 == section })
}
var numberOfSections: Int {
return sections.count
}
func numberOfItems(inSectionAtIndex index: Int) -> Int {
return sections[index].items.count
}
func section(at index: Int) -> Section {
return sections[index]
}
func item(at indexPath: IndexPath) -> Item {
return sections[indexPath.section].items[indexPath.row]
}
}
// Created by Geoff Pado on 4/27/19.
// Copyright © 2019 Cocoatype, LLC. All rights reserved.
import UIKit
class SettingsTableView: UITableView {
init() {
super.init(frame: .zero, style: .grouped)
register(SettingsTableViewCell.self, forCellReuseIdentifier: SettingsTableViewCell.identifier)
}
// MARK: Boilerplate
@available(*, unavailable)
required init(coder: NSCoder) {
let className = String(describing: type(of: self))
fatalError("\(className) does not implement init(coder:)")
}
}
// Created by Geoff Pado on 4/27/19.
// Copyright © 2019 Cocoatype, LLC. All rights reserved.
import UIKit
class SettingsTableViewCell: UITableViewCell {
static let identifier = "SettingsTableViewCell.identifier"
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: .value1, reuseIdentifier: SettingsTableViewCell.identifier)
accessoryType = .disclosureIndicator
}
var item: SettingsContentProvider.Item? {
didSet {
textLabel?.text = item?.title
}
}
// MARK: Boilerplate
@available(*, unavailable)
required init(coder: NSCoder) {
let className = String(describing: type(of: self))
fatalError("\(className) does not implement init(coder:)")
}
}
// Created by Geoff Pado on 4/27/19.
// Copyright © 2019 Cocoatype, LLC. All rights reserved.
import UIKit
class SettingsTableViewDataSource: NSObject, UITableViewDataSource {
init(contentProvider: SettingsContentProvider) {
self.contentProvider = contentProvider
super.init()
}
// MARK: UITableViewDataSource
func numberOfSections(in tableView: UITableView) -> Int {
return contentProvider.numberOfSections
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return contentProvider.numberOfItems(inSectionAtIndex: section)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: SettingsTableViewCell.identifier, for: indexPath)
guard let settingsCell = (cell as? SettingsTableViewCell) else { fatalError("Settings table view cell is not a SettingsTableViewCell") }
settingsCell.item = contentProvider.item(at: indexPath)
return cell
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return contentProvider.section(at: section).header
}
// MARK: Boilerplate
private var contentProvider: SettingsContentProvider
}
......@@ -25,128 +25,3 @@ class SettingsViewController: UIViewController {
fatalError("\(className) does not implement init(coder:)")
}
}
class SettingsTableView: UITableView {
init() {
super.init(frame: .zero, style: .grouped)
register(SettingsTableViewCell.self, forCellReuseIdentifier: SettingsTableViewCell.identifier)
}
// MARK: Boilerplate
@available(*, unavailable)
required init(coder: NSCoder) {
let className = String(describing: type(of: self))
fatalError("\(className) does not implement init(coder:)")
}
}
class SettingsTableViewCell: UITableViewCell {
static let identifier = "SettingsTableViewCell.identifier"
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: .value1, reuseIdentifier: SettingsTableViewCell.identifier)
accessoryType = .disclosureIndicator
}
var item: SettingsContentProvider.Item? {
didSet {
textLabel?.text = item?.title
}
}
// MARK: Boilerplate
@available(*, unavailable)
required init(coder: NSCoder) {
let className = String(describing: type(of: self))
fatalError("\(className) does not implement init(coder:)")
}
}
class SettingsContentProvider: NSObject {
enum Section: Equatable {
case about, otherApps
var items: [Item] {
switch self {
case .about: return [.about, .privacy, .acknowledgements, .contact]
case .otherApps: return []
}
}
var header: String? { return nil }
}
enum Item: Equatable {
case about, acknowledgements, contact, otherApp, privacy
var title: String {
switch self {
case .about: return NSLocalizedString("SettingsContentProvider.Item.about", comment: "Title for the about settings item")
case .acknowledgements: return NSLocalizedString("SettingsContentProvider.Item.acknowledgements", comment: "Title for the acknowledgements settings item")
case .contact: return NSLocalizedString("SettingsContentProvider.Item.contact", comment: "Title for the contact settings item")
case .otherApp: return ""
case .privacy: return NSLocalizedString("SettingsContentProvider.Item.privacy", comment: "Title for the privacy policy settings item")
}
}
}
private var sections: [Section] { return [.about, .otherApps] }
// MARK: Data
func sectionIndex(for section: Section) -> Int? {
return sections.firstIndex(where: { $0 == section })
}
var numberOfSections: Int {
return sections.count
}
func numberOfItems(inSectionAtIndex index: Int) -> Int {
return sections[index].items.count
}
func section(at index: Int) -> Section {
return sections[index]
}
func item(at indexPath: IndexPath) -> Item {
return sections[indexPath.section].items[indexPath.row]
}
}
class SettingsTableViewDataSource: NSObject, UITableViewDataSource {
init(contentProvider: SettingsContentProvider) {
self.contentProvider = contentProvider
super.init()
}
// MARK: UITableViewDataSource
func numberOfSections(in tableView: UITableView) -> Int {
return contentProvider.numberOfSections
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return contentProvider.numberOfItems(inSectionAtIndex: section)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: SettingsTableViewCell.identifier, for: indexPath)
guard let settingsCell = (cell as? SettingsTableViewCell) else { fatalError("Settings table view cell is not a SettingsTableViewCell") }
settingsCell.item = contentProvider.item(at: indexPath)
return cell
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return contentProvider.section(at: section).header
}
// MARK: Boilerplate
private var contentProvider: SettingsContentProvider
}
Markdown is supported
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