Skip to content

Commit

Permalink
PIA-675: Moved UI related code from PIALibrary (#34)
Browse files Browse the repository at this point in the history
Co-authored-by: Waleed Mahmood <[email protected]>
  • Loading branch information
kp-said-rehouni and Waleed Mahmood authored Nov 22, 2023
1 parent cc600bd commit 49ec8a1
Show file tree
Hide file tree
Showing 247 changed files with 16,437 additions and 2,576 deletions.
484 changes: 435 additions & 49 deletions PIA VPN.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions PIA VPN/AboutComponentCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ class AboutLicenseCell: UITableViewCell, Restylable {

var moreImage: UIImage?
if isExpanded {
moreImage = Asset.buttonUp.image
moreImage = Asset.Images.buttonUp.image
textLicense.isScrollEnabled = true
} else {
moreImage = Asset.buttonDown.image
moreImage = Asset.Images.buttonDown.image
textLicense.isScrollEnabled = false
}
buttonMore.setImage(moreImage, for: .normal)

buttonName.accessibilityTraits = UIAccessibilityTraits.none
buttonName.accessibilityLabel = component.name
buttonName.accessibilityHint = L10n.About.Accessibility.Component.expand
buttonName.accessibilityHint = L10n.Localizable.About.Accessibility.Component.expand
}

// MARK: Actions
Expand Down
8 changes: 4 additions & 4 deletions PIA VPN/AboutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AboutViewController: AutolayoutViewController {
override func viewDidLoad() {
super.viewDidLoad()

let textApp = L10n.About.app
let textApp = L10n.Localizable.About.app
labelIntro.text = "Copyright © \(AppConfiguration.About.copyright) \(AppConfiguration.About.companyName)\n\(textApp) \(Macros.versionFullString()!)"
tableView.scrollsToTop = true

Expand All @@ -67,7 +67,7 @@ class AboutViewController: AutolayoutViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
styleNavigationBarWithTitle(L10n.Menu.Item.about)
styleNavigationBarWithTitle(L10n.Localizable.Menu.Item.about)
}

override func viewDidLayoutSubviews() {
Expand All @@ -92,7 +92,7 @@ class AboutViewController: AutolayoutViewController {
// MARK: Helpers

@objc private func viewHasRotated() {
styleNavigationBarWithTitle(L10n.Menu.Item.settings)
styleNavigationBarWithTitle(L10n.Localizable.Menu.Item.settings)
}

private func loadLicensesInBackground() {
Expand Down Expand Up @@ -122,7 +122,7 @@ class AboutViewController: AutolayoutViewController {

tableView.separatorInset = UIEdgeInsets(top: 0, left: 30, bottom: 0, right: 0)
Theme.current.applyDividerToSeparator(tableView)
styleNavigationBarWithTitle(L10n.Menu.Item.about)
styleNavigationBarWithTitle(L10n.Localizable.Menu.Item.about)
// XXX: for some reason, UITableView is not affected by appearance updates
if let viewContainer = viewContainer {
Theme.current.applyPrincipalBackground(view)
Expand Down
4 changes: 2 additions & 2 deletions PIA VPN/AccountObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class AccountObserver {

let note = UNMutableNotificationContent()

note.title = L10n.Expiration.title
note.body = L10n.Expiration.message
note.title = L10n.Localizable.Expiration.title
note.body = L10n.Localizable.Expiration.message
note.userInfo = ["date": date]
note.sound = .default
note.badge = 1
Expand Down
58 changes: 29 additions & 29 deletions PIA VPN/AccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ class AccountViewController: AutolayoutViewController {
override func viewDidLoad() {
super.viewDidLoad()

title = L10n.Menu.Item.account
labelUsername.text = L10n.Account.Username.caption
labelRestoreTitle.text = L10n.Account.Restore.title
labelRestoreInfo.text = L10n.Account.Restore.description
title = L10n.Localizable.Menu.Item.account
labelUsername.text = L10n.Localizable.Account.Username.caption
labelRestoreTitle.text = L10n.Localizable.Account.Restore.title
labelRestoreInfo.text = L10n.Localizable.Account.Restore.description
imageViewTrash.image = Theme.current.trashIconImage()
buttonRestore.setTitle(L10n.Account.Restore.button.uppercased(), for: .normal)
buttonRestore.setTitle(L10n.Localizable.Account.Restore.button.uppercased(), for: .normal)
labelSubscriptions.attributedText = Theme.current.textWithColoredLink(
withMessage: L10n.Account.Subscriptions.message,
link: L10n.Account.Subscriptions.linkMessage)
withMessage: L10n.Localizable.Account.Subscriptions.message,
link: L10n.Localizable.Account.Subscriptions.linkMessage)
labelSubscriptions.isUserInteractionEnabled = true

viewSafe.layoutMargins = .zero
Expand All @@ -98,7 +98,7 @@ class AccountViewController: AutolayoutViewController {
super.viewWillAppear(animated)

// update local state immediately
styleNavigationBarWithTitle(L10n.Menu.Item.account)
styleNavigationBarWithTitle(L10n.Localizable.Menu.Item.account)
redisplayAccount()
}

Expand All @@ -114,7 +114,7 @@ class AccountViewController: AutolayoutViewController {
}

@objc private func viewHasRotated() {
styleNavigationBarWithTitle(L10n.Menu.Item.settings)
styleNavigationBarWithTitle(L10n.Localizable.Menu.Item.settings)
}

// MARK: Actions
Expand All @@ -131,11 +131,11 @@ class AccountViewController: AutolayoutViewController {

@IBAction private func deleteUserAccount(_ sender: Any?) {
let sheet = Macros.alert(
L10n.Account.Delete.Alert.title,
L10n.Account.Delete.Alert.message
L10n.Localizable.Account.Delete.Alert.title,
L10n.Localizable.Account.Delete.Alert.message
)
sheet.addCancelAction(L10n.Global.no)
sheet.addDestructiveActionWithTitle(L10n.Global.yes) {
sheet.addCancelAction(L10n.Localizable.Global.no)
sheet.addDestructiveActionWithTitle(L10n.Localizable.Global.yes) {
self.showLoadingAnimation()
log.debug("Account: Deleting...")

Expand All @@ -154,8 +154,8 @@ class AccountViewController: AutolayoutViewController {
}
} else {
self.hideLoadingAnimation()
let sheet = Macros.alert(nil, L10n.Account.Delete.Alert.failureMessage)
sheet.addCancelAction(L10n.Global.ok)
let sheet = Macros.alert(nil, L10n.Localizable.Account.Delete.Alert.failureMessage)
sheet.addCancelAction(L10n.Localizable.Global.ok)
self.present(sheet, animated: true, completion: nil)
log.debug("Account: Deleting failed...")
}
Expand All @@ -180,37 +180,37 @@ class AccountViewController: AutolayoutViewController {
private func handleReceiptFailureWithError(_ error: Error?) {
log.error("IAP: Failed to restore payment receipt (error: \(error?.localizedDescription ?? ""))")

let alert = Macros.alert(L10n.Global.error, error?.localizedDescription)
alert.addDefaultAction(L10n.Global.close)
let alert = Macros.alert(L10n.Localizable.Global.error, error?.localizedDescription)
alert.addDefaultAction(L10n.Localizable.Global.close)
present(alert, animated: true, completion: nil)
}

private func handleReceiptSubmissionWithError(_ error: Error?) {
if let error = error {
let alert = Macros.alert(L10n.Global.error, error.localizedDescription)
alert.addDefaultAction(L10n.Global.close)
let alert = Macros.alert(L10n.Localizable.Global.error, error.localizedDescription)
alert.addDefaultAction(L10n.Localizable.Global.close)
present(alert, animated: true, completion: nil)
return
}

log.debug("Account: Renewal successfully completed")

let alert = Macros.alert(
L10n.Renewal.Success.title,
L10n.Renewal.Success.message
L10n.Localizable.Renewal.Success.title,
L10n.Localizable.Renewal.Success.message
)
alert.addDefaultAction(L10n.Global.close)
alert.addDefaultAction(L10n.Localizable.Global.close)
present(alert, animated: true, completion: nil)

redisplayAccount()
}

private func handleBadReceipt() {
let alert = Macros.alert(
L10n.Account.Restore.Failure.title,
L10n.Account.Restore.Failure.message
L10n.Localizable.Account.Restore.Failure.title,
L10n.Localizable.Account.Restore.Failure.message
)
alert.addDefaultAction(L10n.Global.close)
alert.addDefaultAction(L10n.Localizable.Global.close)
present(alert, animated: true, completion: nil)
}

Expand All @@ -231,9 +231,9 @@ class AccountViewController: AutolayoutViewController {

if let userInfo = currentUser?.info {
if userInfo.isExpired {
labelExpiryInformation.text = L10n.Account.ExpiryDate.expired
labelExpiryInformation.text = L10n.Localizable.Account.ExpiryDate.expired
} else {
labelExpiryInformation.text = L10n.Account.ExpiryDate.information(userInfo.humanReadableExpirationDate())
labelExpiryInformation.text = L10n.Localizable.Account.ExpiryDate.information(userInfo.humanReadableExpirationDate())
}
styleExpirationDate()

Expand Down Expand Up @@ -264,7 +264,7 @@ class AccountViewController: AutolayoutViewController {

self.viewAccountInfo.layer.cornerRadius = 5.0

styleNavigationBarWithTitle(L10n.Menu.Item.account)
styleNavigationBarWithTitle(L10n.Localizable.Menu.Item.account)

if let viewContainer = viewContainer {
Theme.current.applyPrincipalBackground(view)
Expand All @@ -279,7 +279,7 @@ class AccountViewController: AutolayoutViewController {
for label in [labelExpiryInformation!] {
Theme.current.applySubtitle(label)
}
Theme.current.applyUnderline(labelDeleteAccount, with: L10n.Account.delete)
Theme.current.applyUnderline(labelDeleteAccount, with: L10n.Localizable.Account.delete)
Theme.current.applyTitle(labelRestoreTitle, appearance: .dark)
Theme.current.applySubtitle(labelRestoreInfo)
buttonRestore.style(style: TextStyle.textStyle9)
Expand Down
4 changes: 2 additions & 2 deletions PIA VPN/ActiveDedicatedIpHeaderViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class ActiveDedicatedIpHeaderViewCell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
self.backgroundColor = .clear
self.title.text = L10n.Dedicated.Ip.title
self.subtitle.text = L10n.Dedicated.Ip.Limit.title
self.title.text = L10n.Localizable.Dedicated.Ip.title
self.subtitle.text = L10n.Localizable.Dedicated.Ip.Limit.title
}

func setup() {
Expand Down
161 changes: 161 additions & 0 deletions PIA VPN/ActivityButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
//
// ActivityButton.swift
// PIALibrary-iOS
//
// Created by Davide De Rosa on 10/20/17.
// Copyright © 2020 Private Internet Access, Inc.
//
// This file is part of the Private Internet Access iOS Client.
//
// The Private Internet Access iOS Client 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.
//
// The Private Internet Access iOS Client 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 the Private
// Internet Access iOS Client. If not, see <https://www.gnu.org/licenses/>.
//

import UIKit

/// A button with an embedded `UIActivityIndicatorView` for simulating a running activity.
public class ActivityButton: UIControl {

/// :nodoc:
public override var backgroundColor: UIColor? {
get {
return button.backgroundColor
}
set {
button.backgroundColor = newValue
}
}

/// :nodoc:
public override var isEnabled: Bool {
get {
return button.isEnabled
}
set {
button.isEnabled = newValue
}
}

/// :nodoc:
public override var accessibilityIdentifier: String? {
get {
return button.accessibilityIdentifier
}
set {
button.accessibilityIdentifier = newValue
}
}

/// The button text color.
public var textColor: UIColor? {
get {
return button.titleColor(for: .normal)
}
set {
button.setTitleColor(newValue, for: .normal)
}
}

/// The button title.
public var title: String? {
get {
return button.title(for: .normal)
}
set {
button.setTitle(newValue, for: .normal)
}
}

/// The button font.
public var font: UIFont? {
get {
return button.titleLabel?.font
}
set {
button.titleLabel?.font = newValue
}
}

/// The button corner radius.
public var cornerRadius: CGFloat {
get {
return button.layer.cornerRadius
}
set {
button.layer.cornerRadius = newValue
}
}

/// This is `true` after invoking `startActivity()`.
public var isRunningActivity: Bool {
return activity.isAnimating
}

private lazy var button = UIButton(type: .custom)

private lazy var activity = UIActivityIndicatorView(frame: .zero)

private var previousTitle: String?

/// :nodoc:
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

backgroundColor = .clear

button.showsTouchWhenHighlighted = true // XXX: should replicate IB highlight behaviour
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, action: #selector(handleButtonTouch), for: .touchUpInside)
addSubview(button)

activity.hidesWhenStopped = true
activity.translatesAutoresizingMaskIntoConstraints = false
addSubview(activity)

let top = button.topAnchor.constraint(equalTo: topAnchor)
let bottom = button.bottomAnchor.constraint(equalTo: bottomAnchor)
let left = button.leftAnchor.constraint(equalTo: leftAnchor)
let right = button.rightAnchor.constraint(equalTo: rightAnchor)
let activityX = activity.centerXAnchor.constraint(equalTo: button.centerXAnchor)
let activityY = activity.centerYAnchor.constraint(equalTo: button.centerYAnchor)
NSLayoutConstraint.activate([top, bottom, left, right, activityX, activityY])
}

/**
Simulates an activity by showing a spinning activity indicator.
*/
public func startActivity() {
guard !activity.isAnimating else {
return
}
previousTitle = title
button.isUserInteractionEnabled = false
title = nil
activity.startAnimating()
}

/**
Hides the activity indicator previously shown with `startActivity()`.
*/
public func stopActivity() {
guard activity.isAnimating else {
return
}
activity.stopAnimating()
title = previousTitle
button.isUserInteractionEnabled = true
}

@objc private func handleButtonTouch() {
sendActions(for: .touchUpInside)
}
}
2 changes: 1 addition & 1 deletion PIA VPN/AddCustomNetworksViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ extension AddCustomNetworksViewController: UICollectionViewDelegateFlowLayout, U
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {

let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: Cells.header, for: indexPath) as! PIAHeaderCollectionViewCell
headerView.setup(withTitle: L10n.Network.Management.Tool.Add.rule, andSubtitle: L10n.Network.Management.Tool.Choose.wifi + L10n.Settings.Hotspothelper.Available.help)
headerView.setup(withTitle: L10n.Localizable.Network.Management.Tool.Add.rule, andSubtitle: L10n.Localizable.Network.Management.Tool.Choose.wifi + L10n.Localizable.Settings.Hotspothelper.Available.help)
return headerView

}
Expand Down
Loading

0 comments on commit 49ec8a1

Please sign in to comment.