Display all the extra album info #173
@ -1,7 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use musichoard::collection::{
|
use musichoard::collection::{
|
||||||
album::{Album, AlbumDate, AlbumSeq, AlbumStatus},
|
album::{Album, AlbumDate, AlbumPrimaryType, AlbumSecondaryType, AlbumSeq, AlbumStatus},
|
||||||
artist::Artist,
|
artist::Artist,
|
||||||
musicbrainz::IMusicBrainzRef,
|
musicbrainz::IMusicBrainzRef,
|
||||||
track::{Track, TrackFormat, TrackQuality},
|
track::{Track, TrackFormat, TrackQuality},
|
||||||
@ -296,14 +296,15 @@ impl<'a, 'b> AlbumState<'a, 'b> {
|
|||||||
let album = state.list.selected().map(|i| &albums[i]);
|
let album = state.list.selected().map(|i| &albums[i]);
|
||||||
let info = Paragraph::new(format!(
|
let info = Paragraph::new(format!(
|
||||||
"Title: {}\n\
|
"Title: {}\n\
|
||||||
Date: {}{}\n\
|
Date: {}\n\
|
||||||
|
Type: {}\n\
|
||||||
Status: {}",
|
Status: {}",
|
||||||
album.map(|a| a.id.title.as_str()).unwrap_or(""),
|
album.map(|a| a.id.title.as_str()).unwrap_or(""),
|
||||||
album
|
album
|
||||||
.map(|a| Self::display_album_date(&a.date))
|
.map(|a| Self::display_date(&a.date, &a.seq))
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
album
|
album
|
||||||
.map(|a| Self::display_album_seq(&a.seq))
|
.map(|a| Self::display_type(&a.primary_type, &a.secondary_types))
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
album
|
album
|
||||||
.map(|a| Self::display_album_status(&a.get_status()))
|
.map(|a| Self::display_album_status(&a.get_status()))
|
||||||
@ -329,6 +330,14 @@ impl<'a, 'b> AlbumState<'a, 'b> {
|
|||||||
ListItem::new(line)
|
ListItem::new(line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn display_date(date: &AlbumDate, seq: &AlbumSeq) -> String {
|
||||||
|
if seq.0 > 0 {
|
||||||
|
format!("{} ({})", Self::display_album_date(date), seq.0)
|
||||||
|
} else {
|
||||||
|
format!("{}", Self::display_album_date(date))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn display_album_date(date: &AlbumDate) -> String {
|
fn display_album_date(date: &AlbumDate) -> String {
|
||||||
match date.year {
|
match date.year {
|
||||||
Some(year) => match date.month {
|
Some(year) => match date.month {
|
||||||
@ -342,14 +351,57 @@ impl<'a, 'b> AlbumState<'a, 'b> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_album_seq(seq: &AlbumSeq) -> String {
|
fn display_type(
|
||||||
if seq.0 > 0 {
|
primary: &Option<AlbumPrimaryType>,
|
||||||
format!(" ({})", seq.0)
|
secondary: &Vec<AlbumSecondaryType>,
|
||||||
} else {
|
) -> String {
|
||||||
String::new()
|
match primary {
|
||||||
|
Some(ref primary) => {
|
||||||
|
if secondary.is_empty() {
|
||||||
|
format!("{}", Self::display_primary_type(primary))
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"{} ({})",
|
||||||
|
Self::display_primary_type(primary),
|
||||||
|
Self::display_secondary_types(secondary)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => String::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn display_primary_type(value: &AlbumPrimaryType) -> &'static str {
|
||||||
|
match value {
|
||||||
|
AlbumPrimaryType::Album => "Album",
|
||||||
|
AlbumPrimaryType::Single => "Single",
|
||||||
|
AlbumPrimaryType::Ep => "EP",
|
||||||
|
AlbumPrimaryType::Broadcast => "Broadcast",
|
||||||
|
AlbumPrimaryType::Other => "Other",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn display_secondary_types(values: &Vec<AlbumSecondaryType>) -> String {
|
||||||
|
let mut types: Vec<&'static str> = vec![];
|
||||||
|
for value in values {
|
||||||
|
match value {
|
||||||
|
AlbumSecondaryType::Compilation => types.push("Compilation"),
|
||||||
|
AlbumSecondaryType::Soundtrack => types.push("Soundtrack"),
|
||||||
|
AlbumSecondaryType::Spokenword => types.push("Spokenword"),
|
||||||
|
AlbumSecondaryType::Interview => types.push("Interview"),
|
||||||
|
AlbumSecondaryType::Audiobook => types.push("Audiobook"),
|
||||||
|
AlbumSecondaryType::AudioDrama => types.push("Audio drama"),
|
||||||
|
AlbumSecondaryType::Live => types.push("Live"),
|
||||||
|
AlbumSecondaryType::Remix => types.push("Remix"),
|
||||||
|
AlbumSecondaryType::DjMix => types.push("DJ-mix"),
|
||||||
|
AlbumSecondaryType::MixtapeStreet => types.push("Mixtape/Street"),
|
||||||
|
AlbumSecondaryType::Demo => types.push("Demo"),
|
||||||
|
AlbumSecondaryType::FieldRecording => types.push("Field recording"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
types.join(", ")
|
||||||
|
}
|
||||||
|
|
||||||
fn display_album_status(status: &AlbumStatus) -> &'static str {
|
fn display_album_status(status: &AlbumStatus) -> &'static str {
|
||||||
match status {
|
match status {
|
||||||
AlbumStatus::None => "None",
|
AlbumStatus::None => "None",
|
||||||
@ -818,10 +870,14 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_album_seq() {
|
fn display_date() {
|
||||||
assert_eq!(AlbumState::display_album_seq(&AlbumSeq::default()), "");
|
let date: AlbumDate = 1990.into();
|
||||||
assert_eq!(AlbumState::display_album_seq(&AlbumSeq(0)), "");
|
assert_eq!(
|
||||||
assert_eq!(AlbumState::display_album_seq(&AlbumSeq(5)), " (5)");
|
AlbumState::display_date(&date, &AlbumSeq::default()),
|
||||||
|
"1990"
|
||||||
|
);
|
||||||
|
assert_eq!(AlbumState::display_date(&date, &AlbumSeq(0)), "1990");
|
||||||
|
assert_eq!(AlbumState::display_date(&date, &AlbumSeq(5)), "1990 (5)");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user