Extend ShowsMachine functionality.
This commit is contained in:
parent
e9b6e26f08
commit
ad7f5013f3
@ -81,7 +81,6 @@ pub(crate) fn new_episode(item: &Item, parent_id: i32) -> Result<NewEpisode> {
|
|||||||
.unwrap())
|
.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|||||||
@ -97,69 +97,6 @@ pub struct PodcastsView {}
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct WidgetsView {}
|
pub struct WidgetsView {}
|
||||||
|
|
||||||
impl Into<ContentState<PodcastsView>> for ContentState<Empty> {
|
|
||||||
fn into(self) -> ContentState<PodcastsView> {
|
|
||||||
self.content.stack.set_visible_child_name("podcasts");
|
|
||||||
|
|
||||||
ContentState {
|
|
||||||
content: self.content,
|
|
||||||
state: PodcastsView {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UpdateView for ContentState<Empty> {
|
|
||||||
fn update(&mut self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<ContentState<Empty>> for ContentState<PodcastsView> {
|
|
||||||
fn into(self) -> ContentState<Empty> {
|
|
||||||
self.content.stack.set_visible_child_name("empty");
|
|
||||||
ContentState {
|
|
||||||
content: self.content,
|
|
||||||
state: Empty {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<ContentState<WidgetsView>> for ContentState<PodcastsView> {
|
|
||||||
fn into(self) -> ContentState<WidgetsView> {
|
|
||||||
self.content.stack.set_visible_child_name("widget");
|
|
||||||
|
|
||||||
ContentState {
|
|
||||||
content: self.content,
|
|
||||||
state: WidgetsView {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UpdateView for ContentState<PodcastsView> {
|
|
||||||
fn update(&mut self) {
|
|
||||||
let pop = PopulatedView::new_initialized(&self.content.stack);
|
|
||||||
self.content.replace_podcasts(pop)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<ContentState<PodcastsView>> for ContentState<WidgetsView> {
|
|
||||||
fn into(self) -> ContentState<PodcastsView> {
|
|
||||||
self.content.stack.set_visible_child_name("podcasts");
|
|
||||||
ContentState {
|
|
||||||
content: self.content,
|
|
||||||
state: PodcastsView {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<ContentState<Empty>> for ContentState<WidgetsView> {
|
|
||||||
fn into(self) -> ContentState<Empty> {
|
|
||||||
self.content.stack.set_visible_child_name("empty");
|
|
||||||
ContentState {
|
|
||||||
content: self.content,
|
|
||||||
state: Empty {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UpdateView for ContentState<WidgetsView> {
|
impl UpdateView for ContentState<WidgetsView> {
|
||||||
fn update(&mut self) {
|
fn update(&mut self) {
|
||||||
let old = self.content.stack.get_child_by_name("widget").unwrap();
|
let old = self.content.stack.get_child_by_name("widget").unwrap();
|
||||||
@ -286,6 +223,20 @@ struct ShowsMachine<S> {
|
|||||||
state: S,
|
state: S,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<S> ShowsMachine<S> {
|
||||||
|
fn update(&mut self) {
|
||||||
|
let vis = self.stack.get_visible_child_name().unwrap();
|
||||||
|
let old = self.stack.get_child_by_name("shows").unwrap();
|
||||||
|
self.stack.remove(&old);
|
||||||
|
|
||||||
|
let pop = ShowsPopulated::new_initialized(&self.stack);
|
||||||
|
self.populated = pop;
|
||||||
|
self.stack
|
||||||
|
.add_titled(&self.populated.container, "shows", "Shows");
|
||||||
|
self.stack.set_visible_child_name(&vis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct EpisodesMachine<S> {
|
struct EpisodesMachine<S> {
|
||||||
populated: EpisodesPopulated,
|
populated: EpisodesPopulated,
|
||||||
@ -320,6 +271,7 @@ struct EpisodesMachine<S> {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// TODO: Impl <From> instead of <Into>
|
||||||
impl Into<ShowsMachine<Populated>> for ShowsMachine<Empty> {
|
impl Into<ShowsMachine<Populated>> for ShowsMachine<Empty> {
|
||||||
fn into(self) -> ShowsMachine<Populated> {
|
fn into(self) -> ShowsMachine<Populated> {
|
||||||
self.stack.set_visible_child_name("populated");
|
self.stack.set_visible_child_name("populated");
|
||||||
@ -378,8 +330,8 @@ impl Into<EpisodesMachine<Empty>> for EpisodesMachine<Populated> {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
enum ShowStateWrapper {
|
enum ShowStateWrapper {
|
||||||
Populated(EpisodesMachine<Populated>),
|
Populated(ShowsMachine<Populated>),
|
||||||
Empty(EpisodesMachine<Empty>),
|
Empty(ShowsMachine<Empty>),
|
||||||
}
|
}
|
||||||
|
|
||||||
enum EpisodeStateWrapper {
|
enum EpisodeStateWrapper {
|
||||||
@ -397,12 +349,44 @@ enum EpisodeStateWrapper {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
impl ShowStateWrapper {
|
impl ShowStateWrapper {
|
||||||
|
fn new() -> Self {
|
||||||
|
let stack = gtk::Stack::new();
|
||||||
|
let pop = ShowsPopulated::new_initialized(&stack);
|
||||||
|
let empty = EmptyView::new();
|
||||||
|
|
||||||
|
if pop.flowbox.get_children().is_empty() {
|
||||||
|
stack.set_visible_child_name("empty");
|
||||||
|
ShowStateWrapper::Empty(ShowsMachine {
|
||||||
|
empty,
|
||||||
|
populated: pop,
|
||||||
|
stack,
|
||||||
|
state: Empty {},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
stack.set_visible_child_name("shows");
|
||||||
|
|
||||||
|
ShowStateWrapper::Populated(ShowsMachine {
|
||||||
|
empty,
|
||||||
|
populated: pop,
|
||||||
|
stack,
|
||||||
|
state: Populated {},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn switch(self) -> Self {
|
fn switch(self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
ShowStateWrapper::Populated(val) => ShowStateWrapper::Empty(val.into()),
|
ShowStateWrapper::Populated(val) => ShowStateWrapper::Empty(val.into()),
|
||||||
ShowStateWrapper::Empty(val) => ShowStateWrapper::Populated(val.into()),
|
ShowStateWrapper::Empty(val) => ShowStateWrapper::Populated(val.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update(&mut self) {
|
||||||
|
match *self {
|
||||||
|
ShowStateWrapper::Populated(ref mut val) => val.update(),
|
||||||
|
ShowStateWrapper::Empty(ref mut val) => val.update(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EpisodeStateWrapper {
|
impl EpisodeStateWrapper {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user