From 11785ffa1eb54d9be15e1e5f05209edda7ddee04 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Thu, 2 Jan 2025 23:24:02 +0100 Subject: [PATCH] Use primary type in the album sort key (#243) Part 5 of #231 Closes #231 Reviewed-on: https://git.thenineworlds.net/wojtek/musichoard/pulls/243 --- src/core/collection/album.rs | 15 ++++++++++----- src/core/musichoard/database.rs | 3 ++- src/tui/app/selection/album.rs | 15 ++++++++++----- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/core/collection/album.rs b/src/core/collection/album.rs index d0579b4..0d3fd74 100644 --- a/src/core/collection/album.rs +++ b/src/core/collection/album.rs @@ -101,14 +101,14 @@ impl From<(u32, u8, u8)> for AlbumDate { pub struct AlbumSeq(pub u8); /// Based on [MusicBrainz types](https://musicbrainz.org/doc/Release_Group/Type). -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum AlbumPrimaryType { - /// Album - Album, /// Single Single, /// EP Ep, + /// Album + Album, /// Broadcast Broadcast, /// Other @@ -217,8 +217,13 @@ impl AlbumMeta { self } - pub fn get_sort_key(&self) -> (&AlbumDate, &AlbumSeq, &AlbumId) { - (&self.date, &self.seq, &self.id) + pub fn get_sort_key(&self) -> (&AlbumDate, &AlbumSeq, &str, &Option) { + ( + &self.date, + &self.seq, + &self.id.title, + &self.info.primary_type, + ) } pub fn set_mb_ref(&mut self, mb_ref: AlbumMbRef) { diff --git a/src/core/musichoard/database.rs b/src/core/musichoard/database.rs index 24c872f..0d387aa 100644 --- a/src/core/musichoard/database.rs +++ b/src/core/musichoard/database.rs @@ -871,7 +871,8 @@ mod tests { let album = &music_hoard.collection[0].albums[0]; assert_eq!(album.meta.id.mb_ref, AlbumMbRef::CannotHaveMbid); - // To clear the mb_ref we need the album_id to have the mb_ref to identify the correct album. + // To clear the mb_ref we need the album_id to have the mb_ref to identify the correct + // album. album_id.set_mb_ref(AlbumMbRef::CannotHaveMbid); assert!(music_hoard .clear_album_mb_ref(&artist_id, &album_id) diff --git a/src/tui/app/selection/album.rs b/src/tui/app/selection/album.rs index d4e8f8d..204fbc3 100644 --- a/src/tui/app/selection/album.rs +++ b/src/tui/app/selection/album.rs @@ -1,7 +1,7 @@ use std::cmp; use musichoard::collection::{ - album::{Album, AlbumDate, AlbumId, AlbumSeq}, + album::{Album, AlbumDate, AlbumPrimaryType, AlbumSeq}, track::Track, }; @@ -165,7 +165,7 @@ impl AlbumSelection { } pub struct KeySelectAlbum { - key: (AlbumDate, AlbumSeq, AlbumId), + key: (AlbumDate, AlbumSeq, String, Option), track: Option, } @@ -175,14 +175,19 @@ impl KeySelectAlbum { let album = &albums[index]; let key = album.meta.get_sort_key(); KeySelectAlbum { - key: (key.0.to_owned(), key.1.to_owned(), key.2.to_owned()), + key: ( + key.0.to_owned(), + key.1.to_owned(), + key.2.to_owned(), + key.3.to_owned(), + ), track: KeySelectTrack::get(&album.tracks, &selection.track), } }) } - pub fn get_sort_key(&self) -> (&AlbumDate, &AlbumSeq, &AlbumId) { - (&self.key.0, &self.key.1, &self.key.2) + pub fn get_sort_key(&self) -> (&AlbumDate, &AlbumSeq, &str, &Option) { + (&self.key.0, &self.key.1, &self.key.2, &self.key.3) } }