Skip to content

Commit

Permalink
item info vc subclass and UserInfoVC
Browse files Browse the repository at this point in the history
  • Loading branch information
grenos committed Apr 4, 2020
1 parent c2b2f06 commit db5b277
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 7 deletions.
18 changes: 17 additions & 1 deletion GHFollowers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
7D7C665224388F0900733687 /* GFItemInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D7C665124388F0900733687 /* GFItemInfoView.swift */; };
7D7C6654243897F300733687 /* GFItemInfoVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D7C6653243897F300733687 /* GFItemInfoVC.swift */; };
7D7C665624389E0600733687 /* GFRepoItemVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D7C665524389E0600733687 /* GFRepoItemVC.swift */; };
7D7C66582438A22C00733687 /* GFFollowerItemVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D7C66572438A22C00733687 /* GFFollowerItemVC.swift */; };
7D98BB282428FE73006C53E9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D98BB272428FE73006C53E9 /* AppDelegate.swift */; };
7D98BB2A2428FE73006C53E9 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D98BB292428FE73006C53E9 /* SceneDelegate.swift */; };
7D98BB312428FE75006C53E9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7D98BB302428FE75006C53E9 /* Assets.xcassets */; };
Expand Down Expand Up @@ -40,6 +42,8 @@
/* Begin PBXFileReference section */
7D7C665124388F0900733687 /* GFItemInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFItemInfoView.swift; sourceTree = "<group>"; };
7D7C6653243897F300733687 /* GFItemInfoVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFItemInfoVC.swift; sourceTree = "<group>"; };
7D7C665524389E0600733687 /* GFRepoItemVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFRepoItemVC.swift; sourceTree = "<group>"; };
7D7C66572438A22C00733687 /* GFFollowerItemVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFFollowerItemVC.swift; sourceTree = "<group>"; };
7D98BB242428FE73006C53E9 /* GHFollowers.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GHFollowers.app; sourceTree = BUILT_PRODUCTS_DIR; };
7D98BB272428FE73006C53E9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7D98BB292428FE73006C53E9 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -81,6 +85,16 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
7D7C66592438A2B300733687 /* ItemInfoVCs */ = {
isa = PBXGroup;
children = (
7D7C6653243897F300733687 /* GFItemInfoVC.swift */,
7D7C665524389E0600733687 /* GFRepoItemVC.swift */,
7D7C66572438A22C00733687 /* GFFollowerItemVC.swift */,
);
path = ItemInfoVCs;
sourceTree = "<group>";
};
7D98BB1B2428FE73006C53E9 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -238,9 +252,9 @@
7DA45F7D2433DCE700AB426F /* ViewControllers */ = {
isa = PBXGroup;
children = (
7D7C66592438A2B300733687 /* ItemInfoVCs */,
7D98BB49242A55ED006C53E9 /* GFAlertVC.swift */,
7DA45F842433FAF800AB426F /* GFUserInfoheaderVC.swift */,
7D7C6653243897F300733687 /* GFItemInfoVC.swift */,
);
path = ViewControllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -327,13 +341,15 @@
7DA45F71242BC5C100AB426F /* GFAvatarImageView.swift in Sources */,
7D98BB48242A5507006C53E9 /* GFBodyLabel.swift in Sources */,
7DA45F7C2430E3C900AB426F /* UserInfoVC.swift in Sources */,
7D7C665624389E0600733687 /* GFRepoItemVC.swift in Sources */,
7DA45F64242B73E600AB426F /* Follower.swift in Sources */,
7D98BB46242A52B7006C53E9 /* GFTitleLabel.swift in Sources */,
7D98BB4C242A7327006C53E9 /* UIViewController+EXT.swift in Sources */,
7DA45F812433DE1300AB426F /* GFTitleLabel-Secondary.swift in Sources */,
7D98BB44242A29B4006C53E9 /* FollowerListVC.swift in Sources */,
7DA45F6C242BAEEC00AB426F /* ErrorMessage.swift in Sources */,
7D7C6654243897F300733687 /* GFItemInfoVC.swift in Sources */,
7D7C66582438A22C00733687 /* GFFollowerItemVC.swift in Sources */,
7DA45F73242E332000AB426F /* UIHelper.swift in Sources */,
7DA45F69242B831900AB426F /* NetworkManager.swift in Sources */,
7D98BB282428FE73006C53E9 /* AppDelegate.swift in Sources */,
Expand Down
Binary file not shown.
10 changes: 9 additions & 1 deletion GHFollowers/Components/Buttons/GFButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class GFButton: UIButton {
// dynamic font (app responds to global text size changes)
titleLabel?.font = UIFont.preferredFont(forTextStyle: .headline)
translatesAutoresizingMaskIntoConstraints = false

}



// this is to configure our button after the first init of the button
func set(backgroundColor: UIColor, title: String) {
self.backgroundColor = backgroundColor
setTitle(title, for: .normal)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// GFFollowerItemVC.swift
// GHFollowers
//
// Created by Vasileios Gkreen on 04/04/2020.
// Copyright © 2020 Vasileios Gkreen. All rights reserved.
//

import UIKit

// THIS CLASS IS A SUBLCLASS OF GFItemInfoVC, IT INHERITS ALL OF ITS PROPERTIES

class GFFollowerItemVC: GFItemInfoVC {

override func viewDidLoad() {
super.viewDidLoad()
configureItems()

}

private func configureItems() {
// 1) get itemInfoView1 which is declarered in the superClass GFItemInfoVC
// 2) itemInfoView1 is GFItemInfoView() created to hold the symbols and github info
// 3) set is a func created in GFItemInfoView to controlls what info to show based on what we pass with itemInfoType
// 4) the user object is passed from the superClass, which we pass from the UserInfoVC screen
itemInfoView1.set(itemInfoType: .followers, withCount: user.followers)
itemInfoView2.set(itemInfoType: .following, withCount: user.following)
actionButton.set(backgroundColor: .systemGreen, title: "Get Followers")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,22 @@ class GFItemInfoVC: UIViewController {
let itemInfoView1 = GFItemInfoView()
let itemInfoView2 = GFItemInfoView()
let actionButton = GFButton()


var user: User!

// create a custom initializer
// so when we initialize the VC we can pass the User object
init(user: User) {
super.init(nibName: nil, bundle: nil)
self.user = user
}

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



override func viewDidLoad() {
super.viewDidLoad()
configureBackgroundView()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// GFRepoItemVC.swift
// GHFollowers
//
// Created by Vasileios Gkreen on 04/04/2020.
// Copyright © 2020 Vasileios Gkreen. All rights reserved.
//

import UIKit

// THIS CLASS IS A SUBLCLASS OF GFItemInfoVC, IT INHERITS ALL OF ITS PROPERTIES

class GFRepoItemVC: GFItemInfoVC {

override func viewDidLoad() {
super.viewDidLoad()
configureItems()

}

private func configureItems() {
// 1) get itemInfoView1 which is declarered in the superClass GFItemInfoVC
// 2) itemInfoView1 is GFItemInfoView() created to hold the symbols and github info
// 3) set is a func created in GFItemInfoView to controlls what info to show based on what we pass with itemInfoType
// 4) the user object is passed from the superClass, which we pass from the UserInfoVC screen
itemInfoView1.set(itemInfoType: .repos, withCount: user.publicRepos)
itemInfoView2.set(itemInfoType: .gists, withCount: user.publicGists)
actionButton.set(backgroundColor: .systemPurple, title: "GitHub Profile")
}
}
7 changes: 3 additions & 4 deletions GHFollowers/Screens/UserInfoVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ class UserInfoVC: UIViewController {

switch result {
case .success(let user):

DispatchQueue.main.async {
self.add(childVC: GFUserInfoheaderVC(user: user), to: self.headerView)
self.add(childVC: GFRepoItemVC(user: user), to: self.itemViewOne)
self.add(childVC: GFFollowerItemVC(user: user), to: self.itemViewTwo)
}

case .failure(let error):
Expand All @@ -77,9 +78,7 @@ class UserInfoVC: UIViewController {
])
}

itemViewOne.backgroundColor = .systemPink
itemViewTwo.backgroundColor = .systemBlue


NSLayoutConstraint.activate([
headerView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
headerView.heightAnchor.constraint(equalToConstant: 180),
Expand Down

0 comments on commit db5b277

Please sign in to comment.