Full split of lang.rs
This commit is contained in:
1 parent
22b455a640
commit
c67663141f
17 files changed
+80
-77
No files matched your search
+2
-1
@@ -12,7 +12,8 @@ use crate::data_provider::card_sets::load_sets;
|
||||
use crate::data_provider::settings::get_setting;
|
||||
use crate::data_provider::sqlite::default_connection;
|
||||
use crate::data_provider::words::{load_word_groups, load_words};
|
||||
use crate::lang::{Id, WordData, WordGroup};
|
||||
use crate::data::entities::{ WordData, WordGroup};
|
||||
use crate::data::Id;
|
||||
use crate::navigation::{AppSettings, RootMessage, ScreenState};
|
||||
use crate::navigation::RootMessage::Keyboard;
|
||||
pub const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
||||
|
||||
+3
-4
@@ -10,8 +10,9 @@ use rhai::{Engine, Scope};
|
||||
use crate::app::AppState;
|
||||
use crate::core::srs::{OrderMode, OrderModule, RandomSRSModule, SRSModule, SemiRandomSRSModule, WordOpenMode, WorstWordsSRSModule, FADE_PER_DAY, MAX_SCORE};
|
||||
use crate::data_provider::card_stats::{load_stats_of_deck, update_stat_score};
|
||||
use crate::data_provider::history::{push_note, HistoryItem};
|
||||
use crate::lang::{ Id, WordData};
|
||||
use crate::data_provider::history::{push_note};
|
||||
use crate::data::entities::*;
|
||||
use crate::data::Id;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DeckSettings {
|
||||
@@ -21,7 +22,6 @@ pub struct DeckSettings {
|
||||
pub backward: String,
|
||||
pub filter: String,
|
||||
pub count: Option<usize>,
|
||||
pub worst_words_list: Option<Vec<WordData>>,
|
||||
pub open_mode: OrderMode,
|
||||
}
|
||||
impl DeckSettings {
|
||||
@@ -33,7 +33,6 @@ impl DeckSettings {
|
||||
backward: "".to_string(),
|
||||
filter: "true".to_string(),
|
||||
count: None,
|
||||
worst_words_list: None,
|
||||
open_mode: OrderMode::Default,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ use rand::distr::weighted::WeightedIndex;
|
||||
use rand::prelude::ThreadRng;
|
||||
use rand::prelude::{Distribution, SliceRandom};
|
||||
use rand::rng;
|
||||
use rayon::iter::IndexedParallelIterator;
|
||||
use rayon::iter::ParallelIterator;
|
||||
|
||||
const MAX_HISTORY_LEN: usize = 20;
|
||||
const MAX_HISTORY_LEN_PART: f32 = 0.33;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef};
|
||||
use rusqlite::ToSql;
|
||||
use std::cmp::PartialEq;
|
||||
use std::collections::HashMap;
|
||||
pub mod entities;
|
||||
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::num::ParseIntError;
|
||||
use std::str::FromStr;
|
||||
use rusqlite::ToSql;
|
||||
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef};
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Hash, Copy, Ord, PartialOrd)]
|
||||
pub struct Id(pub(crate) u32);
|
||||
@@ -60,32 +60,3 @@ impl Id {
|
||||
self.0 != 0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct WordData {
|
||||
pub id: Id,
|
||||
pub key: String,
|
||||
pub value: String,
|
||||
pub tags: String,
|
||||
pub additional: HashMap<String, String>,
|
||||
pub group_id: Id,
|
||||
}
|
||||
#[derive(Clone)]
|
||||
pub struct WordGroup {
|
||||
pub id: Id,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
|
||||
impl WordData {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
id: INVALID_ID,
|
||||
key: String::new(),
|
||||
value: String::new(),
|
||||
tags: String::new(),
|
||||
additional: Default::default(),
|
||||
group_id: 1.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
use std::collections::HashMap;
|
||||
use chrono::{DateTime, Utc};
|
||||
use crate::core::srs::WordOpenMode;
|
||||
use crate::data::{Id, INVALID_ID};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct WordData {
|
||||
pub id: Id,
|
||||
pub key: String,
|
||||
pub value: String,
|
||||
pub tags: String,
|
||||
pub additional: HashMap<String, String>,
|
||||
pub group_id: Id,
|
||||
}
|
||||
#[derive(Clone)]
|
||||
pub struct WordGroup {
|
||||
pub id: Id,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
|
||||
impl WordData {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
id: INVALID_ID,
|
||||
key: String::new(),
|
||||
value: String::new(),
|
||||
tags: String::new(),
|
||||
additional: Default::default(),
|
||||
group_id: 1.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct HistoryItem {
|
||||
pub timestamp: DateTime<Utc>,
|
||||
pub word_id: Id,
|
||||
pub mode: WordOpenMode,
|
||||
pub before: u8,
|
||||
pub after: u8,
|
||||
}
|
||||
@@ -16,7 +16,6 @@ pub fn load_sets(connection: &Connection) -> Vec<DeckSettings> {
|
||||
backward: row.get(3)?,
|
||||
filter: row.get(4)?,
|
||||
count: None,
|
||||
worst_words_list: None,
|
||||
open_mode: OrderMode::Default,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
use crate::core::srs::WordOpenMode;
|
||||
use crate::data::entities::HistoryItem;
|
||||
use crate::data::Id;
|
||||
use crate::fs::*;
|
||||
use crate::lang::{Id};
|
||||
use chrono::{DateTime, Utc};
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::NotificationData::PermissionDenied;
|
||||
use chrono::DateTime;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::Write;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::path::PathBuf;
|
||||
use crate::core::srs::WordOpenMode;
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::NotificationData::PermissionDenied;
|
||||
|
||||
pub fn get_history_of_set(id: Id) -> Result<Vec<HistoryItem>, NotificationData> {
|
||||
let app_dir = history_dir()?;
|
||||
@@ -84,11 +85,4 @@ pub fn push_note(set_id: Id, item: HistoryItem) -> Result<(), NotificationData>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct HistoryItem {
|
||||
pub timestamp: DateTime<Utc>,
|
||||
pub word_id: Id,
|
||||
pub mode: WordOpenMode,
|
||||
pub before: u8,
|
||||
pub after: u8,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::lang::{WordData, WordGroup};
|
||||
use rusqlite::{Connection, params};
|
||||
use std::collections::HashMap;
|
||||
use crate::data::entities::{WordData, WordGroup};
|
||||
|
||||
pub fn add_word(word: &mut WordData, connection: &Connection) {
|
||||
let index : u32 = connection
|
||||
|
||||
+2
-1
@@ -2,12 +2,13 @@
|
||||
mod data_provider;
|
||||
pub mod notification;
|
||||
pub mod app;
|
||||
mod lang;
|
||||
mod styling;
|
||||
mod pages;
|
||||
mod navigation;
|
||||
mod fs;
|
||||
mod core;
|
||||
mod data;
|
||||
|
||||
use crate::app::start;
|
||||
use mimalloc::MiMalloc;
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,6 @@ use crate::data_provider::web_api::{
|
||||
get_local_version, get_web_version, load_data, set_local_version,
|
||||
};
|
||||
use crate::fs::*;
|
||||
use crate::lang::Id;
|
||||
use crate::message_navigation;
|
||||
use crate::navigation::Page::*;
|
||||
use crate::navigation::RootMessage::{
|
||||
@@ -41,6 +40,7 @@ use parking_lot::Mutex;
|
||||
use rusqlite::Connection;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use crate::data::Id;
|
||||
|
||||
impl Default for ScreenState {
|
||||
fn default() -> Self {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::data::Id;
|
||||
use crate::data_provider::words::{delete_group, delete_word, update_group, update_word};
|
||||
use crate::pages::dictionary::DictionaryMessage::*;
|
||||
use crate::pages::dictionary_quiz::DictionaryQuizState;
|
||||
use crate::pages::import::ImportState;
|
||||
use crate::lang::{WordData, WordGroup};
|
||||
use crate::navigation::Page::{Import, Word};
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::styling::*;
|
||||
@@ -19,13 +19,12 @@ use iced::{Border, Color, Shadow, Task};
|
||||
use iced_core::Length::Fill;
|
||||
use parking_lot::Mutex;
|
||||
use rand::random_range;
|
||||
use std::fs;
|
||||
use std::ops::Add;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
use log::info;
|
||||
use crate::app::AppState;
|
||||
use crate::data::entities::{WordData, WordGroup};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DictionaryState {
|
||||
@@ -529,7 +528,7 @@ impl DictionaryState {
|
||||
});
|
||||
}
|
||||
|
||||
fn update_words_include(&mut self, group_id: crate::lang::Id) {
|
||||
fn update_words_include(&mut self, group_id: Id) {
|
||||
let include_tags = self
|
||||
.tag_map
|
||||
.iter()
|
||||
@@ -619,14 +618,12 @@ pub fn split_with_coma(ts: &str) -> Vec<String> {
|
||||
.collect::<Vec<String>>()
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Hash, PartialEq, Eq)]
|
||||
struct WordLineState {
|
||||
is_included: bool,
|
||||
key: String,
|
||||
value: String,
|
||||
tags: String,
|
||||
id: crate::lang::Id,
|
||||
id: Id,
|
||||
index: usize,
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::navigation::RootMessage;
|
||||
use crate::pages::dictionary::split_with_coma;
|
||||
use crate::pages::dictionary_quiz::DictionaryQuizMessage::*;
|
||||
use crate::lang::WordData;
|
||||
use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::*;
|
||||
use crate::pages::quiz::Score;
|
||||
@@ -12,6 +11,7 @@ use iced::widget::container::Style;
|
||||
use iced::widget::{Row, button, container, row, space, text, text_input};
|
||||
use iced::{Border, Element, Fill, Task, Theme, alignment};
|
||||
use rand::prelude::SliceRandom;
|
||||
use crate::data::entities::WordData;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DictionaryQuizState {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::data_provider::history::{get_history_of_set, HistoryItem};
|
||||
use crate::lang::{WordData, INVALID_ID};
|
||||
use crate::data_provider::history::{get_history_of_set};
|
||||
use crate::navigation::*;
|
||||
use crate::styling::*;
|
||||
use chrono::Local;
|
||||
@@ -11,6 +10,8 @@ use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
use HistoryMessage::Back;
|
||||
use crate::app::AppState;
|
||||
use crate::data::entities::{HistoryItem, WordData};
|
||||
use crate::data::INVALID_ID;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct HistoryState {
|
||||
@@ -47,7 +48,7 @@ impl NavigatedPage<HistoryMessage> for HistoryState {
|
||||
}
|
||||
|
||||
impl HistoryState {
|
||||
pub fn new(id: crate::lang::Id, state: Arc<Mutex<AppState>>) -> Self {
|
||||
pub fn new(id: crate::data::Id, state: Arc<Mutex<AppState>>) -> Self {
|
||||
let state = state.lock();
|
||||
let history = get_history_of_set(id).unwrap_or_default();
|
||||
let words = history
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
use crate::data_provider::import::{ImportData, ImportGroup, get_words_of_group, load_groups};
|
||||
use crate::data_provider::words::{add_group, add_words};
|
||||
use crate::pages::import::ImportMessage::*;
|
||||
use crate::lang::{WordData, WordGroup};
|
||||
use crate::data::entities::{WordData, WordGroup};
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::notification::NotificationData::OpenFileError;
|
||||
use crate::notification::{NotificationData, NotificationRequest};
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use crate::app::AppState;
|
||||
use crate::core::deck::{CardStatistics, DeckData, DeckSettings};
|
||||
use crate::core::srs::WordOpenMode;
|
||||
use crate::data::entities::WordData;
|
||||
use crate::data::Id;
|
||||
use crate::data_provider::voice::get_voice;
|
||||
use crate::lang::Id;
|
||||
use crate::lang::{ WordData};
|
||||
use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{KeyPressedPage, NavigatedPage, Page, RootMessage};
|
||||
use crate::notification::{NotificationData, NotificationRequest};
|
||||
@@ -10,15 +12,13 @@ use chrono::Local;
|
||||
use iced::alignment::Horizontal::Center;
|
||||
use iced::keyboard::key::Physical::Code;
|
||||
use iced::widget::text::Style;
|
||||
use iced::widget::{Column, button, column, container, row, rule, space, text, tooltip};
|
||||
use iced::{Element, Fill, Task, Theme, alignment, keyboard};
|
||||
use iced::widget::{button, column, container, row, rule, space, text, tooltip, Column};
|
||||
use iced::{alignment, keyboard, Element, Fill, Task, Theme};
|
||||
use parking_lot::Mutex;
|
||||
use rodio::MixerDeviceSink;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
use tokio::task::spawn_blocking;
|
||||
use crate::core::deck::{CardStatistics, DeckData, DeckSettings};
|
||||
use crate::core::srs::{ WordOpenMode};
|
||||
|
||||
pub struct RepetitionState {
|
||||
state: Arc<Mutex<AppState>>,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::data_provider::card_sets::update_deck;
|
||||
use crate::data_provider::card_stats::{add_stat_list, load_stats_of_deck};
|
||||
use crate::pages::history::HistoryState;
|
||||
use crate::lang::{Id};
|
||||
use crate::navigation::Page::{History, PreviousPage, Repetition, RepetitionSettings};
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::pages::repetition::RepetitionState;
|
||||
@@ -27,6 +26,7 @@ use std::sync::Arc;
|
||||
use crate::app::AppState;
|
||||
use crate::core::deck::{CardStatistics, DeckSettings};
|
||||
use crate::core::srs::{AppendMode, OrderMode};
|
||||
use crate::data::Id;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RepetitionsState {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
use crate::data_provider::words::{delete_word, update_word};
|
||||
use crate::lang::WordData;
|
||||
use crate::data::entities::WordData;
|
||||
use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::styling::*;
|
||||
|
||||
Reference in new issue
Block a user