Skip to content

Commit

Permalink
config option to sort artists albums by type over date, i.e. album or…
Browse files Browse the repository at this point in the history
… single
  • Loading branch information
John Oberhauser committed Jan 3, 2025
1 parent 6eb9421 commit 5b50ad1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ NOTES*

# Generated html files for live previewing markdown
*.html

.idea
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ All configuration files should be placed inside the application's configuration
| `cover_img_length` | the length of the cover image (`image` feature only) | `9` |
| `cover_img_scale` | the scale of the cover image (`image` feature only) | `1.0` |
| `seek_duration_secs` | the duration (in seconds) to seek when using `SeekForward` and `SeekBackward` commands | `5` |
| `sort_artist_albums_by_type` | sort albums on artist's pages by type, i.e. album or single | `false` |

### Notes

Expand Down
4 changes: 4 additions & 0 deletions spotify_player/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ pub struct AppConfig {
pub notify_streaming_only: bool,

pub seek_duration_secs: u16,

pub sort_artist_albums_by_type: bool,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
Expand Down Expand Up @@ -324,6 +326,8 @@ impl Default for AppConfig {
notify_streaming_only: false,

seek_duration_secs: 5,

sort_artist_albums_by_type: false,
}
}
}
Expand Down
17 changes: 16 additions & 1 deletion spotify_player/src/ui/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,9 @@ fn render_artist_context_page_windows(
rect: Rect,
artist_data: (&[Track], &[Album], &[Artist]),
) {
let configs = config::get_config();
// 1. Get data
let (tracks, albums, artists) = (
let (tracks, mut albums, artists) = (
ui.search_filtered_items(artist_data.0),
ui.search_filtered_items(artist_data.1),
ui.search_filtered_items(artist_data.2),
Expand Down Expand Up @@ -830,6 +831,20 @@ fn render_artist_context_page_windows(

// 3. Construct the page's widgets
// album table
if configs.app_config.sort_artist_albums_by_type {
albums.sort_by(|a, b| {
let get_priority = |album_type: &str| match album_type {
"album" => 0,
"single" => 1,
"appears_on" => 2,
"compilation" => 3,
_ => 4,
};

get_priority(&a.album_type()).cmp(&get_priority(&b.album_type()))
});
}

let is_albums_active = is_active && focus_state == ArtistFocusState::Albums;
let n_albums = albums.len();
let album_rows = albums
Expand Down

0 comments on commit 5b50ad1

Please sign in to comment.