EpisodeView: Reduce boilderplate.
This commit is contained in:
parent
e4fc7c336e
commit
f49012ab51
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.21.0
|
||||
<!-- Generated with glade 3.22.0
|
||||
|
||||
Copyright (C) 2017 - 2018
|
||||
|
||||
@ -81,7 +81,6 @@ Tobias Bernard
|
||||
<property name="spacing">24</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="today_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<property name="hexpand">True</property>
|
||||
@ -139,7 +138,6 @@ Tobias Bernard
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="yday_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<property name="hexpand">True</property>
|
||||
@ -196,7 +194,6 @@ Tobias Bernard
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="week_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<property name="hexpand">True</property>
|
||||
@ -253,7 +250,6 @@ Tobias Bernard
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="month_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<property name="hexpand">True</property>
|
||||
@ -310,7 +306,6 @@ Tobias Bernard
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="rest_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<property name="hexpand">True</property>
|
||||
|
||||
@ -67,6 +67,7 @@ impl EpisodeStack {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_stack_visible(stack: >k::Stack) -> Result<(), DataError> {
|
||||
if is_episodes_populated()? {
|
||||
stack.set_visible_child_name("episodes");
|
||||
|
||||
@ -81,6 +81,8 @@ impl Default for EpisodesView {
|
||||
impl EpisodesView {
|
||||
#[inline]
|
||||
pub fn new(sender: Sender<Action>) -> Result<Rc<EpisodesView>, Error> {
|
||||
use self::ListSplit::*;
|
||||
|
||||
let view = Rc::new(EpisodesView::default());
|
||||
let ignore = get_ignored_shows()?;
|
||||
let episodes = dbqueries::get_episodes_widgets_filter_limit(&ignore, 200)?;
|
||||
@ -89,52 +91,18 @@ impl EpisodesView {
|
||||
let view_ = view.clone();
|
||||
let func = move |ep: EpisodeWidgetQuery| {
|
||||
let epoch = ep.epoch();
|
||||
let viewep = EpisodesViewWidget::new(ep, sender.clone());
|
||||
let widget = EpisodesViewWidget::new(ep, sender.clone());
|
||||
|
||||
let t = split(&now_utc, i64::from(epoch));
|
||||
match t {
|
||||
ListSplit::Today => {
|
||||
view_.today_list.add(&viewep.container);
|
||||
}
|
||||
ListSplit::Yday => {
|
||||
view_.yday_list.add(&viewep.container);
|
||||
}
|
||||
ListSplit::Week => {
|
||||
view_.week_list.add(&viewep.container);
|
||||
}
|
||||
ListSplit::Month => {
|
||||
view_.month_list.add(&viewep.container);
|
||||
}
|
||||
ListSplit::Rest => {
|
||||
view_.rest_list.add(&viewep.container);
|
||||
}
|
||||
match split(&now_utc, i64::from(epoch)) {
|
||||
Today => add_to_box(&widget, &view_.today_list, &view_.today_box),
|
||||
Yday => add_to_box(&widget, &view_.yday_list, &view_.yday_box),
|
||||
Week => add_to_box(&widget, &view_.week_list, &view_.week_box),
|
||||
Month => add_to_box(&widget, &view_.month_list, &view_.month_box),
|
||||
Rest => add_to_box(&widget, &view_.rest_list, &view_.rest_box),
|
||||
}
|
||||
};
|
||||
|
||||
let callback = clone!(view => move || {
|
||||
if view.today_list.get_children().is_empty() {
|
||||
view.today_box.hide();
|
||||
}
|
||||
|
||||
if view.yday_list.get_children().is_empty() {
|
||||
view.yday_box.hide();
|
||||
}
|
||||
|
||||
if view.week_list.get_children().is_empty() {
|
||||
view.week_box.hide();
|
||||
}
|
||||
|
||||
if view.month_list.get_children().is_empty() {
|
||||
view.month_box.hide();
|
||||
}
|
||||
|
||||
if view.rest_list.get_children().is_empty() {
|
||||
view.rest_box.hide();
|
||||
}
|
||||
});
|
||||
|
||||
lazy_load_full(episodes, func, callback);
|
||||
|
||||
lazy_load_full(episodes, func, || {});
|
||||
view.container.show_all();
|
||||
Ok(view)
|
||||
}
|
||||
@ -146,6 +114,12 @@ impl EpisodesView {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn add_to_box(widget: &EpisodesViewWidget, listbox: >k::ListBox, box_: >k::Box) {
|
||||
listbox.add(&widget.container);
|
||||
box_.show();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn split(now: &DateTime<Utc>, epoch: i64) -> ListSplit {
|
||||
let ep = Utc.timestamp(epoch, 0);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user