Skip to content

Commit

Permalink
Settings: option to display song duration in table rows
Browse files Browse the repository at this point in the history
  • Loading branch information
BLeeEZ committed Dec 31, 2023
1 parent f36458a commit 29dbe6b
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 32 deletions.
4 changes: 4 additions & 0 deletions Amperfy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
50722747286794FC00910574 /* MainWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50722746286794FC00910574 /* MainWindow.swift */; };
507361E02632BA3B005F151D /* GenresVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507361DF2632BA3B005F151D /* GenresVC.swift */; };
5077F936221E6D0E0099CA91 /* DownloadsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5077F935221E6D0E0099CA91 /* DownloadsVC.swift */; };
5078AFB22B40CA5E0038FD17 /* DisplaySettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5078AFB12B40CA5E0038FD17 /* DisplaySettingsView.swift */; };
50791E7828D25845006CE6E5 /* ServerSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50791E7728D25845006CE6E5 /* ServerSettingsView.swift */; };
50791E7A28D31090006CE6E5 /* ServerURLsSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50791E7928D31090006CE6E5 /* ServerURLsSettingsView.swift */; };
50791E7C28D32B8A006CE6E5 /* AlternativeURLAddDialogView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50791E7B28D32B8A006CE6E5 /* AlternativeURLAddDialogView.swift */; };
Expand Down Expand Up @@ -626,6 +627,7 @@
5077F95022279DF40099CA91 /* PlaytimeSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaytimeSlider.swift; sourceTree = "<group>"; };
5077F95222283FED0099CA91 /* RoundedImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundedImage.swift; sourceTree = "<group>"; };
5077F954222C58A10099CA91 /* GenericXmlParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericXmlParser.swift; sourceTree = "<group>"; };
5078AFB12B40CA5E0038FD17 /* DisplaySettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplaySettingsView.swift; sourceTree = "<group>"; };
50791E7728D25845006CE6E5 /* ServerSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerSettingsView.swift; sourceTree = "<group>"; };
50791E7928D31090006CE6E5 /* ServerURLsSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerURLsSettingsView.swift; sourceTree = "<group>"; };
50791E7B28D32B8A006CE6E5 /* AlternativeURLAddDialogView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlternativeURLAddDialogView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1070,6 +1072,7 @@
isa = PBXGroup;
children = (
50E77DB628D2163F00BDF882 /* SettingsView.swift */,
5078AFB12B40CA5E0038FD17 /* DisplaySettingsView.swift */,
50791E8428D36F1F006CE6E5 /* LibrarySettingsView.swift */,
50791E8628D3B7BF006CE6E5 /* PlayerSettingsView.swift */,
5005939628E593F0008C8DF6 /* SleepTimerView.swift */,
Expand Down Expand Up @@ -2020,6 +2023,7 @@
5006320123A174C0000F75A3 /* PlayerView.swift in Sources */,
50BE5D9728511C3200156FC6 /* Amperfy.xcdatamodeld in Sources */,
5007CE4721EF6A8E00BC5CBA /* PlaylistDetailVC.swift in Sources */,
5078AFB22B40CA5E0038FD17 /* DisplaySettingsView.swift in Sources */,
50DEEE07265E27070073FF20 /* DirectoryTableCell.swift in Sources */,
50C16C1821E704CE00F086F0 /* AlbumsVC.swift in Sources */,
5055AA5726835A9000096B8D /* PodcastEpisodeTableCell.swift in Sources */,
Expand Down
9 changes: 1 addition & 8 deletions Amperfy/Screens/View/AlbumSongTableCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,7 @@ class AlbumSongTableCell: SongTableCell {
playIndicator.display(playable: song, rootView: self.trackNumberLabel)
titleLabel.attributedText = NSMutableAttributedString(string: song.title, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 17)])
artistLabel.text = song.creatorName

if song.isCached {
cacheIndicatorImage.isHidden = false
artistLabelLeadConstraint.constant = 20
} else {
cacheIndicatorImage.isHidden = true
artistLabelLeadConstraint.constant = 0
}
refreshCacheAndDuration()
}

