Stuff…
This commit is contained in:
76
TagTunes/AlbumTableCellView.swift
Normal file → Executable file
76
TagTunes/AlbumTableCellView.swift
Normal file → Executable file
@@ -8,9 +8,9 @@
|
||||
|
||||
import Cocoa
|
||||
import AppKitPlus
|
||||
import SearchAPI
|
||||
|
||||
/// A table cell view to represent an `Album`. This view can be initialized using
|
||||
/// `initWithFrame`.
|
||||
/// A table cell view to represent an `Album`.
|
||||
public class AlbumTableCellView: AdvancedTableCellView {
|
||||
|
||||
// MARK: Types
|
||||
@@ -55,19 +55,6 @@ public class AlbumTableCellView: AdvancedTableCellView {
|
||||
return loadingIndicator
|
||||
}()
|
||||
|
||||
/// Intended to be used as accessory view.
|
||||
///
|
||||
/// Displayed for search results.
|
||||
@IBOutlet public lazy var button: NSButton! = {
|
||||
let button = NSButton()
|
||||
button.setButtonType(NSButtonType.MomentaryPushInButton)
|
||||
button.bezelStyle = NSBezelStyle.RoundedBezelStyle
|
||||
button.controlSize = .SmallControlSize
|
||||
button.setContentHuggingPriority(NSLayoutPriorityDefaultHigh, forOrientation: .Horizontal)
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
return button
|
||||
}()
|
||||
|
||||
@IBOutlet public lazy var errorButton: NSButton! = {
|
||||
let errorButton = NSButton()
|
||||
errorButton.setButtonType(NSButtonType.MomentaryChangeButton)
|
||||
@@ -114,22 +101,23 @@ public class AlbumTableCellView: AdvancedTableCellView {
|
||||
/// Configures the receiver to display the specified `album`.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - album: The album to be displayed.
|
||||
/// - loading: `true` if a loading indicator should be displayed at the
|
||||
/// album view.
|
||||
public func setupForAlbum(album: Album, loading: Bool, error: NSError?) {
|
||||
textField?.stringValue = Preferences.sharedPreferences.useCensoredNames ? album.censoredName : album.name
|
||||
secondaryTextField?.stringValue = album.artistName
|
||||
asyncImageView.downloadImageFromURL(album.artwork.displayImageURL)
|
||||
if loading {
|
||||
/// - albumItem: The album to be displayed.
|
||||
/// - height: The height the cell view is going to have. This is used to
|
||||
/// apropriately scale the album's artwork.
|
||||
public func setupForAlbumItem(albumItem: AlbumItem, height: CGFloat) {
|
||||
textField?.stringValue = Preferences.sharedPreferences.useCensoredNames ? albumItem.album.censoredName : albumItem.album.name
|
||||
secondaryTextField?.stringValue = albumItem.album.artist.name
|
||||
asyncImageView.downloadImageFromURL(albumItem.album.artwork.optimalArtworkURLForImageSize(height))
|
||||
switch albumItem.loadingState {
|
||||
case .Loading:
|
||||
textField?.textColor = NSColor.disabledControlTextColor()
|
||||
rightAccessoryView = loadingIndicator
|
||||
} else if error != nil {
|
||||
case .Error:
|
||||
textField?.textColor = NSColor.redColor()
|
||||
rightAccessoryView = errorButton
|
||||
} else {
|
||||
case .Normal:
|
||||
textField?.textColor = NSColor.controlTextColor()
|
||||
if album.saved {
|
||||
if albumItem.saved {
|
||||
let aspectRatioConstraint = NSLayoutConstraint(
|
||||
item: secondaryImageView,
|
||||
attribute: .Width,
|
||||
@@ -145,33 +133,31 @@ public class AlbumTableCellView: AdvancedTableCellView {
|
||||
toItem: nil,
|
||||
attribute: .Width,
|
||||
multiplier: 1,
|
||||
constant: 17)
|
||||
constant: Constants.secondaryImageViewWidth)
|
||||
setRightAccessoryView(secondaryImageView, withConstraints: [aspectRatioConstraint, widthConstraint])
|
||||
} else {
|
||||
rightAccessoryView = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Configures the receiver to display the specified `searchResult`.
|
||||
|
||||
/// Configures the cell to display the specified `album`. This method should
|
||||
/// be used to display search results.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - searchResult: The search result to be displayed.
|
||||
/// - selectable: `true` if the search result can be selected, `false`
|
||||
/// otherwise.
|
||||
public func setupForSearchResult(searchResult: SearchResult, selectable: Bool) {
|
||||
textField?.stringValue = Preferences.sharedPreferences.useCensoredNames ? searchResult.censoredName : searchResult.name
|
||||
/// - album: The `Album` to be displayed.
|
||||
/// - enabled: Wether the cell should appear *enabled*. If not it draws its
|
||||
/// text in a gray color.
|
||||
/// - height: The height the cell view is going to have. This is used to
|
||||
/// appropriately scale the album's artwork.
|
||||
public func setupForAlbum(album: Album, enabled: Bool, height: CGFloat) {
|
||||
textField?.stringValue = Preferences.sharedPreferences.useCensoredNames ? album.censoredName : album.name
|
||||
textField?.textColor = NSColor.controlTextColor()
|
||||
secondaryTextField?.stringValue = searchResult.artistName
|
||||
asyncImageView.downloadImageFromURL(searchResult.artwork.displayImageURL)
|
||||
if selectable {
|
||||
button.title = NSLocalizedString("Select", comment: "Button title for 'selecting a search result'")
|
||||
button.enabled = true
|
||||
} else {
|
||||
button.title = NSLocalizedString("Added", comment: "Button title for a search result that is already present")
|
||||
button.enabled = false
|
||||
}
|
||||
rightAccessoryView = button
|
||||
secondaryTextField?.stringValue = album.artist.name
|
||||
textField?.textColor = enabled ? NSColor.textColor() : NSColor.disabledControlTextColor()
|
||||
secondaryTextField?.textColor = enabled ? NSColor.secondaryLabelColor() : NSColor.disabledControlTextColor()
|
||||
asyncImageView.downloadImageFromURL(album.artwork.optimalArtworkURLForImageSize(height))
|
||||
asyncImageView.enabled = enabled
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user