Cleapup
This commit is contained in:
@@ -39,28 +39,6 @@ pub fn add_stat(stat: &mut CardStatistics, connection: &Connection) {
|
|||||||
stat.id = index;
|
stat.id = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_stat(stat: &mut CardStatistics, connection: &Connection){
|
|
||||||
if stat.id == 0 {
|
|
||||||
add_stat(stat, &connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
connection
|
|
||||||
.execute(
|
|
||||||
"UPDATE card_stats SET word_id = ?1, set_id = ?2, score = ?3, last_opened = ?4 WHERE id = ?5",
|
|
||||||
(
|
|
||||||
&stat.word_id,
|
|
||||||
&stat.set_id,
|
|
||||||
&stat.score,
|
|
||||||
&stat.last_open,
|
|
||||||
&stat.id
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.unwrap_or_else(|e| {println!("{}", e); 0});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pub fn update_stat_score(stat: &CardStatistics, connection: &Connection){
|
pub fn update_stat_score(stat: &CardStatistics, connection: &Connection){
|
||||||
connection
|
connection
|
||||||
.execute(
|
.execute(
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
use crate::dictionary::app_data_dir;
|
use crate::dictionary::app_data_dir;
|
||||||
use rodio::Decoder;
|
use reqwest::Client;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use reqwest::Client;
|
|
||||||
|
|
||||||
pub async fn get_voice(text: &str) -> BufReader<File> {
|
pub async fn get_voice(text: &str) -> BufReader<File> {
|
||||||
let mut path = app_data_dir();
|
let mut path = app_data_dir();
|
||||||
|
|||||||
@@ -124,13 +124,13 @@ pub fn load_words(connection: &Connection) -> Vec<WordData> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let word_iter = stmt
|
let word_iter = stmt
|
||||||
.query_map([], |row| {
|
.query_map([], |row| {
|
||||||
let addinionals: String = row.get(4)?;
|
let additional: String = row.get(4)?;
|
||||||
Ok(WordData {
|
Ok(WordData {
|
||||||
id: row.get(0)?,
|
id: row.get(0)?,
|
||||||
key: row.get(1)?,
|
key: row.get(1)?,
|
||||||
value: row.get(2)?,
|
value: row.get(2)?,
|
||||||
tags: row.get(3)?,
|
tags: row.get(3)?,
|
||||||
additional: serde_json::from_str::<HashMap<String, String>>(&addinionals).unwrap(),
|
additional: serde_json::from_str::<HashMap<String, String>>(&additional).unwrap(),
|
||||||
group_id: row.get(5)?,
|
group_id: row.get(5)?,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-1
@@ -397,7 +397,7 @@ impl CardSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn history_len(&self) -> usize {
|
fn history_len(&self) -> usize {
|
||||||
return min(MAX_HISTORY_LEN, (self.set.len() as f32 * MAX_HISTORY_LEN_PART) as usize);
|
min(MAX_HISTORY_LEN, (self.set.len() as f32 * MAX_HISTORY_LEN_PART) as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
|
|||||||
+3
-3
@@ -151,10 +151,10 @@ impl ScreenState {
|
|||||||
|
|
||||||
fn handle_keyboard(&mut self, message: Event) -> Task<RootMessage> {
|
fn handle_keyboard(&mut self, message: Event) -> Task<RootMessage> {
|
||||||
let page = self.stack.last_mut().unwrap();
|
let page = self.stack.last_mut().unwrap();
|
||||||
return match page {
|
match page {
|
||||||
Repetition(page) => page.press(&message),
|
Repetition(page) => page.press(&message),
|
||||||
_ => Task::none(),
|
_ => Task::none(),
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ trait NavigatedPage<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait KeyPressedPage {
|
pub trait KeyPressedPage {
|
||||||
fn press(&mut self, message: &keyboard::Event) -> Task<RootMessage>;
|
fn press(&mut self, message: &Event) -> Task<RootMessage>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*pub fn danger_button(x: &Theme, status: Status) -> Style{
|
/*pub fn danger_button(x: &Theme, status: Status) -> Style{
|
||||||
|
|||||||
+5
-5
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
pub mod randomizer {
|
pub mod randomizer {
|
||||||
use crate::randomizer::randomizer::RandomizerMessage::{Back, Start};
|
use crate::randomizer::randomizer::RandomizerMessage::{Back, Start, Edit};
|
||||||
use crate::{NavigatedPage, Page, RootMessage};
|
use crate::{NavigatedPage, Page, RootMessage};
|
||||||
use iced::widget::{button, container, text_editor};
|
use iced::widget::{button, container, text_editor};
|
||||||
use iced::Task;
|
use iced::Task;
|
||||||
@@ -21,7 +21,7 @@ pub mod randomizer {
|
|||||||
|
|
||||||
impl NavigatedPage<RandomizerMessage> for RandomizerState {
|
impl NavigatedPage<RandomizerMessage> for RandomizerState {
|
||||||
fn navigate(&self, message: &RandomizerMessage) -> Option<Page> {
|
fn navigate(&self, message: &RandomizerMessage) -> Option<Page> {
|
||||||
if let RandomizerMessage::Back = message {
|
if let Back = message {
|
||||||
return Some(Page::PreviousPage);
|
return Some(Page::PreviousPage);
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
@@ -41,11 +41,11 @@ pub mod randomizer {
|
|||||||
|
|
||||||
pub fn update(&mut self, message: RandomizerMessage) -> Task<RootMessage> {
|
pub fn update(&mut self, message: RandomizerMessage) -> Task<RootMessage> {
|
||||||
match message {
|
match message {
|
||||||
RandomizerMessage::Edit(action) => {
|
Edit(action) => {
|
||||||
self.text.perform(action);
|
self.text.perform(action);
|
||||||
self.list = self.text.text().split("\n").map(|s| s.to_string()).collect();
|
self.list = self.text.text().split("\n").map(|s| s.to_string()).collect();
|
||||||
},
|
},
|
||||||
RandomizerMessage::Start => {
|
Start => {
|
||||||
self.list.shuffle(&mut rand::rng());
|
self.list.shuffle(&mut rand::rng());
|
||||||
self.text = text_editor::Content::with_text(self.list.join("\n").as_str());
|
self.text = text_editor::Content::with_text(self.list.join("\n").as_str());
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ pub mod randomizer {
|
|||||||
container(
|
container(
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
button("Назад").on_press(Back),
|
button("Назад").on_press(Back),
|
||||||
text_editor(&self.text).on_action(RandomizerMessage::Edit
|
text_editor(&self.text).on_action(Edit
|
||||||
).width(400).height(400).placeholder("Каждый элемент с новой строки"),
|
).width(400).height(400).placeholder("Каждый элемент с новой строки"),
|
||||||
button("Перемешать").on_press(Start),
|
button("Перемешать").on_press(Start),
|
||||||
]
|
]
|
||||||
|
|||||||
+2
-4
@@ -15,7 +15,6 @@ use tokio::task::spawn_blocking;
|
|||||||
pub struct RepetitionState {
|
pub struct RepetitionState {
|
||||||
pub settings: CardSetSettings,
|
pub settings: CardSetSettings,
|
||||||
pub set: CardSet,
|
pub set: CardSet,
|
||||||
pub state: Arc<Mutex<AppState>>,
|
|
||||||
current_word: WordData,
|
current_word: WordData,
|
||||||
current_statistic: CardStatistics,
|
current_statistic: CardStatistics,
|
||||||
open: bool,
|
open: bool,
|
||||||
@@ -43,7 +42,6 @@ impl RepetitionState {
|
|||||||
RepetitionState {
|
RepetitionState {
|
||||||
settings: set,
|
settings: set,
|
||||||
set: card_set,
|
set: card_set,
|
||||||
state,
|
|
||||||
current_word: word,
|
current_word: word,
|
||||||
current_statistic: stat,
|
current_statistic: stat,
|
||||||
open: false,
|
open: false,
|
||||||
@@ -86,7 +84,7 @@ impl RepetitionState {
|
|||||||
self.answer(WordOpenMode::None)
|
self.answer(WordOpenMode::None)
|
||||||
} else {
|
} else {
|
||||||
self.open = true;
|
self.open = true;
|
||||||
return Task::none();
|
Task::none()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +221,7 @@ impl RepetitionState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl KeyPressedPage for RepetitionState {
|
impl KeyPressedPage for RepetitionState {
|
||||||
fn press(&mut self, message: &keyboard::Event) -> iced::Task<RootMessage> {
|
fn press(&mut self, message: &keyboard::Event) -> Task<RootMessage> {
|
||||||
if let keyboard::Event::KeyPressed {
|
if let keyboard::Event::KeyPressed {
|
||||||
key: _,
|
key: _,
|
||||||
modified_key: _,
|
modified_key: _,
|
||||||
|
|||||||
+1
-1
@@ -287,6 +287,6 @@ impl CardSetSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn require_speech(&self) -> bool {
|
pub fn require_speech(&self) -> bool {
|
||||||
return self.forward == "speech" || self.backward == "speech"
|
self.forward == "speech" || self.backward == "speech"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -110,10 +110,10 @@ impl WordState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_view_for_more(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
fn get_view_for_more(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
||||||
return match value.0.as_str() {
|
match value.0.as_str() {
|
||||||
"reading" => self.reading_field(value),
|
"reading" => self.reading_field(value),
|
||||||
_ => space().into(),
|
_ => space().into(),
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reading_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
fn reading_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
||||||
|
|||||||
Reference in New Issue
Block a user