2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// AboutViewController.swift
|
|
|
|
// Passepartout-iOS
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 9/28/18.
|
|
|
|
// Copyright (c) 2018 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// https://github.com/keeshux
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
|
class AboutViewController: UITableViewController, TableModelHost {
|
|
|
|
|
|
|
|
// MARK: TableModelHost
|
|
|
|
|
|
|
|
let model: TableModel<SectionType, RowType> = {
|
|
|
|
let model: TableModel<SectionType, RowType> = TableModel()
|
|
|
|
model.add(.info)
|
|
|
|
model.add(.source)
|
2018-10-23 09:40:29 +00:00
|
|
|
model.add(.share)
|
2018-10-11 07:13:19 +00:00
|
|
|
model.add(.feedback)
|
|
|
|
model.setHeader(L10n.About.Sections.Info.header, for: .info)
|
|
|
|
model.setHeader(L10n.About.Sections.Source.header, for: .source)
|
2018-10-23 09:40:29 +00:00
|
|
|
model.setHeader(L10n.About.Sections.Share.header, for: .share)
|
2018-10-11 07:13:19 +00:00
|
|
|
model.setHeader(L10n.About.Sections.Feedback.header, for: .feedback)
|
2018-10-29 20:22:08 +00:00
|
|
|
model.set([.version, .website, .disclaimer, .privacyPolicy], in: .info)
|
2018-10-11 07:13:19 +00:00
|
|
|
model.set([.sourcePassepartout, .sourceTunnelKit], in: .source)
|
2018-10-23 09:40:29 +00:00
|
|
|
model.set([.shareTwitter, .shareGeneric], in: .share)
|
2018-10-24 19:57:27 +00:00
|
|
|
model.set([.joinCommunity, .writeReview], in: .feedback)
|
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()
|
|
|
|
|
|
|
|
title = L10n.About.title
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Actions
|
|
|
|
|
|
|
|
private func showVersion() {
|
|
|
|
perform(segue: StoryboardSegue.Organizer.versionSegueIdentifier)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func visitWebsite() {
|
|
|
|
UIApplication.shared.open(AppConstants.URLs.website, options: [:], completionHandler: nil)
|
|
|
|
}
|
|
|
|
|
2018-10-29 20:22:08 +00:00
|
|
|
private func visitDisclaimer() {
|
|
|
|
UIApplication.shared.open(AppConstants.URLs.disclaimer, options: [:], completionHandler: nil)
|
|
|
|
}
|
|
|
|
|
2018-10-29 19:59:05 +00:00
|
|
|
private func visitPrivacyPolicy() {
|
|
|
|
UIApplication.shared.open(AppConstants.URLs.privacyPolicy, options: [:], completionHandler: nil)
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
private func visitRepository(_ url: URL) {
|
|
|
|
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
|
|
|
}
|
|
|
|
|
2018-10-23 09:28:24 +00:00
|
|
|
private func tweetAboutApp() {
|
|
|
|
UIApplication.shared.open(AppConstants.URLs.twitterIntent, options: [:], completionHandler: nil)
|
|
|
|
}
|
|
|
|
|
2018-10-23 09:40:29 +00:00
|
|
|
private func inviteFriend(sender: UITableViewCell?) {
|
|
|
|
let message = "\(L10n.Share.message) \(AppConstants.URLs.website)"
|
|
|
|
let vc = UIActivityViewController(activityItems: [message], applicationActivities: nil)
|
|
|
|
vc.popoverPresentationController?.sourceView = sender
|
|
|
|
present(vc, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func postSupportRequest() {
|
|
|
|
UIApplication.shared.open(AppConstants.URLs.subreddit, options: [:], completionHandler: nil)
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
private func writeReview() {
|
|
|
|
let url = AppConstants.URLs.review(withId: GroupConstants.App.appId)
|
|
|
|
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction private func dismiss() {
|
|
|
|
dismiss(animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
extension AboutViewController {
|
|
|
|
enum SectionType: Int {
|
|
|
|
case info
|
|
|
|
|
|
|
|
case source
|
|
|
|
|
2018-10-23 09:40:29 +00:00
|
|
|
case share
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case feedback
|
|
|
|
}
|
|
|
|
|
|
|
|
enum RowType: Int {
|
|
|
|
case version
|
|
|
|
|
|
|
|
case website
|
|
|
|
|
2018-10-29 20:22:08 +00:00
|
|
|
case disclaimer
|
|
|
|
|
2018-10-29 19:59:05 +00:00
|
|
|
case privacyPolicy
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case sourcePassepartout
|
|
|
|
|
|
|
|
case sourceTunnelKit
|
|
|
|
|
2018-10-23 09:28:24 +00:00
|
|
|
case shareTwitter
|
|
|
|
|
2018-10-23 09:40:29 +00:00
|
|
|
case shareGeneric
|
|
|
|
|
2018-10-24 19:57:27 +00:00
|
|
|
case joinCommunity
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2018-10-17 21:24:58 +00:00
|
|
|
case writeReview
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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, titleForFooterInSection section: Int) -> String? {
|
|
|
|
return model.footer(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 {
|
|
|
|
switch model.row(at: indexPath) {
|
|
|
|
case .version:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2018-10-29 19:44:01 +00:00
|
|
|
cell.leftText = L10n.Version.title
|
2018-10-11 07:13:19 +00:00
|
|
|
cell.rightText = Utils.versionString()
|
|
|
|
return cell
|
|
|
|
|
|
|
|
case .website:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
cell.leftText = L10n.About.Cells.Website.caption
|
|
|
|
return cell
|
|
|
|
|
2018-10-29 20:22:08 +00:00
|
|
|
case .disclaimer:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
cell.leftText = L10n.About.Cells.Disclaimer.caption
|
|
|
|
return cell
|
|
|
|
|
2018-10-29 19:59:05 +00:00
|
|
|
case .privacyPolicy:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
cell.leftText = L10n.About.Cells.PrivacyPolicy.caption
|
|
|
|
return cell
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .sourcePassepartout:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
cell.leftText = GroupConstants.App.name
|
|
|
|
return cell
|
|
|
|
|
|
|
|
case .sourceTunnelKit:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
cell.leftText = GroupConstants.App.tunnelKitName
|
|
|
|
return cell
|
|
|
|
|
2018-10-23 09:28:24 +00:00
|
|
|
case .shareTwitter:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
cell.leftText = L10n.About.Cells.ShareTwitter.caption
|
|
|
|
return cell
|
|
|
|
|
2018-10-23 09:40:29 +00:00
|
|
|
case .shareGeneric:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
cell.leftText = L10n.About.Cells.ShareGeneric.caption
|
|
|
|
return cell
|
|
|
|
|
2018-10-24 19:57:27 +00:00
|
|
|
case .joinCommunity:
|
2018-10-17 21:24:58 +00:00
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
2018-10-24 19:57:27 +00:00
|
|
|
cell.leftText = L10n.About.Cells.JoinCommunity.caption
|
2018-10-17 21:24:58 +00:00
|
|
|
return cell
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .writeReview:
|
|
|
|
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
|
|
|
cell.leftText = L10n.About.Cells.WriteReview.caption
|
|
|
|
return cell
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
switch model.row(at: indexPath) {
|
|
|
|
case .version:
|
|
|
|
showVersion()
|
|
|
|
|
|
|
|
case .website:
|
|
|
|
visitWebsite()
|
|
|
|
|
2018-10-29 20:22:08 +00:00
|
|
|
case .disclaimer:
|
|
|
|
visitDisclaimer()
|
|
|
|
|
2018-10-29 19:59:05 +00:00
|
|
|
case .privacyPolicy:
|
|
|
|
visitPrivacyPolicy()
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .sourcePassepartout:
|
|
|
|
visitRepository(AppConstants.Repos.passepartout)
|
|
|
|
|
|
|
|
case .sourceTunnelKit:
|
|
|
|
visitRepository(AppConstants.Repos.tunnelKit)
|
|
|
|
|
2018-10-23 09:28:24 +00:00
|
|
|
case .shareTwitter:
|
|
|
|
tweetAboutApp()
|
|
|
|
|
2018-10-23 09:40:29 +00:00
|
|
|
case .shareGeneric:
|
|
|
|
inviteFriend(sender: tableView.cellForRow(at: indexPath))
|
|
|
|
|
2018-10-24 19:57:27 +00:00
|
|
|
case .joinCommunity:
|
2018-10-22 20:42:42 +00:00
|
|
|
postSupportRequest()
|
2018-10-17 21:24:58 +00:00
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
case .writeReview:
|
|
|
|
writeReview()
|
|
|
|
}
|
|
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
|
|
|
}
|
|
|
|
}
|