From 69e87d129a5f71f5d4d615cd2bcbb0ddf8f1b6bc Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Mon, 26 Mar 2018 14:34:54 +0300 Subject: [PATCH] ShowWidget: Hide shows from the Views when unsub is hit. --- hammond-gtk/src/app.rs | 31 +++++++++++++++++++++++++++++-- hammond-gtk/src/appnotif.rs | 15 ++++++++++----- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index ee3184e..75dbf6d 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -195,13 +195,19 @@ impl App { }); let text = "Marked all episodes as listened"; - let notif = InAppNotification::new(text.into(), callback, sender.clone()); + let notif = + InAppNotification::new(text.into(), callback, || {}, sender.clone()); overlay.add_overlay(¬if.revealer); // We need to display the notification after the widget is added to the overlay // so there will be a nice animation. notif.show(); } Ok(Action::RemoveShow(pd)) => { + if let Err(err) = utils::ignore_show(pd.id()) { + error!("Could not insert {} to the ignore list.", pd.title()); + error!("Error: {}", err); + } + let callback = clone!(pd => move || { // Spawn a thread so it won't block the ui. thread::spawn(clone!(pd => move || { @@ -213,8 +219,29 @@ impl App { glib::Continue(false) }); + let undo_callback = clone!(pd, sender => move || { + if let Err(err) = utils::uningore_show(pd.id()) { + error!("Could not insert {} to the ignore list.", pd.title()); + error!("Error: {}", err); + } + + + if let Err(err) = sender.send(Action::RefreshShowsView) { + error!("Action channl blew up, error {}", err) + } + + if let Err(err) = sender.send(Action::RefreshEpisodesView) { + error!("Action channl blew up, error {}", err) + } + }); + let text = format!("Unsubscribed from {}", pd.title()); - let notif = InAppNotification::new(text.into(), callback, sender.clone()); + let notif = InAppNotification::new( + text.into(), + callback, + undo_callback, + sender.clone(), + ); overlay.add_overlay(¬if.revealer); // We need to display the notification after the widget is added to the overlay // so there will be a nice animation. diff --git a/hammond-gtk/src/appnotif.rs b/hammond-gtk/src/appnotif.rs index 07291a7..67168c1 100644 --- a/hammond-gtk/src/appnotif.rs +++ b/hammond-gtk/src/appnotif.rs @@ -35,9 +35,15 @@ impl Default for InAppNotification { } impl InAppNotification { - pub fn new(text: String, mut callback: F, sender: Sender) -> Self + pub fn new( + text: String, + mut callback: F, + undo_callback: U, + sender: Sender, + ) -> Self where F: FnMut() -> glib::Continue + 'static, + U: Fn() + 'static, { let notif = InAppNotification::default(); notif.text.set_text(&text); @@ -57,14 +63,13 @@ impl InAppNotification { glib::source::source_remove(id); } + undo_callback(); + // Hide the notification revealer.set_reveal_child(false); // Refresh the widget if visible if let Err(err) = sender.send(Action::RefreshWidgetIfVis) { - error!( - "Something went horribly wrong with the Action channel: {}", - err - ) + error!("Action channel blew up: {}", err) } });