Skip to content

Commit

Permalink
Last second optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
nssina committed Dec 10, 2020
1 parent 836eafd commit d9224ba
Show file tree
Hide file tree
Showing 31 changed files with 129 additions and 88 deletions.
4 changes: 3 additions & 1 deletion GHFollowers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@
D3E4AE95257AAB3600D5FFE0 /* Utilities */,
D3E4AE91257AA30600D5FFE0 /* Managers */,
D3E4AE89257A9B8800D5FFE0 /* Model */,
D3E4AE86257A914300D5FFE0 /* Support */,
D3E4AE84257A90EA00D5FFE0 /* Extensions */,
D3E4AE83257A90B700D5FFE0 /* Custom Views */,
D3E4AE82257A908500D5FFE0 /* Screens */,
D3E4AE86257A914300D5FFE0 /* Support */,
D31C9AF4257913800091A931 /* Info.plist */,
);
path = GHFollowers;
Expand Down Expand Up @@ -537,6 +537,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.9;
PRODUCT_BUNDLE_IDENTIFIER = com.sinarabiei.GHFollowers;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -556,6 +557,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.9;
PRODUCT_BUNDLE_IDENTIFIER = com.sinarabiei.GHFollowers;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions GHFollowers/Custom Views/Buttons/GFButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,27 @@ class GFButton: UIButton {
configure()
}


required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}


convenience init(backgroundColor: UIColor, title: String) {
self.init(frame: .zero)
self.backgroundColor = backgroundColor
self.setTitle(title, for: .normal)
}


private func configure() {
layer.cornerRadius = 10
setTitleColor(.white, for: .normal)
titleLabel?.font = UIFont.preferredFont(forTextStyle: .headline)
translatesAutoresizingMaskIntoConstraints = false
}


func set(background: UIColor, title: String) {
self.backgroundColor = background
setTitle(title, for: .normal)
Expand Down
6 changes: 1 addition & 5 deletions GHFollowers/Custom Views/Cells/FavoriteCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ class FavoriteCell: UITableViewCell {


func set(favorite: Follower) {
avatarImageView.downloadAvatarImage(fromURL: favorite.avatarUrl)
usernameLabel.text = favorite.login
NetworkManager.shared.donwloadImage(from: favorite.avatarUrl) { [weak self] (image) in
guard let self = self else { return }
DispatchQueue.main.async { self.avatarImageView.image = image }
}
}


Expand All @@ -52,5 +49,4 @@ class FavoriteCell: UITableViewCell {
usernameLabel.heightAnchor.constraint(equalToConstant: 40)
])
}

}
10 changes: 5 additions & 5 deletions GHFollowers/Custom Views/Cells/FollowerCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import UIKit

