Commit e2098eeb authored by Jose Blaya's avatar Jose Blaya
Browse files

Merge branch '222-piax-region-selection-update-cell-style' into...

Merge branch '222-piax-region-selection-update-cell-style' into '221-piax-revamp-region-selection-view'

Resolve "PIAX. Region Selection. Update cell style"

See merge request ios/vpn-ios!340
parents 410ee42a c9991001
This diff is collapsed.
......@@ -14,6 +14,7 @@ import SwiftyBeaver
private let log = SwiftyBeaver.self
class AppPreferences {
private struct Entries {
static let version = "Version"
......@@ -28,6 +29,10 @@ class AppPreferences {
static let lastVPNConnectionStatus = "LastVPNConnectionStatus"
static let piaSocketType = "PIASocketType"
static let favoriteServerIdentifiers = "FavoriteServerIdentifiers"
static let regionFilter = "RegionFilter"
}
static let shared = AppPreferences()
......@@ -104,6 +109,30 @@ class AppPreferences {
}
}
var favoriteServerIdentifiers: [String] {
get {
if let serverIdentifiers = defaults.array(forKey: Entries.favoriteServerIdentifiers) as? [String] {
return serverIdentifiers
}
return []
}
set {
defaults.set(newValue, forKey: Entries.favoriteServerIdentifiers)
}
}
var regionFilter: RegionFilter {
get {
guard let rawValue = defaults.string(forKey: Entries.regionFilter) else {
return .name
}
return RegionFilter(rawValue: rawValue) ?? .name
}
set {
defaults.set(newValue.rawValue, forKey: Entries.regionFilter)
}
}
private init() {
guard let defaults = UserDefaults(suiteName: AppConstants.appGroup) else {
fatalError("Unable to initialize app preferences")
......@@ -113,6 +142,8 @@ class AppPreferences {
defaults.register(defaults: [
Entries.version: AppPreferences.currentVersion,
Entries.launched: false,
Entries.regionFilter: RegionFilter.name.rawValue,
Entries.favoriteServerIdentifiers: [],
Entries.didAskToEnableNotifications: false,
Entries.themeCode: ThemeCode.light.rawValue
])
......
{
"images" : [
{
"idiom" : "universal",
"filename" : "heart7Copy.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "iconRedHeart6Copy2.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "heartCopy.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "group92.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "groupCopy.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "15IllustrationNoResultDarkCopy2.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "15IllustrationNoResultLightCopy2.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -14,7 +14,7 @@ private struct PIAConnectionButtonSettings {
static let outsideBorderWidth: CGFloat = 10.0
static let outsideBorderLightColor = UIColor.piaGrey2.cgColor
static let outsideBorderDarkColor = UIColor.piaGrey10.cgColor
static let animatedShapeWidth: CGFloat = 2.0
static let animatedShapeWidth: CGFloat = 4.0
static let startAngle: CGFloat = -0.25 * 2 * .pi
static let endAngle: CGFloat = PIAConnectionButtonSettings.startAngle + 2 * .pi
static let udpateColorAnimationDuration = 0.3
......
//
// PropertyStoring.swift
// PIA VPN
//
// Created by Jose Antonio Blaya Garcia on 28/12/2018.
// Copyright © 2018 London Trust Media. All rights reserved.
//
import Foundation
protocol PropertyStoring {
associatedtype T
func getAssociatedObject(_ key: UnsafeRawPointer!, defaultValue: T) -> T
}
extension PropertyStoring {
func getAssociatedObject(_ key: UnsafeRawPointer!, defaultValue: T) -> T {
guard let value = objc_getAssociatedObject(self, key) as? T else {
return defaultValue
}
return value
}
}
......@@ -10,14 +10,26 @@ import UIKit
import PIALibrary
class RegionCell: UITableViewCell, Restylable {
@IBOutlet private weak var imvFlag: UIImageView!
@IBOutlet private weak var labelRegion: UILabel!
@IBOutlet private weak var labelPingTime: UILabel!
@IBOutlet private weak var favoriteButton: UIButton!
@IBOutlet private weak var favoriteImageView: UIImageView!
@IBOutlet private weak var selectedRegionImageView: UIImageView!
private var isFavorite: Bool!
private weak var server: Server!
override func setSelected(_ selected: Bool, animated: Bool) {
}
func fill(withServer server: Server, isSelected: Bool) {
viewShouldRestyle()
self.server = server
imvFlag.setImage(fromServer: server)
labelRegion.text = server.name
......@@ -30,7 +42,7 @@ class RegionCell: UITableViewCell, Restylable {
}
labelPingTime.text = pingTimeString
accessoryView?.isHidden = !isSelected
selectedRegionImageView.isHidden = !isSelected
if let pingTimeString = pingTimeString {
accessibilityLabel = "\(server.name), \(pingTimeString)"
......@@ -38,21 +50,54 @@ class RegionCell: UITableViewCell, Restylable {
accessibilityLabel = server.name
}
accessibilityIdentifier = "uitests.regions.region_name"
self.favoriteImageView.image = self.favoriteImageView.image?.withRenderingMode(.alwaysTemplate)
self.favoriteImageView.alpha = CGFloat(NSNumber(booleanLiteral: !server.isAutomatic).floatValue)
self.favoriteButton.alpha = CGFloat(NSNumber(booleanLiteral: !server.isAutomatic).floatValue)
self.isFavorite = server.isFavorite
self.updateFavoriteImage()
self.setSelected(false, animated: false)
}
// MARK: Restylable
func viewShouldRestyle() {
backgroundView = UIView()
backgroundView?.backgroundColor = Theme.current.palette.lightBackground
selectedBackgroundView = UIView()
selectedBackgroundView?.backgroundColor = Theme.current.palette.lightBackground
accessoryView = UIImageView(image: Asset.accessorySelected.image)
Theme.current.applyList(labelRegion, appearance: .dark)
self.backgroundColor = Theme.current.palette.lightBackground
self.contentView.backgroundColor = Theme.current.palette.lightBackground
Theme.current.applySettingsCellTitle(labelRegion, appearance: .dark)
Theme.current.applyTag(labelPingTime, appearance: .dark)
Theme.current.applyFavoriteUnselectedImage(self.favoriteImageView)
if Theme.current.palette.appearance! == .dark {
self.favoriteImageView.tintColor = UIColor.piaGrey10
}
}
@IBAction func favoriteServer(_ sender: UIButton) {
self.isFavorite = !self.isFavorite
self.isFavorite ? self.server.favorite() : self.server.unfavorite()
self.animateFavoriteImage()
}
private func animateFavoriteImage() {
UIView.animate(withDuration: 0.3, animations: {
self.favoriteImageView.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
}, completion: { (finished) in
UIView.animate(withDuration: 0.2, animations: {
self.updateFavoriteImage()
self.favoriteImageView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
})
})
}
private func updateFavoriteImage() {
self.isFavorite ?
self.favoriteImageView.image = Asset.Piax.Global.favoriteSelected.image :
Theme.current.applyFavoriteUnselectedImage(self.favoriteImageView)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment