2018-11-26 15:27:15 +00:00
|
|
|
//
|
|
|
|
// CreditsViewController.swift
|
|
|
|
// Passepartout-iOS
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 11/26/18.
|
2019-03-09 10:44:44 +00:00
|
|
|
// Copyright (c) 2019 Davide De Rosa. All rights reserved.
|
2018-11-26 15:27:15 +00:00
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2019-03-18 10:52:19 +00:00
|
|
|
import Passepartout_Core
|
2018-11-26 15:27:15 +00:00
|
|
|
|
|
|
|
class CreditsViewController: UITableViewController, TableModelHost {
|
|
|
|
private let licenses = AppConstants.License.all
|
|
|
|
|
|
|
|
private let notices = AppConstants.Notice.all
|
|
|
|
|
|
|
|
// MARK: TableModelHost
|
|
|
|
|
|
|
|
var model: TableModel<SectionType, RowType> = TableModel()
|
|
|
|
|
|
|
|
func reloadModel() {
|
|
|
|
model.add(.licenses)
|
|
|
|
model.add(.notices)
|
|
|
|
|
|
|
|
model.setHeader(L10n.Credits.Sections.Licenses.header, for: .licenses)
|
|
|
|
model.setHeader(L10n.Credits.Sections.Notices.header, for: .notices)
|
|
|
|
|
|
|
|
model.set(.license, count: licenses.count, in: .licenses)
|
|
|
|
model.set(.notice, count: notices.count, in: .notices)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: UIViewController
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
title = L10n.Credits.title
|
|
|
|
reloadModel()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
|
|
guard let vc = segue.destination as? LabelViewController else {
|
|
|
|
return
|
|
|
|
}
|
2018-11-26 16:18:58 +00:00
|
|
|
guard let cell = sender as? SettingTableViewCell, let indexPath = tableView.indexPath(for: cell) else {
|
2018-11-26 15:27:15 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
vc.title = cell.leftText
|
2018-11-26 16:18:58 +00:00
|
|
|
switch model.row(at: indexPath) {
|
|
|
|
case .license:
|
2018-12-04 09:41:33 +00:00
|
|
|
vc.license = licenses[indexPath.row]
|
2018-11-26 16:18:58 +00:00
|
|
|
|
|
|
|
case .notice:
|
|
|
|
vc.text = notices[indexPath.row].statement
|
|
|
|
}
|
2018-11-26 15:27:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension CreditsViewController {
|
|
|
|
enum SectionType: Int {
|
|
|
|
case licenses
|
|
|
|
|
|
|
|
case notices
|
|
|
|
}
|
|
|
|
|
|
|
|
enum RowType: Int {
|
|
|
|
case license
|
|
|
|
|
|
|
|
case notice
|
|
|
|
}
|
|
|
|
|
|
|
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
|
return model.count
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
|
|
|
return model.header(for: section)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
|
return model.count(for: section)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
switch model.row(at: indexPath) {
|
|
|
|
case .license:
|
|
|
|
let obj = licenses[indexPath.row]
|
|
|
|
cell.leftText = obj.name
|
|
|
|
cell.rightText = obj.type
|
|
|
|
|
|
|
|
case .notice:
|
|
|
|
let obj = notices[indexPath.row]
|
|
|
|
cell.leftText = obj.name
|
|
|
|
cell.rightText = nil
|
|
|
|
}
|
|
|
|
return cell
|
|
|
|
}
|
|
|
|
}
|