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(
&mut self,
artists: &[Artist],
mut index: usize,
mut active_album: Option<ActiveAlbum>,
index: usize,
active_album: Option<ActiveAlbum>,
) {
if artists.is_empty() {
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 {
if index >= artists.len() {
index = artists.len() - 1;
active_album = None;
}
self.state.select(Some(index));
self.album
.reinitialise(&artists[index].albums, active_album);
@ -234,17 +234,17 @@ impl AlbumSelection {
fn reinitialise_with_index(
&mut self,
albums: &[Album],
mut index: usize,
mut active_track: Option<ActiveTrack>,
index: usize,
active_track: Option<ActiveTrack>,
) {
if albums.is_empty() {
self.state.select(None);
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 {
if index >= albums.len() {
index = albums.len() - 1;
active_track = None;
}
self.state.select(Some(index));
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() {
self.state.select(None);
} else if index >= tracks.len() {
self.state.select(Some(tracks.len() - 1));
} else {
if index >= tracks.len() {
index = tracks.len() - 1;
}
self.state.select(Some(index));
}
}