feat: visual improvments for advices
This commit is contained in:
parent
609fc65816
commit
0e1167adb2
2 changed files with 56 additions and 36 deletions
|
@ -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 {
|
||||
|
@ -47,12 +47,21 @@ impl FactoryComponent for AppAdvice {
|
|||
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_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)]
|
||||
set_child = >k::Picture {
|
||||
|
@ -73,7 +82,9 @@ impl FactoryComponent for AppAdvice {
|
|||
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,12 +94,20 @@ 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<Self>) {
|
||||
match message {
|
||||
AppAdviceCmds::GotTexture(texture) => self.set_texture(Some(texture)),
|
||||
AppAdviceCmds::Error(err) => todo!()
|
||||
AppAdviceCmds::Error(err) => todo!(),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -77,7 +77,9 @@ impl Component for Ready {
|
|||
set_title: "No mail notifications available."
|
||||
},
|
||||
#[name = "advices_page_have_some"]
|
||||
add = >k::Box {
|
||||
add = &adw::Clamp {
|
||||
#[wrap(Some)]
|
||||
set_child = >k::Box {
|
||||
set_orientation: gtk::Orientation::Horizontal,
|
||||
|
||||
#[local_ref]
|
||||
|
@ -87,9 +89,12 @@ impl Component for Ready {
|
|||
},
|
||||
|
||||
adw::CarouselIndicatorDots {
|
||||
#[watch]
|
||||
set_carousel: Some(advices_carousel),
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
#[track(model.changed_advices_state())]
|
||||
set_visible_child: {
|
||||
|
@ -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>, _: &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();
|
||||
}
|
||||
}
|
||||
Err(err) => sender.output(ReadyOutput::FatalError(err)).unwrap(),
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue