Notification base
This commit is contained in:
1 parent
dfaff30efa
commit
e1bfd9494d
4 files changed
+177
-9
No files matched your search
+23
-9
@@ -1,14 +1,15 @@
|
||||
use crate::data_provider::history::{get_history_of_set, history_dir};
|
||||
use crate::data_provider::sqlite::{create_db, default_connection};
|
||||
use crate::data_provider::web_api::{get_local_version, get_web_version, load_data, set_local_version};
|
||||
use crate::dictionary::{DictionaryMessage, DictionaryState, app_data_dir};
|
||||
use crate::dictionary::{app_data_dir, DictionaryMessage, DictionaryState};
|
||||
use crate::dictionary_quiz::{DictionaryQuizMessage, DictionaryQuizState};
|
||||
use crate::history::{HistoryMessage, HistoryState};
|
||||
use crate::import::{ImportMessage, ImportState};
|
||||
use crate::lang::Id;
|
||||
use crate::message_navigation;
|
||||
use crate::navigation::Page::*;
|
||||
use crate::navigation::RootMessage::{DataLoaded, Keyboard, UpdateData};
|
||||
use crate::navigation::RootMessage::{DataLoaded, Keyboard, PushNotification, UpdateData, Notification};
|
||||
use crate::notification::{NotificationRequest, NotificationManager, NotificationMessage};
|
||||
use crate::quiz::{QuizMessage, QuizState};
|
||||
use crate::randomizer::{RandomizerMessage, RandomizerState};
|
||||
use crate::repetition::{RepetitionMessage, RepetitionState};
|
||||
@@ -21,16 +22,18 @@ use crate::sync::{SyncMessage, SyncState};
|
||||
use crate::view_navigation;
|
||||
use crate::word::{WordMessage, WordState};
|
||||
use crate::writing::{WritingMessage, WritingState};
|
||||
use crate::{AppState, fill_state};
|
||||
use crate::{fill_state, AppState};
|
||||
use chrono::NaiveDate;
|
||||
use hashbrown::HashMap;
|
||||
use iced::keyboard::Event;
|
||||
use iced::widget::stack;
|
||||
use iced::{Element, Task};
|
||||
use parking_lot::Mutex;
|
||||
use reqwest::Error;
|
||||
use rusqlite::Connection;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use iced_core::Length::Fill;
|
||||
|
||||
impl Default for ScreenState {
|
||||
fn default() -> Self {
|
||||
@@ -40,6 +43,7 @@ impl Default for ScreenState {
|
||||
ScreenState {
|
||||
stack: vec![Selector(SelectorState::new(state.clone()))],
|
||||
app_state: state.clone(),
|
||||
notification_manager: NotificationManager::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,6 +65,8 @@ pub enum RootMessage {
|
||||
Import(ImportMessage),
|
||||
Keyboard(Event),
|
||||
DataLoaded(HashMap<Id, Vec<(NaiveDate, u32)>>),
|
||||
PushNotification(NotificationRequest),
|
||||
Notification(NotificationMessage),
|
||||
None,
|
||||
UpdateData,
|
||||
}
|
||||
@@ -85,6 +91,7 @@ pub enum Page {
|
||||
pub struct ScreenState {
|
||||
stack: Vec<Page>,
|
||||
app_state: Arc<Mutex<AppState>>,
|
||||
notification_manager: NotificationManager
|
||||
}
|
||||
|
||||
impl ScreenState {
|
||||
@@ -187,6 +194,15 @@ impl ScreenState {
|
||||
fill_state(&mut state);
|
||||
return Task::none();
|
||||
}
|
||||
|
||||
if let Notification(message) = message {
|
||||
return self.notification_manager.update(message);
|
||||
}
|
||||
|
||||
if let PushNotification(notification) = &message {
|
||||
return self.notification_manager.push(notification.clone())
|
||||
}
|
||||
|
||||
let task: (Task<RootMessage>, bool) = self.navigate_or_update(message);
|
||||
|
||||
if task.1 {
|
||||
@@ -233,6 +249,7 @@ impl ScreenState {
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, RootMessage> {
|
||||
|
||||
println!("View update");
|
||||
let time = Instant::now();
|
||||
let view = view_navigation!(
|
||||
@@ -252,8 +269,10 @@ impl ScreenState {
|
||||
Import
|
||||
);
|
||||
|
||||
let notifications = self.notification_manager.draw().map(RootMessage::Notification);
|
||||
|
||||
println!("View took {:?}", time.elapsed());
|
||||
view
|
||||
stack![view, notifications].width(Fill).height(Fill).into()
|
||||
}
|
||||
|
||||
fn handle_keyboard(&mut self, message: Event) -> Task<RootMessage> {
|
||||
@@ -281,7 +300,6 @@ macro_rules! view_navigation {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! state_update {
|
||||
($message:expr, $stack:expr, $($e:ident), *) => {
|
||||
@@ -300,7 +318,6 @@ macro_rules! state_update {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! message_navigation {
|
||||
($msg:expr, $stack:expr, $state:expr) => {
|
||||
@@ -321,7 +338,6 @@ macro_rules! message_navigation {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! state_navigate_handle {
|
||||
($stack:expr, $($e:ident), *) => {
|
||||
@@ -335,14 +351,12 @@ macro_rules! state_navigate_handle {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait NavigatedPage<T> {
|
||||
fn navigate(&mut self, message: &T) -> Option<Page>;
|
||||
fn navigated(&mut self);
|
||||
fn update(&mut self, message: T) -> Task<RootMessage>;
|
||||
fn view(&self) -> Element<'_, T>;
|
||||
}
|
||||
|
||||
pub trait KeyPressedPage {
|
||||
fn press(&mut self, message: &Event) -> Task<RootMessage>;
|
||||
}
|
||||
Reference in new issue
Block a user