get next playlist
This commit is contained in:
parent
5af37c5187
commit
8583accc6c
@ -1,23 +1,41 @@
|
||||
use crate::utils::get_config;
|
||||
use crate::utils::json_reader::{Program, read_json};
|
||||
use crate::utils::{
|
||||
get_config,
|
||||
json_reader::{read_json, Program},
|
||||
};
|
||||
|
||||
pub struct CurrentProgram {
|
||||
nodes: Vec<Program>,
|
||||
idx: usize,
|
||||
}
|
||||
|
||||
impl CurrentProgram {
|
||||
fn new() -> Self {
|
||||
let config = get_config();
|
||||
let program: Vec<Program> = read_json(&config).program;
|
||||
Self {
|
||||
nodes: program,
|
||||
idx: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for CurrentProgram {
|
||||
type Item = Program;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.idx == self.nodes.len() - 1 {
|
||||
if self.idx < self.nodes.len() {
|
||||
let current = self.nodes[self.idx].clone();
|
||||
self.idx = 0;
|
||||
self.idx += 1;
|
||||
|
||||
Some(current)
|
||||
} else {
|
||||
let current = self.nodes[self.idx].clone();
|
||||
self.idx += 1;
|
||||
// play first item from next playlist
|
||||
let config = get_config();
|
||||
let program: Vec<Program> = read_json(&config).program;
|
||||
self.nodes = program;
|
||||
self.idx = 1;
|
||||
|
||||
let current = self.nodes[0].clone();
|
||||
|
||||
Some(current)
|
||||
}
|
||||
@ -25,12 +43,5 @@ impl Iterator for CurrentProgram {
|
||||
}
|
||||
|
||||
pub fn program() -> CurrentProgram {
|
||||
let config = get_config();
|
||||
|
||||
let program: Vec<Program> = read_json(&config).program;
|
||||
|
||||
CurrentProgram {
|
||||
nodes: program,
|
||||
idx: 0,
|
||||
}
|
||||
CurrentProgram::new()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user