-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gallery of images #277
Merged
Merged
Gallery of images #277
Changes from 13 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
83a6c41
Implemented bookmark display name
mneuwert dcb3335
Merge branch 'master' into feature/bookmark_displayname
hosy 627bcd6
Fixed indentation
mneuwert a537c41
Merge branch 'master' into feature/bookmark_displayname
mneuwert 789d536
Implemented different solution to use displayName
mneuwert fee87b1
Merge branch 'master' into feature/bookmark_displayname
hosy 5d1ac6b
- First gallery approach
pablocarmu 301a6d7
- Changed the structure of the hostViewController to be more 'query f…
pablocarmu 4d642b7
- Made some improvements in the host controller
pablocarmu 100a2cb
- Coded new gesture recognizers
pablocarmu ee8df02
- Removed weak reference of item in DisplayViewController!
pablocarmu bf31d65
- Removed unused code.
pablocarmu 1968da8
- remove lint warnings
pablocarmu d95aee8
- Make the gallery background Themeable
pablocarmu 5fdc021
- Code review changes
pablocarmu 24d6ed1
- Removed unused files
pablocarmu 2228204
- Reset the zoom when the view disappear.
pablocarmu 6d383c6
- Fix indentation issues
pablocarmu 998fd65
moved reset zoom to viewDidDisappear, to remove UI animation from scr…
hosy 41f708a
Merge branch 'master' into feature/bookmark_displayname
hosy 93db9a2
Merge branch 'master' into feature/gallery_of_images
hosy f386624
adapt OCConnection init method to SDK changes
hosy b3152e0
Merge branch 'master' into feature/bookmark_displayname
hosy 971e197
Merge branch 'master' into feature/bookmark_displayname
hosy 0539d17
- Removed the use of `self`.
pablocarmu 6db86cf
- Made a comment in the gallery filter regexp to better explain what
pablocarmu ea31e59
Merge branch 'master' into feature/gallery_of_images
pablocarmu f525a67
Merge branch 'master' of github.com:owncloud/ios-app
hosy bbfcc5d
- Adapt constants to code style guide.
pablocarmu 2458f59
Merge branch 'master' into feature/gallery_of_images
hosy 1a6be86
Merge branch 'master' into feature/gallery_of_images
hosy a50b263
- Fixed a nasty bug related with zero bounds inside the image previewer.
pablocarmu c5621c0
Merge branch 'master' into feature/gallery_of_images
pablocarmu 3b776d7
- Fixed a theme issue in DiplayViewController
pablocarmu 504ab3d
- Fixed the progress bar constraint issues
pablocarmu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule ios-sdk
updated
16 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
// | ||
// AlternativePageViewController.swift | ||
// ownCloud | ||
// | ||
// Created by Pablo Carrascal on 14/02/2019. | ||
// Copyright © 2019 ownCloud GmbH. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import ownCloudSDK | ||
|
||
class GalleryHostViewController: UIPageViewController { | ||
|
||
typealias Filter = ([OCItem]) -> [OCItem] | ||
|
||
// MARK: - Constants | ||
let hasChangesAvailableKeyPath: String = "hasChangesAvailable" | ||
let imageFilterRegexp: String = "\\A((image/(?!(gif|svg*))))" | ||
|
||
// MARK: - Instance Variables | ||
weak private var core: OCCore? | ||
private var selectedItem: OCItem | ||
private var items: [OCItem]? | ||
private var query: OCQuery | ||
private weak var viewControllerToTansition: DisplayViewController? | ||
private var selectedFilter: Filter? | ||
|
||
// MARK: - Filters | ||
lazy var filterImageFiles: Filter = { items in | ||
let filteredItems = items.filter({$0.type != .collection && $0.mimeType?.matches(regExp: self.imageFilterRegexp) ?? false}) | ||
return filteredItems | ||
} | ||
|
||
lazy var filterOneItem: Filter = { items in | ||
let filteredItems = items.filter({$0.type != .collection && $0.fileID == self.selectedItem.fileID}) | ||
return filteredItems | ||
} | ||
|
||
// MARK: - Init & deinit | ||
init(core: OCCore, selectedItem: OCItem, query: OCQuery) { | ||
self.core = core | ||
self.selectedItem = selectedItem | ||
self.query = query | ||
|
||
super.init(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil) | ||
query.addObserver(self, forKeyPath: hasChangesAvailableKeyPath, options: [.initial, .new], context: nil) | ||
Theme.shared.register(client: self) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
deinit { | ||
query.removeObserver(self, forKeyPath: hasChangesAvailableKeyPath) | ||
Theme.shared.unregister(client: self) | ||
} | ||
|
||
// MARK: - ViewController lifecycle | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
dataSource = self | ||
mneuwert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
delegate = self | ||
|
||
if selectedItem.mimeType?.matches(regExp: imageFilterRegexp) ?? false { | ||
selectedFilter = filterImageFiles | ||
} else { | ||
selectedFilter = filterOneItem | ||
} | ||
|
||
query.requestChangeSet(withFlags: .onlyResults) { [weak self] ( _, changeSet) in | ||
guard let `self` = self else { return} | ||
mneuwert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
guard let queryResult = changeSet?.queryResult else { return } | ||
|
||
self.items = self.selectedFilter?(queryResult) | ||
|
||
if let items = self.items, let index = items.firstIndex(where: {$0.fileID == self.selectedItem.fileID}) { | ||
let itemToDisplay = items[index] | ||
|
||
guard let mimeType = itemToDisplay.mimeType else { return } | ||
OnMainThread { | ||
let viewController = self.selectDisplayViewControllerBasedOn(mimeType: mimeType) | ||
let configuration = self.configurationFor(itemToDisplay, viewController: viewController) | ||
|
||
viewController.configure(configuration) | ||
self.addChild(viewController) | ||
viewController.didMove(toParent: self) | ||
|
||
self.setViewControllers([viewController], direction: .forward, animated: false, completion: nil) | ||
|
||
viewController.present(item: itemToDisplay) | ||
viewController.updateNavigationBarItems() | ||
} | ||
} | ||
} | ||
} | ||
|
||
override var childForHomeIndicatorAutoHidden : UIViewController? { | ||
if let childViewController = self.children.first { | ||
return childViewController | ||
} | ||
return nil | ||
} | ||
|
||
// swiftlint:disable block_based_kvo | ||
// Would love to use the block-based KVO, but it doesn't seem to work when used on the .state property of the query :-( | ||
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { | ||
if (object as? OCQuery) === query { | ||
query.requestChangeSet(withFlags: .onlyResults) { ( _, changeSet) in | ||
guard changeSet != nil else { return } | ||
self.items = self.selectedFilter?(changeSet!.queryResult) | ||
} | ||
} | ||
} | ||
// swiftlint:enable block_based_kvo | ||
|
||
// MARK: - Extension selection | ||
private func selectDisplayViewControllerBasedOn(mimeType: String) -> (DisplayViewController) { | ||
|
||
let locationIdentifier = OCExtensionLocationIdentifier(rawValue: mimeType) | ||
let location: OCExtensionLocation = OCExtensionLocation(ofType: .viewer, identifier: locationIdentifier) | ||
let context = OCExtensionContext(location: location, requirements: nil, preferences: nil) | ||
|
||
var extensions: [OCExtensionMatch]? | ||
|
||
do { | ||
try extensions = OCExtensionManager.shared.provideExtensions(for: context) | ||
} catch { | ||
return DisplayViewController() | ||
} | ||
|
||
guard let matchedExtensions = extensions else { | ||
return DisplayViewController() | ||
} | ||
|
||
guard matchedExtensions.count > 0 else { | ||
return DisplayViewController() | ||
} | ||
|
||
let preferedExtension: OCExtension = matchedExtensions[0].extension | ||
|
||
let extensionObject = preferedExtension.provideObject(for: context) | ||
|
||
guard let controllerType = extensionObject as? (DisplayViewController & DisplayExtension) else { | ||
return DisplayViewController() | ||
} | ||
|
||
return controllerType | ||
} | ||
|
||
// MARK: - Helper methods | ||
private func viewControllerAtIndex(index: Int) -> UIViewController? { | ||
guard let items = items else { return nil } | ||
|
||
guard index >= 0, index < items.count else { return nil } | ||
|
||
let item = items[index] | ||
|
||
let newViewController = selectDisplayViewControllerBasedOn(mimeType: item.mimeType!) | ||
let configuration = configurationFor(item, viewController: newViewController) | ||
|
||
newViewController.configure(configuration) | ||
newViewController.present(item: item) | ||
return newViewController | ||
} | ||
|
||
private func configurationFor(_ item: OCItem, viewController: UIViewController) -> DisplayViewConfiguration { | ||
let shouldDownload = viewController is (DisplayViewController & DisplayExtension) ? true : false | ||
var configuration: DisplayViewConfiguration | ||
if !shouldDownload { | ||
configuration = DisplayViewConfiguration(item: item, core: core, state: .notSupportedMimeType) | ||
} else { | ||
configuration = DisplayViewConfiguration(item: item, core: core, state: .hasNetworkConnection) | ||
} | ||
return configuration | ||
} | ||
} | ||
|
||
extension GalleryHostViewController: UIPageViewControllerDataSource { | ||
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { | ||
if let displayViewController = viewControllers?.first as? DisplayViewController, | ||
let item = displayViewController.item, | ||
let index = items?.firstIndex(where: {$0.fileID == item.fileID}) { | ||
return viewControllerAtIndex(index: index + 1) | ||
} | ||
|
||
return nil | ||
|
||
} | ||
|
||
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { | ||
|
||
if let displayViewController = viewControllers?.first as? DisplayViewController, | ||
let item = displayViewController.item, | ||
let index = items?.firstIndex(where: {$0.fileID == item.fileID}) { | ||
return viewControllerAtIndex(index: index - 1) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
extension GalleryHostViewController: UIPageViewControllerDelegate { | ||
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) { | ||
|
||
let previousViewController = previousViewControllers[0] | ||
previousViewController.didMove(toParent: nil) | ||
|
||
if completed, let viewControllerToTransition = self.viewControllerToTansition { | ||
if self.children.contains(viewControllerToTransition) == false { | ||
self.addChild(viewControllerToTransition) | ||
} | ||
viewControllerToTransition.didMove(toParent: self) | ||
viewControllerToTransition.updateNavigationBarItems() | ||
} | ||
} | ||
|
||
func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) { | ||
if let viewControllerToTransition = pendingViewControllers[0] as? DisplayViewController { | ||
mneuwert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.viewControllerToTansition = viewControllerToTransition | ||
} | ||
} | ||
} | ||
|
||
extension GalleryHostViewController: Themeable { | ||
func applyThemeCollection(theme: Theme, collection: ThemeCollection, event: ThemeEvent) { | ||
self.view.backgroundColor = collection.tableBackgroundColor | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pablocarmu It means all
image/...
but notimage/gif
and notimage/svg,
right? May be put a short comment explaining what it matches, so that somebody who reads doesn't need to think twice;)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll code a comment here, also I've removed the blacklist for
gif
andsvg
and now can be previewed as well in the gallery.