@@ -6,6 +6,7 @@ use std::{fs, process};
|
|||||||
use cursive::theme::Theme;
|
use cursive::theme::Theme;
|
||||||
use platform_dirs::AppDirs;
|
use platform_dirs::AppDirs;
|
||||||
|
|
||||||
|
use crate::command::{SortDirection, SortKey};
|
||||||
use crate::playable::Playable;
|
use crate::playable::Playable;
|
||||||
use crate::queue;
|
use crate::queue;
|
||||||
|
|
||||||
@@ -53,12 +54,19 @@ pub struct ConfigTheme {
|
|||||||
pub search_match: Option<String>,
|
pub search_match: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct SortingOrder {
|
||||||
|
pub key: SortKey,
|
||||||
|
pub direction: SortDirection,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct UserState {
|
pub struct UserState {
|
||||||
pub volume: u16,
|
pub volume: u16,
|
||||||
pub shuffle: bool,
|
pub shuffle: bool,
|
||||||
pub repeat: queue::RepeatSetting,
|
pub repeat: queue::RepeatSetting,
|
||||||
pub queue: Vec<Playable>,
|
pub queue: Vec<Playable>,
|
||||||
|
pub playlist_orders: HashMap<String, SortingOrder>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for UserState {
|
impl Default for UserState {
|
||||||
@@ -68,6 +76,7 @@ impl Default for UserState {
|
|||||||
shuffle: false,
|
shuffle: false,
|
||||||
repeat: queue::RepeatSetting::None,
|
repeat: queue::RepeatSetting::None,
|
||||||
queue: Vec::new(),
|
queue: Vec::new(),
|
||||||
|
playlist_orders: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ impl PlaylistView {
|
|||||||
|
|
||||||
let spotify = queue.get_spotify();
|
let spotify = queue.get_spotify();
|
||||||
let list = ListView::new(Arc::new(RwLock::new(tracks)), queue, library.clone());
|
let list = ListView::new(Arc::new(RwLock::new(tracks)), queue, library.clone());
|
||||||
|
if let Some(order) = library.cfg.state().playlist_orders.get(&playlist.id) {
|
||||||
|
list.sort(&order.key, &order.direction);
|
||||||
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
playlist,
|
playlist,
|
||||||
@@ -74,6 +77,15 @@ impl ViewExt for PlaylistView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Command::Sort(key, direction) = cmd {
|
if let Command::Sort(key, direction) = cmd {
|
||||||
|
self.library.cfg.with_state_mut(|mut state| {
|
||||||
|
let order = crate::config::SortingOrder {
|
||||||
|
key: key.clone(),
|
||||||
|
direction: direction.clone(),
|
||||||
|
};
|
||||||
|
state
|
||||||
|
.playlist_orders
|
||||||
|
.insert(self.playlist.id.clone(), order);
|
||||||
|
});
|
||||||
self.list.sort(key, direction);
|
self.list.sort(key, direction);
|
||||||
return Ok(CommandResult::Consumed(None));
|
return Ok(CommandResult::Consumed(None));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user