🏡 index : ~doyle/shalom.git

author Jordan Doyle <jordan@doyle.la> 2023-11-03 23:59:42.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-11-03 23:59:42.0 +00:00:00
commit
cb5e286540280e450a57780d952f146eed84c904 [patch]
tree
3addc67d821d80a983cb5522f1d7a630eb96126e
parent
bd1f65dcb901a909ad7a10618bd81c920cecba94
download
cb5e286540280e450a57780d952f146eed84c904.tar.gz

Add shuffle support to media player



Diff

 assets/icons/shuffle.svg           |  3 +++
 shalom/src/main.rs                 |  8 ++++++++
 shalom/src/pages/room.rs           |  8 +++++++-
 shalom/src/theme.rs                |  2 ++
 shalom/src/widgets/media_player.rs | 16 ++++++++++++++++
 5 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/assets/icons/shuffle.svg b/assets/icons/shuffle.svg
new file mode 100644
index 0000000..a5d2841
--- /dev/null
+++ b/assets/icons/shuffle.svg
@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
    <path stroke-linecap="round" stroke-linejoin="round" d="M7.5 21L3 16.5m0 0L7.5 12M3 16.5h13.5m0-13.5L21 7.5m0 0L16.5 12M21 7.5H7.5" />
</svg>
diff --git a/shalom/src/main.rs b/shalom/src/main.rs
index 6980114..b417c5b 100644
--- a/shalom/src/main.rs
+++ b/shalom/src/main.rs
@@ -205,6 +205,14 @@ impl Application for Shalom {
                        Message::UpdateLightResult,
                    )
                }
                Some(pages::room::Event::SetSpeakerShuffle(id, new)) => {
                    let oracle = self.oracle.as_ref().unwrap().clone();

                    Command::perform(
                        async move { oracle.speaker(id).set_shuffle(new).await },
                        Message::UpdateLightResult,
                    )
                }
                None => Command::none(),
            },
            (Message::LightControlMenu(e), _, Some(ActiveContextMenu::LightControl(menu))) => {
diff --git a/shalom/src/pages/room.rs b/shalom/src/pages/room.rs
index eba6a2f..14edfb6 100644
--- a/shalom/src/pages/room.rs
+++ b/shalom/src/pages/room.rs
@@ -118,6 +118,9 @@ impl Room {
            Message::OnSpeakerPreviousTrack => {
                Some(Event::SpeakerPreviousTrack(self.speaker.as_ref()?.0))
            }
            Message::OnSpeakerShuffleChange(new) => {
                Some(Event::SetSpeakerShuffle(self.speaker.as_ref()?.0, new))
            }
        }
    }

@@ -163,7 +166,8 @@ impl Room {
                        .on_state_change(Message::OnSpeakerStateChange)
                        .on_position_change(Message::OnSpeakerPositionChange)
                        .on_next_track(Message::OnSpeakerNextTrack)
                        .on_previous_track(Message::OnSpeakerPreviousTrack),
                        .on_previous_track(Message::OnSpeakerPreviousTrack)
                        .on_shuffle_change(Message::OnSpeakerShuffleChange),
                )
                .padding([12, 0, 24, 0]),
            );
@@ -230,6 +234,7 @@ pub enum Event {
    SetSpeakerPosition(&'static str, Duration),
    SetSpeakerPlaying(&'static str, bool),
    SetSpeakerMuted(&'static str, bool),
    SetSpeakerShuffle(&'static str, bool),
    SetSpeakerRepeat(&'static str, MediaPlayerRepeat),
    SpeakerNextTrack(&'static str),
    SpeakerPreviousTrack(&'static str),
@@ -246,6 +251,7 @@ pub enum Message {
    OnSpeakerPositionChange(Duration),
    OnSpeakerStateChange(bool),
    OnSpeakerMuteChange(bool),
    OnSpeakerShuffleChange(bool),
    OnSpeakerRepeatChange(MediaPlayerRepeat),
    OnSpeakerNextTrack,
    OnSpeakerPreviousTrack,
diff --git a/shalom/src/theme.rs b/shalom/src/theme.rs
index 77466fc..6004df6 100644
--- a/shalom/src/theme.rs
+++ b/shalom/src/theme.rs
@@ -56,6 +56,7 @@ pub enum Icon {
    Snow,
    ClearDay,
    Wind,
    Shuffle,
}

impl Icon {
@@ -93,6 +94,7 @@ impl Icon {
            Self::Snow => image!("snow"),
            Self::ClearDay => image!("clear-day"),
            Self::Wind => image!("wind"),
            Self::Shuffle => image!("shuffle"),
        }
    }
}
diff --git a/shalom/src/widgets/media_player.rs b/shalom/src/widgets/media_player.rs
index ea16907..ef10954 100644
--- a/shalom/src/widgets/media_player.rs
+++ b/shalom/src/widgets/media_player.rs
@@ -35,6 +35,7 @@ pub fn media_player<M>(device: MediaPlayerSpeaker, image: Option<Handle>) -> Med
        on_repeat_change: None,
        on_next_track: None,
        on_previous_track: None,
        on_shuffle_change: None,
    }
}

@@ -51,6 +52,7 @@ pub struct MediaPlayer<M> {
    on_repeat_change: Option<fn(MediaPlayerRepeat) -> M>,
    on_next_track: Option<M>,
    on_previous_track: Option<M>,
    on_shuffle_change: Option<fn(bool) -> M>,
}

impl<M> MediaPlayer<M> {
@@ -88,6 +90,11 @@ impl<M> MediaPlayer<M> {
        self.on_previous_track = Some(msg);
        self
    }

    pub fn on_shuffle_change(mut self, f: fn(bool) -> M) -> Self {
        self.on_shuffle_change = Some(f);
        self
    }
}

impl<M: Clone> Component<M, Renderer> for MediaPlayer<M> {
@@ -131,6 +138,7 @@ impl<M: Clone> Component<M, Renderer> for MediaPlayer<M> {
                }
            }
            Event::NextTrack => self.on_next_track.clone(),
            Event::ToggleShuffle => self.on_shuffle_change.map(|f| f(!self.device.shuffle)),
        }
    }

@@ -172,6 +180,13 @@ impl<M: Clone> Component<M, Renderer> for MediaPlayer<M> {
                    // .width(Length::Fill),
                    row![
                        mouse_area(
                            svg(Icon::Shuffle)
                                .height(24)
                                .width(24)
                                .style(icon_style(self.device.shuffle)),
                        )
                        .on_press(Event::ToggleShuffle),
                        mouse_area(
                            svg(Icon::Backward)
                                .height(24)
                                .width(24)
@@ -270,6 +285,7 @@ pub enum Event {
    TogglePlaying,
    ToggleMute,
    ToggleRepeat,
    ToggleShuffle,
    VolumeChange(f32),
    PositionChange(f64),
    OnVolumeRelease,