Commit 5fac29eb authored by Jose Blaya's avatar Jose Blaya
Browse files

Update RegionCell style to PIAX

parent 410ee42a
This diff is collapsed.
{
"images" : [
{
"idiom" : "universal",
"filename" : "heart7Copy.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" : "groupCopy.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -10,12 +10,22 @@ 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!
override func setSelected(_ selected: Bool, animated: Bool) {
}
func fill(withServer server: Server, isSelected: Bool) {
viewShouldRestyle()
......@@ -30,7 +40,7 @@ class RegionCell: UITableViewCell, Restylable {
}
labelPingTime.text = pingTimeString
accessoryView?.isHidden = !isSelected
selectedRegionImageView.isHidden = !isSelected
if let pingTimeString = pingTimeString {
accessibilityLabel = "\(server.name), \(pingTimeString)"
......@@ -38,21 +48,47 @@ class RegionCell: UITableViewCell, Restylable {
accessibilityLabel = server.name
}
accessibilityIdentifier = "uitests.regions.region_name"
self.favoriteImageView.alpha = CGFloat(NSNumber(booleanLiteral: server.name != L10n.Global.automatic).floatValue)
self.favoriteButton.alpha = CGFloat(NSNumber(booleanLiteral: server.name != L10n.Global.automatic).floatValue)
self.isFavorite = isSelected
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)
self.backgroundColor = Theme.current.palette.lightBackground
self.contentView.backgroundColor = Theme.current.palette.lightBackground
Theme.current.applyList(labelRegion, appearance: .dark)
Theme.current.applyTag(labelPingTime, appearance: .dark)
}
@IBAction func favoriteServer(_ sender: UIButton) {
self.isFavorite = !self.isFavorite
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.favoriteImageView.image = self.isFavorite ?
Asset.Piax.Global.favoriteSelected.image :
Asset.Piax.Global.favoriteUnselected.image
}
}
......@@ -69,7 +69,9 @@ class RegionsViewController: AutolayoutViewController {
return
}
Client.preferences.displayedServer = selectedServer
NotificationCenter.default.post(name: .PIAThemeDidChange,
object: self,
userInfo: nil)
default:
break
}
......@@ -125,7 +127,8 @@ extension RegionsViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: Cells.region, for: indexPath) as! RegionCell
cell.selectionStyle = .none
cell.separatorInset = .zero
let server = servers[indexPath.row]
let isSelected = (server.identifier == selectedServer.identifier)
cell.fill(withServer: server, isSelected: isSelected)
......
......@@ -49,9 +49,12 @@ enum Asset {
static let vpnButton = ImageAsset(name: "vpn-button")
}
enum Global {
static let favoriteSelected = ImageAsset(name: "favorite-selected")
static let favoriteUnselected = ImageAsset(name: "favorite-unselected")
static let iconBack = ImageAsset(name: "icon-back")
static let pagecontrolSelectedDot = ImageAsset(name: "pagecontrol-selected-dot")
static let pagecontrolUnselectedDot = ImageAsset(name: "pagecontrol-unselected-dot")
static let regionSelected = ImageAsset(name: "region-selected")
static let scrollableMapDark = ImageAsset(name: "scrollableMap-dark")
static let scrollableMapLight = ImageAsset(name: "scrollableMap-light")
}
......@@ -319,9 +322,12 @@ enum Asset {
]
static let allImages: [ImageAsset] = [
Piax.Dashboard.vpnButton,
Piax.Global.favoriteSelected,
Piax.Global.favoriteUnselected,
Piax.Global.iconBack,
Piax.Global.pagecontrolSelectedDot,
Piax.Global.pagecontrolUnselectedDot,
Piax.Global.regionSelected,
Piax.Global.scrollableMapDark,
Piax.Global.scrollableMapLight,
Piax.Splash.darkSplash,
......
This diff is collapsed.
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