mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-01-12 17:22:45 +08:00
adds navBarTitle
This commit is contained in:
@@ -22,6 +22,7 @@ class UserProfileModel {
|
||||
let name: String?
|
||||
let url: String
|
||||
let viewerCanFollow: Bool
|
||||
let viewIsFollowing: Bool
|
||||
|
||||
let repositoriesCount: Int
|
||||
let starredReposCount: Int
|
||||
@@ -43,6 +44,7 @@ class UserProfileModel {
|
||||
self.name = user.name
|
||||
self.url = user.url
|
||||
self.viewerCanFollow = user.viewerCanFollow
|
||||
self.viewIsFollowing = user.viewerIsFollowing
|
||||
|
||||
self.followingCount = user.following.totalCount
|
||||
self.followersCount = user.followers.totalCount
|
||||
|
||||
@@ -11,8 +11,9 @@ import Apollo
|
||||
import SnapKit
|
||||
import IGListKit
|
||||
|
||||
protocol SetsTabmanTitlesDelegate: class {
|
||||
func setTitles(userRepoCount: Int, starredReposCount: Int)
|
||||
protocol ConfigureRootProfileViewController: class {
|
||||
func configureNavbarTitle(userLogin: String, username: String?)
|
||||
func configureTabmanTitles(userRepoCount: Int, starredReposCount: Int)
|
||||
}
|
||||
|
||||
class UserProfileOverviewViewController:
|
||||
@@ -21,11 +22,10 @@ class UserProfileOverviewViewController:
|
||||
SearchResultSectionControllerDelegate
|
||||
{
|
||||
|
||||
|
||||
private let client: UserProfileClient
|
||||
private let gitHubClient: GithubClient
|
||||
private var userProfileModel: UserProfileModel?
|
||||
weak var setTabmanTitlesDelegate: SetsTabmanTitlesDelegate?
|
||||
weak var configureRootViewControllerDelegate: ConfigureRootProfileViewController?
|
||||
|
||||
private lazy var adapter: ListAdapter = { ListAdapter(updater: ListAdapterUpdater(),
|
||||
viewController: self) }()
|
||||
@@ -65,8 +65,12 @@ class UserProfileOverviewViewController:
|
||||
|
||||
case .success(let userProfile):
|
||||
self.userProfileModel = userProfile
|
||||
setTabmanTitlesDelegate?.setTitles(userRepoCount: userProfile.repositoriesCount,
|
||||
starredReposCount: userProfile.starredReposCount)
|
||||
|
||||
configureRootViewControllerDelegate?.configureNavbarTitle(userLogin: userProfile.login,
|
||||
username: userProfile.name)
|
||||
|
||||
configureRootViewControllerDelegate?.configureTabmanTitles(userRepoCount: userProfile.repositoriesCount,
|
||||
starredReposCount: userProfile.starredReposCount)
|
||||
|
||||
adapter.reloadData()
|
||||
}
|
||||
|
||||
@@ -13,19 +13,16 @@ import Pageboy
|
||||
class UserProfileViewController:
|
||||
TabmanViewController,
|
||||
PageboyViewControllerDataSource,
|
||||
SetsTabmanTitlesDelegate
|
||||
ConfigureRootProfileViewController
|
||||
{
|
||||
|
||||
private let controllers: [UIViewController]
|
||||
private let client: UserProfileClient
|
||||
private let userLogin: String
|
||||
|
||||
init(gitHubClient: GithubClient,
|
||||
userLogin: String)
|
||||
{
|
||||
let userProfileClient = UserProfileClient(client: gitHubClient, userLogin: userLogin)
|
||||
self.client = userProfileClient
|
||||
self.userLogin = userLogin
|
||||
|
||||
|
||||
self.controllers = [
|
||||
UserProfileOverviewViewController(client: userProfileClient,
|
||||
gitHubClient: gitHubClient),
|
||||
@@ -42,7 +39,7 @@ class UserProfileViewController:
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
|
||||
if let vc = controllers[0] as? UserProfileOverviewViewController {
|
||||
vc.setTabmanTitlesDelegate = self
|
||||
vc.configureRootViewControllerDelegate = self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,13 +75,21 @@ class UserProfileViewController:
|
||||
return nil
|
||||
}
|
||||
|
||||
// MARK: SetsTabmanTitlesDelegate
|
||||
// MARK: ConfigureRootProfileViewControllerDelegate
|
||||
|
||||
func configureTabmanTitles(userRepoCount: Int, starredReposCount: Int) {
|
||||
|
||||
func setTitles(userRepoCount: Int, starredReposCount: Int) {
|
||||
controllers[0].title = "Overview"
|
||||
controllers[1].title = "Repositories (\(userRepoCount))"
|
||||
controllers[2].title = "Starred (\(starredReposCount))"
|
||||
|
||||
bar.items = controllers.map { Item(title: $0.title ?? "" )}
|
||||
}
|
||||
|
||||
func configureNavbarTitle(userLogin: String, username: String?) {
|
||||
let titlelabel = NavbarTitleLabel()
|
||||
self.navigationItem.titleView = titlelabel
|
||||
titlelabel.configure(title: userLogin, subtitle: username)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
58
Classes/User Profile/Views/NavbarTitle.swift
Normal file
58
Classes/User Profile/Views/NavbarTitle.swift
Normal file
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// NavbarTitle.swift
|
||||
// Freetime
|
||||
//
|
||||
// Created by B_Litwin on 8/13/18.
|
||||
// Copyright © 2018 Ryan Nystrom. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
//heavy inspiration from
|
||||
|
||||
class NavbarTitleLabel: UILabel {
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
backgroundColor = .clear
|
||||
numberOfLines = 2
|
||||
textAlignment = .center
|
||||
lineBreakMode = .byTruncatingMiddle
|
||||
adjustsFontSizeToFitWidth = true
|
||||
minimumScaleFactor = 0.75
|
||||
setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
||||
setContentCompressionResistancePriority(.defaultLow, for: .vertical)
|
||||
}
|
||||
|
||||
func configure(
|
||||
title: String,
|
||||
subtitle: String?,
|
||||
accessibilityLabel: String? = nil,
|
||||
accessibilityHint: String? = nil
|
||||
) {
|
||||
let titleAttributes: [NSAttributedStringKey: Any] = [
|
||||
.font: Styles.Text.bodyBold.preferredFont,
|
||||
.foregroundColor: Styles.Colors.Gray.dark.color
|
||||
]
|
||||
|
||||
let attributedTitle = NSMutableAttributedString(string: title, attributes: titleAttributes)
|
||||
if let subtitle = subtitle {
|
||||
attributedTitle.append(NSAttributedString(string: "\n"))
|
||||
attributedTitle.append(NSAttributedString(string: subtitle, attributes: [
|
||||
.font: Styles.Text.secondaryBold.preferredFont,
|
||||
.foregroundColor: Styles.Colors.Gray.light.color
|
||||
]))
|
||||
}
|
||||
|
||||
attributedText = attributedTitle
|
||||
self.accessibilityLabel = accessibilityLabel ?? title
|
||||
self.accessibilityHint = accessibilityHint
|
||||
}
|
||||
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,6 +452,7 @@
|
||||
BDC1053B21212CE400DB7976 /* ProfileHeaderKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDC1053A21212CE400DB7976 /* ProfileHeaderKey.swift */; };
|
||||
BDC1053D21212CF200DB7976 /* ProfileHeaderSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDC1053C21212CF200DB7976 /* ProfileHeaderSectionController.swift */; };
|
||||
BDC1053F21212F2500DB7976 /* ProfileHeaderCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDC1053E21212F2500DB7976 /* ProfileHeaderCollectionViewCell.swift */; };
|
||||
BDC105442121BFEA00DB7976 /* NavbarTitle.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDC105432121BFEA00DB7976 /* NavbarTitle.swift */; };
|
||||
D8BAD0601FDA0A1A00C41071 /* LabelListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8BAD05F1FDA0A1A00C41071 /* LabelListCell.swift */; };
|
||||
D8BAD0641FDF221900C41071 /* LabelListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8BAD0631FDF221900C41071 /* LabelListView.swift */; };
|
||||
D8BAD0661FDF224600C41071 /* WrappingStaticSpacingFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8BAD0651FDF224600C41071 /* WrappingStaticSpacingFlowLayout.swift */; };
|
||||
@@ -997,6 +998,7 @@
|
||||
BDC1053A21212CE400DB7976 /* ProfileHeaderKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileHeaderKey.swift; sourceTree = "<group>"; };
|
||||
BDC1053C21212CF200DB7976 /* ProfileHeaderSectionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileHeaderSectionController.swift; sourceTree = "<group>"; };
|
||||
BDC1053E21212F2500DB7976 /* ProfileHeaderCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileHeaderCollectionViewCell.swift; sourceTree = "<group>"; };
|
||||
BDC105432121BFEA00DB7976 /* NavbarTitle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavbarTitle.swift; sourceTree = "<group>"; };
|
||||
D396E0DA66FED629384A84BC /* Pods_FreetimeWatch.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FreetimeWatch.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D8BAD05F1FDA0A1A00C41071 /* LabelListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelListCell.swift; sourceTree = "<group>"; };
|
||||
D8BAD0631FDF221900C41071 /* LabelListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LabelListView.swift; sourceTree = "<group>"; };
|
||||
@@ -2122,6 +2124,7 @@
|
||||
BD6C5C832120ABE300E93D31 /* User Profile */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
BDC105422121BFD300DB7976 /* Views */,
|
||||
BDC105402121363300DB7976 /* Profile Models */,
|
||||
BDC105412121365000DB7976 /* Profile ViewControllers */,
|
||||
BDC1053921212CCA00DB7976 /* Section Headers */,
|
||||
@@ -2163,6 +2166,14 @@
|
||||
path = "Profile ViewControllers";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
BDC105422121BFD300DB7976 /* Views */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
BDC105432121BFEA00DB7976 /* NavbarTitle.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
CF4CC0BFE456879DD6DBC714 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -3146,6 +3157,7 @@
|
||||
29C9FDE11EC667AE00EE3A52 /* Styles.swift in Sources */,
|
||||
29622B45210520E6000C428D /* CardCollectionViewCell.swift in Sources */,
|
||||
294B11201F7B07DD00E04F2D /* TabBarControllerDelegate.swift in Sources */,
|
||||
BDC105442121BFEA00DB7976 /* NavbarTitle.swift in Sources */,
|
||||
294B111E1F7B07BB00E04F2D /* TabNavRootViewControllerType.swift in Sources */,
|
||||
754488B11F7ADF8D0032D08C /* UIAlertController+Action.swift in Sources */,
|
||||
2958406F1EE9F21E007723C6 /* UIButton+Label.swift in Sources */,
|
||||
|
||||
Reference in New Issue
Block a user