Change unnecessary usage of Arc to borrow instead
Some basic cleanup of function signatures that took ownership of their parameters, even though they didn't need ownership. Switching over the usage of `Arc` to a normal borrow has the added benefit of cleaning up the code a bit since now a reference can be given instead of having to clone the values. The other benefit is that a lot of clones aren't necessary anymore. It's not going to have noticable performance benefits, but it is still a good thing to have less clones all over the code.
This commit is contained in:
@@ -79,10 +79,8 @@ impl ContextMenu {
|
||||
|
||||
already_added_dialog.add_button("Add anyway", move |c| {
|
||||
let mut playlist = playlist.clone();
|
||||
let spotify = spotify.clone();
|
||||
let library = library.clone();
|
||||
|
||||
playlist.append_tracks(&[Playable::Track(track.clone())], spotify, library);
|
||||
playlist.append_tracks(&[Playable::Track(track.clone())], &spotify, &library);
|
||||
c.pop_layer();
|
||||
|
||||
// Close add_track_dialog too
|
||||
@@ -92,7 +90,7 @@ impl ContextMenu {
|
||||
let modal = Modal::new(already_added_dialog);
|
||||
s.add_layer(modal);
|
||||
} else {
|
||||
playlist.append_tracks(&[Playable::Track(track)], spotify, library);
|
||||
playlist.append_tracks(&[Playable::Track(track)], &spotify, &library);
|
||||
s.pop_layer();
|
||||
}
|
||||
});
|
||||
@@ -170,9 +168,9 @@ impl ContextMenu {
|
||||
}
|
||||
false => {
|
||||
if library.clone().is_followed_artist(&moved_artist) {
|
||||
moved_artist.clone().unsave(library.clone());
|
||||
moved_artist.clone().unsave(&library);
|
||||
} else {
|
||||
moved_artist.clone().save(library.clone());
|
||||
moved_artist.clone().save(&library);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,13 +203,13 @@ impl ContextMenu {
|
||||
let mut content: SelectView<ContextMenuAction> = SelectView::new();
|
||||
|
||||
if item.is_playable() {
|
||||
if item.is_playing(queue.clone())
|
||||
if item.is_playing(&queue)
|
||||
&& queue.get_spotify().get_current_status()
|
||||
== PlayerEvent::Paused(queue.get_spotify().get_current_progress())
|
||||
{
|
||||
// the item is the current track, but paused
|
||||
content.insert_item(0, "Resume", ContextMenuAction::TogglePlayback);
|
||||
} else if !item.is_playing(queue.clone()) {
|
||||
} else if !item.is_playing(&queue) {
|
||||
// the item is not the current track
|
||||
content.insert_item(0, "Play", ContextMenuAction::Play(item.as_listitem()));
|
||||
} else {
|
||||
@@ -241,7 +239,7 @@ impl ContextMenu {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(a) = item.album(queue.clone()) {
|
||||
if let Some(a) = item.album(&queue) {
|
||||
content.add_item("Show album", ContextMenuAction::ShowItem(Box::new(a)));
|
||||
}
|
||||
|
||||
@@ -250,7 +248,7 @@ impl ContextMenu {
|
||||
if let Some(url) = item.share_url() {
|
||||
content.add_item("Share", ContextMenuAction::ShareUrl(url));
|
||||
}
|
||||
if let Some(url) = item.album(queue.clone()).and_then(|a| a.share_url()) {
|
||||
if let Some(url) = item.album(&queue).and_then(|a| a.share_url()) {
|
||||
content.add_item("Share album", ContextMenuAction::ShareUrl(url));
|
||||
}
|
||||
}
|
||||
@@ -266,7 +264,7 @@ impl ContextMenu {
|
||||
)
|
||||
}
|
||||
// If the item is saveable, its save state will be set
|
||||
if let Some(savestatus) = item.is_saved(library.clone()) {
|
||||
if let Some(savestatus) = item.is_saved(&library) {
|
||||
content.add_item(
|
||||
match savestatus {
|
||||
true => "Unsave",
|
||||
@@ -276,8 +274,8 @@ impl ContextMenu {
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(album) = item.album(queue.clone()) {
|
||||
if let Some(savestatus) = album.is_saved(library.clone()) {
|
||||
if let Some(album) = item.album(&queue) {
|
||||
if let Some(savestatus) = album.is_saved(&library) {
|
||||
content.add_item(
|
||||
match savestatus {
|
||||
true => "Unsave album",
|
||||
@@ -326,18 +324,18 @@ impl ContextMenu {
|
||||
s.add_layer(dialog);
|
||||
}
|
||||
ContextMenuAction::ToggleSavedStatus(item) => {
|
||||
item.as_listitem().toggle_saved(library)
|
||||
item.as_listitem().toggle_saved(&library)
|
||||
}
|
||||
ContextMenuAction::Play(item) => item.as_listitem().play(queue),
|
||||
ContextMenuAction::PlayNext(item) => item.as_listitem().play_next(queue),
|
||||
ContextMenuAction::Play(item) => item.as_listitem().play(&queue),
|
||||
ContextMenuAction::PlayNext(item) => item.as_listitem().play_next(&queue),
|
||||
ContextMenuAction::TogglePlayback => queue.toggleplayback(),
|
||||
ContextMenuAction::Queue(item) => item.as_listitem().queue(queue),
|
||||
ContextMenuAction::Queue(item) => item.as_listitem().queue(&queue),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let dialog = Dialog::new()
|
||||
.title(item.display_left(library))
|
||||
.title(item.display_left(&library))
|
||||
.dismiss_button("Close")
|
||||
.padding(Margins::lrtb(1, 1, 1, 0))
|
||||
.content(content.with_name("contextmenu_select"));
|
||||
|
||||
@@ -231,12 +231,12 @@ impl ViewExt for CoverView {
|
||||
match cmd {
|
||||
Command::Save => {
|
||||
if let Some(mut track) = self.queue.get_current() {
|
||||
track.save(self.library.clone());
|
||||
track.save(&self.library);
|
||||
}
|
||||
}
|
||||
Command::Delete => {
|
||||
if let Some(mut track) = self.queue.get_current() {
|
||||
track.unsave(self.library.clone());
|
||||
track.unsave(&self.library);
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "share_clipboard")]
|
||||
@@ -259,7 +259,7 @@ impl ViewExt for CoverView {
|
||||
|
||||
match mode {
|
||||
GotoMode::Album => {
|
||||
if let Some(album) = track.album(queue.clone()) {
|
||||
if let Some(album) = track.album(&queue) {
|
||||
let view =
|
||||
AlbumView::new(queue, library, &album).into_boxed_view_ext();
|
||||
return Ok(CommandResult::View(view));
|
||||
|
||||
@@ -142,7 +142,7 @@ impl<I: ListItem + Clone> ListView<I> {
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, i)| {
|
||||
i.display_left(self.library.clone())
|
||||
i.display_left(&self.library)
|
||||
.to_lowercase()
|
||||
.contains(&query[..].to_lowercase())
|
||||
})
|
||||
@@ -208,7 +208,7 @@ impl<I: ListItem + Clone> View for ListView<I> {
|
||||
|
||||
let item = &content[current_index];
|
||||
|
||||
let currently_playing = item.is_playing(self.queue.clone())
|
||||
let currently_playing = item.is_playing(&self.queue)
|
||||
&& self.queue.get_current_index() == Some(current_index);
|
||||
|
||||
let style = if self.selected == i {
|
||||
@@ -231,9 +231,9 @@ impl<I: ListItem + Clone> View for ListView<I> {
|
||||
ColorStyle::primary()
|
||||
};
|
||||
|
||||
let left = item.display_left(self.library.clone());
|
||||
let center = item.display_center(self.library.clone());
|
||||
let right = item.display_right(self.library.clone());
|
||||
let left = item.display_left(&self.library);
|
||||
let center = item.display_center(&self.library);
|
||||
let right = item.display_right(&self.library);
|
||||
let draw_center = !center.is_empty();
|
||||
|
||||
// draw left string
|
||||
@@ -443,7 +443,7 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
|
||||
if !self.attempt_play_all_tracks() {
|
||||
let mut content = self.content.write().unwrap();
|
||||
if let Some(item) = content.get_mut(self.selected) {
|
||||
item.play(self.queue.clone());
|
||||
item.play(&self.queue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,7 +453,7 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
|
||||
info!("played next");
|
||||
let mut content = self.content.write().unwrap();
|
||||
if let Some(item) = content.get_mut(self.selected) {
|
||||
item.play_next(self.queue.clone());
|
||||
item.play_next(&self.queue);
|
||||
}
|
||||
|
||||
return Ok(CommandResult::Consumed(None));
|
||||
@@ -461,7 +461,7 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
|
||||
Command::Queue => {
|
||||
let mut content = self.content.write().unwrap();
|
||||
if let Some(item) = content.get_mut(self.selected) {
|
||||
item.queue(self.queue.clone());
|
||||
item.queue(&self.queue);
|
||||
}
|
||||
|
||||
return Ok(CommandResult::Consumed(None));
|
||||
@@ -473,7 +473,7 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
|
||||
};
|
||||
|
||||
if let Some(item) = item.as_mut() {
|
||||
item.save(self.library.clone());
|
||||
item.save(&self.library);
|
||||
}
|
||||
|
||||
return Ok(CommandResult::Consumed(None));
|
||||
@@ -485,7 +485,7 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
|
||||
};
|
||||
|
||||
if let Some(item) = item.as_mut() {
|
||||
item.unsave(self.library.clone());
|
||||
item.unsave(&self.library);
|
||||
}
|
||||
|
||||
return Ok(CommandResult::Consumed(None));
|
||||
@@ -607,7 +607,7 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
|
||||
|
||||
match mode {
|
||||
GotoMode::Album => {
|
||||
if let Some(album) = item.album(queue.clone()) {
|
||||
if let Some(album) = item.album(&queue) {
|
||||
let view =
|
||||
AlbumView::new(queue, library, &album).into_boxed_view_ext();
|
||||
return Ok(CommandResult::View(view));
|
||||
|
||||
@@ -82,7 +82,7 @@ impl ViewExt for PlaylistView {
|
||||
let pos = self.list.get_selected_index();
|
||||
if self
|
||||
.playlist
|
||||
.delete_track(pos, self.spotify.clone(), self.library.clone())
|
||||
.delete_track(pos, self.spotify.clone(), &self.library)
|
||||
{
|
||||
self.list.remove(pos);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ impl StatusBar {
|
||||
.statusbar_format
|
||||
.clone()
|
||||
.unwrap_or_else(|| "%artists - %title".to_string());
|
||||
Playable::format(t, &format, self.library.clone())
|
||||
Playable::format(t, &format, &self.library)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user