2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// AboutViewController.swift
|
|
|
|
// Passepartout-iOS
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 9/28/18.
|
2019-03-09 10:44:44 +00:00
|
|
|
// Copyright (c) 2019 Davide De Rosa. All rights reserved.
|
2018-10-11 07:13:19 +00:00
|
|
|
//
|
2018-11-03 21:33:30 +00:00
|
|
|
// https://github.com/passepartoutvpn
|
2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// 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-05-26 06:56:39 +00:00
|
|
|
import PassepartoutCore
|
2019-10-11 08:56:23 +00:00
|
|
|
import Convenience
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
class AboutViewController: UITableViewController, StrongTableHost {
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
// MARK: StrongTableHost
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-10-11 08:56:23 +00:00
|
|
|
let model: StrongTableModel<SectionType, RowType> = {
|
|
|
|
let model: StrongTableModel<SectionType, RowType> = StrongTableModel()
|
2018-10-11 07:13:19 +00:00
|
|
|
model.add(.info)
|
2019-04-27 07:21:49 +00:00
|
|
|
model.add(.github)
|
2018-10-30 19:44:18 +00:00
|
|
|
model.add(.web)
|
2018-10-23 09:40:29 +00:00
|
|
|
model.add(.share)
|
2019-10-11 08:56:23 +00:00
|
|
|
model.setHeader("", forSection: .info)
|
|
|
|
model.setHeader("GitHub", forSection: .github)
|
|
|
|
model.setHeader(L10n.Core.About.Sections.Web.header, forSection: .web)
|
|
|
|
model.setHeader(L10n.Core.About.Sections.Share.header, forSection: .share)
|
|
|
|
model.set([.version, .credits], forSection: .info)
|
|
|
|
model.set([.readme, .changelog], forSection: .github)
|
|
|
|
model.set([.website, .faq, .disclaimer, .privacyPolicy], forSection: .web)
|
|
|
|
model.set([.shareTwitter, .shareGeneric], forSection: .share)
|
2018-10-11 07:13:19 +00:00
|
|
|
return model
|
|
|
|
}()
|
|
|
|
|
|
|
|
func reloadModel() {
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: UIViewController
|
|
|
|
|
|
|
|
override func awakeFromNib() {
|
|
|
|
super.awakeFromNib()
|
|
|
|
|
|
|
|
applyDetailTitle(Theme.current)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
2019-06-21 21:15:43 +00:00
|
|
|
title = L10n.Core.About.title
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Actions
|
|
|
|
|
|
|
|
private func showVersion() {
|
2019-04-06 21:26:41 +00:00
|
|
|
perform(segue: StoryboardSegue.About.versionSegueIdentifier)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 16:20:37 +00:00
|
|
|
private func openCredits() {
|
|
|
|
perform(segue: StoryboardSegue.About.creditsSegueIdentifier)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 16:20:37 +00:00
|
|
|
private func visit(_ url: URL) {
|
2018-10-11 07:13:19 +00:00
|
|
|
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
|
|
|
}
|
|
|
|
|
2018-10-23 09:40:29 +00:00
|
|
|
private func inviteFriend(sender: UITableViewCell?) {
|
2019-06-21 21:15:43 +00:00
|
|
|
let message = "\(L10n.Core.Share.message) \(AppConstants.URLs.website)"
|
2018-10-23 09:40:29 +00:00
|
|
|
let vc = UIActivityViewController(activityItems: [message], applicationActivities: nil)
|
|
|
|
vc.popoverPresentationController?.sourceView = sender
|
|
|
|
present(vc, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
@IBAction private func dismiss() {
|
|
|
|
dismiss(animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
extension AboutViewController {
|
|
|
|
enum SectionType: Int {
|
|
|
|
case info
|
|
|
|
|
2019-04-27 07:21:49 +00:00
|
|
|
case github
|
2019-04-26 16:20:37 +00:00
|
|
|
|
2018-10-30 19:44:18 +00:00
|
|
|
case web
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-23 09:40:29 +00:00
|
|
|
case share
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum RowType: Int {
|
|
|
|
case version
|
|
|
|
|
2019-04-27 07:21:49 +00:00
|
|
|
case credits
|
2019-04-26 16:20:37 +00:00
|
|
|
|
2019-04-27 07:21:49 +00:00
|
|
|
case readme
|
|
|
|
|
|
|
|
case changelog
|
2019-04-26 16:20:37 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case website
|
|
|
|
|
2019-02-03 21:07:10 +00:00
|
|
|
case faq
|
|
|
|
|
2018-10-29 20:22:08 +00:00
|
|
|
case disclaimer
|
|
|
|
|
2018-10-29 19:59:05 +00:00
|
|
|
case privacyPolicy
|
|
|
|
|
2018-10-23 09:28:24 +00:00
|
|
|
case shareTwitter
|
|
|
|
|
2018-10-23 09:40:29 +00:00
|
|
|
case shareGeneric
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.numberOfSections
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.header(forSection: section)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.footer(forSection: section)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 16:20:37 +00:00
|
|
|
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
|
|
return model.headerHeight(for: section)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
|
|
|
|
return model.footerHeight(for: section)
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
2019-10-11 08:56:23 +00:00
|
|
|
return model.numberOfRows(forSection: section)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
2019-04-26 16:20:37 +00:00
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2018-10-11 07:13:19 +00:00
|
|
|
switch model.row(at: indexPath) {
|
|
|
|
case .version:
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.Version.title
|
2019-10-11 08:56:23 +00:00
|
|
|
cell.rightText = ApplicationInfo.appVersion
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-04-27 07:21:49 +00:00
|
|
|
case .credits:
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.About.Cells.Credits.caption
|
2019-04-26 16:20:37 +00:00
|
|
|
|
2019-04-27 07:21:49 +00:00
|
|
|
case .readme:
|
|
|
|
cell.leftText = "README"
|
|
|
|
|
|
|
|
case .changelog:
|
|
|
|
cell.leftText = "CHANGELOG"
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .website:
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.About.Cells.Website.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-02-03 21:07:10 +00:00
|
|
|
case .faq:
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.About.Cells.Faq.caption
|
2019-02-03 21:07:10 +00:00
|
|
|
|
2018-10-29 20:22:08 +00:00
|
|
|
case .disclaimer:
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.About.Cells.Disclaimer.caption
|
2018-10-29 20:22:08 +00:00
|
|
|
|
2018-10-29 19:59:05 +00:00
|
|
|
case .privacyPolicy:
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.About.Cells.PrivacyPolicy.caption
|
2018-10-29 19:59:05 +00:00
|
|
|
|
2018-10-23 09:28:24 +00:00
|
|
|
case .shareTwitter:
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.About.Cells.ShareTwitter.caption
|
2018-10-23 09:28:24 +00:00
|
|
|
|
2018-10-23 09:40:29 +00:00
|
|
|
case .shareGeneric:
|
2019-06-21 21:15:43 +00:00
|
|
|
cell.leftText = L10n.Core.About.Cells.ShareGeneric.caption
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
2019-04-26 16:20:37 +00:00
|
|
|
return cell
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
switch model.row(at: indexPath) {
|
|
|
|
case .version:
|
|
|
|
showVersion()
|
|
|
|
|
2019-04-27 07:21:49 +00:00
|
|
|
case .credits:
|
|
|
|
openCredits()
|
|
|
|
|
|
|
|
case .readme:
|
2019-05-26 22:29:53 +00:00
|
|
|
visit(AppConstants.URLs.iOS.readme)
|
2019-04-27 07:21:49 +00:00
|
|
|
|
|
|
|
case .changelog:
|
2019-05-26 22:29:53 +00:00
|
|
|
visit(AppConstants.URLs.iOS.changelog)
|
2019-04-26 16:20:37 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .website:
|
2019-04-26 16:20:37 +00:00
|
|
|
visit(AppConstants.URLs.website)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-02-03 21:07:10 +00:00
|
|
|
case .faq:
|
2019-04-26 16:20:37 +00:00
|
|
|
visit(AppConstants.URLs.faq)
|
2019-02-03 21:07:10 +00:00
|
|
|
|
2018-10-29 20:22:08 +00:00
|
|
|
case .disclaimer:
|
2019-04-26 16:20:37 +00:00
|
|
|
visit(AppConstants.URLs.disclaimer)
|
|
|
|
|
2018-10-29 19:59:05 +00:00
|
|
|
case .privacyPolicy:
|
2019-04-26 16:20:37 +00:00
|
|
|
visit(AppConstants.URLs.privacyPolicy)
|
|
|
|
|
2018-10-23 09:28:24 +00:00
|
|
|
case .shareTwitter:
|
2019-06-21 21:15:43 +00:00
|
|
|
visit(AppConstants.URLs.twitterIntent(withMessage: L10n.Core.Share.message))
|
2019-04-26 16:20:37 +00:00
|
|
|
|
2018-10-23 09:40:29 +00:00
|
|
|
case .shareGeneric:
|
|
|
|
inviteFriend(sender: tableView.cellForRow(at: indexPath))
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
|
|
|
}
|
|
|
|
}
|