From 6eb099176805cfc2ddca54ea134cfde85fff3659 Mon Sep 17 00:00:00 2001 From: Shaps Benkau Date: Sun, 23 Jul 2017 14:55:20 +0100 Subject: [PATCH] Introduced FeedSelectionProviding to indicate when a selection has been made Updated IssuesViewController and NotificationsViewController to conform to FeedSelectionProviding Updated NotificationsViewController to show the placeholder when toggling the filter Updated the SplitViewDelegate to depend on the current selection rather than a placeholder view --- Classes/Issues/IssuesViewController.swift | 5 ++++- .../NotificationsViewController.swift | 8 ++++++- Classes/Systems/FeedSelectionProviding.swift | 17 ++++++++++++++ .../SplitViewControllerDelegate.swift | 22 ++++++++++++++----- Freetime.xcodeproj/project.pbxproj | 6 +++++ .../AppIcon.appiconset/Contents.json | 5 ----- 6 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 Classes/Systems/FeedSelectionProviding.swift diff --git a/Classes/Issues/IssuesViewController.swift b/Classes/Issues/IssuesViewController.swift index ac4c49f4..943417a9 100644 --- a/Classes/Issues/IssuesViewController.swift +++ b/Classes/Issues/IssuesViewController.swift @@ -11,7 +11,7 @@ import IGListKit import TUSafariActivity import SafariServices -final class IssuesViewController: UIViewController, ListAdapterDataSource, FeedDelegate, AddCommentListener { +final class IssuesViewController: UIViewController, ListAdapterDataSource, FeedDelegate, AddCommentListener, FeedSelectionProviding { private let client: GithubClient private let owner: String @@ -21,6 +21,9 @@ final class IssuesViewController: UIViewController, ListAdapterDataSource, FeedD private var newCommentToken: IssueNewCommentToken? = nil private var models = [ListDiffable]() lazy private var feed: Feed = { Feed(viewController: self, delegate: self) }() + var feedContainsSelection: Bool { + return feed.collectionView.indexPathsForSelectedItems?.count != 0 + } init( client: GithubClient, diff --git a/Classes/Notifications/NotificationsViewController.swift b/Classes/Notifications/NotificationsViewController.swift index 8bc36f67..39685f60 100644 --- a/Classes/Notifications/NotificationsViewController.swift +++ b/Classes/Notifications/NotificationsViewController.swift @@ -15,7 +15,8 @@ class NotificationsViewController: UIViewController, SegmentedControlSectionControllerDelegate, FeedDelegate, NotificationClientListener, -NotificationNextPageSectionControllerDelegate { +NotificationNextPageSectionControllerDelegate, +FeedSelectionProviding { private let client: NotificationClient private let selection = SegmentedControlModel.forNotifications() @@ -24,6 +25,9 @@ NotificationNextPageSectionControllerDelegate { private let emptyKey: ListDiffable = "emptyKey" as ListDiffable private lazy var feed: Feed = { Feed(viewController: self, delegate: self) }() private var page: NSNumber? = 1 + var feedContainsSelection: Bool { + return feed.collectionView.indexPathsForSelectedItems?.count != 0 + } init(client: GithubClient) { self.client = NotificationClient(githubClient: client) @@ -119,6 +123,8 @@ NotificationNextPageSectionControllerDelegate { ) feed.finishLoading(dismissRefresh: dismissRefresh, animated: animated) updateMarkAllEnabled() + + showDetailViewController(SplitPlaceholderViewController(), sender: self) } private func handle(result: NotificationClient.Result, append: Bool, animated: Bool, page: Int) { diff --git a/Classes/Systems/FeedSelectionProviding.swift b/Classes/Systems/FeedSelectionProviding.swift new file mode 100644 index 00000000..71b5ef23 --- /dev/null +++ b/Classes/Systems/FeedSelectionProviding.swift @@ -0,0 +1,17 @@ +// +// SelectionProviding.swift +// Freetime +// +// Created by Shahpour Benkau on 23/07/2017. +// Copyright © 2017 Ryan Nystrom. All rights reserved. +// + +import Foundation + +/// Specifies that the provider contains a feed and whether or not it currently contains a selection +protocol FeedSelectionProviding { + + /// Returns true when a selection has been made, false otherwise + var feedContainsSelection: Bool { get } + +} diff --git a/Classes/View Controllers/SplitViewControllerDelegate.swift b/Classes/View Controllers/SplitViewControllerDelegate.swift index 81196e86..4c0135af 100644 --- a/Classes/View Controllers/SplitViewControllerDelegate.swift +++ b/Classes/View Controllers/SplitViewControllerDelegate.swift @@ -9,18 +9,28 @@ import UIKit final class SplitViewControllerDelegate: UISplitViewControllerDelegate { + + private func containsSelection(in primaryViewController: UIViewController) -> Bool { + guard let nav = primaryViewController as? UINavigationController else { return false } + + if let provider = nav.topViewController as? FeedSelectionProviding { + return provider.feedContainsSelection + } + + if let nav = nav.topViewController as? UINavigationController, + let provider = nav.topViewController as? FeedSelectionProviding { + return provider.feedContainsSelection + } + + return false + } func splitViewController( _ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController ) -> Bool { - // use an empty class to detect if displaying a placeholder VC as details - if let nav = secondaryViewController as? UINavigationController, - nav.viewControllers.first is SplitPlaceholderViewController { - return true - } - return false + return !containsSelection(in: primaryViewController) } } diff --git a/Freetime.xcodeproj/project.pbxproj b/Freetime.xcodeproj/project.pbxproj index 57cad6d7..5adcb645 100644 --- a/Freetime.xcodeproj/project.pbxproj +++ b/Freetime.xcodeproj/project.pbxproj @@ -333,6 +333,8 @@ 29FF85A31EE1CFF7007B8762 /* IssueLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29FF85A21EE1CFF7007B8762 /* IssueLabelModel.swift */; }; 29FF85A51EE1EA7A007B8762 /* ReactionContent+ReactionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29FF85A41EE1EA7A007B8762 /* ReactionContent+ReactionType.swift */; }; 4C733A0B57F91680B08D3CEC /* Pods_Freetime.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 665D835932698FC1ED93ABE3 /* Pods_Freetime.framework */; }; + 54AD5E8E1F24D953004A4BD6 /* FeedSelectionProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54AD5E8D1F24D953004A4BD6 /* FeedSelectionProviding.swift */; }; + 54AD5E8F1F24DA28004A4BD6 /* FeedSelectionProviding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54AD5E8D1F24D953004A4BD6 /* FeedSelectionProviding.swift */; }; 6224B05BDD260B22C7D6684F /* Pods_FreetimeTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB06D68438D845EC6D23788D /* Pods_FreetimeTests.framework */; }; 98835BCE1F1965E2005BA24F /* UIDevice+Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98835BCD1F1965E2005BA24F /* UIDevice+Model.swift */; }; 98835BD01F1A14EC005BA24F /* SettingsVersionInfoSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98835BCF1F1A14EC005BA24F /* SettingsVersionInfoSectionController.swift */; }; @@ -581,6 +583,7 @@ 29FF85A21EE1CFF7007B8762 /* IssueLabelModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueLabelModel.swift; sourceTree = ""; }; 29FF85A41EE1EA7A007B8762 /* ReactionContent+ReactionType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ReactionContent+ReactionType.swift"; sourceTree = ""; }; 2DFFA8FCC50B686D7424BC06 /* Pods-Freetime.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Freetime.release.xcconfig"; path = "Pods/Target Support Files/Pods-Freetime/Pods-Freetime.release.xcconfig"; sourceTree = ""; }; + 54AD5E8D1F24D953004A4BD6 /* FeedSelectionProviding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedSelectionProviding.swift; sourceTree = ""; }; 665D835932698FC1ED93ABE3 /* Pods_Freetime.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Freetime.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7ADC39F0C328AE48CFFA207E /* Pods-FreetimeTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FreetimeTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FreetimeTests/Pods-FreetimeTests.debug.xcconfig"; sourceTree = ""; }; 98835BCD1F1965E2005BA24F /* UIDevice+Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIDevice+Model.swift"; sourceTree = ""; }; @@ -1041,6 +1044,7 @@ 29316DCC1ECD31E9007CAE3F /* StatusBar.swift */, 29416BFC1F118DD700D03E1A /* String+QueryItemValue.swift */, 292CD3CF1F0DBB5C00D3D57B /* WebviewCellHeightCache.swift */, + 54AD5E8D1F24D953004A4BD6 /* FeedSelectionProviding.swift */, ); path = Systems; sourceTree = ""; @@ -1520,6 +1524,7 @@ 29C9FDD31EC65FEE00EE3A52 /* Repository.swift in Sources */, 292FCB191EDFCC510026635E /* IssueTitleSectionController.swift in Sources */, 29C167741ECA0DBB00439D62 /* GithubAPIDateFormatter.swift in Sources */, + 54AD5E8E1F24D953004A4BD6 /* FeedSelectionProviding.swift in Sources */, 29AC90E51F00A7C8000B80E4 /* SplitViewControllerDelegate.swift in Sources */, 295840671EE89FE4007723C6 /* IssueStatusEventCell.swift in Sources */, 29C9FDD01EC65FEE00EE3A52 /* Permission.swift in Sources */, @@ -1686,6 +1691,7 @@ 29C167761ECA0DE100439D62 /* NSAttributedStringSizing.swift in Sources */, 295840B01EEA00E1007723C6 /* Subject.swift in Sources */, 297DD5F31F069497006E7E63 /* SettingsReportSectionController.swift in Sources */, + 54AD5E8F1F24DA28004A4BD6 /* FeedSelectionProviding.swift in Sources */, 2981A8AC1EFF49EE00E25EF1 /* NSAttributedString+Trim.swift in Sources */, 2958409E1EEA00E1007723C6 /* IssueLabelSummaryCell.swift in Sources */, 29C2950E1EC7B43B00D46CD2 /* ListKitTestCase.swift in Sources */, diff --git a/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json b/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json index 0d49d1df..8be78501 100644 --- a/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -101,11 +101,6 @@ "idiom" : "ipad", "filename" : "Icon-App-83.5x83.5@2x.png", "scale" : "2x" - }, - { - "idiom" : "ios-marketing", - "size" : "1024x1024", - "scale" : "1x" } ], "info" : {