Skip to content

Commit

Permalink
Config option to sort artists albums by type (#654)
Browse files Browse the repository at this point in the history
Co-authored-by: John Oberhauser <[email protected]>
Co-authored-by: Thang Pham <[email protected]>
  • Loading branch information
3 people authored Jan 5, 2025
1 parent 7cc39b3 commit d1c20f7
Show file tree
Hide file tree
Showing 4 changed files with 22 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 @@ -55,6 +55,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
16 changes: 15 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,19 @@ fn render_artist_context_page_windows(

// 3. Construct the page's widgets
// album table
if configs.app_config.sort_artist_albums_by_type {
fn get_priority(album_type: &str) -> usize {
match album_type {
"album" => 0,
"single" => 1,
"appears_on" => 2,
"compilation" => 3,
_ => 4,
}
}
albums.sort_by_key(|a| get_priority(&a.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 d1c20f7

Please sign in to comment.