Skip to content
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
2 changes: 1 addition & 1 deletion flo/ArtistDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct ArtistDetailView: View {
.padding(.bottom, 3)
.frame(maxWidth: .infinity, alignment: .leading)

Text(stripBiography(biography: artist.biography))
Text(stripBiography(biography: artist.biography ?? ""))
.customFont(.subheadline)
.lineSpacing(3)
.multilineTextAlignment(.leading)
Expand Down
29 changes: 19 additions & 10 deletions flo/ArtistsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ struct ArtistsView: View {
@EnvironmentObject private var viewModel: AlbumViewModel

@State private var searchArtist = ""
@State private var filterAlbumArtistOnly: Bool = true

let artists: [Artist]

var filteredArtists: [Artist] {
if searchArtist.isEmpty {
return artists
} else {
return artists.filter { artist in
artist.name.localizedCaseInsensitiveContains(searchArtist)
|| artist.fullText.localizedCaseInsensitiveContains(searchArtist)
}
artists.filter { artist in
let matchesAlbumArtist = !filterAlbumArtistOnly || artist.stats.albumartist != nil
let matchesSearch = searchArtist.isEmpty || artist.name.localizedCaseInsensitiveContains(searchArtist)
return matchesAlbumArtist && matchesSearch
}
}

Expand All @@ -39,16 +37,16 @@ struct ArtistsView: View {
Text(artist.name)
.customFont(.headline)
.multilineTextAlignment(.leading)

Spacer()

Image(systemName: "chevron.right")
.foregroundColor(.gray)
.font(.caption)
}
.padding(.horizontal)
.padding(.vertical, 5)

Divider()
}
}
Expand All @@ -59,6 +57,17 @@ struct ArtistsView: View {
.searchable(
text: $searchArtist, placement: .navigationBarDrawer(displayMode: .always), prompt: "Search"
)
.toolbar {
Menu {
Button {
self.filterAlbumArtistOnly.toggle()
} label: {
Label("Album Artist Only", systemImage: self.filterAlbumArtistOnly ? "checkmark.circle" : "circle")
}
} label: {
Label("", systemImage: "ellipsis.circle")
}
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions flo/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@
}
}
}
},
"Album Artist Only" : {

},
"Album Info" : {
"localizations" : {
Expand Down
54 changes: 42 additions & 12 deletions flo/Shared/Models/Artist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,48 @@

import Foundation

struct Artist: Codable, Identifiable, Hashable {
let id: String
let name: String
let fullText: String
let biography: String
struct Artist: Codable, Hashable, Identifiable {
static func == (lhs: Artist, rhs: Artist) -> Bool {
lhs.id == rhs.id
}

func hash(into hasher: inout Hasher) {
hasher.combine(id)
}

let id, name, orderArtistName: String
let stats: ArtistStats
let size, albumCount, songCount: Int
let missing: Bool
let createdAt, updatedAt: String
let sortArtistName: String?
let playCount: Int?
let playDate, mbzArtistID, biography: String?
let smallImageURL, mediumImageURL, largeImageURL: String?
let externalURL: String?
let externalInfoUpdatedAt: String?
let fullText: String?

enum CodingKeys: String, CodingKey {
case id, name, orderArtistName, stats, size, albumCount, songCount, missing, createdAt, updatedAt, sortArtistName, playCount, playDate, fullText
case mbzArtistID = "mbzArtistId"
case biography
case smallImageURL = "smallImageUrl"
case mediumImageURL = "mediumImageUrl"
case largeImageURL = "largeImageUrl"
case externalURL = "externalUrl"
case externalInfoUpdatedAt
}
}

init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
// MARK: - Stats
struct ArtistStats: Codable {
let producer, composer, artist, maincredit: Albumartist?
let albumartist, arranger, engineer, performer: Albumartist?
let mixer, lyricist, conductor: Albumartist?
}

self.id = try container.decode(String.self, forKey: .id)
self.name = try container.decode(String.self, forKey: .name)
self.fullText = try container.decodeIfPresent(String.self, forKey: .fullText) ?? ""
self.biography = try container.decodeIfPresent(String.self, forKey: .biography) ?? ""
}
// MARK: - Albumartist
struct Albumartist: Codable {
let songCount, albumCount, size: Int
}