diff --git a/src/core/collection/album.rs b/src/core/collection/album.rs index f27192a..308e901 100644 --- a/src/core/collection/album.rs +++ b/src/core/collection/album.rs @@ -138,16 +138,16 @@ pub enum AlbumSecondaryType { } /// The album's ownership status. -pub enum AlbumStatus { +pub enum AlbumOwnership { None, Owned(TrackFormat), } -impl AlbumStatus { - pub fn from_tracks(tracks: &[Track]) -> AlbumStatus { +impl AlbumOwnership { + pub fn from_tracks(tracks: &[Track]) -> AlbumOwnership { match tracks.iter().map(|t| t.quality.format).min() { - Some(format) => AlbumStatus::Owned(format), - None => AlbumStatus::None, + Some(format) => AlbumOwnership::Owned(format), + None => AlbumOwnership::None, } } } @@ -165,8 +165,8 @@ impl Album { self } - pub fn get_status(&self) -> AlbumStatus { - AlbumStatus::from_tracks(&self.tracks) + pub fn get_ownership(&self) -> AlbumOwnership { + AlbumOwnership::from_tracks(&self.tracks) } } diff --git a/src/tui/ui/browse_state.rs b/src/tui/ui/browse_state.rs index 72254ff..b5e2201 100644 --- a/src/tui/ui/browse_state.rs +++ b/src/tui/ui/browse_state.rs @@ -1,5 +1,5 @@ use musichoard::collection::{ - album::{Album, AlbumStatus}, + album::{Album, AlbumOwnership}, artist::Artist, track::{Track, TrackFormat}, }; @@ -175,7 +175,7 @@ impl<'a, 'b> AlbumState<'a, 'b> { )) .unwrap_or_default(), album - .map(|a| UiDisplay::display_album_status(&a.get_status())) + .map(|a| UiDisplay::display_album_status(&a.get_ownership())) .unwrap_or("") )); @@ -188,9 +188,9 @@ impl<'a, 'b> AlbumState<'a, 'b> { } fn to_list_item(album: &Album) -> ListItem { - let line = match album.get_status() { - AlbumStatus::None => Line::raw(album.meta.id.title.as_str()), - AlbumStatus::Owned(format) => match format { + let line = match album.get_ownership() { + AlbumOwnership::None => Line::raw(album.meta.id.title.as_str()), + AlbumOwnership::Owned(format) => match format { TrackFormat::Mp3 => Line::styled(album.meta.id.title.as_str(), UiColor::FG_WARN), TrackFormat::Flac => Line::styled(album.meta.id.title.as_str(), UiColor::FG_GOOD), }, diff --git a/src/tui/ui/display.rs b/src/tui/ui/display.rs index 68c2281..1dcc4bb 100644 --- a/src/tui/ui/display.rs +++ b/src/tui/ui/display.rs @@ -1,7 +1,7 @@ use musichoard::collection::{ album::{ - AlbumDate, AlbumId, AlbumLibId, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType, AlbumSeq, - AlbumStatus, + AlbumDate, AlbumId, AlbumLibId, AlbumMeta, AlbumOwnership, AlbumPrimaryType, + AlbumSecondaryType, AlbumSeq, }, artist::ArtistMeta, musicbrainz::{IMusicBrainzRef, MbRefOption}, @@ -101,10 +101,10 @@ impl UiDisplay { types.join(", ") } - pub fn display_album_status(status: &AlbumStatus) -> &'static str { + pub fn display_album_status(status: &AlbumOwnership) -> &'static str { match status { - AlbumStatus::None => "None", - AlbumStatus::Owned(format) => match format { + AlbumOwnership::None => "None", + AlbumOwnership::Owned(format) => match format { TrackFormat::Mp3 => "MP3", TrackFormat::Flac => "FLAC", }, @@ -284,13 +284,16 @@ mod tests { #[test] fn display_album_status() { - assert_eq!(UiDisplay::display_album_status(&AlbumStatus::None), "None"); assert_eq!( - UiDisplay::display_album_status(&AlbumStatus::Owned(TrackFormat::Mp3)), + UiDisplay::display_album_status(&AlbumOwnership::None), + "None" + ); + assert_eq!( + UiDisplay::display_album_status(&AlbumOwnership::Owned(TrackFormat::Mp3)), "MP3" ); assert_eq!( - UiDisplay::display_album_status(&AlbumStatus::Owned(TrackFormat::Flac)), + UiDisplay::display_album_status(&AlbumOwnership::Owned(TrackFormat::Flac)), "FLAC" ); }