Change some reinits to inits

This commit is contained in:
Wojciech Kozlowski 2024-02-02 12:40:43 +01:00
parent 272b41a6a0
commit 48572fe03b

View File

@ -147,17 +147,17 @@ impl ArtistSelection {
fn reinitialise_with_index( fn reinitialise_with_index(
&mut self, &mut self,
artists: &[Artist], artists: &[Artist],
mut index: usize, index: usize,
mut active_album: Option<ActiveAlbum>, active_album: Option<ActiveAlbum>,
) { ) {
if artists.is_empty() { if artists.is_empty() {
self.state.select(None); self.state.select(None);
self.album.reinitialise(&[], None); self.album = AlbumSelection::initialise(&[]);
} else if index >= artists.len() {
let end = artists.len() - 1;
self.state.select(Some(end));
self.album = AlbumSelection::initialise(&artists[end].albums);
} else { } else {
if index >= artists.len() {
index = artists.len() - 1;
active_album = None;
}
self.state.select(Some(index)); self.state.select(Some(index));
self.album self.album
.reinitialise(&artists[index].albums, active_album); .reinitialise(&artists[index].albums, active_album);
@ -234,17 +234,17 @@ impl AlbumSelection {
fn reinitialise_with_index( fn reinitialise_with_index(
&mut self, &mut self,
albums: &[Album], albums: &[Album],
mut index: usize, index: usize,
mut active_track: Option<ActiveTrack>, active_track: Option<ActiveTrack>,
) { ) {
if albums.is_empty() { if albums.is_empty() {
self.state.select(None); self.state.select(None);
self.track = TrackSelection::initialise(&[]); self.track = TrackSelection::initialise(&[]);
} else if index >= albums.len() {
let end = albums.len() - 1;
self.state.select(Some(end));
self.track = TrackSelection::initialise(&albums[end].tracks);
} else { } else {
if index >= albums.len() {
index = albums.len() - 1;
active_track = None;
}
self.state.select(Some(index)); self.state.select(Some(index));
self.track.reinitialise(&albums[index].tracks, active_track); self.track.reinitialise(&albums[index].tracks, active_track);
} }
@ -303,13 +303,12 @@ impl TrackSelection {
} }
} }
fn reinitialise_with_index(&mut self, tracks: &[Track], mut index: usize) { fn reinitialise_with_index(&mut self, tracks: &[Track], index: usize) {
if tracks.is_empty() { if tracks.is_empty() {
self.state.select(None); self.state.select(None);
} else if index >= tracks.len() {
self.state.select(Some(tracks.len() - 1));
} else { } else {
if index >= tracks.len() {
index = tracks.len() - 1;
}
self.state.select(Some(index)); self.state.select(Some(index));
} }
} }