2018-10-11 07:13:19 +00:00
|
|
|
//
|
|
|
|
// Theme.swift
|
|
|
|
// Passepartout-iOS
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 6/14/18.
|
2020-01-11 08:27:22 +00:00
|
|
|
// Copyright (c) 2020 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
|
|
|
|
import MessageUI
|
2019-04-06 21:58:19 +00:00
|
|
|
import StoreKit
|
2019-05-26 06:56:39 +00:00
|
|
|
import PassepartoutCore
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
struct Theme {
|
|
|
|
struct Palette {
|
2019-04-08 20:44:57 +00:00
|
|
|
var primaryBackground = UIColor(rgb: 0x515d71, alpha: 1.0)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-04-08 20:44:57 +00:00
|
|
|
var accent1 = UIColor(rgb: 0xd69c68, alpha: 1.0)
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-09-02 17:51:21 +00:00
|
|
|
var primaryText: UIColor = {
|
|
|
|
guard #available(iOS 13, *) else {
|
|
|
|
return .darkText
|
|
|
|
}
|
|
|
|
return .label
|
|
|
|
}()
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-04-08 20:44:57 +00:00
|
|
|
var primaryLightText: UIColor = .white
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-09-02 17:51:21 +00:00
|
|
|
var secondaryText: UIColor = {
|
|
|
|
guard #available(iOS 13, *) else {
|
|
|
|
return .gray
|
|
|
|
}
|
|
|
|
return .secondaryLabel
|
|
|
|
}()
|
2018-10-11 07:13:19 +00:00
|
|
|
|
2019-04-08 20:44:57 +00:00
|
|
|
var on: UIColor {
|
|
|
|
return accent1
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 20:44:57 +00:00
|
|
|
var indeterminate: UIColor {
|
|
|
|
return secondaryText
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 20:44:57 +00:00
|
|
|
var off: UIColor {
|
|
|
|
return secondaryText
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 20:44:57 +00:00
|
|
|
// var action = UIColor(red: 214.0 / 255.0, green: 156.0 / 255.0, blue: 104.0 / 255.0, alpha: 1.0)
|
|
|
|
var action: UIColor {
|
|
|
|
return accent1
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 20:44:57 +00:00
|
|
|
var accessory: UIColor {
|
|
|
|
return accent1.withAlphaComponent(0.7)
|
2018-10-14 22:12:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 20:44:57 +00:00
|
|
|
var destructive = UIColor(red: 0.8, green: 0.27, blue: 0.2, alpha: 1.0)
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static let current = Theme()
|
|
|
|
|
|
|
|
var palette: Palette
|
|
|
|
|
2019-04-09 08:34:19 +00:00
|
|
|
var modalPresentationStyle: UIModalPresentationStyle
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
private init() {
|
|
|
|
palette = Palette()
|
2019-04-09 08:34:19 +00:00
|
|
|
modalPresentationStyle = .formSheet
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Theme {
|
|
|
|
func applyAppearance() {
|
|
|
|
let bar = UINavigationBar.appearance()
|
2019-04-08 20:44:57 +00:00
|
|
|
bar.barTintColor = palette.primaryBackground
|
|
|
|
bar.tintColor = palette.primaryLightText
|
|
|
|
bar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: palette.primaryLightText]
|
2018-10-11 07:13:19 +00:00
|
|
|
bar.largeTitleTextAttributes = bar.titleTextAttributes
|
2020-05-26 21:59:40 +00:00
|
|
|
|
|
|
|
let pickerBar = UINavigationBar.appearance(whenContainedInInstancesOf: [UIDocumentBrowserViewController.self])
|
2020-05-27 05:38:35 +00:00
|
|
|
pickerBar.barTintColor = nil
|
2020-05-26 21:59:40 +00:00
|
|
|
pickerBar.tintColor = nil
|
2020-05-27 05:38:35 +00:00
|
|
|
pickerBar.titleTextAttributes = nil
|
|
|
|
pickerBar.largeTitleTextAttributes = nil
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
let toolbar = UIToolbar.appearance()
|
2019-04-08 20:44:57 +00:00
|
|
|
toolbar.barTintColor = palette.primaryBackground
|
|
|
|
toolbar.tintColor = palette.primaryLightText
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
let toggle = UISwitch.appearance()
|
2019-04-08 20:44:57 +00:00
|
|
|
toggle.onTintColor = palette.accessory
|
2019-04-08 19:10:28 +00:00
|
|
|
|
|
|
|
let activity = UIActivityIndicatorView.appearance()
|
|
|
|
activity.color = palette.accessory
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 22:20:22 +00:00
|
|
|
extension UIViewController {
|
|
|
|
func applyModalPresentation(_ theme: Theme) {
|
|
|
|
modalPresentationStyle = theme.modalPresentationStyle
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-12 17:04:43 +00:00
|
|
|
//extension UIView {
|
|
|
|
// func applyPrimaryBackground(_ theme: Theme) {
|
|
|
|
// backgroundColor = theme.palette.primaryBackground
|
|
|
|
// }
|
|
|
|
//}
|
2018-10-11 07:13:19 +00:00
|
|
|
|
|
|
|
extension UILabel {
|
|
|
|
func apply(_ theme: Theme) {
|
2019-11-20 18:17:34 +00:00
|
|
|
font = .preferredFont(forTextStyle: .body)
|
2019-04-08 20:44:57 +00:00
|
|
|
textColor = theme.palette.primaryText
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func applyLight(_ theme: Theme) {
|
2019-11-20 18:17:34 +00:00
|
|
|
font = .preferredFont(forTextStyle: .body)
|
2019-04-08 20:44:57 +00:00
|
|
|
textColor = theme.palette.primaryLightText
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
2019-10-30 12:12:58 +00:00
|
|
|
|
|
|
|
func applyAccent(_ theme: Theme) {
|
2019-11-20 18:17:34 +00:00
|
|
|
font = .preferredFont(forTextStyle: .body)
|
2019-10-30 12:12:58 +00:00
|
|
|
textColor = theme.palette.accent1
|
|
|
|
}
|
2019-11-20 19:00:51 +00:00
|
|
|
|
|
|
|
func applySecondarySize(_ theme: Theme) {
|
|
|
|
font = .preferredFont(forTextStyle: .callout)
|
|
|
|
}
|
2018-10-11 07:13:19 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 10:19:59 +00:00
|
|
|
extension UITextField {
|
2020-05-11 20:53:09 +00:00
|
|
|
func applyHostTitle(_ theme: Theme) {
|
2019-06-21 21:15:43 +00:00
|
|
|
placeholder = L10n.Core.Global.Host.TitleInput.placeholder
|
2018-11-02 10:19:59 +00:00
|
|
|
clearButtonMode = .always
|
2020-05-11 20:53:09 +00:00
|
|
|
keyboardType = .default
|
2018-11-02 10:19:59 +00:00
|
|
|
returnKeyType = .done
|
|
|
|
autocapitalizationType = .none
|
|
|
|
autocorrectionType = .no
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 08:02:33 +00:00
|
|
|
extension UIActivityIndicatorView {
|
|
|
|
func applyAccent(_ theme: Theme) {
|
2019-04-08 20:44:57 +00:00
|
|
|
color = theme.palette.accent1
|
2018-12-01 08:02:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-21 14:01:39 +00:00
|
|
|
extension UIBarButtonItem {
|
|
|
|
func apply(_ theme: Theme) {
|
|
|
|
tintColor = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func applyAccent(_ theme: Theme) {
|
|
|
|
tintColor = theme.palette.accent1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-21 14:08:05 +00:00
|
|
|
extension UIContextualAction {
|
|
|
|
func applyNormal(_ theme: Theme) {
|
|
|
|
backgroundColor = theme.palette.primaryBackground
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
// XXX: status bar is broken
|
|
|
|
extension MFMailComposeViewController {
|
|
|
|
func apply(_ theme: Theme) {
|
2019-04-09 08:34:19 +00:00
|
|
|
modalPresentationStyle = theme.modalPresentationStyle
|
|
|
|
|
2018-10-11 07:13:19 +00:00
|
|
|
let bar = navigationBar
|
2019-04-08 20:44:57 +00:00
|
|
|
bar.barTintColor = theme.palette.primaryBackground
|
|
|
|
bar.tintColor = theme.palette.primaryLightText
|
|
|
|
bar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: theme.palette.primaryLightText]
|
2018-10-11 07:13:19 +00:00
|
|
|
bar.largeTitleTextAttributes = bar.titleTextAttributes
|
|
|
|
}
|
|
|
|
}
|
2019-04-04 22:18:50 +00:00
|
|
|
|
2019-11-23 13:22:34 +00:00
|
|
|
extension Infrastructure.Metadata {
|
2019-11-30 10:04:16 +00:00
|
|
|
var logo: UIImage? {
|
|
|
|
let bundle = Bundle(for: AppDelegate.self)
|
2020-07-07 21:34:42 +00:00
|
|
|
guard let image = ImageAsset.Image(named: name, in: bundle, compatibleWith: nil) else {
|
2019-11-30 10:04:16 +00:00
|
|
|
return Asset.Providers.placeholder.image
|
|
|
|
}
|
|
|
|
return image
|
2019-04-05 09:59:39 +00:00
|
|
|
}
|
2020-02-29 16:56:24 +00:00
|
|
|
|
|
|
|
var guidanceString: String? {
|
|
|
|
let key = "account.sections.guidance.footer.infrastructure.\(name)"
|
|
|
|
let format = NSLocalizedString(key, tableName: "Core", bundle: Bundle(for: AppDelegate.self), comment: "")
|
2020-05-09 15:33:19 +00:00
|
|
|
guard format != key else {
|
2020-02-29 16:56:24 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return String(format: format, locale: .current, description)
|
|
|
|
}
|
2019-04-05 09:59:39 +00:00
|
|
|
}
|
2019-04-04 22:18:50 +00:00
|
|
|
|
2019-04-25 18:40:50 +00:00
|
|
|
extension PoolGroup {
|
2019-04-04 22:18:50 +00:00
|
|
|
var logo: UIImage? {
|
2019-04-05 09:59:39 +00:00
|
|
|
return ImageAsset(name: country.lowercased()).image
|
2019-04-04 22:18:50 +00:00
|
|
|
}
|
|
|
|
}
|