56
src/ui/browse.rs
Normal file
56
src/ui/browse.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use cursive::view::ViewWrapper;
|
||||
use cursive::Cursive;
|
||||
|
||||
use crate::command::Command;
|
||||
use crate::commands::CommandResult;
|
||||
use crate::library::Library;
|
||||
use crate::model::category::Category;
|
||||
use crate::queue::Queue;
|
||||
use crate::traits::ViewExt;
|
||||
|
||||
use crate::ui::listview::ListView;
|
||||
|
||||
pub struct BrowseView {
|
||||
list: ListView<Category>,
|
||||
}
|
||||
|
||||
impl BrowseView {
|
||||
pub fn new(queue: Arc<Queue>, library: Arc<Library>) -> Self {
|
||||
let items = Arc::new(RwLock::new(Vec::new()));
|
||||
let list = ListView::new(items.clone(), queue.clone(), library);
|
||||
|
||||
let pagination = list.get_pagination().clone();
|
||||
std::thread::spawn(move || {
|
||||
let categories = queue.get_spotify().api.categories();
|
||||
items
|
||||
.write()
|
||||
.expect("could not writelock category items")
|
||||
.extend(
|
||||
categories
|
||||
.items
|
||||
.read()
|
||||
.expect("could not readlock fetched categories")
|
||||
.clone(),
|
||||
);
|
||||
categories.apply_pagination(&pagination);
|
||||
});
|
||||
|
||||
Self { list }
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewWrapper for BrowseView {
|
||||
wrap_impl!(self.list: ListView<Category>);
|
||||
}
|
||||
|
||||
impl ViewExt for BrowseView {
|
||||
fn title(&self) -> String {
|
||||
"Browse".to_string()
|
||||
}
|
||||
|
||||
fn on_command(&mut self, s: &mut Cursive, cmd: &Command) -> Result<CommandResult, String> {
|
||||
self.list.on_command(s, cmd)
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,7 @@ use crate::sharing::write_share;
|
||||
use crate::traits::{ListItem, ViewExt};
|
||||
use crate::ui::layout::Layout;
|
||||
use crate::ui::modal::Modal;
|
||||
use crate::{
|
||||
command::{Command, MoveAmount, MoveMode},
|
||||
spotify::Spotify,
|
||||
};
|
||||
use crate::{command::Command, spotify::Spotify};
|
||||
use cursive::traits::{Finder, Nameable};
|
||||
|
||||
pub struct ContextMenu {
|
||||
|
||||
@@ -10,6 +10,7 @@ use crate::config::LibraryTab;
|
||||
use crate::library::Library;
|
||||
use crate::queue::Queue;
|
||||
use crate::traits::ViewExt;
|
||||
use crate::ui::browse::BrowseView;
|
||||
use crate::ui::listview::ListView;
|
||||
use crate::ui::playlists::PlaylistsView;
|
||||
use crate::ui::tabview::TabView;
|
||||
@@ -55,6 +56,9 @@ impl LibraryView {
|
||||
ListView::new(library.shows.clone(), queue.clone(), library.clone())
|
||||
.with_title("Podcasts"),
|
||||
),
|
||||
LibraryTab::Browse => {
|
||||
tabview.add_tab("browse", BrowseView::new(queue.clone(), library.clone()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod album;
|
||||
pub mod artist;
|
||||
pub mod browse;
|
||||
pub mod contextmenu;
|
||||
pub mod help;
|
||||
pub mod layout;
|
||||
|
||||
@@ -21,6 +21,11 @@ impl<I: ListItem + Clone> ApiResult<I> {
|
||||
pub fn new(limit: u32, fetch_page: Arc<FetchPageFn<I>>) -> ApiResult<I> {
|
||||
let items = Arc::new(RwLock::new(Vec::new()));
|
||||
if let Some(first_page) = fetch_page(0) {
|
||||
debug!(
|
||||
"fetched first page, items: {}, total: {}",
|
||||
first_page.items.len(),
|
||||
first_page.total
|
||||
);
|
||||
items.write().unwrap().extend(first_page.items);
|
||||
ApiResult {
|
||||
offset: Arc::new(RwLock::new(first_page.offset)),
|
||||
|
||||
Reference in New Issue
Block a user