Compare commits

..

No commits in common. "cd2bc321cd9254205345b5723613e1b0b7a2b6da" and "609fc6581697ab82876bd2712c52467ae6e7ea0e" have entirely different histories.

3 changed files with 42 additions and 226 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 adw::prelude::*;
use gio::prelude::*;
use glib::prelude::*;
use relm4::prelude::*;
use adw::prelude::*;
use glib::prelude::*;
use gio::prelude::*;
#[derive(Debug)]
pub struct AppAdviceMetadata {
@ -47,20 +47,11 @@ impl FactoryComponent for AppAdvice {
set_visible: self.texture.is_none(),
},
add_overlay = &gtk::Box {
add_css_class: relm4::css::OSD,
add_css_class: relm4::css::NUMERIC,
add_overlay = &gtk::Label {
set_halign: gtk::Align::Center,
set_valign: gtk::Align::Center,
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(),
},
set_label: self.metadata.date.as_str(),
},
#[wrap(Some)]
@ -82,9 +73,7 @@ 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,
@ -94,20 +83,12 @@ 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())
});
@ -118,7 +99,8 @@ 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

@ -13,7 +13,6 @@ mod advices;
mod constants;
mod login;
mod ready;
mod tracking;
#[derive(Debug, PartialEq)]
enum AppState {
@ -283,7 +282,6 @@ fn convert_ready_response(response: ReadyOutput) -> AppInput {
long: "There is no feature on your account which is supported by this app. You need the offical app and register for one or more of:\n\"Briefasnkündigung\"".to_string(),
}),
ReadyOutput::Error(err) => AppInput::ErrorOccoured(AppError { short: "meow".to_string(), long: err.to_string() }),
ReadyOutput::Notification(value) => AppInput::Notification(value, 60),
ReadyOutput::Ready => AppInput::SwitchToReady,
}
}

View file

