Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Pr0gramm/Pr0gramm/Detail/Comments/CommentsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,31 @@ class CommentsViewController: UIViewController, Storyboarded, UIScrollViewDelega

@objc
func expand() {
self.topConstraint.constant = 0
changeHeight(distanceFromTop: 0, draggerColor: #colorLiteral(red: 0.0862745098, green: 0.0862745098, blue: 0.09411764706, alpha: 1))
}

func collapse() {
guard let hostingViewController = hostingViewController else { return }
changeHeight(distanceFromTop: hostingViewController.view.frame.height - draggerView.frame.height, draggerColor: .clear)
}

func toggle() {
if topConstraint.constant == 0 {
collapse()
} else {
expand()
}
}

private func changeHeight(distanceFromTop: CGFloat, draggerColor: UIColor) {
self.topConstraint.constant = distanceFromTop

UIView.animate(withDuration: 0.25,
delay: 0.0,
options: [.allowUserInteraction, .curveEaseInOut],
animations: {
self.hostingViewController?.view.layoutIfNeeded()
self.draggerView.backgroundColor = #colorLiteral(red: 0.0862745098, green: 0.0862745098, blue: 0.09411764706, alpha: 1)
Copy link
Copy Markdown
Owner

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?

Copy link
Copy Markdown
Author

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.

self.draggerView.backgroundColor = draggerColor
})

reloadDataIfNeeded()
Expand Down
53 changes: 53 additions & 0 deletions Pr0gramm/Pr0gramm/Detail/DetailCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -76,6 +96,39 @@ class DetailCollectionViewController: UICollectionViewController, Storyboarded {
collectionView.scrollToItem(at: newIndexPath, at: .centeredHorizontally, animated: true)
}

@objc func upvoteCurrentPost() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warum die ganzen actions auf dem DetailCollectionViewController und nicht auf dem DetailViewController?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weil du CollectionView verwendest, hast du immer mehrere aktive DetailViewController.
Daher werden die Shortcuts auf dem DetailCollectionViewController alleine abgefangen und dann an den jeweils aktiven DetailViewController weitergeleitet.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ja stimmt, überlege grad wie man das noch optimieren könnte...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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
Expand Down
52 changes: 48 additions & 4 deletions Pr0gramm/Pr0gramm/Detail/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ class DetailViewController: ScrollingContentViewController, Storyboarded {

infoView.showReplyAction = { [unowned self] in self.coordinator?.showReplyForPost(viewModel: self.viewModel) }
infoView.showCommentsAction = { [unowned self] in self.showComments() }
infoView.upvoteAction = { [weak self] in self?.navigation?.showBanner(with: "Han blussert") }
infoView.downvoteAction = { [weak self] in self?.navigation?.showBanner(with: "Han miesert") }
infoView.upvoteAction = { [weak self] in self?.didFinishUpvote() }
infoView.downvoteAction = { [weak self] in self?.didFinishDownvote() }
infoView.showUserAction = { [weak self] name in
guard let navigationController = self?.navigationController else { return }
self?.coordinator?.showUserProfile(for: name, viewController: navigationController)
Expand All @@ -142,6 +142,51 @@ class DetailViewController: ScrollingContentViewController, Storyboarded {
setupVideo(for: item)
}
}

func upvotePost() {
viewModel.vote(.up)
didFinishUpvote()
}

func downvotePost() {
viewModel.vote(.down)
didFinishDownvote()
}

func favoritePost() {
viewModel.vote(.favorite)
}

func toggleCommentPanel() {
commentsViewController?.toggle()
}

func enterFullscreen() {
showImageDetail()
avPlayerViewController?.goFullScreen()
}

func toggleMute() {
avPlayerViewController?.player?.isMuted.toggle()
}

func toggleVideoPlayback() {
guard let player = avPlayerViewController?.player,
player.error == nil else { return }
if player.rate != 0 {
player.pause()
} else {
player.play()
}
}

private func didFinishUpvote() {
navigation?.showBanner(with: "Han blussert")
}

private func didFinishDownvote() {
navigation?.showBanner(with: "Han miesert")
}

func cleanup() {
avPlayer = nil
Expand Down Expand Up @@ -245,8 +290,7 @@ extension DetailViewController: UIContextMenuInteractionDelegate {
}

let fullscreenAction = UIAction(title: "Vollbild", image: UIImage(systemName: "rectangle.expand.vertical")) { [unowned self] _ in
self.showImageDetail()
self.avPlayerViewController?.goFullScreen()
self.enterFullscreen()
}

let saveToCameraRollAction = UIAction(title: "In Fotos speichern", image: UIImage(systemName: "photo")) { [unowned self] _ in
Expand Down
15 changes: 15 additions & 0 deletions Pr0gramm/Pr0gramm/Misc/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ extension Theme {
$0.font = font15
}

// Prevent theming of text in the keyboard shortcut discovery overlay (appearing when holding the Command key)
// TODO: The overlay class should be more specific, but I can't find any resource about the name or class of this system overlay.
// TODO: Maybe it is a wise idea to scrap the global styling of UITextViews altogether because of the side-effects.
UITextView.appearance(whenContainedInInstancesOf: [UIVisualEffectView.self]).with {
$0.textColor = nil
$0.font = nil
}

UITextField.appearance().with {
$0.font = font15
}
Expand Down Expand Up @@ -172,6 +180,13 @@ extension Theme {
$0.tintColor = tint
}

// Prevent theming of text containing icons in the keyboard shortcut discovery overlay (appearing when holding the Command key)
// TODO: The overlay class should be more specific, but I can't find any resource about the name or class of this system overlay.
// TODO: Maybe it is a wise idea to scrap the global styling of UIImageView altogether because of the side-effects.
UIImageView.appearance(whenContainedInInstancesOf: [UIVisualEffectView.self]).with {
$0.tintColor = nil
}

UISegmentedControl.appearance().with {
$0.setTitleTextAttributes([.font: font12,
.foregroundColor: #colorLiteral(red: 0.9490196078, green: 0.9607843137, blue: 0.9568627451, alpha: 1)], for: .normal)
Expand Down