initial track queue implementation
This commit is contained in:
@@ -4,17 +4,21 @@ use cursive::traits::Identifiable;
|
||||
use cursive::views::*;
|
||||
use cursive::Cursive;
|
||||
use std::sync::Arc;
|
||||
use std::rc::Rc;
|
||||
use std::cell::RefCell;
|
||||
|
||||
use librespot::core::spotify_id::SpotifyId;
|
||||
|
||||
use spotify::Spotify;
|
||||
use queue::Queue;
|
||||
|
||||
pub struct SearchView {
|
||||
pub view: Panel<LinearLayout>,
|
||||
queue: Rc<RefCell<Queue>>,
|
||||
}
|
||||
|
||||
impl SearchView {
|
||||
pub fn search_handler(s: &mut Cursive, input: &str, spotify: Arc<Spotify>) {
|
||||
fn search_handler(s: &mut Cursive, input: &str, spotify: Arc<Spotify>, queue: Rc<RefCell<Queue>>) {
|
||||
let mut results: ViewRef<ListView> = s.find_id("search_results").unwrap();
|
||||
let tracks = spotify.search(input, 50, 0);
|
||||
|
||||
@@ -33,16 +37,23 @@ impl SearchView {
|
||||
s.load(trackid);
|
||||
s.play();
|
||||
});
|
||||
results.add_child("", button);
|
||||
let p = queue.clone();
|
||||
let button_queue = OnEventView::new(button)
|
||||
.on_event(' ', move |_cursive| {
|
||||
p.borrow_mut().enqueue(track.clone());
|
||||
debug!("Added to queue: {}", track.name);
|
||||
});
|
||||
results.add_child("", button_queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(spotify: Arc<Spotify>) -> SearchView {
|
||||
pub fn new(spotify: Arc<Spotify>, queue: Rc<RefCell<Queue>>) -> SearchView {
|
||||
let spotify_ref = spotify.clone();
|
||||
let queue_ref = queue.clone();
|
||||
let searchfield = EditView::new()
|
||||
.on_submit(move |s, input| {
|
||||
SearchView::search_handler(s, input, spotify_ref.clone());
|
||||
SearchView::search_handler(s, input, spotify_ref.clone(), queue_ref.clone());
|
||||
})
|
||||
.with_id("search_edit")
|
||||
.full_width()
|
||||
@@ -53,6 +64,9 @@ impl SearchView {
|
||||
.child(searchfield)
|
||||
.child(scrollable);
|
||||
let rootpanel = Panel::new(layout).title("Search");
|
||||
return SearchView { view: rootpanel };
|
||||
return SearchView {
|
||||
view: rootpanel,
|
||||
queue: queue,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user