settings action SCs

This commit is contained in:
Ryan Nystrom
2017-05-17 11:40:27 -04:00
parent c03d4c4204
commit af595ce9cf
7 changed files with 123 additions and 3 deletions

View File

@@ -0,0 +1,33 @@
//
// SettingsAddAccountSectionController.swift
// Freetime
//
// Created by Ryan Nystrom on 5/17/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//
import UIKit
import IGListKit
final class SettingsAddAccountSectionController: IGListSectionController {
override func sizeForItem(at index: Int) -> CGSize {
guard let context = collectionContext else { return .zero }
return CGSize(width: context.containerSize.width, height: Styles.Sizes.tableCellHeight)
}
override func cellForItem(at index: Int) -> UICollectionViewCell {
guard let context = collectionContext,
let cell = context.dequeueReusableCell(of: CenteredButtonCell.self, for: self, at: index) as? CenteredButtonCell
else { return UICollectionViewCell() }
cell.label.text = NSLocalizedString("Add another account", comment: "")
cell.label.textColor = Styles.Colors.blue
cell.configure(topSeparatorHidden: false, bottomSeparatorHidden: false)
return cell
}
override func didSelectItem(at index: Int) {
}
}

View File

@@ -0,0 +1,26 @@
//
// SettingsAddUserSectionController.swift
// Freetime
//
// Created by Ryan Nystrom on 5/17/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//
import UIKit
import IGListKit
func newAddUserSectionController() -> IGListSingleSectionController {
let configureBlock = { (object: Any, cell: UICollectionViewCell) in
guard let cell = cell as? CenteredButtonCell else { return }
cell.label.text = NSLocalizedString("Add another account", comment: "")
}
let sizeBlock = { (object: Any, context: IGListCollectionContext?) -> CGSize in
guard let context = context else { return .zero }
return CGSize(width: context.containerSize.width, height: Styles.Sizes.tableCellHeight)
}
return IGListSingleSectionController(
cellClass: CenteredButtonCell.self,
configureBlock: configureBlock,
sizeBlock: sizeBlock
)
}

View File

@@ -0,0 +1,33 @@
//
// SettingsSignoutSectionController.swift
// Freetime
//
// Created by Ryan Nystrom on 5/17/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//
import UIKit
import IGListKit
final class SettingsSignoutSectionController: IGListSectionController {
override func sizeForItem(at index: Int) -> CGSize {
guard let context = collectionContext else { return .zero }
return CGSize(width: context.containerSize.width, height: Styles.Sizes.tableCellHeight)
}
override func cellForItem(at index: Int) -> UICollectionViewCell {
guard let context = collectionContext,
let cell = context.dequeueReusableCell(of: CenteredButtonCell.self, for: self, at: index) as? CenteredButtonCell
else { return UICollectionViewCell() }
cell.label.text = NSLocalizedString("Sign out", comment: "")
cell.label.textColor = Styles.Colors.red
cell.configure(topSeparatorHidden: false, bottomSeparatorHidden: false)
return cell
}
override func didSelectItem(at index: Int) {
}
}

View File

