Display shuffle order
This commit is contained in:
@@ -120,7 +120,13 @@ impl CommandManager {
|
|||||||
self.queue.get_current_index()
|
self.queue.get_current_index()
|
||||||
);
|
);
|
||||||
s.queuestate.queue = queue.clone();
|
s.queuestate.queue = queue.clone();
|
||||||
s.queuestate.random_order = self.queue.get_random_order();
|
s.queuestate.random_order = self
|
||||||
|
.queue
|
||||||
|
.get_random_order()
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.as_ref()
|
||||||
|
.cloned();
|
||||||
s.queuestate.current_track = self.queue.get_current_index();
|
s.queuestate.current_track = self.queue.get_current_index();
|
||||||
s.queuestate.track_progress = self.spotify.get_current_progress();
|
s.queuestate.track_progress = self.spotify.get_current_progress();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ pub struct Queue {
|
|||||||
/// the raw data only.
|
/// the raw data only.
|
||||||
pub queue: Arc<RwLock<Vec<Playable>>>,
|
pub queue: Arc<RwLock<Vec<Playable>>>,
|
||||||
/// The playback order of the queue, as indices into `self.queue`.
|
/// The playback order of the queue, as indices into `self.queue`.
|
||||||
random_order: RwLock<Option<Vec<usize>>>,
|
random_order: Arc<RwLock<Option<Vec<usize>>>>,
|
||||||
current_track: RwLock<Option<usize>>,
|
current_track: RwLock<Option<usize>>,
|
||||||
spotify: Spotify,
|
spotify: Spotify,
|
||||||
cfg: Arc<Config>,
|
cfg: Arc<Config>,
|
||||||
@@ -62,7 +62,7 @@ impl Queue {
|
|||||||
queue: Arc::new(RwLock::new(queue_state.queue)),
|
queue: Arc::new(RwLock::new(queue_state.queue)),
|
||||||
spotify: spotify.clone(),
|
spotify: spotify.clone(),
|
||||||
current_track: RwLock::new(queue_state.current_track),
|
current_track: RwLock::new(queue_state.current_track),
|
||||||
random_order: RwLock::new(queue_state.random_order),
|
random_order: Arc::new(RwLock::new(queue_state.random_order)),
|
||||||
cfg,
|
cfg,
|
||||||
#[cfg(feature = "notify")]
|
#[cfg(feature = "notify")]
|
||||||
notification_id: Arc::new(AtomicU32::new(0)),
|
notification_id: Arc::new(AtomicU32::new(0)),
|
||||||
@@ -442,8 +442,8 @@ impl Queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current order that is used to shuffle.
|
/// Get the current order that is used to shuffle.
|
||||||
pub fn get_random_order(&self) -> Option<Vec<usize>> {
|
pub fn get_random_order(&self) -> Arc<RwLock<Option<Vec<usize>>>> {
|
||||||
self.random_order.read().unwrap().clone()
|
self.random_order.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// (Re)generate the random shuffle order.
|
/// (Re)generate the random shuffle order.
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ use crate::ui::pagination::Pagination;
|
|||||||
|
|
||||||
pub struct ListView<I: ListItem> {
|
pub struct ListView<I: ListItem> {
|
||||||
content: Arc<RwLock<Vec<I>>>,
|
content: Arc<RwLock<Vec<I>>>,
|
||||||
|
order: Arc<RwLock<Option<Vec<usize>>>>,
|
||||||
last_content_len: usize,
|
last_content_len: usize,
|
||||||
selected: usize,
|
selected: usize,
|
||||||
search_query: String,
|
search_query: String,
|
||||||
@@ -61,6 +62,7 @@ impl<I: ListItem + Clone> ListView<I> {
|
|||||||
pub fn new(content: Arc<RwLock<Vec<I>>>, queue: Arc<Queue>, library: Arc<Library>) -> Self {
|
pub fn new(content: Arc<RwLock<Vec<I>>>, queue: Arc<Queue>, library: Arc<Library>) -> Self {
|
||||||
let result = Self {
|
let result = Self {
|
||||||
content,
|
content,
|
||||||
|
order: Arc::new(RwLock::new(None)),
|
||||||
last_content_len: 0,
|
last_content_len: 0,
|
||||||
selected: 0,
|
selected: 0,
|
||||||
search_query: String::new(),
|
search_query: String::new(),
|
||||||
@@ -77,6 +79,11 @@ impl<I: ListItem + Clone> ListView<I> {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_order(mut self, order: Arc<RwLock<Option<Vec<usize>>>>) -> Self {
|
||||||
|
self.order = order;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_title(mut self, title: &str) -> Self {
|
pub fn with_title(mut self, title: &str) -> Self {
|
||||||
self.title = title.to_string();
|
self.title = title.to_string();
|
||||||
self
|
self
|
||||||
@@ -193,11 +200,19 @@ impl<I: ListItem + Clone> View for ListView<I> {
|
|||||||
printer.print((0, 0), &buf);
|
printer.print((0, 0), &buf);
|
||||||
});
|
});
|
||||||
} else if i < content.len() {
|
} else if i < content.len() {
|
||||||
let item = &content[i];
|
let current_index = if self.order.read().unwrap().is_some() {
|
||||||
|
self.order.read().unwrap().as_ref().unwrap()[i]
|
||||||
|
} else {
|
||||||
|
i
|
||||||
|
};
|
||||||
|
|
||||||
|
let item = &content[current_index];
|
||||||
|
|
||||||
let currently_playing = item.is_playing(self.queue.clone())
|
let currently_playing = item.is_playing(self.queue.clone())
|
||||||
&& self.queue.get_current_index() == Some(i);
|
&& self.queue.get_current_index() == Some(current_index);
|
||||||
|
|
||||||
let style = if self.selected == i {
|
let style = if self.selected == i {
|
||||||
|
// Highlight the currently selected item.
|
||||||
if currently_playing {
|
if currently_playing {
|
||||||
ColorStyle::new(
|
ColorStyle::new(
|
||||||
*printer.theme.palette.custom("playing_selected").unwrap(),
|
*printer.theme.palette.custom("playing_selected").unwrap(),
|
||||||
@@ -207,6 +222,7 @@ impl<I: ListItem + Clone> View for ListView<I> {
|
|||||||
ColorStyle::highlight()
|
ColorStyle::highlight()
|
||||||
}
|
}
|
||||||
} else if currently_playing {
|
} else if currently_playing {
|
||||||
|
// Apply a different color to the currently playing item.
|
||||||
ColorStyle::new(
|
ColorStyle::new(
|
||||||
ColorType::Color(*printer.theme.palette.custom("playing").unwrap()),
|
ColorType::Color(*printer.theme.palette.custom("playing").unwrap()),
|
||||||
ColorType::Color(*printer.theme.palette.custom("playing_bg").unwrap()),
|
ColorType::Color(*printer.theme.palette.custom("playing_bg").unwrap()),
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ pub struct QueueView {
|
|||||||
|
|
||||||
impl QueueView {
|
impl QueueView {
|
||||||
pub fn new(queue: Arc<Queue>, library: Arc<Library>) -> QueueView {
|
pub fn new(queue: Arc<Queue>, library: Arc<Library>) -> QueueView {
|
||||||
let list = ListView::new(queue.queue.clone(), queue.clone(), library.clone());
|
let list = ListView::new(queue.queue.clone(), queue.clone(), library.clone())
|
||||||
|
.with_order(queue.get_random_order());
|
||||||
|
|
||||||
QueueView {
|
QueueView {
|
||||||
list,
|
list,
|
||||||
|
|||||||
Reference in New Issue
Block a user