Skip to content

Commit

Permalink
Remove play button related functions from trait and move onto specifi…
Browse files Browse the repository at this point in the history
…c models
  • Loading branch information
Zaedus committed Jun 7, 2023
1 parent 30c200d commit e442379
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 35 deletions.
5 changes: 2 additions & 3 deletions src/app/components/details/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use super::release_details::ReleaseDetailsWindow;
use super::DetailsModel;

use crate::app::components::{
playlist::PlaylistModel, Component, EventListener, HeaderBarComponent, HeaderBarWidget,
Playlist, ScrollingHeaderWidget,
Component, EventListener, HeaderBarComponent, HeaderBarWidget, Playlist, ScrollingHeaderWidget,
};
use crate::app::dispatch::Worker;
use crate::app::loader::ImageLoader;
Expand Down Expand Up @@ -246,7 +245,7 @@ impl Details {
}

fn update_playing(&self, is_playing: bool) {
if !self.model.playlist_is_playing() || !self.model.is_playing() {
if !self.model.album_is_playing() || !self.model.is_playing() {
self.widget.set_playing(false);
return;
}
Expand Down
22 changes: 11 additions & 11 deletions src/app/components/details/details_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,19 @@ impl DetailsModel {
}
}

pub fn is_playing(&self) -> bool {
self.state().playback.is_playing()
}

pub fn album_is_playing(&self) -> bool {
matches!(
self.app_model.get_state().playback.current_source(),
Some(SongsSource::Album(ref id)) if id == &self.id)
}

pub fn toggle_play_album(&self) {
if let Some(album) = self.get_album_description() {
if !self.playlist_is_playing() {
if !self.album_is_playing() {
if self.state().playback.is_shuffled() {
self.dispatcher
.dispatch(AppAction::PlaybackAction(PlaybackAction::ToggleShuffle));
Expand Down Expand Up @@ -197,16 +207,6 @@ impl PlaylistModel for DetailsModel {
self.state().playback.current_song_id()
}

fn is_playing(&self) -> bool {
self.state().playback.is_playing()
}

fn playlist_is_playing(&self) -> bool {
matches!(
self.app_model.get_state().playback.current_source(),
Some(SongsSource::Album(ref id)) if id == &self.id)
}

fn play_song_at(&self, pos: usize, id: &str) {
let source = SongsSource::Album(self.id.clone());
let batch = self.song_list_model().song_batch_for(pos);
Expand Down
10 changes: 0 additions & 10 deletions src/app/components/playlist/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ pub trait PlaylistModel {

fn current_song_id(&self) -> Option<String>;

// NOTE: `is_playing` is for if there is *any* song being played
// `playlist_is_playing` is for if the specific playlist is being played
fn is_playing(&self) -> bool {
false
}

fn playlist_is_playing(&self) -> bool {
false
}

fn play_song_at(&self, pos: usize, id: &str);

fn autoscroll_to_playing(&self) -> bool {
Expand Down
22 changes: 11 additions & 11 deletions src/app/components/playlist_details/playlist_details_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl PlaylistDetailsModel {
}
}

fn state(&self) -> Ref<'_, AppState> {
pub fn state(&self) -> Ref<'_, AppState> {
self.app_model.get_state()
}

Expand All @@ -45,6 +45,16 @@ impl PlaylistDetailsModel {
})
}

pub fn is_playing(&self) -> bool {
self.state().playback.is_playing()
}

pub fn playlist_is_playing(&self) -> bool {
matches!(
self.app_model.get_state().playback.current_source(),
Some(SongsSource::Playlist(ref id)) if id == &self.id)
}

pub fn toggle_play_playlist(&self) {
if let Some(playlist) = self.get_playlist_info() {
if !self.playlist_is_playing() {
Expand Down Expand Up @@ -157,16 +167,6 @@ impl PlaylistModel for PlaylistDetailsModel {
self.state().playback.current_song_id()
}

fn is_playing(&self) -> bool {
self.state().playback.is_playing()
}

fn playlist_is_playing(&self) -> bool {
matches!(
self.app_model.get_state().playback.current_source(),
Some(SongsSource::Album(ref id)) if id == &self.id)
}

fn play_song_at(&self, pos: usize, id: &str) {
let source = SongsSource::Playlist(self.id.clone());
let batch = self.song_list_model().song_batch_for(pos);
Expand Down

0 comments on commit e442379

Please sign in to comment.