Change notification layout
This commit is contained in:
1 parent
5a926b1419
commit
f113d2b3d7
3 files changed
+49
-34
No files matched your search
@@ -21,7 +21,6 @@ pub mod app;
|
|||||||
|
|
||||||
use crate::app::start;
|
use crate::app::start;
|
||||||
use crate::navigation::RootMessage;
|
use crate::navigation::RootMessage;
|
||||||
use crate::quiz::*;
|
|
||||||
use mimalloc::MiMalloc;
|
use mimalloc::MiMalloc;
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
@@ -31,4 +30,3 @@ static GLOBAL: MiMalloc = MiMalloc;
|
|||||||
fn main() -> iced::Result {
|
fn main() -> iced::Result {
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
|
|
||||||
+24
-13
@@ -2,13 +2,14 @@ use crate::navigation::RootMessage;
|
|||||||
use crate::styling::{BUTTON_RADIUS, HALF_SPACING};
|
use crate::styling::{BUTTON_RADIUS, HALF_SPACING};
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use iced::widget::container::Style;
|
use iced::widget::container::Style;
|
||||||
use iced::widget::{column, container, scrollable, text, Column};
|
use iced::widget::{Column, column, container, row, scrollable, text};
|
||||||
use iced::{Element, Task};
|
use iced::{Element, Task};
|
||||||
use iced_core::alignment::Horizontal::Right;
|
use iced_core::Alignment::Center;
|
||||||
use iced_core::alignment::Vertical;
|
|
||||||
use iced_core::Background::Color;
|
use iced_core::Background::Color;
|
||||||
use iced_core::Border;
|
use iced_core::Border;
|
||||||
use iced_core::Length::Fill;
|
use iced_core::Length::Fill;
|
||||||
|
use iced_core::alignment::Horizontal::Right;
|
||||||
|
use iced_core::alignment::Vertical;
|
||||||
|
|
||||||
pub struct NotificationManager {
|
pub struct NotificationManager {
|
||||||
list: Vec<(u32, NotificationRequest, u32)>,
|
list: Vec<(u32, NotificationRequest, u32)>,
|
||||||
@@ -43,9 +44,12 @@ impl NotificationManager {
|
|||||||
column = column.push(Self::draw_notif(id, notif, time));
|
column = column.push(Self::draw_notif(id, notif, time));
|
||||||
}
|
}
|
||||||
|
|
||||||
container(scrollable(column)).width(Fill).height(Fill)
|
container(scrollable(column))
|
||||||
|
.width(Fill)
|
||||||
|
.height(Fill)
|
||||||
.align_x(Right)
|
.align_x(Right)
|
||||||
.align_y(Vertical::Top).padding(HALF_SPACING)
|
.align_y(Vertical::Top)
|
||||||
|
.padding(HALF_SPACING)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,12 +103,15 @@ impl NotificationManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let container = container(column![
|
let container = container(
|
||||||
iced::widget::button("✕")
|
row![
|
||||||
.on_press(NotificationMessage::Remove(*id))
|
content,
|
||||||
.style(iced::widget::button::text),
|
iced::widget::button("✕")
|
||||||
content
|
.on_press(NotificationMessage::Remove(*id))
|
||||||
].align_x(Right).padding(HALF_SPACING));
|
.style(iced::widget::button::text)
|
||||||
|
].align_y(Center).width(300)
|
||||||
|
.padding(HALF_SPACING),
|
||||||
|
);
|
||||||
container
|
container
|
||||||
.style(move |theme| {
|
.style(move |theme| {
|
||||||
let color = match color_id {
|
let color = match color_id {
|
||||||
@@ -116,7 +123,10 @@ impl NotificationManager {
|
|||||||
Style {
|
Style {
|
||||||
text_color: None,
|
text_color: None,
|
||||||
background: Some(Color(color.scale_alpha(0.3))),
|
background: Some(Color(color.scale_alpha(0.3))),
|
||||||
border: Border::default().width(1).color(color).rounded(BUTTON_RADIUS),
|
border: Border::default()
|
||||||
|
.width(1)
|
||||||
|
.color(color)
|
||||||
|
.rounded(BUTTON_RADIUS),
|
||||||
shadow: Default::default(),
|
shadow: Default::default(),
|
||||||
snap: false,
|
snap: false,
|
||||||
}
|
}
|
||||||
@@ -145,6 +155,7 @@ impl NotificationManager {
|
|||||||
text!("У приложение недостаточно прав")
|
text!("У приложение недостаточно прав")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.width(Fill)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,5 +174,5 @@ pub enum NotificationData {
|
|||||||
ImportError,
|
ImportError,
|
||||||
IncorrectAnkiFile,
|
IncorrectAnkiFile,
|
||||||
OpenFileError,
|
OpenFileError,
|
||||||
VoiceVoxUnavailable
|
VoiceVoxUnavailable,
|
||||||
}
|
}
|
||||||
+25
-19
@@ -1,21 +1,22 @@
|
|||||||
|
use crate::app::AppState;
|
||||||
use crate::data_provider::voice::get_voice;
|
use crate::data_provider::voice::get_voice;
|
||||||
use crate::lang::Id;
|
use crate::lang::Id;
|
||||||
use crate::lang::{CardStatistics, DeckData, DeckSettings, WordData, WordOpenMode};
|
use crate::lang::{CardStatistics, DeckData, DeckSettings, WordData, WordOpenMode};
|
||||||
use crate::navigation::Page::PreviousPage;
|
use crate::navigation::Page::PreviousPage;
|
||||||
use crate::navigation::{KeyPressedPage, NavigatedPage, Page, RootMessage};
|
use crate::navigation::{KeyPressedPage, NavigatedPage, Page, RootMessage};
|
||||||
|
use crate::notification::{NotificationData, NotificationRequest};
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
use iced::alignment::Horizontal::Center;
|
use iced::alignment::Horizontal::Center;
|
||||||
use iced::keyboard::key::Physical::Code;
|
use iced::keyboard::key::Physical::Code;
|
||||||
use iced::widget::text::Style;
|
use iced::widget::text::Style;
|
||||||
use iced::widget::{button, column, container, row, rule, space, text, tooltip, Column};
|
use iced::widget::{Column, button, column, container, row, rule, space, text, tooltip};
|
||||||
use iced::{alignment, keyboard, Element, Fill, Task, Theme};
|
use iced::{Element, Fill, Task, Theme, alignment, keyboard};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use rodio::MixerDeviceSink;
|
use rodio::MixerDeviceSink;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::task::spawn_blocking;
|
use tokio::task::spawn_blocking;
|
||||||
use crate::app::AppState;
|
|
||||||
|
|
||||||
pub struct RepetitionState {
|
pub struct RepetitionState {
|
||||||
state: Arc<Mutex<AppState>>,
|
state: Arc<Mutex<AppState>>,
|
||||||
@@ -52,8 +53,9 @@ impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
|||||||
self.can_play = false;
|
self.can_play = false;
|
||||||
let value = self.current_word.key.clone();
|
let value = self.current_word.key.clone();
|
||||||
if self.settings.require_speech() {
|
if self.settings.require_speech() {
|
||||||
return Task::perform(play_sound(self.sink.clone(), value), |_| {
|
return Task::perform(play_sound(self.sink.clone(), value), |r| match r {
|
||||||
RootMessage::Repetition(RepetitionMessage::PlayFinished)
|
Ok(_) => RootMessage::Repetition(RepetitionMessage::PlayFinished),
|
||||||
|
Err(err) => RootMessage::PushNotification(NotificationRequest::Error(err)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,8 +148,9 @@ impl RepetitionState {
|
|||||||
if self.settings.require_speech() && self.sink.is_some() {
|
if self.settings.require_speech() && self.sink.is_some() {
|
||||||
let sink = self.sink.clone();
|
let sink = self.sink.clone();
|
||||||
let task = play_sound(sink, self.current_word.key.clone());
|
let task = play_sound(sink, self.current_word.key.clone());
|
||||||
return Task::perform(task, |_| {
|
return Task::perform(task, |r| match r {
|
||||||
RootMessage::Repetition(RepetitionMessage::PlayFinished)
|
Ok(_) => RootMessage::Repetition(RepetitionMessage::PlayFinished),
|
||||||
|
Err(err) => RootMessage::PushNotification(NotificationRequest::Error(err)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
self.increment_counter();
|
self.increment_counter();
|
||||||
@@ -322,16 +325,19 @@ pub enum RepetitionMessage {
|
|||||||
PlayFinished,
|
PlayFinished,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn play_sound(sink: Arc<Option<MixerDeviceSink>>, text: String) {
|
async fn play_sound(
|
||||||
if let Ok(data) = get_voice(text.as_str()).await {
|
sink: Arc<Option<MixerDeviceSink>>,
|
||||||
spawn_blocking(move || {
|
text: String,
|
||||||
if let Some(sink) = sink.as_ref()
|
) -> Result<(), NotificationData> {
|
||||||
&& let Ok(play) = rodio::play(sink.mixer(), data)
|
let data = get_voice(text.as_str()).await?;
|
||||||
{
|
spawn_blocking(move || {
|
||||||
play.sleep_until_end()
|
if let Some(sink) = sink.as_ref()
|
||||||
}
|
&& let Ok(play) = rodio::play(sink.mixer(), data)
|
||||||
})
|
{
|
||||||
.await
|
play.sleep_until_end()
|
||||||
.unwrap();
|
}
|
||||||
}
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user