private func configureTrackNumberLabel() {
Expand Down
17 changes: 14 additions & 3 deletions Amperfy/Screens/View/AlbumSongTableCell.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -53,6 +53,12 @@
<constraint firstAttribute="width" secondItem="59g-M4-BV0" secondAttribute="height" multiplier="1:1" id="TLv-DM-CAd"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="99:59:59" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="isF-fg-ddx" userLabel="Duration">
<rect key="frame" x="411" y="19" width="61" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" systemColor="secondaryLabelColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="hPr-VQ-rTt" secondAttribute="trailing" id="0Jf-pS-3te"/>
Expand All @@ -61,20 +67,25 @@
<constraint firstItem="59g-M4-BV0" firstAttribute="leading" secondItem="hPr-VQ-rTt" secondAttribute="leading" id="69g-Qg-fnj"/>
<constraint firstItem="GFX-bI-uSL" firstAttribute="centerY" secondItem="WOq-tb-OTF" secondAttribute="centerY" id="9NK-Zt-Udb"/>
<constraint firstItem="59g-M4-BV0" firstAttribute="width" secondItem="59g-M4-BV0" secondAttribute="height" multiplier="1:1" id="Ggl-Rc-JWp"/>
<constraint firstAttribute="trailingMargin" secondItem="isF-fg-ddx" secondAttribute="trailing" id="Jrg-hR-I0V"/>
<constraint firstItem="isF-fg-ddx" firstAttribute="centerY" secondItem="WOq-tb-OTF" secondAttribute="centerY" id="a5K-hW-aMk"/>
<constraint firstItem="hPr-VQ-rTt" firstAttribute="centerY" secondItem="WOq-tb-OTF" secondAttribute="centerY" constant="-10" id="bvj-Mr-vRL"/>
<constraint firstItem="GFX-bI-uSL" firstAttribute="leading" secondItem="WOq-tb-OTF" secondAttribute="leadingMargin" id="fOI-Fn-425"/>
<constraint firstItem="YMj-gk-9M5" firstAttribute="top" secondItem="hPr-VQ-rTt" secondAttribute="bottom" constant="2" id="hWk-ln-K9O"/>
<constraint firstItem="hPr-VQ-rTt" firstAttribute="leading" secondItem="GFX-bI-uSL" secondAttribute="trailing" constant="16" id="lqV-fj-OxU"/>
<constraint firstItem="YMj-gk-9M5" firstAttribute="trailing" secondItem="hPr-VQ-rTt" secondAttribute="trailing" id="y6K-XE-CyN"/>
<constraint firstItem="YMj-gk-9M5" firstAttribute="trailing" secondItem="WOq-tb-OTF" secondAttribute="trailingMargin" id="y6K-XE-CyN"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="artistLabel" destination="YMj-gk-9M5" id="uoo-D3-R7t"/>
<outlet property="artistLabelLeadConstraint" destination="0cg-qO-oSe" id="Bg8-Eh-uKj"/>
<outlet property="artistLabelLeadingConstraint" destination="69g-Qg-fnj" id="bGd-dv-it9"/>
<outlet property="artistLabelTrailingConstraint" destination="y6K-XE-CyN" id="f8N-lG-no9"/>
<outlet property="cacheIconImage" destination="59g-M4-BV0" id="cob-f2-gd9"/>
<outlet property="cacheIndicatorImage" destination="59g-M4-BV0" id="DEG-6l-yYB"/>
<outlet property="durationLabel" destination="isF-fg-ddx" id="rSJ-6b-a0y"/>
<outlet property="titleLabel" destination="hPr-VQ-rTt" id="wmq-Vm-6lz"/>
<outlet property="titleLabelTrailingConstraint" destination="0Jf-pS-3te" id="uiR-Wp-UNA"/>
<outlet property="trackNumberLabel" destination="GFX-bI-uSL" id="Vzm-7H-jGn"/>
</connections>
<point key="canvasLocation" x="233.59999999999999" y="-210.04497751124438"/>
Expand Down
34 changes: 30 additions & 4 deletions Amperfy/Screens/View/PlayableTableCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ class PlayableTableCell: BasicTableCell {

@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var artistLabel: UILabel!
@IBOutlet weak var durationLabel: UILabel!
@IBOutlet weak var entityImage: EntityImageView!
@IBOutlet weak var downloadProgress: UIProgressView!
@IBOutlet weak var reorderLabel: UILabel?
@IBOutlet weak var cacheIconImage: UIImageView!
@IBOutlet weak var artistLabelLeadingConstraint: NSLayoutConstraint!

@IBOutlet weak var titleLabelTrailingConstraint: NSLayoutConstraint!

@IBOutlet weak var artistLabelTrailingConstraint: NSLayoutConstraint!


static let rowHeight: CGFloat = 48 + margin.bottom + margin.top

private var playerIndexCb: GetPlayerIndexFromTableCellCallback?
Expand Down Expand Up @@ -82,6 +88,18 @@ class PlayableTableCell: BasicTableCell {
}

refreshSubtitleColor()
refreshCacheAndDuration()

if let download = download, download.isDownloading {
downloadProgress.isHidden = false
downloadProgress.progress = download.progress
} else {
downloadProgress.isHidden = true
}
}

func refreshCacheAndDuration() {
guard let playable = playable else { return }

if playable.isCached {
cacheIconImage.isHidden = false
Expand All @@ -91,11 +109,16 @@ class PlayableTableCell: BasicTableCell {
artistLabelLeadingConstraint.constant = 0
}

if let download = download, download.isDownloading {
downloadProgress.isHidden = false
downloadProgress.progress = download.progress
let isDurationVisible = appDelegate.storage.settings.isShowSongDuration && (playable.duration > 0)
durationLabel.isHidden = !isDurationVisible
if isDurationVisible {
durationLabel.text = playable.duration.asColonDurationString
durationLabel.layoutIfNeeded()
artistLabelTrailingConstraint.constant = durationLabel.frame.width + 16
titleLabelTrailingConstraint.constant = durationLabel.frame.width + 16
} else {
downloadProgress.isHidden = true
artistLabelTrailingConstraint.constant = 8
titleLabelTrailingConstraint.constant = 8
}
}

Expand All @@ -109,13 +132,16 @@ class PlayableTableCell: BasicTableCell {
if let subtitleColor = self.subtitleColor {
cacheIconImage.tintColor = subtitleColor
artistLabel.textColor = subtitleColor
durationLabel.textColor = subtitleColor
} else {
cacheIconImage.tintColor = UIColor.labelColor
artistLabel.textColor = UIColor.labelColor
durationLabel.textColor = UIColor.labelColor
}
} else {
cacheIconImage.tintColor = UIColor.secondaryLabelColor
artistLabel.textColor = UIColor.secondaryLabelColor
durationLabel.textColor = UIColor.secondaryLabelColor
}
}

Expand Down
15 changes: 13 additions & 2 deletions Amperfy/Screens/View/PlayableTableCell.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -64,8 +64,15 @@
<constraint firstAttribute="width" secondItem="EMS-3K-XAV" secondAttribute="height" multiplier="1:1" id="vaM-EW-tAR"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="99:59:59" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bDU-qd-xRC" userLabel="Duration">
<rect key="frame" x="363" y="26.5" width="61" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" systemColor="secondaryLabelColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="4OZ-v0-bY2" firstAttribute="leading" secondItem="bDU-qd-xRC" secondAttribute="trailing" constant="8" id="4g8-wG-La2"/>
<constraint firstItem="4OZ-v0-bY2" firstAttribute="leading" secondItem="hPr-VQ-rTt" secondAttribute="trailing" constant="8" id="AUO-iE-pDI"/>
<constraint firstItem="nJe-7h-3tU" firstAttribute="top" secondItem="hPr-VQ-rTt" secondAttribute="bottom" constant="2" id="E4f-kL-YK1"/>
<constraint firstAttribute="trailingMargin" secondItem="4OZ-v0-bY2" secondAttribute="trailing" id="GoY-7G-GF0"/>
Expand All @@ -76,6 +83,7 @@
<constraint firstItem="moK-d1-lj1" firstAttribute="leading" secondItem="nJe-7h-3tU" secondAttribute="leading" id="Yix-AI-aoZ"/>
<constraint firstItem="hPr-VQ-rTt" firstAttribute="leading" secondItem="Kod-kR-xnX" secondAttribute="trailing" constant="8" id="YjP-mp-fEC"/>
<constraint firstItem="Kod-kR-xnX" firstAttribute="leading" secondItem="WOq-tb-OTF" secondAttribute="leadingMargin" id="afU-ZR-sb0"/>
<constraint firstItem="bDU-qd-xRC" firstAttribute="centerY" secondItem="WOq-tb-OTF" secondAttribute="centerY" id="amf-YE-T5X"/>
<constraint firstAttribute="trailingMargin" relation="greaterThanOrEqual" secondItem="hPr-VQ-rTt" secondAttribute="trailing" id="hho-eL-Cqq"/>
<constraint firstAttribute="trailingMargin" secondItem="moK-d1-lj1" secondAttribute="trailing" id="huL-V9-Zmu"/>
<constraint firstItem="4OZ-v0-bY2" firstAttribute="leading" secondItem="nJe-7h-3tU" secondAttribute="trailing" constant="8" id="mcC-ks-bMI"/>
Expand All @@ -88,11 +96,14 @@
<connections>
<outlet property="artistLabel" destination="nJe-7h-3tU" id="SlX-ew-mVM"/>
<outlet property="artistLabelLeadingConstraint" destination="Pwh-zQ-8MT" id="dvC-i3-lJg"/>
<outlet property="artistLabelTrailingConstraint" destination="mcC-ks-bMI" id="rIa-aI-ac3"/>
<outlet property="cacheIconImage" destination="EMS-3K-XAV" id="iht-Wf-bpc"/>
<outlet property="downloadProgress" destination="moK-d1-lj1" id="Jof-Zl-a7H"/>
<outlet property="durationLabel" destination="bDU-qd-xRC" id="kpP-DX-RaK"/>
<outlet property="entityImage" destination="Kod-kR-xnX" id="Ovk-jM-HNG"/>
<outlet property="reorderLabel" destination="4OZ-v0-bY2" id="5zb-zm-AcA"/>
<outlet property="titleLabel" destination="hPr-VQ-rTt" id="Gwv-hx-ZdG"/>
<outlet property="titleLabelTrailingConstraint" destination="AUO-iE-pDI" id="dyR-Nv-wiS"/>
</connections>
<point key="canvasLocation" x="217.59999999999999" y="-203.29835082458771"/>
</tableViewCell>
Expand Down
21 changes: 20 additions & 1 deletion Amperfy/Screens/View/SongTableCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ class SongTableCell: BasicTableCell {

@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var artistLabel: UILabel!
@IBOutlet weak var durationLabel: UILabel!
@IBOutlet weak var entityImage: EntityImageView!
@IBOutlet weak private var cacheIconImage: UIImageView!
@IBOutlet weak private var artistLabelLeadingConstraint: NSLayoutConstraint!
@IBOutlet weak var artistLabelTrailingConstraint: NSLayoutConstraint!
@IBOutlet weak var titleLabelTrailingConstraint: NSLayoutConstraint!

static let rowHeight: CGFloat = 48 + margin.bottom + margin.top

Expand Down Expand Up @@ -60,8 +63,12 @@ class SongTableCell: BasicTableCell {
playIndicator.display(playable: song, rootView: self.entityImage, isOnImage: true)
titleLabel.attributedText = NSMutableAttributedString(string: song.title, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 17)])
artistLabel.text = song.creatorName

entityImage.display(container: song)
refreshCacheAndDuration()
}

func refreshCacheAndDuration() {
guard let song = song else { return }

if song.isCached {
cacheIconImage.isHidden = false
Expand All @@ -70,6 +77,18 @@ class SongTableCell: BasicTableCell {
cacheIconImage.isHidden = true
artistLabelLeadingConstraint.constant = 0
}

let isDurationVisible = appDelegate.storage.settings.isShowSongDuration && (song.duration > 0)
durationLabel.isHidden = !isDurationVisible
if isDurationVisible {
durationLabel.text = song.duration.asColonDurationString
durationLabel.layoutIfNeeded()
artistLabelTrailingConstraint.constant = durationLabel.frame.width + 8
titleLabelTrailingConstraint.constant = durationLabel.frame.width + 8
} else {
artistLabelTrailingConstraint.constant = 0
titleLabelTrailingConstraint.constant = 0
}
}

override func prepareForReuse() {
Expand Down
Loading

0 comments on commit 29dbe6b

Please sign in to comment.