@ -1,21 +1,14 @@
// managed the various pages...
use std::hash::DefaultHasher;
use std::string;
use std::time::Duration;
use adw::prelude::*;
use libpaket::{
self,
advices::{AdvicesList, UatToken},
tracking::{Shipment, TrackingParams},
LibraryError, LibraryResult,
};
use relm4::{
adw,
factory::{FactoryHashMap, FactorySender, FactoryVecDeque},
prelude::*,
};
use relm4::{adw, factory::FactoryVecDeque, prelude::*};
use crate::advices::AppAdviceMetadata;
@ -32,13 +25,9 @@ pub struct Ready {
login: crate::LoginSharedState,
activate: bool,
have_service_advices: bool,
#[do_not_track]
advices_factory: FactoryVecDeque<crate::advices::AppAdvice>,
advices_state: ReadyAdvicesState,
#[do_not_track]
tracking_factory: FactoryHashMap<String, crate::tracking::ShipmentView>,
}
#[derive(Debug)]
@ -46,7 +35,6 @@ pub enum ReadyOutput {
Ready,
Error(LibraryError),
FatalError(LibraryError),
Notification(String),
NoServicesEnabled,
}
@ -57,7 +45,6 @@ pub enum ReadyCmds {
GotCustomerDataFull(LibraryResult<libpaket::stammdaten::CustomerDataFull>),
RetryAdvices,
GotAdvices((LibraryResult<Vec<AppAdviceMetadata>>, Option<UatToken>)),
GotTracking(LibraryResult<Vec<Shipment>>),
}
#[derive(Debug)]
@ -65,8 +52,6 @@ pub enum ReadyInput {
Activate,
Deactivate,
HaveAdvicesService,
HavePaketankuendigungService,
SearchTracking(String),
}
#[relm4::component(pub)]
@ -92,23 +77,18 @@ impl Component for Ready {
set_title: "No mail notifications available."
},
#[name = "advices_page_have_some"]
add = &adw::Clamp {
#[wrap(Some)]
set_child = &gtk::Box {
set_orientation: gtk::Orientation::Horizontal,
add = &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())]
@ -123,44 +103,9 @@ 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,*/
},
add = &adw::Bin {
#[wrap(Some)]
set_child = &gtk::ScrolledWindow {
#[wrap(Some)]
set_child = &gtk::Box {
set_orientation: gtk::Orientation::Vertical,
gtk::Box {
set_orientation: gtk::Orientation::Horizontal,
set_margin_all: 8,
add_css_class: relm4::css::TOOLBAR,
#[name = "tracking_entry"]
gtk::Entry {
set_input_hints: gtk::InputHints::PRIVATE,
set_hexpand: true,
},
#[name = "tracking_entry_button"]
gtk::Button {}
},
#[local_ref]
tracking_box -> gtk::Box {
set_spacing: 8
},
}
}
} -> /*page_tracking: adw::ViewStackPage*/ {
set_title: Some("Shipment tracking"),
set_name: Some("page_tracking"),
},
}
}
}
@ -169,9 +114,9 @@ impl Component for Ready {
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let advices_factory = FactoryVecDeque::builder().launch_default().detach();
let tracking_factory = FactoryHashMap::builder().launch_default().detach();
let advices_factory = FactoryVecDeque::builder()
.launch(adw::Carousel::new())
.detach();
let model = Ready {
have_service_advices: false,
@ -179,12 +124,10 @@ impl Component for Ready {
advices_state: ReadyAdvicesState::Loading,
login: init.clone(),
activate: false,
tracking_factory,
tracker: 0,
};
let advices_carousel = model.advices_factory.widget();
let tracking_box = model.tracking_factory.widget();
let widgets = view_output!();
{
@ -205,21 +148,6 @@ impl Component for Ready {
.drop_on_shutdown()
});
}
{
let sender = sender.clone();
widgets.tracking_entry.connect_activate(move |entry| {
sender.input(ReadyInput::SearchTracking(entry.text().into()));
entry.set_text("");
});
}
{
let sender = sender.clone();
let entry = widgets.tracking_entry.clone();
widgets.tracking_entry_button.connect_clicked(move |_| {
sender.input(ReadyInput::SearchTracking(entry.text().into()));
entry.set_text("");
});
}
ComponentParts { model, widgets }
}
@ -227,11 +155,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();
@ -239,48 +167,10 @@ impl Component for Ready {
});
}
}
ReadyInput::SearchTracking(value) => {
sender.oneshot_command(async move {
let client = libpaket::WebClient::new();
let mut vec = Vec::new();
vec.push(value);
ReadyCmds::GotTracking(
client
.tracking_search(
TrackingParams {
language: Some("de".to_string()),
},
vec,
None,
)
.await,
)
});
}
ReadyInput::Deactivate => {
self.set_activate(false);
}
ReadyInput::HavePaketankuendigungService => {
let token = self.login.clone();
sender.oneshot_command(async move {
// fetching advices
let dhli_token = crate::login::get_id_token(&token).await.unwrap();
let client = libpaket::WebClient::new();
ReadyCmds::GotTracking(
client
.tracking_search(
TrackingParams {
language: Some("de".to_string()),
},
Vec::new(),
Some(&dhli_token),
)
.await,
)
});
}
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();
@ -327,81 +217,27 @@ 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 => (),
libpaket::stammdaten::CustomerDataService::Paketankuendigung => {
sender.input(ReadyInput::HavePaketankuendigungService);
}
libpaket::stammdaten::CustomerDataService::Paketankuendigung => (),
libpaket::stammdaten::CustomerDataService::PostfilialeDirekt => (),
libpaket::stammdaten::CustomerDataService::Digiben => (),
libpaket::stammdaten::CustomerDataService::GeraetAktiviert => (),
libpaket::stammdaten::CustomerDataService::Briefankuendigung => {
a_service_was_activated = true;
sender.input(ReadyInput::HaveAdvicesService);
}
}
}
sender.output(ReadyOutput::Ready).unwrap()
}
Err(err) => sender.output(ReadyOutput::FatalError(err)).unwrap(),
},
ReadyCmds::GotTracking(res) => match res {
Ok(shipment_vec) => {
for item in shipment_vec {
if let Some(err) = item.error {
// TODO: gettext
if err.id_invalid {
sender
.output(ReadyOutput::Notification(format!(
"The id is invalid ({})",
item.id
)))
.unwrap();
} else if err.letter_not_found {
sender
.output(ReadyOutput::Notification(format!(
"The letter wasn't found ({})",
item.id
)))
.unwrap();
} else if err.id_not_searchable {
sender
.output(ReadyOutput::Notification(format!(
"The id is not searchable ({})",
item.id
)))
.unwrap();
} else if err.data_to_old {
sender
.output(ReadyOutput::Notification(format!(
"No data available with id ({}) (data expired)",
item.id
)))
.unwrap();
} else if err.not_from_dhl {
sender
.output(ReadyOutput::Notification(format!(
"The id is not from DHL ({})",
item.id
)))
.unwrap();
} else if err.no_data_available {
sender
.output(ReadyOutput::Notification(format!(
"No data available with id ({})",
item.id
)))
.unwrap();
}
} else {
self.tracking_factory.insert(item.id.clone(), item);
}
if a_service_was_activated {
sender.output(ReadyOutput::Ready).unwrap()
} else {
sender.output(ReadyOutput::NoServicesEnabled).unwrap();
}
}
Err(err) => {
sender.output(ReadyOutput::Error(err)).unwrap();
}
Err(err) => sender.output(ReadyOutput::FatalError(err)).unwrap(),
},
ReadyCmds::GotAdvices(res) => match res.0 {
Ok(advices_vec) => {