fix: preserve video selection order for playback
This commit is contained in:
+26
-21
@@ -93,7 +93,7 @@ struct DisplayRow {
|
||||
struct Screen {
|
||||
content: Content,
|
||||
selection: ListState,
|
||||
checked: BTreeSet<String>,
|
||||
checked: Vec<String>,
|
||||
description_scroll: u16,
|
||||
error: Option<String>,
|
||||
title: String,
|
||||
@@ -106,7 +106,7 @@ impl Screen {
|
||||
let mut screen = Self {
|
||||
content,
|
||||
selection: ListState::default(),
|
||||
checked: BTreeSet::new(),
|
||||
checked: Vec::new(),
|
||||
description_scroll: 0,
|
||||
error: None,
|
||||
title: String::new(),
|
||||
@@ -163,10 +163,13 @@ impl Screen {
|
||||
}
|
||||
fn toggle_checked(&mut self) {
|
||||
if self.playable()
|
||||
&& let Some(id) = self.selected_key().map(str::to_owned)
|
||||
&& let Some(id) = self.selected_key()
|
||||
{
|
||||
if !self.checked.remove(&id) {
|
||||
self.checked.insert(id);
|
||||
if let Some(index) = self.checked.iter().position(|checked| checked == id) {
|
||||
self.checked.remove(index);
|
||||
} else {
|
||||
let id = id.to_owned();
|
||||
self.checked.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,22 +177,24 @@ impl Screen {
|
||||
if self.checked.is_empty() {
|
||||
return self.selected_video().into_iter().collect();
|
||||
}
|
||||
match &self.content {
|
||||
Content::Series {
|
||||
media,
|
||||
data: Some(data),
|
||||
} => data
|
||||
.iter()
|
||||
.filter(|episode| self.checked.contains(&episode.identity.key()))
|
||||
.map(|episode| episode.snapshot(media))
|
||||
.collect(),
|
||||
Content::Collection { videos, .. } => videos
|
||||
.iter()
|
||||
.filter(|video| self.checked.contains(&video.id))
|
||||
.cloned()
|
||||
.collect(),
|
||||
_ => Vec::new(),
|
||||
}
|
||||
// ponytail: scan rows per check; index IDs if very large lists need it.
|
||||
self.checked
|
||||
.iter()
|
||||
.filter_map(|id| {
|
||||
let index = self
|
||||
.rows
|
||||
.iter()
|
||||
.position(|row| row.key.as_ref() == Some(id))?;
|
||||
match &self.content {
|
||||
Content::Series {
|
||||
media,
|
||||
data: Some(data),
|
||||
} => data.get(index).map(|episode| episode.snapshot(media)),
|
||||
Content::Collection { videos, .. } => videos.get(index).cloned(),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
fn selected_key(&self) -> Option<&str> {
|
||||
self.selection
|
||||
|
||||
Reference in New Issue
Block a user