-
Notifications
You must be signed in to change notification settings - Fork 9
Feature/keyboard commands #30
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
base: Development
Are you sure you want to change the base?
Changes from all commits
289ce8d
052c6b1
5f92526
4e2b69f
70b28b2
3023fd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,26 @@ class DetailCollectionViewController: UICollectionViewController, Storyboarded { | |
| super.viewWillDisappear(animated) | ||
| NotificationCenter.default.removeObserver(self) | ||
| } | ||
|
|
||
| override var keyCommands: [UIKeyCommand]? { | ||
| return [ | ||
| UIKeyCommand(action: #selector(previousItem), input: UIKeyCommand.inputLeftArrow, discoverabilityTitle: "Vorheriger Post"), | ||
| UIKeyCommand(action: #selector(nextItem), input: UIKeyCommand.inputRightArrow, discoverabilityTitle: "Nächster Post"), | ||
| UIKeyCommand(action: #selector(upvoteCurrentPost), input: UIKeyCommand.inputUpArrow, discoverabilityTitle: "Blussi geben"), | ||
| UIKeyCommand(action: #selector(downvoteCurrentPost), input: UIKeyCommand.inputDownArrow, discoverabilityTitle: "Minus geben"), | ||
|
|
||
| UIKeyCommand(action: #selector(previousItem), input: "a", discoverabilityTitle: "Vorheriger Post"), | ||
| UIKeyCommand(action: #selector(nextItem), input: "d", discoverabilityTitle: "Nächster Post"), | ||
| UIKeyCommand(action: #selector(upvoteCurrentPost), input: "w", discoverabilityTitle: "Blussi geben"), | ||
| UIKeyCommand(action: #selector(downvoteCurrentPost), input: "s", discoverabilityTitle: "Minus geben"), | ||
| UIKeyCommand(action: #selector(favoriteCurrentPost), input: "f", discoverabilityTitle: "Favorisieren"), | ||
| UIKeyCommand(action: #selector(toggleCommentPanel), input: "c", discoverabilityTitle: "Kommentare öffnen"), | ||
|
|
||
| UIKeyCommand(action: #selector(enterFullscreen), input: "f", modifierFlags: [.control, .command], discoverabilityTitle: "Vollbild"), | ||
| UIKeyCommand(action: #selector(toggleMute), input: "m", discoverabilityTitle: "Video stummschalten"), | ||
| UIKeyCommand(action: #selector(toggleVideoPlayback), input: " ", discoverabilityTitle: "Video starten") | ||
| ] | ||
| } | ||
|
|
||
| @objc | ||
| func nextItem() { | ||
|
|
@@ -76,6 +96,39 @@ class DetailCollectionViewController: UICollectionViewController, Storyboarded { | |
| collectionView.scrollToItem(at: newIndexPath, at: .centeredHorizontally, animated: true) | ||
| } | ||
|
|
||
| @objc func upvoteCurrentPost() { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warum die ganzen actions auf dem DetailCollectionViewController und nicht auf dem DetailViewController?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weil du CollectionView verwendest, hast du immer mehrere aktive DetailViewController.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ansonsten würden alle aktiven DetailViewController den Shortcut bekommen und alle dann Blussi vergeben oder was auch immer.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ja stimmt, überlege grad wie man das noch optimieren könnte...
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ich wollte übrigens zuerst das Observer Pattern verwenden, aber das scheiterte aus dem gleichen Grund.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UIPageViewController löst wie gesagt diese ganzen Probleme. Da wird viewWillDisappear und der ganze andere Schnutzbutz gleich gefeuert, wenn du auf die nächste Seite wischst. UICollectionView ist halt nicht für solche Fullscreensachen gedacht. Aber trotzdem damit wirklich cool umgesetzt. |
||
| getCurrentDetailController()?.upvotePost() | ||
| } | ||
|
|
||
| @objc func downvoteCurrentPost() { | ||
| getCurrentDetailController()?.downvotePost() | ||
| } | ||
|
|
||
| @objc func favoriteCurrentPost() { | ||
| getCurrentDetailController()?.favoritePost() | ||
| } | ||
|
|
||
| @objc func toggleCommentPanel() { | ||
| getCurrentDetailController()?.toggleCommentPanel() | ||
| } | ||
|
|
||
| @objc func enterFullscreen() { | ||
| getCurrentDetailController()?.enterFullscreen() | ||
| } | ||
|
|
||
| @objc func toggleMute() { | ||
| getCurrentDetailController()?.toggleMute() | ||
| } | ||
|
|
||
| @objc func toggleVideoPlayback() { | ||
| getCurrentDetailController()?.toggleVideoPlayback() | ||
| } | ||
|
|
||
| func getCurrentDetailController() -> DetailViewController? { | ||
| guard let cell = collectionView.visibleCells.first as? DetailCollectionViewCell else { return nil } | ||
| return cell.detailViewController | ||
| } | ||
|
|
||
| override func collectionView(_ collectionView: UICollectionView, | ||
| numberOfItemsInSection section: Int) -> Int { | ||
| viewModel.items.count | ||
|
|
||
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.
warum übergibst du die Farbe als Parameter?
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.
changeHeight wird von expand() und collapse() aufgerufen, und beim Collapsen möchtest du den Dragger transparent machen, und beim Expandieren schwarz.
Die Aufgabe der Methode ist es, die Höhe zu ändern, nicht die Farbe zu bestimmen.
Farbbestimmung könnte man in eine eigene Methode auslagern.