Refactor Empty states

This commit is contained in:
Jordan Petridis 2018-08-12 03:04:26 +03:00
parent acaa06749e
commit d4a822fa7e
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
9 changed files with 77 additions and 84 deletions

View File

@ -5,7 +5,6 @@ podcasts-gtk/resources/org.gnome.Podcasts.desktop
podcasts-gtk/resources/org.gnome.Podcasts.appdata.xml
# ui files
podcasts-gtk/resources/gtk/empty_show.ui
podcasts-gtk/resources/gtk/empty_view.ui
podcasts-gtk/resources/gtk/episode_widget.ui
podcasts-gtk/resources/gtk/hamburger.ui

View File

@ -1,63 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkBox" id="empty_show">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixel_size">128</property>
<property name="icon_name">application-rss+xml-symbolic</property>
<property name="use_fallback">True</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">This show does not have any episodes</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.4399999999999999"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">If you think this is an error, please consider opening a bug report.</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</interface>

View File

@ -30,6 +30,47 @@ Tobias Bernard
<!-- interface-description A podcast client for the GNOME Desktop -->
<!-- interface-copyright 2017 - 2018 -->
<!-- interface-authors Jordan Petridis\nTobias Bernard -->
<object class="GtkBox" id="empty_show">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">This show does not have episodes yet</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.4399999999999999"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">If you think this is an error, please consider writting a bug report.</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<object class="GtkBox" id="empty_view">
<property name="visible">True</property>
<property name="can_focus">False</property>

View File

@ -4,7 +4,6 @@
<file compressed="true" preprocess="xml-stripblanks">gtk/episode_widget.ui</file>
<file compressed="true" preprocess="xml-stripblanks">gtk/show_widget.ui</file>
<file compressed="true" preprocess="xml-stripblanks">gtk/empty_view.ui</file>
<file compressed="true" preprocess="xml-stripblanks">gtk/empty_show.ui</file>
<file compressed="true" preprocess="xml-stripblanks">gtk/home_view.ui</file>
<file compressed="true" preprocess="xml-stripblanks">gtk/home_episode.ui</file>
<file compressed="true" preprocess="xml-stripblanks">gtk/headerbar.ui</file>

View File

@ -10,6 +10,7 @@ use podcasts_data::errors::DataError;
use app::Action;
use widgets::{EmptyView, HomeView};
use std::ops::Deref;
use std::rc::Rc;
#[derive(Debug, Clone, Copy)]
@ -30,12 +31,12 @@ pub(crate) struct HomeStack {
impl HomeStack {
pub(crate) fn new(sender: Sender<Action>) -> Result<HomeStack, Error> {
let episodes = HomeView::new(sender.clone(), None)?;
let empty = EmptyView::new();
let empty = EmptyView::default();
let stack = gtk::Stack::new();
let state = State::Empty;
stack.add_named(episodes.view.container(), "home");
stack.add_named(&empty.container, "empty");
stack.add_named(empty.deref(), "empty");
let mut home = HomeStack {
empty,

View File

@ -11,6 +11,7 @@ use utils::get_ignored_shows;
use widgets::EmptyView;
use std::cell::RefCell;
use std::ops::Deref;
use std::rc::Rc;
#[derive(Debug, Clone, Copy)]
@ -31,12 +32,12 @@ pub(crate) struct ShowStack {
impl ShowStack {
pub(crate) fn new(sender: Sender<Action>) -> Self {
let populated = Rc::new(RefCell::new(PopulatedStack::new(sender.clone())));
let empty = EmptyView::new();
let empty = EmptyView::default();
let stack = gtk::Stack::new();
let state = ShowState::Empty;
stack.add_named(&populated.borrow().container(), "populated");
stack.add_named(&empty.container, "empty");
stack.add_named(empty.deref(), "empty");
let mut show = ShowStack {
empty,

View File

@ -1,21 +1,38 @@
use gtk;
use std::ops::Deref;
#[derive(Debug, Clone)]
pub(crate) struct EmptyView {
pub(crate) container: gtk::Box,
#[derive(Clone, Debug)]
pub(crate) struct EmptyView(gtk::Box);
impl Deref for EmptyView {
type Target = gtk::Box;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Default for EmptyView {
fn default() -> Self {
let builder = gtk::Builder::new_from_resource("/org/gnome/Podcasts/gtk/empty_view.ui");
let view: gtk::Box = builder.get_object("empty_view").unwrap();
EmptyView { container: view }
EmptyView(view)
}
}
impl EmptyView {
pub(crate) fn new() -> EmptyView {
EmptyView::default()
#[derive(Clone, Debug)]
pub(crate) struct EmptyShow(gtk::Box);
impl Deref for EmptyShow {
type Target = gtk::Box;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Default for EmptyShow {
fn default() -> Self {
let builder = gtk::Builder::new_from_resource("/org/gnome/Podcasts/gtk/empty_view.ui");
let box_: gtk::Box = builder.get_object("empty_show").unwrap();
EmptyShow(box_)
}
}

View File

@ -11,7 +11,7 @@ mod shows_view;
pub(crate) use self::aboutdialog::about_dialog;
pub(crate) use self::base_view::BaseView;
pub(crate) use self::empty::EmptyView;
pub(crate) use self::empty::{EmptyShow, EmptyView};
pub(crate) use self::episode::EpisodeWidget;
pub(crate) use self::home_view::HomeView;
pub(crate) use self::show::ShowWidget;

View File

@ -13,8 +13,9 @@ use podcasts_data::Show;
use app::Action;
use utils::{self, lazy_load};
use widgets::{BaseView, EpisodeWidget, ShowMenu};
use widgets::{BaseView, EmptyShow, EpisodeWidget, ShowMenu};
use std::ops::Deref;
use std::rc::Rc;
use std::sync::Arc;
@ -122,11 +123,8 @@ fn populate_listbox(
}));
if count == 0 {
let builder = gtk::Builder::new_from_resource("/org/gnome/Podcasts/gtk/empty_show.ui");
let container: gtk::Box = builder
.get_object("empty_show")
.ok_or_else(|| format_err!("FOO"))?;
show.episodes.add(&container);
let empty = EmptyShow::default();
show.episodes.add(empty.deref());
return Ok(());
}