Change notification layout

This commit is contained in:
micialware committed 2026-08-23 22:05:08 +03:00
1 parent 5a926b1419
commit f113d2b3d7
3 files changed
+38 -23

No files matched your search

-2
View File
@@ -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()
} }
+22 -11
View File
@@ -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(
row![
content,
iced::widget::button("✕") iced::widget::button("✕")
.on_press(NotificationMessage::Remove(*id)) .on_press(NotificationMessage::Remove(*id))
.style(iced::widget::button::text), .style(iced::widget::button::text)
content ].align_y(Center).width(300)
].align_x(Right).padding(HALF_SPACING)); .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,
} }
+16 -10
View File
@@ -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,8 +325,11 @@ 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>>,
text: String,
) -> Result<(), NotificationData> {
let data = get_voice(text.as_str()).await?;
spawn_blocking(move || { spawn_blocking(move || {
if let Some(sink) = sink.as_ref() if let Some(sink) = sink.as_ref()
&& let Ok(play) = rodio::play(sink.mixer(), data) && let Ok(play) = rodio::play(sink.mixer(), data)
@@ -333,5 +339,5 @@ async fn play_sound(sink: Arc<Option<MixerDeviceSink>>, text: String) {
}) })
.await .await
.unwrap(); .unwrap();
} Ok(())
} }