1
1
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:
Daniel Barber 2019-05-20 22:24:02 -04:00
parent 63c55e1bd4
commit 31b764905a
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
6 changed files with 55 additions and 18 deletions

View File

@ -22,6 +22,8 @@ class AlbumDetailView: NSViewController {
albumTracksView.dataSource = dataSource
albumTracksView.delegate = self
albumTracksView.intercellSpacing = CGSize(width: 0, height: 13)
albumTracksView.gridStyleMask = .solidHorizontalGridLineMask
albumCoverView.wantsLayer = true
albumCoverView.layer?.cornerRadius = 5
@ -80,11 +82,19 @@ extension AlbumDetailView: NSTableViewDelegate {
return cellForTrackNumber(tableView, with: song)
case "trackTitleColumn":
return cellForSongTitle(tableView, with: song)
case "trackDurationColumn":
return cellForSongDuration(tableView, with: song)
default:
return nil
}
}
func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
let view = NSTableRowView()
return view
}
func cellForTrackNumber(_ tableView: NSTableView, with song: Song) -> NSView {
let cellView = tableView.makeView(
withIdentifier: .trackNumber,
@ -106,4 +116,16 @@ extension AlbumDetailView: NSTableViewDelegate {
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
}
}

View File

@ -11,6 +11,7 @@ import AppKit
class AlbumViewItem: NSCollectionViewItem {
var observer: NSKeyValueObservation?
var album: Album?
var detailPopover: NSPopover?
override func viewDidLoad() {
super.viewDidLoad()
@ -27,6 +28,12 @@ class AlbumViewItem: NSCollectionViewItem {
}
}
override func prepareForReuse() {
super.prepareForReuse()
detailPopover?.close()
}
func setAlbum(_ album: Album) {
self.album = album
albumTitle.stringValue = album.title
@ -63,10 +70,10 @@ class AlbumViewItem: NSCollectionViewItem {
detailViewController.setAlbum(album)
let popoverView = NSPopover()
popoverView.contentViewController = detailViewController
popoverView.behavior = .transient
popoverView.show(
detailPopover = NSPopover()
detailPopover?.contentViewController = detailViewController
detailPopover?.behavior = .transient
detailPopover?.show(
relativeTo: sender.bounds,
of: sender,
preferredEdge: .maxY

View File

@ -20,5 +20,5 @@ extension NSUserInterfaceItemIdentifier {
static let trackNumber = NSUserInterfaceItemIdentifier("trackNumberCell")
static let songTitle = NSUserInterfaceItemIdentifier("songTitleCell")
static let songDuration = NSUserInterfaceItemIdentifier("durationCell")
static let songDuration = NSUserInterfaceItemIdentifier("songDurationCell")
}

View File

@ -49,6 +49,10 @@ extension MPDClient {
return String(cString: uri)
}
var duration: Int {
return Int(mpd_song_get_duration(song))
}
var album: MPDAlbum {
return MPDAlbum(
title: getTag(.album),

View File

@ -23,6 +23,10 @@ struct Song {
return mpdSong.getTag(.artist)
}
var duration: Time {
return Time(timeInSeconds: mpdSong.duration)
}
var album: Album {
return Album(mpdAlbum: mpdSong.album)
}

View File

@ -57,13 +57,13 @@
</buttonCell>
</button>
<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">
<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"/>
<subviews>
<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"/>
<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"/>
@ -88,7 +88,7 @@
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="6eU-Jx-HDR">
<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"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
@ -106,7 +106,7 @@
</tableCellView>
</prototypeCellViews>
</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">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
@ -120,12 +120,12 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<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"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="R8t-bV-9LI">
<rect key="frame" x="0.0" y="0.0" width="325" height="17"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="My Song Title" id="Sdi-jJ-EOM">
<rect key="frame" x="0.0" y="0.0" width="353" height="17"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="left" title="My Song Title" id="Sdi-jJ-EOM">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
@ -143,7 +143,7 @@
</tableCellView>
</prototypeCellViews>
</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">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
@ -156,12 +156,12 @@
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="Lbx-5u-OFw">
<rect key="frame" x="372" y="1" width="70" height="17"/>
<tableCellView identifier="songDurationCell" id="Lbx-5u-OFw">
<rect key="frame" x="400" y="1" width="42" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<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">
<font key="font" metaFont="system"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
@ -196,7 +196,7 @@
</scrollView>
</subviews>
<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="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"/>