Skip to content

Commit

Permalink
Merge pull request #80 from Rigellute/hoverable-playbar
Browse files Browse the repository at this point in the history
Make playbar selectable/hoverable
  • Loading branch information
Rigellute committed Oct 19, 2019
2 parents 0e3c00e + de5e11b commit f524420
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Implement library "Artists" view - [#67](https://github.com/Rigellute/spotify-tui/pull/67) thanks [@svenvNL](https://github.com/svenvNL). NOTE that this adds an additional scope (`user-follow-read`), so you'll be prompted to grant this new permissions when you upgrade.
- Fix searching with non-english characters - [#30](https://github.com/Rigellute/spotify-tui/pull/30). Thanks to [@fangyi-zhou](https://github.com/fangyi-zhou)
- Remove hardcoded country (was always set to UK). We now fetch the user to get their country. [#68](https://github.com/Rigellute/spotify-tui/pull/68). Thanks to [@svenvNL](https://github.com/svenvNL)
- Save currently playing track - the playbar is now selectable/hoverable [#80](https://github.com/Rigellute/spotify-tui/pull/80)

## [0.0.6] - 2019-10-14

Expand Down
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub enum SearchResultBlock {

#[derive(Clone, Copy, PartialEq, Debug)]
pub enum ActiveBlock {
PlayBar,
AlbumTracks,
AlbumList,
Artist,
Expand Down
33 changes: 22 additions & 11 deletions src/handlers/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,36 @@ pub fn handler(key: Key, app: &mut App) {
ActiveBlock::Library => {
app.set_current_route_state(None, Some(ActiveBlock::MyPlaylists));
}
ActiveBlock::MyPlaylists => {
// Go to player
}
ActiveBlock::AlbumTracks | ActiveBlock::Home | ActiveBlock::TrackTable => {
// Go to player
ActiveBlock::Artist
| ActiveBlock::AlbumList
| ActiveBlock::AlbumTracks
| ActiveBlock::Artists
| ActiveBlock::Home
| ActiveBlock::MadeForYou
| ActiveBlock::MyPlaylists
| ActiveBlock::RecentlyPlayed
| ActiveBlock::TrackTable => {
app.set_current_route_state(None, Some(ActiveBlock::PlayBar));
}
_ => {}
},
k if common_key_events::up_event(k) => {
if let ActiveBlock::MyPlaylists = app.get_current_route().hovered_block {
k if common_key_events::up_event(k) => match app.get_current_route().hovered_block {
ActiveBlock::MyPlaylists => {
app.set_current_route_state(None, Some(ActiveBlock::Library));
}
}
ActiveBlock::PlayBar => {
app.set_current_route_state(None, Some(ActiveBlock::MyPlaylists));
}
_ => {}
},
k if common_key_events::left_event(k) => match app.get_current_route().hovered_block {
ActiveBlock::RecentlyPlayed
| ActiveBlock::AlbumTracks
ActiveBlock::Artist
| ActiveBlock::AlbumList
| ActiveBlock::Artist
| ActiveBlock::AlbumTracks
| ActiveBlock::Artists
| ActiveBlock::Home
| ActiveBlock::MadeForYou
| ActiveBlock::RecentlyPlayed
| ActiveBlock::TrackTable => {
app.set_current_route_state(None, Some(ActiveBlock::Library));
}
Expand Down
4 changes: 4 additions & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod home;
mod input;
mod library;
mod made_for_you;
mod playbar;
mod playlist;
mod podcasts;
mod recently_played;
Expand Down Expand Up @@ -154,5 +155,8 @@ fn handle_block_events(key: Key, app: &mut App) {
ActiveBlock::Podcasts => {
podcasts::handler(key, app);
}
ActiveBlock::PlayBar => {
playbar::handler(key, app);
}
}
}
37 changes: 37 additions & 0 deletions src/handlers/playbar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use super::super::app::{ActiveBlock, App};
use super::common_key_events;
use termion::event::Key;

pub fn handler(key: Key, app: &mut App) {
match key {
k if common_key_events::up_event(k) => {
app.set_current_route_state(Some(ActiveBlock::Empty), Some(ActiveBlock::MyPlaylists));
}
Key::Char('s') => {
if let Some(playing_context) = &app.current_playback_context {
if let Some(track) = &playing_context.item {
if let Some(id) = track.id.to_owned() {
app.save_tracks(vec![id]);
}
}
}
}
_ => {}
};
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn on_left_press() {
let mut app = App::new();
app.set_current_route_state(Some(ActiveBlock::PlayBar), Some(ActiveBlock::PlayBar));

handler(Key::Up, &mut app);
let current_route = app.get_current_route();
assert_eq!(current_route.active_block, ActiveBlock::Empty);
assert_eq!(current_route.hovered_block, ActiveBlock::MyPlaylists);
}
}
14 changes: 10 additions & 4 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ where
draw_routes(f, app, parent_layout[1]);

// Currently playing
draw_playing_block(f, app, parent_layout[2]);
draw_playbar(f, app, parent_layout[2]);
}

pub fn draw_routes<B>(f: &mut Frame<B>, app: &App, layout_chunk: Rect)
Expand Down Expand Up @@ -527,7 +527,7 @@ where
)
}

pub fn draw_playing_block<B>(f: &mut Frame<B>, app: &App, layout_chunk: Rect)
pub fn draw_playbar<B>(f: &mut Frame<B>, app: &App, layout_chunk: Rect)
where
B: Backend,
{
Expand Down Expand Up @@ -568,11 +568,17 @@ where
current_playback_context.device.volume_percent
);

let current_route = app.get_current_route();
let highlight_state = (
current_route.active_block == ActiveBlock::PlayBar,
current_route.hovered_block == ActiveBlock::PlayBar,
);

Block::default()
.borders(Borders::ALL)
.title(&title)
.title_style(Style::default().fg(Color::Gray))
.border_style(Style::default().fg(Color::Gray))
.title_style(get_color(highlight_state))
.border_style(get_color(highlight_state))
.render(f, layout_chunk);

Paragraph::new(
Expand Down

0 comments on commit f524420

Please sign in to comment.