class FollowerCell: UICollectionViewCell {

static let reuseID = "FollowerCell"
let avatarImageView = GFAvatarImageView(frame: .zero)
let usernameLabel = GFTitleLabel(textAlignment: .center, fontSize: 16)


override init(frame: CGRect) {
super.init(frame: frame)
configure()
Expand All @@ -22,17 +24,15 @@ class FollowerCell: UICollectionViewCell {
fatalError("init(coder:) has not been implemented")
}


func set(follower: Follower) {
avatarImageView.downloadAvatarImage(fromURL: follower.avatarUrl)
usernameLabel.text = follower.login
NetworkManager.shared.donwloadImage(from: follower.avatarUrl) { [weak self] (image) in
guard let self = self else { return }
DispatchQueue.main.async { self.avatarImageView.image = image }
}
}


private func configure() {
addSubviews(avatarImageView, usernameLabel)

let padding: CGFloat = 8

NSLayoutConstraint.activate([
Expand Down
8 changes: 8 additions & 0 deletions GHFollowers/Custom Views/ImageViews/GFAvatarImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ class GFAvatarImageView: UIImageView {
image = placeHolderImage
translatesAutoresizingMaskIntoConstraints = false
}


func downloadAvatarImage(fromURL url: String) {
NetworkManager.shared.donwloadImage(from: url) { [weak self] (image) in
guard let self = self else { return }
DispatchQueue.main.async { self.image = image }
}
}
}
3 changes: 3 additions & 0 deletions GHFollowers/Custom Views/Labels/GFBodyLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ class GFBodyLabel: UILabel {
configure()
}


required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}


convenience init(textAlignment: NSTextAlignment) {
self.init(frame: .zero)
self.textAlignment = textAlignment
}


private func configure() {
textColor = .secondaryLabel
font = UIFont.preferredFont(forTextStyle: .body)
Expand Down
3 changes: 3 additions & 0 deletions GHFollowers/Custom Views/Labels/GFSecondaryTitleLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ class GFSecondaryTitleLabel: UILabel {
configure()
}


required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}


convenience init(fontSize: CGFloat) {
self.init(frame: .zero)
font = UIFont.systemFont(ofSize: fontSize, weight: .medium)
}


private func configure() {
textColor = .secondaryLabel
adjustsFontSizeToFitWidth = true
Expand Down
3 changes: 3 additions & 0 deletions GHFollowers/Custom Views/Labels/GFTitleLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ class GFTitleLabel: UILabel {
configure()
}


required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}


convenience init(textAlignment: NSTextAlignment, fontSize: CGFloat) {
self.init(frame: .zero)
self.textAlignment = textAlignment
self.font = UIFont.systemFont(ofSize: fontSize, weight: .bold)
}


private func configure() {
textColor = .label
adjustsFontSizeToFitWidth = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class GFTabbarController: UITabBarController {
viewControllers = [createSearchNC(), createFavoritesNC()]
}


func createSearchNC() -> UINavigationController {
let searchVC = SearchVC()
searchVC.title = "Search"
Expand All @@ -23,6 +24,7 @@ class GFTabbarController: UITabBarController {
return UINavigationController(rootViewController: searchVC)
}


func createFavoritesNC() -> UINavigationController {
let favoritesListVC = FavoritesListVC()
favoritesListVC.title = "Favorites"
Expand Down
2 changes: 2 additions & 0 deletions GHFollowers/Custom Views/TextFields/GFTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ class GFTextField: UITextField {
configure()
}


required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}


private func configure() {
translatesAutoresizingMaskIntoConstraints = false

Expand Down
6 changes: 6 additions & 0 deletions GHFollowers/Custom Views/ViewControllers/GFAlertVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GFAlertVC: UIViewController {

let padding: CGFloat = 20


init(title: String, message: String, buttonTitle: String) {
super.init(nibName: nil, bundle: nil)
self.alertTitle = title
Expand All @@ -37,6 +38,7 @@ class GFAlertVC: UIViewController {
super.viewDidLoad()
view.backgroundColor = UIColor.black.withAlphaComponent(0.75)
view.addSubviews(containerView, titleLabel, actionButton, messageLabel)

configureContainerView()
configureTitleLabel()
configureActionButton()
Expand All @@ -53,6 +55,7 @@ class GFAlertVC: UIViewController {
])
}


func configureTitleLabel() {
titleLabel.text = alertTitle ?? "Something went wrong"

Expand All @@ -64,6 +67,7 @@ class GFAlertVC: UIViewController {
])
}


func configureActionButton() {
actionButton.setTitle(buttonTitle ?? "OK", for: .normal)
actionButton.addTarget(self, action: #selector(dismissVC), for: .touchUpInside)
Expand All @@ -76,6 +80,7 @@ class GFAlertVC: UIViewController {
])
}


func configureMessageLabel() {
messageLabel.text = message ?? "Unable to complete request"
messageLabel.numberOfLines = 4
Expand All @@ -88,6 +93,7 @@ class GFAlertVC: UIViewController {
])
}


@objc func dismissVC() {
dismiss(animated: true, completion: nil)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import UIKit
class GFDataLoadingVC: UIViewController {

var containerView: UIView!

override func viewDidLoad() {
super.viewDidLoad()

}


func showLoadingView() {
Expand Down
17 changes: 2 additions & 15 deletions GHFollowers/Custom Views/ViewControllers/GFUserInfoHeaderVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ class GFUserInfoHeaderVC: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
addSubviews()
view.addSubviews(avatarImageView, usernameLabel, nameLabel, locationImageView, locationLabel, bioLabel)
layoutUI()
configureUIElements()
}


func configureUIElements() {
downloadAvatarImage()
avatarImageView.downloadAvatarImage(fromURL: user.avatarUrl)
usernameLabel.text = user.login
nameLabel.text = user.name ?? ""
locationLabel.text = user.location ?? "No Location"
Expand All @@ -51,19 +51,6 @@ class GFUserInfoHeaderVC: UIViewController {
}


func downloadAvatarImage() {
NetworkManager.shared.donwloadImage(from: user.avatarUrl) { [weak self] (image) in
guard let self = self else { return }
DispatchQueue.main.async { self.avatarImageView.image = image }
}
}


func addSubviews() {
view.addSubviews(avatarImageView, usernameLabel, nameLabel, locationImageView, locationLabel, bioLabel)
}


func layoutUI() {
let padding: CGFloat = 20
let textImagePadding: CGFloat = 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class GFFollowerItemVC: GFItemInfoVC {

weak var delegate: GFFollowerItemVCDelegate!


init(user: User, delegate: GFFollowerItemVCDelegate) {
super.init(user: user)
self.delegate = delegate
Expand All @@ -38,6 +39,7 @@ class GFFollowerItemVC: GFItemInfoVC {
actionButton.set(background: .systemGreen, title: "Get Followers")
}


override func actionButtonTapped() {
delegate.didTapGetFollowers(for: user)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class GFItemInfoVC: UIViewController {

var user: User!


init(user: User) {
super.init(nibName: nil, bundle: nil)
self.user = user
Expand Down Expand Up @@ -58,6 +59,7 @@ class GFItemInfoVC: UIViewController {

@objc func actionButtonTapped() {}


private func layoutUI() {
view.addSubviews(stackView, actionButton)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class GFRepoItemVC: GFItemInfoVC {

weak var delegate: GFRepoItemVCDelegate!


init(user: User, delegate: GFRepoItemVCDelegate) {
super.init(user: user)
self.delegate = delegate
Expand Down
10 changes: 4 additions & 6 deletions GHFollowers/Custom Views/Views/GFEmptyStateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class GFEmptyStateView: UIView {
let messageLabel = GFTitleLabel(textAlignment: .center, fontSize: 28)
let logoImageView = UIImageView()


override init(frame: CGRect) {
super.init(frame: frame)
configure()
Expand Down Expand Up @@ -42,10 +43,8 @@ class GFEmptyStateView: UIView {

let labelCenterYCostant: CGFloat = DeviceType.isiPhoneSE || DeviceType.isiPhone8Zoomed ? -80 : -150

let messageLabelCenterYConstraint = messageLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: labelCenterYCostant)
messageLabelCenterYConstraint.isActive = true

NSLayoutConstraint.activate([
messageLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: labelCenterYCostant),
messageLabel.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 40),
messageLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -40),
messageLabel.heightAnchor.constraint(equalToConstant: 200)
Expand All @@ -58,13 +57,12 @@ class GFEmptyStateView: UIView {
logoImageView.translatesAutoresizingMaskIntoConstraints = false

let logoBottomConstant: CGFloat = DeviceType.isiPhoneSE || DeviceType.isiPhone8Zoomed ? 80 : 40
let logoImageViewConstraint = messageLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: logoBottomConstant)
logoImageViewConstraint.isActive = true

NSLayoutConstraint.activate([
logoImageView.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 1.3),
logoImageView.heightAnchor.constraint(equalTo: self.widthAnchor, multiplier: 1.3),
logoImageView.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: 170)
logoImageView.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: 170),
logoImageView.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: logoBottomConstant)
])
}
}
Loading

0 comments on commit d9224ba

Please sign in to comment.