remove queue struct, and use generics of ContentList
This commit is contained in:
parent
b29846fb72
commit
955532893f
|
|
@ -3,7 +3,6 @@ use std::time::Duration;
|
|||
use crate::browser::FileBrowser;
|
||||
use crate::connection::Connection;
|
||||
use crate::list::ContentList;
|
||||
use crate::queue::Queue;
|
||||
use crate::ui::InputMode;
|
||||
use mpd::{Client, Song};
|
||||
|
||||
|
|
@ -17,7 +16,7 @@ pub struct App {
|
|||
pub running: bool,
|
||||
pub conn: Connection,
|
||||
pub browser: FileBrowser, // Directory browser
|
||||
pub queue_list: Queue, // Stores the current playing queue
|
||||
pub queue_list: ContentList<Song>, // Stores the current playing queue
|
||||
pub pl_list: ContentList<String>, // Stores list of playlists
|
||||
pub selected_tab: SelectedTab, // Used to switch between tabs
|
||||
|
||||
|
|
@ -44,7 +43,7 @@ pub enum SelectedTab {
|
|||
impl App {
|
||||
pub fn builder(addrs: &str) -> AppResult<Self> {
|
||||
let mut conn = Connection::new(addrs).unwrap();
|
||||
let mut queue_list = Queue::new();
|
||||
let mut queue_list = ContentList::new();
|
||||
let mut pl_list = ContentList::new();
|
||||
pl_list.list = Self::get_playlist(&mut conn.conn)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,3 @@ pub mod handler;
|
|||
|
||||
/// Application
|
||||
pub mod app;
|
||||
|
||||
/// The Queue structure
|
||||
pub mod queue;
|
||||
|
|
|
|||
41
src/queue.rs
41
src/queue.rs
|
|
@ -1,41 +0,0 @@
|
|||
use mpd::Song;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Queue {
|
||||
pub list: Vec<Song>,
|
||||
pub index: usize,
|
||||
}
|
||||
|
||||
impl Queue {
|
||||
pub fn new() -> Self {
|
||||
Queue {
|
||||
list: Vec::new(),
|
||||
index: 0,
|
||||
}
|
||||
}
|
||||
|
||||
// Go to next item in list
|
||||
pub fn next(&mut self) {
|
||||
let len = self.list.len();
|
||||
if len != 0 && self.index < len - 1 {
|
||||
self.index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// Go to previous item in list
|
||||
pub fn prev(&mut self) {
|
||||
if self.index != 0 {
|
||||
self.index -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset_index(&mut self) {
|
||||
self.index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Queue {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
|
@ -362,9 +362,9 @@ fn draw_playlist_viewer(frame: &mut Frame, app: &mut App, area: Rect) {
|
|||
let table = Table::new(
|
||||
rows,
|
||||
vec![
|
||||
Constraint::Min(40),
|
||||
Constraint::Percentage(40),
|
||||
Constraint::Percentage(20),
|
||||
Constraint::Min(48),
|
||||
Constraint::Percentage(48),
|
||||
Constraint::Percentage(4),
|
||||
],
|
||||
)
|
||||
.block(title)
|
||||
|
|
|
|||
Reference in New Issue