diff --git a/paket/src/advices.rs b/paket/src/advices.rs index 98f91c1..0e7a5ab 100644 --- a/paket/src/advices.rs +++ b/paket/src/advices.rs @@ -1,13 +1,13 @@ +use adw::{gio, glib}; +use gtk::gdk; use libpaket::advices::UatToken; use libpaket::LibraryError; use relm4::gtk; -use gtk::gdk; -use adw::{gio, glib}; -use relm4::prelude::*; use adw::prelude::*; -use glib::prelude::*; use gio::prelude::*; +use glib::prelude::*; +use relm4::prelude::*; #[derive(Debug)] pub struct AppAdviceMetadata { @@ -42,16 +42,25 @@ impl FactoryComponent for AppAdvice { add_overlay = >k::Spinner { start: (), set_align: gtk::Align::Center, - + #[track(self.changed_texture())] set_visible: self.texture.is_none(), }, - add_overlay = >k::Label { - set_halign: gtk::Align::Center, - set_valign: gtk::Align::Center, + add_overlay = >k::Box { + add_css_class: relm4::css::OSD, + add_css_class: relm4::css::NUMERIC, - set_label: self.metadata.date.as_str(), + set_valign: gtk::Align::End, + set_halign: gtk::Align::End, + + set_margin_all: 8, + + gtk::Label { + set_margin_all: 4, + + set_label: self.metadata.date.as_str(), + }, }, #[wrap(Some)] @@ -71,9 +80,11 @@ impl FactoryComponent for AppAdvice { let advice = _self.metadata.advice.clone(); let uat = value.1; - + sender.oneshot_command(async move { - let res = libpaket::advices::AdviceClient::new().fetch_advice_image(&advice, &uat).await; + let res = libpaket::advices::AdviceClient::new() + .fetch_advice_image(&advice, &uat) + .await; let res = match res { Ok(res) => res, @@ -83,13 +94,21 @@ impl FactoryComponent for AppAdvice { let file = { let (file, io_stream) = gio::File::new_tmp(None::<&std::path::Path>).unwrap(); let output_stream = io_stream.output_stream(); - output_stream.write(res.as_slice(), None::<&gio::Cancellable>).unwrap(); + output_stream + .write(res.as_slice(), None::<&gio::Cancellable>) + .unwrap(); file }; - let image = glycin::Loader::new(file).load().await.expect("Image decoding failed"); - let frame = image.next_frame().await.expect("Image frame decoding failed"); - + let image = glycin::Loader::new(file) + .load() + .await + .expect("Image decoding failed"); + let frame = image + .next_frame() + .await + .expect("Image frame decoding failed"); + AppAdviceCmds::GotTexture(frame.texture()) }); @@ -99,8 +118,7 @@ impl FactoryComponent for AppAdvice { fn update_cmd(&mut self, message: Self::CommandOutput, sender: FactorySender) { match message { AppAdviceCmds::GotTexture(texture) => self.set_texture(Some(texture)), - AppAdviceCmds::Error(err) => todo!() + AppAdviceCmds::Error(err) => todo!(), }; } - -} \ No newline at end of file +} diff --git a/paket/src/ready.rs b/paket/src/ready.rs index 6d30515..5717b75 100644 --- a/paket/src/ready.rs +++ b/paket/src/ready.rs @@ -77,18 +77,23 @@ impl Component for Ready { set_title: "No mail notifications available." }, #[name = "advices_page_have_some"] - add = >k::Box { - set_orientation: gtk::Orientation::Horizontal, + add = &adw::Clamp { + #[wrap(Some)] + set_child = >k::Box { + set_orientation: gtk::Orientation::Horizontal, - #[local_ref] - advices_carousel -> adw::Carousel { - set_orientation: gtk::Orientation::Vertical, + #[local_ref] + advices_carousel -> adw::Carousel { + set_orientation: gtk::Orientation::Vertical, + }, + + adw::CarouselIndicatorDots { + #[watch] + set_carousel: Some(advices_carousel), + set_orientation: gtk::Orientation::Vertical, + } }, - - adw::CarouselIndicatorDots { - set_carousel: Some(advices_carousel), - } }, #[track(model.changed_advices_state())] @@ -103,9 +108,10 @@ impl Component for Ready { }, } -> /*page_advices: adw::ViewStackPage*/ { set_title: Some("Mail notification"), + set_name: Some("page_advices"), /*#[track(model.changed_have_service_advices())] set_visible: model.have_service_advices,*/ - } + }, } } @@ -155,11 +161,11 @@ impl Component for Ready { fn update(&mut self, message: Self::Input, sender: ComponentSender, _: &Self::Root) { self.reset(); - let token = self.login.clone(); match message { ReadyInput::Activate => { self.set_activate(true); if self.changed_activate() { + let token = self.login.clone(); sender.oneshot_command(async move { let token = crate::login::get_id_token(&token).await.unwrap(); let client = libpaket::StammdatenClient::new(); @@ -171,6 +177,7 @@ impl Component for Ready { self.set_activate(false); } ReadyInput::HaveAdvicesService => { + let token = self.login.clone(); sender.oneshot_command(async move { // fetching advices let dhli_token = crate::login::get_id_token(&token).await.unwrap(); @@ -217,7 +224,6 @@ impl Component for Ready { ReadyCmds::LoggedOut => sender.input(ReadyInput::Deactivate), ReadyCmds::GotCustomerDataFull(res) => match res { Ok(res) => { - let mut a_service_was_activated = false; for service in &res.common.services { match service { libpaket::stammdaten::CustomerDataService::Packstation => (), @@ -226,16 +232,12 @@ impl Component for Ready { libpaket::stammdaten::CustomerDataService::Digiben => (), libpaket::stammdaten::CustomerDataService::GeraetAktiviert => (), libpaket::stammdaten::CustomerDataService::Briefankuendigung => { - a_service_was_activated = true; sender.input(ReadyInput::HaveAdvicesService); } } } - if a_service_was_activated { - sender.output(ReadyOutput::Ready).unwrap() - } else { - sender.output(ReadyOutput::NoServicesEnabled).unwrap(); - } + + sender.output(ReadyOutput::Ready).unwrap() } Err(err) => sender.output(ReadyOutput::FatalError(err)).unwrap(), },