mirror of
https://github.com/danbee/persephone
synced 2025-03-04 08:39:11 +00:00
WIP: Display tracks with duration
We also seem to have fixed the crashing bug! 🎉
This commit is contained in:
parent
ba75dee158
commit
ee20f14e38
@ -22,6 +22,8 @@ class AlbumDetailView: NSViewController {
|
|||||||
|
|
||||||
albumTracksView.dataSource = dataSource
|
albumTracksView.dataSource = dataSource
|
||||||
albumTracksView.delegate = self
|
albumTracksView.delegate = self
|
||||||
|
albumTracksView.intercellSpacing = CGSize(width: 0, height: 13)
|
||||||
|
albumTracksView.gridStyleMask = .solidHorizontalGridLineMask
|
||||||
|
|
||||||
albumCoverView.wantsLayer = true
|
albumCoverView.wantsLayer = true
|
||||||
albumCoverView.layer?.cornerRadius = 5
|
albumCoverView.layer?.cornerRadius = 5
|
||||||
@ -80,11 +82,19 @@ extension AlbumDetailView: NSTableViewDelegate {
|
|||||||
return cellForTrackNumber(tableView, with: song)
|
return cellForTrackNumber(tableView, with: song)
|
||||||
case "trackTitleColumn":
|
case "trackTitleColumn":
|
||||||
return cellForSongTitle(tableView, with: song)
|
return cellForSongTitle(tableView, with: song)
|
||||||
|
case "trackDurationColumn":
|
||||||
|
return cellForSongDuration(tableView, with: song)
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
|
||||||
|
let view = NSTableRowView()
|
||||||
|
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
|
||||||
func cellForTrackNumber(_ tableView: NSTableView, with song: Song) -> NSView {
|
func cellForTrackNumber(_ tableView: NSTableView, with song: Song) -> NSView {
|
||||||
let cellView = tableView.makeView(
|
let cellView = tableView.makeView(
|
||||||
withIdentifier: .trackNumber,
|
withIdentifier: .trackNumber,
|
||||||
@ -106,4 +116,16 @@ extension AlbumDetailView: NSTableViewDelegate {
|
|||||||
|
|
||||||
return cellView
|
return cellView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cellForSongDuration(_ tableView: NSTableView, with song: Song) -> NSView {
|
||||||
|
let cellView = tableView.makeView(
|
||||||
|
withIdentifier: .songDuration,
|
||||||
|
owner: self
|
||||||
|
) as! NSTableCellView
|
||||||
|
|
||||||
|
cellView.textField?.font = .timerFont
|
||||||
|
cellView.textField?.stringValue = song.duration.formattedTime
|
||||||
|
|
||||||
|
return cellView
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import AppKit
|
|||||||
class AlbumViewItem: NSCollectionViewItem {
|
class AlbumViewItem: NSCollectionViewItem {
|
||||||
var observer: NSKeyValueObservation?
|
var observer: NSKeyValueObservation?
|
||||||
var album: Album?
|
var album: Album?
|
||||||
|
var detailPopover: NSPopover?
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
@ -27,6 +28,12 @@ class AlbumViewItem: NSCollectionViewItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func prepareForReuse() {
|
||||||
|
super.prepareForReuse()
|
||||||
|
|
||||||
|
detailPopover?.close()
|
||||||
|
}
|
||||||
|
|
||||||
func setAlbum(_ album: Album) {
|
func setAlbum(_ album: Album) {
|
||||||
self.album = album
|
self.album = album
|
||||||
albumTitle.stringValue = album.title
|
albumTitle.stringValue = album.title
|
||||||
@ -63,10 +70,10 @@ class AlbumViewItem: NSCollectionViewItem {
|
|||||||
|
|
||||||
detailViewController.setAlbum(album)
|
detailViewController.setAlbum(album)
|
||||||
|
|
||||||
let popoverView = NSPopover()
|
detailPopover = NSPopover()
|
||||||
popoverView.contentViewController = detailViewController
|
detailPopover?.contentViewController = detailViewController
|
||||||
popoverView.behavior = .transient
|
detailPopover?.behavior = .transient
|
||||||
popoverView.show(
|
detailPopover?.show(
|
||||||
relativeTo: sender.bounds,
|
relativeTo: sender.bounds,
|
||||||
of: sender,
|
of: sender,
|
||||||
preferredEdge: .maxY
|
preferredEdge: .maxY
|
||||||
|
|||||||
@ -20,5 +20,5 @@ extension NSUserInterfaceItemIdentifier {
|
|||||||
|
|
||||||
static let trackNumber = NSUserInterfaceItemIdentifier("trackNumberCell")
|
static let trackNumber = NSUserInterfaceItemIdentifier("trackNumberCell")
|
||||||
static let songTitle = NSUserInterfaceItemIdentifier("songTitleCell")
|
static let songTitle = NSUserInterfaceItemIdentifier("songTitleCell")
|
||||||
static let songDuration = NSUserInterfaceItemIdentifier("durationCell")
|
static let songDuration = NSUserInterfaceItemIdentifier("songDurationCell")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,6 +49,10 @@ extension MPDClient {
|
|||||||
return String(cString: uri)
|
return String(cString: uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var duration: Int {
|
||||||
|
return Int(mpd_song_get_duration(song))
|
||||||
|
}
|
||||||
|
|
||||||
var album: MPDAlbum {
|
var album: MPDAlbum {
|
||||||
return MPDAlbum(
|
return MPDAlbum(
|
||||||
title: getTag(.album),
|
title: getTag(.album),
|
||||||
|
|||||||
@ -23,6 +23,10 @@ struct Song {
|
|||||||
return mpdSong.getTag(.artist)
|
return mpdSong.getTag(.artist)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var duration: Time {
|
||||||
|
return Time(timeInSeconds: mpdSong.duration)
|
||||||
|
}
|
||||||
|
|
||||||
var album: Album {
|
var album: Album {
|
||||||
return Album(mpdAlbum: mpdSong.album)
|
return Album(mpdAlbum: mpdSong.album)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,13 +57,13 @@
|
|||||||
</buttonCell>
|
</buttonCell>
|
||||||
</button>
|
</button>
|
||||||
<scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="BOb-Lr-10M">
|
<scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="BOb-Lr-10M">
|
||||||
<rect key="frame" x="359" y="20" width="444" height="436"/>
|
<rect key="frame" x="359" y="30" width="444" height="426"/>
|
||||||
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="9QN-UB-b4l">
|
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="9QN-UB-b4l">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="444" height="436"/>
|
<rect key="frame" x="0.0" y="0.0" width="444" height="426"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="none" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" id="ehr-qh-87Q">
|
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="none" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" id="ehr-qh-87Q">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="444" height="436"/>
|
<rect key="frame" x="0.0" y="0.0" width="444" height="426"/>
|
||||||
<autoresizingMask key="autoresizingMask"/>
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
<size key="intercellSpacing" width="3" height="2"/>
|
<size key="intercellSpacing" width="3" height="2"/>
|
||||||
<color key="backgroundColor" red="0.11764705882352941" green="0.11764705882352941" blue="0.11764705882352941" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
|
<color key="backgroundColor" red="0.11764705882352941" green="0.11764705882352941" blue="0.11764705882352941" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
@ -88,7 +88,7 @@
|
|||||||
<subviews>
|
<subviews>
|
||||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="6eU-Jx-HDR">
|
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="6eU-Jx-HDR">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="40" height="17"/>
|
<rect key="frame" x="0.0" y="0.0" width="40" height="17"/>
|
||||||
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="1." id="Z5y-oS-Qm8">
|
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="left" title="1." id="Z5y-oS-Qm8">
|
||||||
<font key="font" metaFont="system"/>
|
<font key="font" metaFont="system"/>
|
||||||
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
|
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
|
||||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||||
@ -106,7 +106,7 @@
|
|||||||
</tableCellView>
|
</tableCellView>
|
||||||
</prototypeCellViews>
|
</prototypeCellViews>
|
||||||
</tableColumn>
|
</tableColumn>
|
||||||
<tableColumn identifier="trackTitleColumn" width="325" minWidth="40" maxWidth="1000" id="7yp-QQ-EzC">
|
<tableColumn identifier="trackTitleColumn" width="353" minWidth="40" maxWidth="1000" id="7yp-QQ-EzC">
|
||||||
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Song Title">
|
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Song Title">
|
||||||
<font key="font" metaFont="smallSystem"/>
|
<font key="font" metaFont="smallSystem"/>
|
||||||
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
|
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
|
||||||
@ -120,12 +120,12 @@
|
|||||||
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
|
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
|
||||||
<prototypeCellViews>
|
<prototypeCellViews>
|
||||||
<tableCellView identifier="songTitleCell" id="41U-5i-Oot">
|
<tableCellView identifier="songTitleCell" id="41U-5i-Oot">
|
||||||
<rect key="frame" x="44" y="1" width="325" height="17"/>
|
<rect key="frame" x="44" y="1" width="353" height="17"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="R8t-bV-9LI">
|
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="R8t-bV-9LI">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="325" height="17"/>
|
<rect key="frame" x="0.0" y="0.0" width="353" height="17"/>
|
||||||
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="My Song Title" id="Sdi-jJ-EOM">
|
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="left" title="My Song Title" id="Sdi-jJ-EOM">
|
||||||
<font key="font" metaFont="system"/>
|
<font key="font" metaFont="system"/>
|
||||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||||
@ -143,7 +143,7 @@
|
|||||||
</tableCellView>
|
</tableCellView>
|
||||||
</prototypeCellViews>
|
</prototypeCellViews>
|
||||||
</tableColumn>
|
</tableColumn>
|
||||||
<tableColumn identifier="trackDurationColumn" width="70" minWidth="40" maxWidth="1000" id="ha5-ff-2az">
|
<tableColumn identifier="trackDurationColumn" width="42" minWidth="40" maxWidth="1000" id="ha5-ff-2az">
|
||||||
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Duration">
|
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Duration">
|
||||||
<font key="font" metaFont="smallSystem"/>
|
<font key="font" metaFont="smallSystem"/>
|
||||||
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
|
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
|
||||||
@ -156,12 +156,12 @@
|
|||||||
</textFieldCell>
|
</textFieldCell>
|
||||||
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
|
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
|
||||||
<prototypeCellViews>
|
<prototypeCellViews>
|
||||||
<tableCellView id="Lbx-5u-OFw">
|
<tableCellView identifier="songDurationCell" id="Lbx-5u-OFw">
|
||||||
<rect key="frame" x="372" y="1" width="70" height="17"/>
|
<rect key="frame" x="400" y="1" width="42" height="17"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="pCr-f1-wNs">
|
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="pCr-f1-wNs">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="70" height="17"/>
|
<rect key="frame" x="0.0" y="0.0" width="42" height="17"/>
|
||||||
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="right" title="0:00" id="Qe2-WO-eXr">
|
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="right" title="0:00" id="Qe2-WO-eXr">
|
||||||
<font key="font" metaFont="system"/>
|
<font key="font" metaFont="system"/>
|
||||||
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
|
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
|
||||||
@ -196,7 +196,7 @@
|
|||||||
</scrollView>
|
</scrollView>
|
||||||
</subviews>
|
</subviews>
|
||||||
<constraints>
|
<constraints>
|
||||||
<constraint firstAttribute="bottom" secondItem="BOb-Lr-10M" secondAttribute="bottom" constant="20" symbolic="YES" id="AaR-Nq-vZD"/>
|
<constraint firstAttribute="bottom" secondItem="BOb-Lr-10M" secondAttribute="bottom" constant="30" id="AaR-Nq-vZD"/>
|
||||||
<constraint firstItem="4Jx-I5-Nkv" firstAttribute="top" secondItem="m2v-pR-e9v" secondAttribute="bottom" constant="8" symbolic="YES" id="P10-cj-Iaz"/>
|
<constraint firstItem="4Jx-I5-Nkv" firstAttribute="top" secondItem="m2v-pR-e9v" secondAttribute="bottom" constant="8" symbolic="YES" id="P10-cj-Iaz"/>
|
||||||
<constraint firstItem="m2v-pR-e9v" firstAttribute="leading" secondItem="4Jx-I5-Nkv" secondAttribute="leading" id="PVJ-Rk-9K5"/>
|
<constraint firstItem="m2v-pR-e9v" firstAttribute="leading" secondItem="4Jx-I5-Nkv" secondAttribute="leading" id="PVJ-Rk-9K5"/>
|
||||||
<constraint firstItem="m2v-pR-e9v" firstAttribute="trailing" secondItem="4Jx-I5-Nkv" secondAttribute="trailing" id="PlO-jD-clF"/>
|
<constraint firstItem="m2v-pR-e9v" firstAttribute="trailing" secondItem="4Jx-I5-Nkv" secondAttribute="trailing" id="PlO-jD-clF"/>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user