diff --git a/Classes/Settings/SettingsAddAccountSectionController.swift b/Classes/Settings/SettingsAddAccountSectionController.swift new file mode 100644 index 00000000..bfb56bfa --- /dev/null +++ b/Classes/Settings/SettingsAddAccountSectionController.swift @@ -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) { + + } + +} diff --git a/Classes/Settings/SettingsAddUserSectionController.swift b/Classes/Settings/SettingsAddUserSectionController.swift new file mode 100644 index 00000000..5febf0c8 --- /dev/null +++ b/Classes/Settings/SettingsAddUserSectionController.swift @@ -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 + ) +} diff --git a/Classes/Settings/SettingsSignoutSectionController.swift b/Classes/Settings/SettingsSignoutSectionController.swift new file mode 100644 index 00000000..108f4be0 --- /dev/null +++ b/Classes/Settings/SettingsSignoutSectionController.swift @@ -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) { + + } + +} diff --git a/Classes/Settings/SettingsViewController.swift b/Classes/Settings/SettingsViewController.swift index 58ea5ec7..41125c49 100644 --- a/Classes/Settings/SettingsViewController.swift +++ b/Classes/Settings/SettingsViewController.swift @@ -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 } diff --git a/Classes/Systems/RootNavigationManager.swift b/Classes/Systems/RootNavigationManager.swift index a904cbf5..8146460d 100644 --- a/Classes/Systems/RootNavigationManager.swift +++ b/Classes/Systems/RootNavigationManager.swift @@ -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 } } diff --git a/Classes/Views/CenteredButtonCell.swift b/Classes/Views/CenteredButtonCell.swift index 96d5c930..d57f8269 100644 --- a/Classes/Views/CenteredButtonCell.swift +++ b/Classes/Views/CenteredButtonCell.swift @@ -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) diff --git a/Freetime.xcodeproj/project.pbxproj b/Freetime.xcodeproj/project.pbxproj index 71460dea..5cea4abe 100644 --- a/Freetime.xcodeproj/project.pbxproj +++ b/Freetime.xcodeproj/project.pbxproj @@ -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 = ""; }; 29316DC21ECC981D007CAE3F /* RootNavigationManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RootNavigationManager.swift; sourceTree = ""; }; 29316DC41ECC9841007CAE3F /* Alamofire+GithubAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Alamofire+GithubAPI.swift"; sourceTree = ""; }; + 29316DC61ECCA37B007CAE3F /* SettingsAddUserSectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsAddUserSectionController.swift; sourceTree = ""; }; + 29316DC81ECCA47E007CAE3F /* SettingsAddAccountSectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsAddAccountSectionController.swift; sourceTree = ""; }; + 29316DCA1ECCA581007CAE3F /* SettingsSignoutSectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsSignoutSectionController.swift; sourceTree = ""; }; 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 = ""; }; @@ -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 = ""; @@ -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 */,