Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make track list cells display entire album and artist #90

Open
wants to merge 1 commit into
base: hotfix/cover-art-issue-and-ios13-missing-icons
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 65 additions & 16 deletions Classes/View Controllers/Table Cells/UniversalTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
import UIKit
import SnapKit

@objc final class UniversalTableViewCell: UITableViewCell {
@objc class UniversalTableViewCell: UITableViewCell {
@objc static let reuseId = "UniversalTableViewCell"

private var tableCellModel: TableCellModel?

private let headerLabel = UILabel()
private let cachedIndicator = CellCachedIndicatorView()
private let numberLabel = UILabel()
private let coverArtView = AsyncImageView()
private let primaryLabel = UILabel()
private let secondaryLabel = UILabel()
private let durationLabel = UILabel()
fileprivate let headerLabel = UILabel()
fileprivate let cachedIndicator = CellCachedIndicatorView()
fileprivate let numberLabel = UILabel()
fileprivate let coverArtView = AsyncImageView()
fileprivate let primaryLabel = UILabel()
fileprivate let secondaryLabel = UILabel()
fileprivate let durationLabel = UILabel()

// @objc var autoScroll: Bool {
// get { return primaryLabel.autoScroll }
// set {
Expand Down Expand Up @@ -128,7 +128,7 @@ import SnapKit
required init?(coder: NSCoder) {
fatalError("unimplemented")
}

@objc func update(model: TableCellModel?) {
tableCellModel = model;
if let model = model {
Expand Down Expand Up @@ -178,15 +178,15 @@ import SnapKit

// MARK: AutoLayout

private func makeHeaderLabelConstraints() {
fileprivate func makeHeaderLabelConstraints() {
headerLabel.snp.remakeConstraints { make in
if hideHeaderLabel { make.height.equalTo(0) }
else { make.height.equalTo(20)}
make.leading.trailing.top.equalToSuperview()
}
}

private func makeNumberLabelConstraints() {
fileprivate func makeNumberLabelConstraints() {
numberLabel.snp.remakeConstraints { make in
if hideNumberLabel { make.width.equalTo(0) }
else { make.width.equalTo(30) }
Expand All @@ -195,7 +195,7 @@ import SnapKit
}
}

private func makeCoverArtConstraints() {
fileprivate func makeCoverArtConstraints() {
coverArtView.snp.remakeConstraints { make in
if hideCoverArt { make.width.equalTo(0) }
else { make.width.equalTo(coverArtView.snp.height) }
Expand All @@ -205,7 +205,7 @@ import SnapKit
}
}

private func makePrimaryLabelConstraints() {
fileprivate func makePrimaryLabelConstraints() {
primaryLabel.snp.remakeConstraints { make in
if hideSecondaryLabel {
make.height.equalTo(coverArtView).multipliedBy(0.66)
Expand All @@ -218,7 +218,7 @@ import SnapKit
}
}

private func makeSecondaryLabelConstraints() {
fileprivate func makeSecondaryLabelConstraints() {
secondaryLabel.snp.remakeConstraints { make in
if hideSecondaryLabel { make.height.equalTo(0) }
else { make.height.equalTo(coverArtView).multipliedBy(0.33) }
Expand All @@ -228,7 +228,7 @@ import SnapKit
}
}

private func makeDurationLabelConstraints() {
fileprivate func makeDurationLabelConstraints() {
durationLabel.snp.remakeConstraints { make in
if hideDurationLabel { make.width.equalTo(0) }
else { make.width.equalTo(30) }
Expand All @@ -238,3 +238,52 @@ import SnapKit
}
}
}

@objc final class TrackTableViewCell: UniversalTableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

primaryLabel.numberOfLines = 0
primaryLabel.setContentCompressionResistancePriority(.required, for: .vertical)
primaryLabel.setContentHuggingPriority(.required, for: .vertical)
if #available(iOS 14.0, *) {
primaryLabel.lineBreakStrategy = .init()
}

secondaryLabel.numberOfLines = 0
secondaryLabel.setContentCompressionResistancePriority(.required, for: .vertical)
secondaryLabel.setContentHuggingPriority(.required, for: .vertical)
if #available(iOS 14.0, *) {
secondaryLabel.lineBreakStrategy = .init()
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

fileprivate override func makePrimaryLabelConstraints() {
primaryLabel.snp.remakeConstraints { make in
if hideSecondaryLabel {
make.bottom.equalToSuperview().offset(UIDevice.isSmall() ? -5 : -10)
} else {
make.bottom.equalTo(secondaryLabel.snp.top)
}
make.leading.equalTo(coverArtView.snp.trailing).offset(hideCoverArt ? 5 : 10)
make.trailing.equalTo(durationLabel.snp.leading).offset(-10)
make.top.equalTo(headerLabel.snp.bottom).offset(UIDevice.isSmall() ? 5 : 10)
}
}

fileprivate override func makeSecondaryLabelConstraints() {
secondaryLabel.snp.remakeConstraints { make in
if hideSecondaryLabel {
make.height.equalTo(0)
} else {
make.height.equalTo(1).priority(10) // resolve potential "ambiguity"
}
make.leading.equalTo(primaryLabel)
make.trailing.equalTo(primaryLabel)
make.bottom.equalToSuperview().offset(UIDevice.isSmall() ? -5 : -10)
}
}
}
14 changes: 11 additions & 3 deletions Classes/View Controllers/Tabs/Folders/AlbumViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,18 @@ - (void)viewDidLoad {
[weakSelf.dataModel startLoad];
}];

self.tableView.rowHeight = Defines.rowHeight;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
self.tableView.separatorColor = UIColor.clearColor;
[self.tableView registerClass:UniversalTableViewCell.class forCellReuseIdentifier:UniversalTableViewCell.reuseId];
if (self.myAlbum) {
[self.tableView registerClass: TrackTableViewCell.class forCellReuseIdentifier: UniversalTableViewCell.reuseId];
self.tableView.estimatedRowHeight = Defines.rowHeight;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.separatorColor = UIColor.labelColor;
self.tableView.separatorInset = UIEdgeInsetsZero;
} else {
[self.tableView registerClass: UniversalTableViewCell.class forCellReuseIdentifier: UniversalTableViewCell.reuseId];
self.tableView.rowHeight = Defines.rowHeight;
self.tableView.separatorColor = UIColor.clearColor;
}
}

- (void)reloadData {
Expand Down