feat: visual improvments for advices

This commit is contained in:
jane400 2024-08-22 13:18:01 +02:00 committed by jane400
parent 609fc65816
commit 0e1167adb2
2 changed files with 56 additions and 36 deletions

View file

@ -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,11 +47,20 @@ impl FactoryComponent for AppAdvice {
set_visible: self.texture.is_none(),
},
add_overlay = &gtk::Label {
set_halign: gtk::Align::Center,
set_valign: gtk::Align::Center,
add_overlay = &gtk::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)]
@ -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!(),
};
}
}

View file

@ -77,18 +77,23 @@ impl Component for Ready {
set_title: "No mail notifications available."
},
#[name = "advices_page_have_some"]
add = &gtk::Box {
set_orientation: gtk::Orientation::Horizontal,
add = &adw::Clamp {
#[wrap(Some)]
set_child = &gtk::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>, _: &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(),
},