1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00
persephone/Persephone/Controllers/AlbumViewController.swift
Dan Barber 2d6aa478a7
Add a button to albums that plays the album
This works by clearing the queue, adding all the tracks from the album
to the queue and playing the first track.

Fix bug where resize might leave a play button visible

Had to refactor the QueueView somewhat as there was a bug that only
surfaced on clearing and refilling the playlist. The bug was due to the
way NSOutlineView reuses subviews.

Add screenshot with album play button

Move queue datasource and refactor view controller

Move album datasource out of the view controller
2019-02-22 13:09:09 -05:00

64 lines
1.5 KiB
Swift

//
// AlbumViewController.swift
// Persephone
//
// Created by Daniel Barber on 2019/2/08.
// Copyright © 2019 Dan Barber. All rights reserved.
//
import Cocoa
class AlbumViewController: NSViewController,
NSCollectionViewDelegate,
NSCollectionViewDelegateFlowLayout {
let paddingWidth: CGFloat = 40
let gutterWidth: CGFloat = 20
var dataSource = AlbumDataSource()
override func viewDidLoad() {
super.viewDidLoad()
albumScrollView.postsBoundsChangedNotifications = true
NotificationCenter.default.addObserver(
self,
selector: #selector(updateAlbums(_:)),
name: Notification.loadedAlbums,
object: AppDelegate.mpdClient
)
NotificationCenter.default.addObserver(
self,
selector: #selector(clearAlbums(_:)),
name: Notification.willDisconnect,
object: AppDelegate.mpdClient
)
albumCollectionView.dataSource = dataSource
}
override func viewWillLayout() {
super.viewWillLayout()
albumCollectionView.collectionViewLayout?.invalidateLayout()
}
@objc func updateAlbums(_ notification: Notification) {
guard let albums = notification.userInfo?[Notification.albumsKey] as? [MPDClient.Album]
else { return }
dataSource.albums = albums
albumCollectionView.reloadData()
}
@objc func clearAlbums(_ notification: Notification) {
dataSource.albums = []
albumCollectionView.reloadData()
}
@IBOutlet var albumScrollView: NSScrollView!
@IBOutlet var albumCollectionView: NSCollectionView!
}