EpisodeWidget: Only update if it's visible.
This commit is contained in:
parent
ea70addbc6
commit
0ba5e14d7f
@ -20,7 +20,10 @@ pub enum Action {
|
|||||||
RefreshAllViews,
|
RefreshAllViews,
|
||||||
RefreshEpisodesView,
|
RefreshEpisodesView,
|
||||||
RefreshEpisodesViewBGR,
|
RefreshEpisodesViewBGR,
|
||||||
|
RefreshShowsView,
|
||||||
RefreshWidget,
|
RefreshWidget,
|
||||||
|
RefreshWidgetIfVis,
|
||||||
|
RefreshWidgetIfSame(i32),
|
||||||
HeaderBarShowTile(String),
|
HeaderBarShowTile(String),
|
||||||
HeaderBarNormal,
|
HeaderBarNormal,
|
||||||
HeaderBarHideUpdateIndicator,
|
HeaderBarHideUpdateIndicator,
|
||||||
@ -137,7 +140,10 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Action::RefreshAllViews) => content.update(),
|
Ok(Action::RefreshAllViews) => content.update(),
|
||||||
|
Ok(Action::RefreshShowsView) => content.update_shows_view(),
|
||||||
Ok(Action::RefreshWidget) => content.update_widget(),
|
Ok(Action::RefreshWidget) => content.update_widget(),
|
||||||
|
Ok(Action::RefreshWidgetIfVis) => content.update_widget_if_visible(),
|
||||||
|
Ok(Action::RefreshWidgetIfSame(id)) => content.update_widget_if_same(id),
|
||||||
Ok(Action::RefreshEpisodesView) => content.update_episode_view(),
|
Ok(Action::RefreshEpisodesView) => content.update_episode_view(),
|
||||||
Ok(Action::RefreshEpisodesViewBGR) => content.update_episode_view_if_baground(),
|
Ok(Action::RefreshEpisodesViewBGR) => content.update_episode_view_if_baground(),
|
||||||
Ok(Action::HeaderBarShowTile(title)) => headerbar.switch_to_back(&title),
|
Ok(Action::HeaderBarShowTile(title)) => headerbar.switch_to_back(&title),
|
||||||
|
|||||||
@ -64,6 +64,18 @@ impl Content {
|
|||||||
self.shows.update_widget();
|
self.shows.update_widget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_widget_if_same(&self, pid: i32) {
|
||||||
|
self.shows.update_widget_if_same(pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_widget_if_visible(&self) {
|
||||||
|
if self.stack.get_visible_child_name() == Some("shows".to_string())
|
||||||
|
&& self.shows.get_stack().get_visible_child_name() == Some("widget".to_string())
|
||||||
|
{
|
||||||
|
self.shows.update_widget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_stack(&self) -> gtk::Stack {
|
pub fn get_stack(&self) -> gtk::Stack {
|
||||||
self.stack.clone()
|
self.stack.clone()
|
||||||
}
|
}
|
||||||
@ -186,12 +198,12 @@ impl ShowStack {
|
|||||||
let vis = self.stack.get_visible_child_name().unwrap();
|
let vis = self.stack.get_visible_child_name().unwrap();
|
||||||
let old = self.stack.get_child_by_name("widget").unwrap();
|
let old = self.stack.get_child_by_name("widget").unwrap();
|
||||||
|
|
||||||
let id = WidgetExt::get_name(&old).unwrap();
|
let id = WidgetExt::get_name(&old);
|
||||||
if id == "GtkBox" {
|
if id == Some("GtkBox".to_string()) || id.is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let pd = dbqueries::get_podcast_from_id(id.parse::<i32>().unwrap());
|
let pd = dbqueries::get_podcast_from_id(id.unwrap().parse::<i32>().unwrap());
|
||||||
if let Ok(pd) = pd {
|
if let Ok(pd) = pd {
|
||||||
self.replace_widget(&pd);
|
self.replace_widget(&pd);
|
||||||
self.stack.set_visible_child_name(&vis);
|
self.stack.set_visible_child_name(&vis);
|
||||||
@ -199,6 +211,17 @@ impl ShowStack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only update widget if it's podcast_id is equal to pid.
|
||||||
|
pub fn update_widget_if_same(&self, pid: i32) {
|
||||||
|
let old = self.stack.get_child_by_name("widget").unwrap();
|
||||||
|
|
||||||
|
let id = WidgetExt::get_name(&old);
|
||||||
|
if id != Some(pid.to_string()) || id.is_none() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.update_widget();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn switch_podcasts_animated(&self) {
|
pub fn switch_podcasts_animated(&self) {
|
||||||
self.stack
|
self.stack
|
||||||
.set_visible_child_full("podcasts", gtk::StackTransitionType::SlideRight);
|
.set_visible_child_full("podcasts", gtk::StackTransitionType::SlideRight);
|
||||||
|
|||||||
@ -81,6 +81,7 @@ pub fn add(id: i32, directory: &str, sender: Sender<Action>) {
|
|||||||
let dir = directory.to_owned();
|
let dir = directory.to_owned();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
if let Ok(episode) = dbqueries::get_episode_from_rowid(id) {
|
if let Ok(episode) = dbqueries::get_episode_from_rowid(id) {
|
||||||
|
let id = episode.podcast_id();
|
||||||
get_episode(&mut episode.into(), dir.as_str(), Some(prog))
|
get_episode(&mut episode.into(), dir.as_str(), Some(prog))
|
||||||
.err()
|
.err()
|
||||||
.map(|err| {
|
.map(|err| {
|
||||||
@ -93,7 +94,7 @@ pub fn add(id: i32, directory: &str, sender: Sender<Action>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sender.send(Action::RefreshEpisodesView).unwrap();
|
sender.send(Action::RefreshEpisodesView).unwrap();
|
||||||
sender.send(Action::RefreshWidget).unwrap();
|
sender.send(Action::RefreshWidgetIfSame(id)).unwrap();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -251,7 +251,7 @@ fn on_download_clicked(ep: &EpisodeWidgetQuery, sender: Sender<Action>) {
|
|||||||
|
|
||||||
// Update Views
|
// Update Views
|
||||||
sender.send(Action::RefreshEpisodesView).unwrap();
|
sender.send(Action::RefreshEpisodesView).unwrap();
|
||||||
sender.send(Action::RefreshWidget).unwrap();
|
sender.send(Action::RefreshWidgetIfVis).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_play_bttn_clicked(episode_id: i32) {
|
fn on_play_bttn_clicked(episode_id: i32) {
|
||||||
|
|||||||
@ -71,7 +71,6 @@ impl ShowWidget {
|
|||||||
self.unsub
|
self.unsub
|
||||||
.connect_clicked(clone!(shows, pd, sender => move |bttn| {
|
.connect_clicked(clone!(shows, pd, sender => move |bttn| {
|
||||||
on_unsub_button_clicked(shows.clone(), &pd, bttn, sender.clone());
|
on_unsub_button_clicked(shows.clone(), &pd, bttn, sender.clone());
|
||||||
sender.send(Action::HeaderBarNormal).unwrap();
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
self.setup_listbox(pd, sender.clone());
|
self.setup_listbox(pd, sender.clone());
|
||||||
@ -137,8 +136,10 @@ fn on_unsub_button_clicked(
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
shows.switch_podcasts_animated();
|
shows.switch_podcasts_animated();
|
||||||
|
sender.send(Action::HeaderBarNormal).unwrap();
|
||||||
// Queue a refresh after the switch to avoid blocking the db.
|
// Queue a refresh after the switch to avoid blocking the db.
|
||||||
sender.send(Action::RefreshAllViews).unwrap();
|
sender.send(Action::RefreshShowsView).unwrap();
|
||||||
|
sender.send(Action::RefreshEpisodesView).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user