diff --git a/CHMeetupApp.xcodeproj/project.pbxproj b/CHMeetupApp.xcodeproj/project.pbxproj index 7e654b52..042e3206 100644 --- a/CHMeetupApp.xcodeproj/project.pbxproj +++ b/CHMeetupApp.xcodeproj/project.pbxproj @@ -110,6 +110,7 @@ 32DD63021EA8C92E005B565E /* ChooseProfilePhotoTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DD63001EA8C92E005B565E /* ChooseProfilePhotoTableViewCell.swift */; }; 32DD63031EA8C92E005B565E /* ChooseProfilePhotoTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 32DD63011EA8C92E005B565E /* ChooseProfilePhotoTableViewCell.xib */; }; 32DD63051EA8CED0005B565E /* ChooseProfilePhotoTableViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DD63041EA8CED0005B565E /* ChooseProfilePhotoTableViewModel.swift */; }; + 3630B8E41FAF272E00DF3F31 /* Previewing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3630B8E31FAF272E00DF3F31 /* Previewing.swift */; }; 4C18F5F21F4257360062CCA2 /* UIViewController+HUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C18F5F11F4257360062CCA2 /* UIViewController+HUD.swift */; }; 4D0E6B561E86E11100C44DC0 /* ActionCellConfigurationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D0E6B551E86E11100C44DC0 /* ActionCellConfigurationController.swift */; }; 4D8851021E9F8FC400A49ADD /* PushNotificationsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D8851011E9F8FC400A49ADD /* PushNotificationsController.swift */; }; @@ -402,6 +403,7 @@ 32DD63001EA8C92E005B565E /* ChooseProfilePhotoTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChooseProfilePhotoTableViewCell.swift; sourceTree = ""; }; 32DD63011EA8C92E005B565E /* ChooseProfilePhotoTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ChooseProfilePhotoTableViewCell.xib; sourceTree = ""; }; 32DD63041EA8CED0005B565E /* ChooseProfilePhotoTableViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChooseProfilePhotoTableViewModel.swift; sourceTree = ""; }; + 3630B8E31FAF272E00DF3F31 /* Previewing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Previewing.swift; sourceTree = ""; }; 4C18F5F11F4257360062CCA2 /* UIViewController+HUD.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+HUD.swift"; sourceTree = ""; }; 4D0E6B551E86E11100C44DC0 /* ActionCellConfigurationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ActionCellConfigurationController.swift; path = ActionCellConfigurationController/ActionCellConfigurationController.swift; sourceTree = ""; }; 4D8851011E9F8FC400A49ADD /* PushNotificationsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PushNotificationsController.swift; path = PushNotification/PushNotificationsController.swift; sourceTree = ""; }; @@ -952,6 +954,7 @@ 22323F1B1E70C0E500522E5C /* Utility */, 22323F1D1E70C0E500522E5C /* WebService */, 8AB256971E78680500B319AA /* Share */, + 3630B8E21FAF270000DF3F31 /* Previewing */, 9F487A6C1E73EE710016CE0B /* Swizzling */, ); path = Helpers; @@ -1410,6 +1413,14 @@ name = ChooseProfilePhotoCell; sourceTree = ""; }; + 3630B8E21FAF270000DF3F31 /* Previewing */ = { + isa = PBXGroup; + children = ( + 3630B8E31FAF272E00DF3F31 /* Previewing.swift */, + ); + path = Previewing; + sourceTree = ""; + }; 4D0E6B541E86E0D100C44DC0 /* ActionCellConfigurationController */ = { isa = PBXGroup; children = ( @@ -2512,6 +2523,7 @@ 8A6A84481E99AA8A00C3A9E7 /* EventFetching.swift in Sources */, 32AA9BBE1E7A91C000140413 /* PhotosPresentationView.swift in Sources */, 22323F301E70C0E500522E5C /* RequestContentParser.swift in Sources */, + 3630B8E41FAF272E00DF3F31 /* Previewing.swift in Sources */, 22323F941E70C2BE00522E5C /* PastEventsViewController.swift in Sources */, B744FA581FB07B2A00F92D4B /* AlertHeaderTableViewCell.swift in Sources */, 22323F561E70C18700522E5C /* UserPlainObject+Requests.swift in Sources */, diff --git a/CHMeetupApp/Sources/Common/Helpers/Previewing/Previewing.swift b/CHMeetupApp/Sources/Common/Helpers/Previewing/Previewing.swift new file mode 100644 index 00000000..b661be16 --- /dev/null +++ b/CHMeetupApp/Sources/Common/Helpers/Previewing/Previewing.swift @@ -0,0 +1,48 @@ +// +// Previewing.swift +// CHMeetupApp +// +// Created by Filipp Fediakov on 05.11.17. +// Copyright © 2017 CocoaHeads Community. All rights reserved. +// + +import UIKit + +extension UIViewControllerPreviewingDelegate where Self: UIViewController { + @discardableResult + func registerForPreviewing() -> Bool { + if traitCollection.forceTouchCapability == .available { + registerForPreviewing(with: self, sourceView: view) + return true + } else { + return false + } + } +} + +protocol PreviewingContentProvider { + func commitPreview(_ : UIViewController) + func preview(at: IndexPath) -> UIViewController? +} + +extension UIViewControllerPreviewingDelegate where Self: UIViewControllerWithTableView { + func previewingContextProvided(by contentProvider: PreviewingContentProvider, + at location: CGPoint, + previewingContext: UIViewControllerPreviewing) -> UIViewController? { + guard let indexPath = tableView.indexPathForRow(at: location), + let viewController = contentProvider.preview(at: indexPath) else { + return nil + } + + let sourceRect = tableView.rectForRow(at: indexPath) + previewingContext.sourceRect = sourceRect + return viewController + } +} + +extension UIViewControllerPreviewingDelegate { + func commitPreview(by contentProvider: PreviewingContentProvider, + viewController: UIViewController) { + contentProvider.commitPreview(viewController) + } +} diff --git a/CHMeetupApp/Sources/ViewControllers/Feed/Main/MainViewController.swift b/CHMeetupApp/Sources/ViewControllers/Feed/Main/MainViewController.swift index c81e816e..43ad396f 100644 --- a/CHMeetupApp/Sources/ViewControllers/Feed/Main/MainViewController.swift +++ b/CHMeetupApp/Sources/ViewControllers/Feed/Main/MainViewController.swift @@ -30,8 +30,8 @@ class MainViewController: UIViewController, DisplayCollectionWithTableViewDelega setCurrentState() fetchEvents() title = "CocoaHeads Russia".localized - PermissionsManager.requireAccess(from: self, to: .notifications) { _ in } + registerForPreviewing() } override func viewWillAppear(_ animated: Bool) { @@ -99,3 +99,17 @@ fileprivate extension MainViewController { } extension MainViewController: ProfileHierarhyViewControllerType { } + +extension MainViewController: UIViewControllerPreviewingDelegate { + func previewingContext(_ previewingContext: UIViewControllerPreviewing, + commit viewControllerToCommit: UIViewController) { + self.commitPreview(by: displayCollection, viewController: viewControllerToCommit) + } + + func previewingContext(_ previewingContext: UIViewControllerPreviewing, + viewControllerForLocation location: CGPoint) -> UIViewController? { + return self.previewingContextProvided(by: displayCollection, + at: location, + previewingContext: previewingContext) + } +} diff --git a/CHMeetupApp/Sources/ViewControllers/Feed/Main/MainViewDisplayCollection.swift b/CHMeetupApp/Sources/ViewControllers/Feed/Main/MainViewDisplayCollection.swift index 6495365a..ba6b6755 100644 --- a/CHMeetupApp/Sources/ViewControllers/Feed/Main/MainViewDisplayCollection.swift +++ b/CHMeetupApp/Sources/ViewControllers/Feed/Main/MainViewDisplayCollection.swift @@ -13,7 +13,7 @@ class MainViewDisplayCollection: DisplayCollection, DisplayCollectionAction { return [EventPreviewTableViewCellModel.self, ActionTableViewCellModel.self] } - private enum `Type` { + fileprivate enum `Type` { case events case actionButtons case collectionIsEmpty @@ -21,7 +21,7 @@ class MainViewDisplayCollection: DisplayCollection, DisplayCollectionAction { weak var delegate: DisplayCollectionWithTableViewDelegate? - private var sections: [Type] = [.events, .actionButtons, .collectionIsEmpty] + fileprivate var sections: [Type] = [.events, .actionButtons, .collectionIsEmpty] private var actionPlainObjects: [ActionPlainObject] = [] let groupImageLoader = GroupImageLoader.standard @@ -111,3 +111,23 @@ extension MainViewDisplayCollection: EventPreviewTableViewCellDelegate { delegate?.push(viewController: viewController) } } + +extension MainViewDisplayCollection: PreviewingContentProvider { + func preview(at indexPath: IndexPath) -> UIViewController? { + switch sections[indexPath.section] { + case .events: + if modelCollection[indexPath.row].isTemplate { + return nil + } + let eventPreviewViewController = Storyboards.EventPreview.instantiateEventPreviewViewController() + eventPreviewViewController.selectedEventId = modelCollection[indexPath.row].id + return eventPreviewViewController + case .actionButtons, .collectionIsEmpty: + return nil + } + } + + func commitPreview(_ viewControllerToCommit: UIViewController) { + delegate?.push(viewController: viewControllerToCommit) + } +} diff --git a/CHMeetupApp/Sources/ViewControllers/Feed/PastEvents/DisplayModel/PastEventsDisplayCollection.swift b/CHMeetupApp/Sources/ViewControllers/Feed/PastEvents/DisplayModel/PastEventsDisplayCollection.swift index 324f9b45..0fc46b9a 100644 --- a/CHMeetupApp/Sources/ViewControllers/Feed/PastEvents/DisplayModel/PastEventsDisplayCollection.swift +++ b/CHMeetupApp/Sources/ViewControllers/Feed/PastEvents/DisplayModel/PastEventsDisplayCollection.swift @@ -71,3 +71,18 @@ extension PastEventsDisplayCollection: EventPreviewTableViewCellDelegate { delegate?.push(viewController: viewController) } } + +extension PastEventsDisplayCollection: PreviewingContentProvider { + func preview(at indexPath: IndexPath) -> UIViewController? { + if modelCollection[indexPath.row].isTemplate { + return nil + } + let eventPreviewViewController = Storyboards.EventPreview.instantiateEventPreviewViewController() + eventPreviewViewController.selectedEventId = modelCollection[indexPath.row].id + return eventPreviewViewController + } + + func commitPreview(_ viewControllerToCommit: UIViewController) { + delegate?.push(viewController: viewControllerToCommit) + } +} diff --git a/CHMeetupApp/Sources/ViewControllers/Feed/PastEvents/PastEventsViewController.swift b/CHMeetupApp/Sources/ViewControllers/Feed/PastEvents/PastEventsViewController.swift index e07fa83c..05861f2b 100644 --- a/CHMeetupApp/Sources/ViewControllers/Feed/PastEvents/PastEventsViewController.swift +++ b/CHMeetupApp/Sources/ViewControllers/Feed/PastEvents/PastEventsViewController.swift @@ -27,6 +27,8 @@ class PastEventsViewController: UIViewController, DisplayCollectionWithTableView displayCollection.delegate = self tableView.registerNibs(from: displayCollection) title = "Прошедшие встречи".localized + + registerForPreviewing() } override func viewWillAppear(_ animated: Bool) { @@ -76,3 +78,17 @@ fileprivate extension PastEventsViewController { }) } } + +extension PastEventsViewController: UIViewControllerPreviewingDelegate { + func previewingContext(_ previewingContext: UIViewControllerPreviewing, + commit viewControllerToCommit: UIViewController) { + self.commitPreview(by: displayCollection, viewController: viewControllerToCommit) + } + + func previewingContext(_ previewingContext: UIViewControllerPreviewing, + viewControllerForLocation location: CGPoint) -> UIViewController? { + return self.previewingContextProvided(by: displayCollection, + at: location, + previewingContext: previewingContext) + } +}