ShowWidget: display a notification before removing the show.

This commit is contained in:
Jordan Petridis 2018-03-26 10:57:44 +03:00
parent 482ed7c3c6
commit b2c95e5a73
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 24 additions and 9 deletions

View File

@ -7,6 +7,7 @@ use gtk::SettingsExt as GtkSettingsExt;
use gtk::prelude::*; use gtk::prelude::*;
use hammond_data::{Podcast, Source}; use hammond_data::{Podcast, Source};
use hammond_data::utils::delete_show;
use appnotif::*; use appnotif::*;
use headerbar::Header; use headerbar::Header;
@ -17,6 +18,7 @@ use widgets::mark_all_watched;
use std::sync::Arc; use std::sync::Arc;
use std::sync::mpsc::{channel, Receiver, Sender}; use std::sync::mpsc::{channel, Receiver, Sender};
use std::time::Duration; use std::time::Duration;
use std::thread;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Action { pub enum Action {
@ -36,6 +38,7 @@ pub enum Action {
HeaderBarShowUpdateIndicator, HeaderBarShowUpdateIndicator,
HeaderBarHideUpdateIndicator, HeaderBarHideUpdateIndicator,
MarkAllPlayerNotification(Arc<Podcast>), MarkAllPlayerNotification(Arc<Podcast>),
RemoveShow(Arc<Podcast>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -198,6 +201,25 @@ impl App {
// so there will be a nice animation. // so there will be a nice animation.
notif.show(); notif.show();
} }
Ok(Action::RemoveShow(pd)) => {
let callback = clone!(pd => move || {
// Spawn a thread so it won't block the ui.
thread::spawn(clone!(pd => move || {
if let Err(err) = delete_show(&pd) {
error!("Something went wrong trying to remove {}", pd.title());
error!("Error: {}", err);
}
}));
glib::Continue(false)
});
let text = format!("Unsubscribed from {}", pd.title());
let notif = InAppNotification::new(text.into(), callback, sender.clone());
overlay.add_overlay(&notif.revealer);
// We need to display the notification after the widget is added to the overlay
// so there will be a nice animation.
notif.show();
}
Err(_) => (), Err(_) => (),
} }

View File

@ -7,7 +7,7 @@ use open;
use hammond_data::Podcast; use hammond_data::Podcast;
use hammond_data::dbqueries; use hammond_data::dbqueries;
use hammond_data::utils::{delete_show, replace_extra_spaces}; use hammond_data::utils::{replace_extra_spaces};
use app::Action; use app::Action;
use utils::get_pixbuf_from_path; use utils::get_pixbuf_from_path;
@ -15,7 +15,6 @@ use widgets::episode::episodes_listbox;
use std::sync::Arc; use std::sync::Arc;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use std::thread;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ShowWidget { pub struct ShowWidget {
@ -141,13 +140,7 @@ fn on_unsub_button_clicked(
// hack to get away without properly checking for none. // hack to get away without properly checking for none.
// if pressed twice would panic. // if pressed twice would panic.
unsub_button.hide(); unsub_button.hide();
// Spawn a thread so it won't block the ui. sender.send(Action::RemoveShow(pd))?;
thread::spawn(move || {
if let Err(err) = delete_show(&pd) {
error!("Something went wrong trying to remove {}", pd.title());
error!("Error: {}", err);
}
});
sender.send(Action::HeaderBarNormal)?; sender.send(Action::HeaderBarNormal)?;
sender.send(Action::ShowShowsAnimated)?; sender.send(Action::ShowShowsAnimated)?;