Verified Commit bd7f5e5b authored by Geoff Pado's avatar Geoff Pado

Add content to settings page

parent eefe8d4c
......@@ -9,10 +9,14 @@ class SettingsViewController: UIViewController {
}
override func loadView() {
view = SettingsTableView()
let tableView = SettingsTableView()
tableView.dataSource = dataSource
view = tableView
}
// MARK: Boilerplate
private let contentProvider = SettingsContentProvider()
private lazy var dataSource = SettingsTableViewDataSource(contentProvider: contentProvider)
@available(*, unavailable)
required init(coder: NSCoder) {
......@@ -43,6 +47,12 @@ class SettingsTableViewCell: UITableViewCell {
super.init(style: .value1, reuseIdentifier: SettingsTableViewCell.identifier)
}
var item: SettingsContentProvider.Item? {
didSet {
textLabel?.text = item?.title
}
}
// MARK: Boilerplate
@available(*, unavailable)
......@@ -51,3 +61,90 @@ class SettingsTableViewCell: UITableViewCell {
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