@@ -12,6 +12,8 @@ import IGListKit
final class SettingsViewController: UIViewController {
let addKey = "add"
let signoutKey = "signout"
let sessionManager: GithubSessionManager
lazy var adapter: IGListAdapter = { IGListAdapter(updater: IGListAdapterUpdater(), viewController: self) }()
lazy var collectionView: UICollectionView = {
@@ -49,11 +51,21 @@ final class SettingsViewController: UIViewController {
extension SettingsViewController: IGListAdapterDataSource {
func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] {
return [sessionManager]
return [
addKey as IGListDiffable,
sessionManager,
signoutKey as IGListDiffable
]
}
func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController {
return SettingsUsersSectionController()
if let str = object as? String, str == addKey {
return SettingsAddAccountSectionController()
} else if let str = object as? String, str == signoutKey {
return SettingsSignoutSectionController()
} else {
return SettingsUsersSectionController()
}
}
func emptyView(for listAdapter: IGListAdapter) -> UIView? { return nil }

View File

@@ -50,6 +50,8 @@ final class RootNavigationManager {
public func resetRootViewController(userSession: GithubUserSession?) {
guard let userSession = userSession else { return }
let selectedIndex = rootTabBarController?.selectedIndex ?? 0
var viewControllers = [UIViewController]()
let client = newGithubClient(sessionManager: sessionManager, userSession: userSession)
viewControllers.append(newNotificationsRootViewController(client: client))
@@ -59,7 +61,7 @@ final class RootNavigationManager {
}
rootTabBarController?.viewControllers = viewControllers
rootTabBarController?.selectedIndex = 0
rootTabBarController?.selectedIndex = selectedIndex
}
}

View File

@@ -19,6 +19,8 @@ final class CenteredButtonCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
contentView.backgroundColor = .white
topSeparator = contentView.addBorder(bottom: false, left: 0, right: 0)
bottomSeparator = contentView.addBorder(bottom: true, left: 0, right: 0)

View File

@@ -17,6 +17,9 @@
29316DBF1ECC95DB007CAE3F /* RootViewControllers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29316DBE1ECC95DB007CAE3F /* RootViewControllers.swift */; };
29316DC31ECC981D007CAE3F /* RootNavigationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29316DC21ECC981D007CAE3F /* RootNavigationManager.swift */; };
29316DC51ECC9841007CAE3F /* Alamofire+GithubAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29316DC41ECC9841007CAE3F /* Alamofire+GithubAPI.swift */; };
29316DC71ECCA37B007CAE3F /* SettingsAddUserSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29316DC61ECCA37B007CAE3F /* SettingsAddUserSectionController.swift */; };
29316DC91ECCA47E007CAE3F /* SettingsAddAccountSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29316DC81ECCA47E007CAE3F /* SettingsAddAccountSectionController.swift */; };
29316DCB1ECCA581007CAE3F /* SettingsSignoutSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29316DCA1ECCA581007CAE3F /* SettingsSignoutSectionController.swift */; };
297AE84D1EC0D58A00B44A1F /* DateDisplayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 297AE84C1EC0D58A00B44A1F /* DateDisplayTests.swift */; };
297AE8741EC0D5C200B44A1F /* GithubLogin.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 297AE8591EC0D5C100B44A1F /* GithubLogin.storyboard */; };
297AE8751EC0D5C200B44A1F /* LoginRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 297AE85A1EC0D5C100B44A1F /* LoginRequest.swift */; };
@@ -129,6 +132,9 @@
29316DBE1ECC95DB007CAE3F /* RootViewControllers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RootViewControllers.swift; sourceTree = "<group>"; };
29316DC21ECC981D007CAE3F /* RootNavigationManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RootNavigationManager.swift; sourceTree = "<group>"; };
29316DC41ECC9841007CAE3F /* Alamofire+GithubAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Alamofire+GithubAPI.swift"; sourceTree = "<group>"; };
29316DC61ECCA37B007CAE3F /* SettingsAddUserSectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsAddUserSectionController.swift; sourceTree = "<group>"; };
29316DC81ECCA47E007CAE3F /* SettingsAddAccountSectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsAddAccountSectionController.swift; sourceTree = "<group>"; };
29316DCA1ECCA581007CAE3F /* SettingsSignoutSectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsSignoutSectionController.swift; sourceTree = "<group>"; };
297AE8341EC0D58A00B44A1F /* Freetime.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Freetime.app; sourceTree = BUILT_PRODUCTS_DIR; };
297AE8481EC0D58A00B44A1F /* FreetimeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FreetimeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
297AE84C1EC0D58A00B44A1F /* DateDisplayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateDisplayTests.swift; sourceTree = "<group>"; };
@@ -424,6 +430,9 @@
29316DB61ECC83AC007CAE3F /* SettingsUserModel.swift */,
29316DB01ECC7D89007CAE3F /* SettingsUsersSectionController.swift */,
29C1677E1ECA1D7300439D62 /* SettingsViewController.swift */,
29316DCA1ECCA581007CAE3F /* SettingsSignoutSectionController.swift */,
29316DC61ECCA37B007CAE3F /* SettingsAddUserSectionController.swift */,
29316DC81ECCA47E007CAE3F /* SettingsAddAccountSectionController.swift */,
);
path = Settings;
sourceTree = "<group>";
@@ -698,6 +707,7 @@
29C9FDCB1EC65FEE00EE3A52 /* Label.swift in Sources */,
29A1950A1EC78B4800C3E289 /* NotificationType+Icon.swift in Sources */,
29C9FDD31EC65FEE00EE3A52 /* Repository.swift in Sources */,
29316DC71ECCA37B007CAE3F /* SettingsAddUserSectionController.swift in Sources */,
29C167741ECA0DBB00439D62 /* GithubAPIDateFormatter.swift in Sources */,
29C9FDD11EC65FEE00EE3A52 /* PullRequest.swift in Sources */,
29C9FDD01EC65FEE00EE3A52 /* Permission.swift in Sources */,
@@ -732,7 +742,9 @@
29A195041EC74C4800C3E289 /* Date+Display.swift in Sources */,
29A195131EC7AD2D00C3E289 /* RepoNotificationsSectionController.swift in Sources */,
298BA0971EC947F100B01946 /* SegmentedControlCell.swift in Sources */,
29316DCB1ECCA581007CAE3F /* SettingsSignoutSectionController.swift in Sources */,
29316DC51ECC9841007CAE3F /* Alamofire+GithubAPI.swift in Sources */,
29316DC91ECCA47E007CAE3F /* SettingsAddAccountSectionController.swift in Sources */,
29C9FDC61EC65FEE00EE3A52 /* Comment.swift in Sources */,
29C9FDD81EC65FEE00EE3A52 /* User.swift in Sources */,
29C167671ECA005500439D62 /* Strings.swift in Sources */,