Compare commits
27
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01f0999772 | ||
|
|
39f8845119 | ||
|
|
e7023752f1 | ||
|
|
746071125a | ||
|
|
bb673ed7c7 | ||
|
|
98c8093961 | ||
|
|
a4d77196d0 | ||
|
|
4187344a29 | ||
|
|
d3c28179b6 | ||
|
|
3cd7c12baa | ||
|
|
306febc514 | ||
|
|
80785ff9e6 | ||
|
|
9e28b05167 | ||
|
|
97c76350e1 | ||
|
|
99b3818181 | ||
|
|
3fcbd235cf | ||
|
|
dcf7352553 | ||
|
|
11b38479c1 | ||
|
|
51c8d7be74 | ||
|
|
8f789facd7 | ||
|
|
e676898135 | ||
|
|
9917702c4c | ||
|
|
0332e40feb | ||
|
|
eb6c9c5084 | ||
|
|
17e06256c1 | ||
|
|
4d0788e0f5 | ||
|
|
4ca7aa7044 |
Generated
+298
@@ -24,6 +24,17 @@ version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||
|
||||
[[package]]
|
||||
name = "aes"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8eb277bec05f56a0e0591f155a484cbd0f4f07ff2905051a48c72f004f7ed58"
|
||||
dependencies = [
|
||||
"cipher",
|
||||
"cpubits",
|
||||
"cpufeatures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.12"
|
||||
@@ -62,6 +73,12 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "allocator-api2"
|
||||
version = "0.2.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
|
||||
|
||||
[[package]]
|
||||
name = "alsa"
|
||||
version = "0.11.0"
|
||||
@@ -386,6 +403,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be"
|
||||
dependencies = [
|
||||
"hybrid-array",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -457,6 +475,15 @@ version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
||||
|
||||
[[package]]
|
||||
name = "bzip2"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3a53fac24f34a81bc9954b5d6cfce0c21e18ec6959f44f56e8e90e4bb7c346c"
|
||||
dependencies = [
|
||||
"libbz2-rs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop"
|
||||
version = "0.13.0"
|
||||
@@ -595,6 +622,16 @@ dependencies = [
|
||||
"half",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cipher"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e34d8227fe1ba289043aeb13792056ff80fd6de1a9f49137a5f499de8e8c78ea"
|
||||
dependencies = [
|
||||
"crypto-common",
|
||||
"inout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.6.1"
|
||||
@@ -668,6 +705,12 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cmov"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a"
|
||||
|
||||
[[package]]
|
||||
name = "codespan-reporting"
|
||||
version = "0.12.0"
|
||||
@@ -730,6 +773,12 @@ dependencies = [
|
||||
"tiny-keccak",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b"
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.4"
|
||||
@@ -868,6 +917,12 @@ dependencies = [
|
||||
"windows 0.62.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cpubits"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.3.0"
|
||||
@@ -980,6 +1035,15 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b29fccfdaeb0f9bd90da5759b1d0eaa2f6cfcfe90960124cfc83141ed4e111fd"
|
||||
|
||||
[[package]]
|
||||
name = "ctutils"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d5515a3834141de9eafb9717ad39eea8247b5674e6066c404e8c4b365d2a29e"
|
||||
dependencies = [
|
||||
"cmov",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cursor-icon"
|
||||
version = "1.2.0"
|
||||
@@ -998,6 +1062,18 @@ version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376"
|
||||
|
||||
[[package]]
|
||||
name = "deflate64"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac6b926516df9c60bfa16e107b21086399f8285a44ca9711344b9e553c5146e2"
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.5.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.11.2"
|
||||
@@ -1007,6 +1083,8 @@ dependencies = [
|
||||
"block-buffer",
|
||||
"const-oid",
|
||||
"crypto-common",
|
||||
"ctutils",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1043,6 +1121,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"block2 0.6.2",
|
||||
"libc",
|
||||
"objc2 0.6.3",
|
||||
]
|
||||
|
||||
@@ -1244,6 +1324,7 @@ checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
"zlib-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1675,6 +1756,8 @@ version = "0.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||
dependencies = [
|
||||
"allocator-api2",
|
||||
"equivalent",
|
||||
"foldhash 0.2.0",
|
||||
]
|
||||
|
||||
@@ -1717,6 +1800,15 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
|
||||
|
||||
[[package]]
|
||||
name = "hmac"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f"
|
||||
dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.4.0"
|
||||
@@ -2175,6 +2267,15 @@ dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inout"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7"
|
||||
dependencies = [
|
||||
"hybrid-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.12.0"
|
||||
@@ -2213,11 +2314,15 @@ dependencies = [
|
||||
"chrono",
|
||||
"criterion",
|
||||
"dirs",
|
||||
"hashbrown 0.17.1",
|
||||
"hex",
|
||||
"iced",
|
||||
"iced_core",
|
||||
"mimalloc",
|
||||
"rand",
|
||||
"rayon",
|
||||
"reqwest",
|
||||
"rfd",
|
||||
"rhai",
|
||||
"rodio",
|
||||
"rusqlite",
|
||||
@@ -2225,6 +2330,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"tokio",
|
||||
"zip",
|
||||
"zstd",
|
||||
]
|
||||
|
||||
@@ -2369,6 +2475,12 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
||||
|
||||
[[package]]
|
||||
name = "libbz2-rs-sys"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34b357333733e8260735ba5894eb928c02ecc69c78715f01a8019e7fa7f2db4c"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.189"
|
||||
@@ -2391,6 +2503,15 @@ version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
||||
|
||||
[[package]]
|
||||
name = "libmimalloc-sys"
|
||||
version = "0.1.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a45a52f43e1c16f667ccfe4dd8c85b7f7c204fd5e3bf46c5b0db9a5c3c0b8e9"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libredox"
|
||||
version = "0.1.12"
|
||||
@@ -2479,6 +2600,15 @@ version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
|
||||
|
||||
[[package]]
|
||||
name = "lzma-rust2"
|
||||
version = "0.16.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca93e534d1142d1d0dcca6d25fe302508a5dfb40b302802904577725ea0b695b"
|
||||
dependencies = [
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mach2"
|
||||
version = "0.5.0"
|
||||
@@ -2536,6 +2666,15 @@ dependencies = [
|
||||
"paste",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mimalloc"
|
||||
version = "0.1.52"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d4139bb28d14ad1facf21d5eb8825051b326e172d216b39f6d31df53cc97862"
|
||||
dependencies = [
|
||||
"libmimalloc-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.17"
|
||||
@@ -2654,6 +2793,15 @@ dependencies = [
|
||||
"jni-sys 0.3.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "no-std-compat"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c"
|
||||
dependencies = [
|
||||
"spin",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.4.6"
|
||||
@@ -2664,6 +2812,12 @@ dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441"
|
||||
|
||||
[[package]]
|
||||
name = "num-derive"
|
||||
version = "0.4.2"
|
||||
@@ -3280,6 +3434,16 @@ version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||
|
||||
[[package]]
|
||||
name = "pbkdf2"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "112d82ceb8c5bf524d9af484d4e4970c9fd5a0cc15ba14ad93dccd28873b0629"
|
||||
dependencies = [
|
||||
"digest",
|
||||
"hmac",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.2"
|
||||
@@ -3396,6 +3560,12 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pollster"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.13.1"
|
||||
@@ -3420,6 +3590,18 @@ dependencies = [
|
||||
"zerovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "ppmd-rust"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "efca4c95a19a79d1c98f791f10aebd5c1363b473244630bb7dbde1dc98455a24"
|
||||
|
||||
[[package]]
|
||||
name = "presser"
|
||||
version = "0.3.1"
|
||||
@@ -3779,6 +3961,33 @@ dependencies = [
|
||||
"zune-jpeg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rfd"
|
||||
version = "0.17.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20dafead71c16a34e1ff357ddefc8afc11e7d51d6d2b9fbd07eaa48e3e540220"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"dispatch2",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"log",
|
||||
"objc2 0.6.3",
|
||||
"objc2-app-kit 0.3.2",
|
||||
"objc2-core-foundation",
|
||||
"objc2-foundation 0.3.2",
|
||||
"percent-encoding",
|
||||
"pollster",
|
||||
"raw-window-handle",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"web-sys",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rgb"
|
||||
version = "0.8.53"
|
||||
@@ -3796,6 +4005,7 @@ checksum = "dd4dd0f8c36625202a4ba553c416c19b719947cd2a31d1bda06126e4a5727daf"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bitflags 2.10.0",
|
||||
"no-std-compat",
|
||||
"num-traits",
|
||||
"once_cell",
|
||||
"rhai_codegen",
|
||||
@@ -4162,6 +4372,17 @@ dependencies = [
|
||||
"syn 2.0.114",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha1"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.11.0"
|
||||
@@ -4381,6 +4602,12 @@ dependencies = [
|
||||
"x11rb",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||
|
||||
[[package]]
|
||||
name = "spirv"
|
||||
version = "0.3.0+sdk-1.3.268.0"
|
||||
@@ -4743,6 +4970,26 @@ dependencies = [
|
||||
"syn 2.0.114",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"js-sys",
|
||||
"num-conv",
|
||||
"powerfmt",
|
||||
"serde_core",
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109"
|
||||
|
||||
[[package]]
|
||||
name = "tiny-keccak"
|
||||
version = "2.0.2"
|
||||
@@ -4997,6 +5244,12 @@ dependencies = [
|
||||
"core_maths",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typed-path"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e28f89b80c87b8fb0cf04ab448d5dd0dd0ade2f8891bae878de66a75a28600e"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.20.0"
|
||||
@@ -6437,12 +6690,57 @@ dependencies = [
|
||||
"syn 2.0.114",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "8.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d04a6b5381502aa6087c94c669499eb1602eb9c5e8198e534de571f7154809b"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"bzip2",
|
||||
"constant_time_eq",
|
||||
"crc32fast",
|
||||
"deflate64",
|
||||
"flate2",
|
||||
"getrandom 0.4.1",
|
||||
"hmac",
|
||||
"indexmap",
|
||||
"lzma-rust2",
|
||||
"memchr",
|
||||
"pbkdf2",
|
||||
"ppmd-rust",
|
||||
"sha1",
|
||||
"time",
|
||||
"typed-path",
|
||||
"zeroize",
|
||||
"zopfli",
|
||||
"zstd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zlib-rs"
|
||||
version = "0.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34b31d188d9d685a4f9c7b46d6e36631b07058d2cfe190267adce54dc230bf12"
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4de98dfa5d5b7fef4ee834d0073d560c9ca7b6c46a71d058c48db7960f8cfaf7"
|
||||
|
||||
[[package]]
|
||||
name = "zopfli"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"crc32fast",
|
||||
"log",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd"
|
||||
version = "0.13.3"
|
||||
|
||||
+17
-8
@@ -10,7 +10,7 @@ rand = "0.10.2"
|
||||
dirs = "6.0.0"
|
||||
serde = { version = "1.0.229", features = ["derive"] }
|
||||
serde_json = "1.0.151"
|
||||
rhai = "1.25.1"
|
||||
rhai = { version = "1.25.1", features = ["sync"] }
|
||||
chrono = "0.4.45"
|
||||
rusqlite = { version = "0.40.2", features = ["chrono", "bundled"] }
|
||||
reqwest = { version = "0.13.4", features = ["json", "stream", "multipart"] }
|
||||
@@ -19,16 +19,25 @@ sha2 = "0.11.0"
|
||||
tokio = { version = "1.53.1", features = ["rt", "rt-multi-thread", "macros"] }
|
||||
hex = "0.4.3"
|
||||
zstd = "0.13.3"
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.8.2"
|
||||
|
||||
[[bench]]
|
||||
name = "split_bench" # Имя файла в benches/ без расширения
|
||||
harness = false # Отключаем стандартный тестовый раннер
|
||||
zip = "8.6.0"
|
||||
rfd = "0.17.2"
|
||||
mimalloc = "0.1.52"
|
||||
hashbrown = "0.17.1"
|
||||
rayon = "1.12.0"
|
||||
|
||||
[profile.super-release]
|
||||
inherits = "release"
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
opt-level = 3
|
||||
strip = true
|
||||
panic = "abort"
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0.8.2", features = ["html_reports"] }
|
||||
|
||||
[[bench]]
|
||||
name = "map_bench"
|
||||
harness = false
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
use criterion::{Criterion, criterion_group, criterion_main};
|
||||
use std::collections::HashMap as StdHashMap;
|
||||
use std::hint::black_box;
|
||||
|
||||
use hashbrown::HashMap as BrownHashMap;
|
||||
|
||||
const SIZES: [usize; 3] = [5, 10, 50];
|
||||
const QUERY_COUNT: usize = 4096;
|
||||
|
||||
/// Детерминированный ключ ~17 символов, например "key_9e3779b9_0042".
|
||||
fn make_key(i: u64) -> String {
|
||||
let h = i.wrapping_mul(0x9E37_79B9_7F4A_7C15);
|
||||
format!("key_{:08x}_{:04}", h & 0xFFFF_FFFF, i)
|
||||
}
|
||||
|
||||
// Для длинных ключей (пути/URL) замени на:
|
||||
// fn make_key(i: u64) -> String {
|
||||
// format!(
|
||||
// "/api/v2/users/{i}/settings/visibility_{:08x}",
|
||||
// i.wrapping_mul(0x9E37_79B9)
|
||||
// )
|
||||
// }
|
||||
|
||||
fn make_vec(n: usize) -> Vec<(String, u64)> {
|
||||
(0..n as u64).map(|i| (make_key(i), i)).collect()
|
||||
}
|
||||
|
||||
fn make_std_map(data: &[(String, u64)]) -> StdHashMap<String, u64> {
|
||||
data.iter().map(|(k, v)| (k.clone(), *v)).collect()
|
||||
}
|
||||
|
||||
fn make_brown_map(data: &[(String, u64)]) -> BrownHashMap<String, u64> {
|
||||
data.iter().map(|(k, v)| (k.clone(), *v)).collect()
|
||||
}
|
||||
|
||||
fn make_queries(n: usize, with_misses: bool) -> Vec<String> {
|
||||
let keys: Vec<String> = (0..n as u64).map(make_key).collect();
|
||||
let missing = "__missing_key__".to_string();
|
||||
|
||||
(0..QUERY_COUNT)
|
||||
.map(|i| {
|
||||
if with_misses && i % 16 == 15 {
|
||||
missing.clone()
|
||||
} else {
|
||||
let idx = i.wrapping_mul(2_654_435_761) % n;
|
||||
keys[idx].clone()
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn lookup_std(map: &StdHashMap<String, u64>, queries: &[String]) -> u64 {
|
||||
let mut sum = 0u64;
|
||||
for q in queries {
|
||||
match map.get(black_box(q.as_str())) {
|
||||
Some(v) => sum = sum.wrapping_add(*v),
|
||||
None => sum = sum.wrapping_add(1),
|
||||
}
|
||||
}
|
||||
black_box(sum)
|
||||
}
|
||||
|
||||
fn lookup_brown(map: &BrownHashMap<String, u64>, queries: &[String]) -> u64 {
|
||||
let mut sum = 0u64;
|
||||
for q in queries {
|
||||
match map.get(black_box(q.as_str())) {
|
||||
Some(v) => sum = sum.wrapping_add(*v),
|
||||
None => sum = sum.wrapping_add(1),
|
||||
}
|
||||
}
|
||||
black_box(sum)
|
||||
}
|
||||
|
||||
fn lookup_vec(data: &[(String, u64)], queries: &[String]) -> u64 {
|
||||
let mut sum = 0u64;
|
||||
for q in queries {
|
||||
let q = black_box(q);
|
||||
match data.iter().find(|(k, _)| k == q) {
|
||||
Some((_, v)) => sum = sum.wrapping_add(*v),
|
||||
None => sum = sum.wrapping_add(1),
|
||||
}
|
||||
}
|
||||
black_box(sum)
|
||||
}
|
||||
|
||||
fn bench(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("map_vs_vec_str");
|
||||
|
||||
for n in SIZES {
|
||||
let vec_data = make_vec(n);
|
||||
let std_map = make_std_map(&vec_data);
|
||||
let brown_map = make_brown_map(&vec_data);
|
||||
|
||||
let queries_hit = make_queries(n, false);
|
||||
let queries_mixed = make_queries(n, true);
|
||||
|
||||
// std::collections::HashMap (SipHash)
|
||||
group.bench_function(format!("std_hashmap_hit/{n}"), |b| {
|
||||
b.iter(|| lookup_std(black_box(&std_map), black_box(&queries_hit)))
|
||||
});
|
||||
group.bench_function(format!("std_hashmap_mixed/{n}"), |b| {
|
||||
b.iter(|| lookup_std(black_box(&std_map), black_box(&queries_mixed)))
|
||||
});
|
||||
|
||||
// hashbrown (SwissTable + foldhash)
|
||||
group.bench_function(format!("hashbrown_hit/{n}"), |b| {
|
||||
b.iter(|| lookup_brown(black_box(&brown_map), black_box(&queries_hit)))
|
||||
});
|
||||
group.bench_function(format!("hashbrown_mixed/{n}"), |b| {
|
||||
b.iter(|| lookup_brown(black_box(&brown_map), black_box(&queries_mixed)))
|
||||
});
|
||||
|
||||
// Vec<(String, u64)>, линейный поиск
|
||||
group.bench_function(format!("vec_linear_hit/{n}"), |b| {
|
||||
b.iter(|| lookup_vec(black_box(&vec_data), black_box(&queries_hit)))
|
||||
});
|
||||
group.bench_function(format!("vec_linear_mixed/{n}"), |b| {
|
||||
b.iter(|| lookup_vec(black_box(&vec_data), black_box(&queries_mixed)))
|
||||
});
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench);
|
||||
criterion_main!(benches);
|
||||
@@ -1,43 +0,0 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
fn bench_split(c: &mut Criterion) {
|
||||
let input = "data_1";
|
||||
|
||||
c.bench_function("split_with_comma", |b| {
|
||||
b.iter(|| {
|
||||
// black_box запрещает компилятору оптимизировать результат
|
||||
black_box(split_with_coma(black_box(input)))
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_split_new(c: &mut Criterion) {
|
||||
let input = "data_1";
|
||||
|
||||
c.bench_function("split_with_comma gpt", |b| {
|
||||
b.iter(|| {
|
||||
// black_box запрещает компилятору оптимизировать результат
|
||||
black_box(split_with_coma(black_box(input)))
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
pub fn split_with_coma(ts: &str) -> Vec<String> {
|
||||
ts.split(',')
|
||||
.map(|ts| ts.to_lowercase().trim().to_string())
|
||||
.filter(|t| !t.is_empty())
|
||||
.collect::<Vec<String>>()
|
||||
}
|
||||
|
||||
pub fn new_split_with_coma(ts: &str) -> Vec<String> {
|
||||
ts.split(',')
|
||||
.map(|s| s.trim()) // 0 аллокаций, просто срез
|
||||
.filter(|s| !s.is_empty()) // отбрасываем пустые до аллокации
|
||||
.map(|s| s.to_lowercase()) // 1 аллокация на валидный токен
|
||||
.collect()
|
||||
}
|
||||
|
||||
// Можно добавить несколько бенчмарков в группу
|
||||
criterion_group!(benches, bench_split, bench_split_new);
|
||||
criterion_main!(benches);
|
||||
@@ -1,14 +1,14 @@
|
||||
use crate::lang::SetOrderMode;
|
||||
use crate::repetitions::CardSetSettings;
|
||||
use crate::lang::{DeckSettings, OrderMode};
|
||||
|
||||
use rusqlite::Connection;
|
||||
|
||||
pub fn load_sets(connection: &Connection) -> Vec<CardSetSettings> {
|
||||
pub fn load_sets(connection: &Connection) -> Vec<DeckSettings> {
|
||||
let mut stmt = connection
|
||||
.prepare("SELECT id, name, forward, backward, filter FROM card_set")
|
||||
.unwrap();
|
||||
let iter = stmt
|
||||
.query_map([], |row| {
|
||||
Ok(CardSetSettings {
|
||||
Ok(DeckSettings {
|
||||
id: row.get(0)?,
|
||||
name: row.get(1)?,
|
||||
forward: row.get(2)?,
|
||||
@@ -16,7 +16,7 @@ pub fn load_sets(connection: &Connection) -> Vec<CardSetSettings> {
|
||||
filter: row.get(4)?,
|
||||
count: None,
|
||||
worst_words_list: None,
|
||||
open_mode: SetOrderMode::Default,
|
||||
open_mode: OrderMode::Default,
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
@@ -29,7 +29,7 @@ pub fn load_sets(connection: &Connection) -> Vec<CardSetSettings> {
|
||||
buffer
|
||||
}
|
||||
|
||||
pub fn add_set(set: &mut CardSetSettings, connection: &Connection) {
|
||||
pub fn add_set(set: &mut DeckSettings, connection: &Connection) {
|
||||
let index = connection
|
||||
.query_row(
|
||||
"INSERT INTO card_set (name, forward, backward, filter) VALUES (?1, ?2, ?3, ?4) RETURNING id",
|
||||
@@ -43,12 +43,12 @@ pub fn add_set(set: &mut CardSetSettings, connection: &Connection) {
|
||||
)
|
||||
.unwrap_or_else(|e| {println!("{}", e); 0});
|
||||
|
||||
set.id = index;
|
||||
set.id = index.into();
|
||||
}
|
||||
|
||||
pub fn update_card_set(set: &mut CardSetSettings, connection: &Connection) {
|
||||
if set.id == 0 {
|
||||
add_set(set, &connection);
|
||||
pub fn update_deck(set: &mut DeckSettings, connection: &Connection) {
|
||||
if !set.id.is_valid() {
|
||||
add_set(set, connection);
|
||||
} else {
|
||||
connection
|
||||
.execute(
|
||||
@@ -65,8 +65,8 @@ pub fn update_card_set(set: &mut CardSetSettings, connection: &Connection) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delete_set(set: &CardSetSettings, connection: &Connection) {
|
||||
if set.id == 0 {
|
||||
pub fn delete_set(set: &DeckSettings, connection: &Connection) {
|
||||
if !set.id.is_valid() {
|
||||
return;
|
||||
}
|
||||
connection
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use crate::lang::CardStatistics;
|
||||
use crate::repetitions::CardSetSettings;
|
||||
use rusqlite::Connection;
|
||||
use crate::lang::{CardStatistics, DeckSettings};
|
||||
use rusqlite::{params, Connection};
|
||||
use std::time::Instant;
|
||||
|
||||
pub fn load_stats_of_set(set: &CardSetSettings, connection: &Connection) -> Vec<CardStatistics> {
|
||||
pub fn load_stats_of_deck(set: &DeckSettings, connection: &Connection) -> Vec<CardStatistics> {
|
||||
let mut stmt = connection
|
||||
.prepare("SELECT id, word_id, score, last_opened FROM card_stats WHERE set_id = ?1")
|
||||
.unwrap();
|
||||
@@ -27,66 +26,40 @@ pub fn load_stats_of_set(set: &CardSetSettings, connection: &Connection) -> Vec<
|
||||
buffer
|
||||
}
|
||||
|
||||
pub fn add_stat_list(stat: &mut Vec<CardStatistics>, connection: &Connection) {
|
||||
let inserting = stat
|
||||
.iter()
|
||||
.map(|stat| {
|
||||
format!(
|
||||
"({}, {}, {}, {})",
|
||||
stat.word_id.to_string(),
|
||||
stat.set_id.to_string(),
|
||||
stat.score.to_string(),
|
||||
stat.last_open.timestamp().to_string()
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let query = format!(
|
||||
"INSERT INTO card_stats (word_id, set_id, score, last_opened) VALUES {}",
|
||||
inserting
|
||||
);
|
||||
let count = connection.execute(query.as_str(), ());
|
||||
pub fn add_stat_list(stats: &mut [CardStatistics], connection: &mut Connection) {
|
||||
let time = Instant::now();
|
||||
let tx = connection.transaction().unwrap();
|
||||
let count = stats.len();
|
||||
|
||||
if count.is_err() {
|
||||
println!("{}", count.unwrap_err());
|
||||
return;
|
||||
}
|
||||
|
||||
let last_index: u32 = connection
|
||||
.query_one(
|
||||
"SELECT seq from sqlite_sequence WHERE name == ?1",
|
||||
("card_stats".to_string(),),
|
||||
|row| row.get(0),
|
||||
{
|
||||
let mut stmt = tx
|
||||
.prepare(
|
||||
"INSERT INTO card_stats (word_id, set_id, score, last_opened) VALUES (?1, ?2, ?3, ?4)",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let start_index = last_index - (count.unwrap() as u32) + 1;
|
||||
|
||||
let mut index = 0;
|
||||
for id in start_index..=last_index {
|
||||
stat[index].id = id;
|
||||
index += 1;
|
||||
for stat in stats.iter() {
|
||||
stmt.execute(params![
|
||||
stat.word_id,
|
||||
stat.set_id,
|
||||
stat.score,
|
||||
stat.last_open.timestamp()
|
||||
])
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn add_stat(stat: &mut CardStatistics, connection: &Connection) {
|
||||
// let time = Instant::now();
|
||||
// let index = connection
|
||||
// .query_row(
|
||||
// "INSERT INTO card_stats (word_id, set_id, score, last_opened) VALUES (?1, ?2, ?3, ?4) RETURNING id",
|
||||
// (
|
||||
// &stat.word_id,
|
||||
// &stat.set_id,
|
||||
// &stat.score,
|
||||
// &stat.last_open.timestamp(),
|
||||
// ),
|
||||
// |row| row.get(0)
|
||||
// )
|
||||
// .unwrap_or_else(|e| {println!("{}", e); 0});
|
||||
//
|
||||
// stat.id = index;
|
||||
// println!("Added stat: {}", time.elapsed().as_millis());
|
||||
// }
|
||||
let last_index: u32 = tx.last_insert_rowid() as u32;
|
||||
tx.commit().unwrap();
|
||||
|
||||
let start_index = last_index - (count as u32) + 1;
|
||||
|
||||
for (index, id) in (start_index..=last_index).enumerate() {
|
||||
stats[index].id = id.into();
|
||||
}
|
||||
|
||||
println!("Added {} cards for {:?}", stats.len(), time.elapsed());
|
||||
}
|
||||
|
||||
pub fn update_stat_score(stat: &CardStatistics, connection: &Connection) {
|
||||
let time = Instant::now();
|
||||
@@ -104,7 +77,7 @@ pub fn update_stat_score(stat: &CardStatistics, connection: &Connection) {
|
||||
}
|
||||
|
||||
pub fn delete_stat(stat: &CardStatistics, connection: &Connection) {
|
||||
if stat.id == 0 {
|
||||
if !stat.id.is_valid() {
|
||||
return;
|
||||
}
|
||||
connection
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use std::fs;
|
||||
use crate::dictionary::app_data_dir;
|
||||
use crate::lang::WordOpenMode;
|
||||
use crate::lang::{Id, WordOpenMode};
|
||||
use chrono::{DateTime, Utc};
|
||||
use std::fs;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::Write;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn get_history_of_set(id: u32) -> Vec<HistoryItem> {
|
||||
pub fn get_history_of_set(id: Id) -> Vec<HistoryItem> {
|
||||
let app_dir = history_dir();
|
||||
let head = app_dir.clone().join(format!("set_{}_history.csv", id));
|
||||
let mut lines = Vec::new();
|
||||
@@ -32,7 +32,7 @@ fn parse_history_items(strings: Vec<String>) -> Vec<HistoryItem> {
|
||||
if let [time, word, mode, before, after] = string.split(';').collect::<Vec<&str>>()[..] {
|
||||
items.push(HistoryItem {
|
||||
timestamp: DateTime::from_timestamp(time.parse().unwrap(), 0).unwrap(),
|
||||
word_id: word.parse::<u32>().unwrap(),
|
||||
word_id: word.parse::<Id>().unwrap(),
|
||||
mode: match mode.parse::<u8>().unwrap() {
|
||||
2 => WordOpenMode::Hard,
|
||||
3 => WordOpenMode::Ok,
|
||||
@@ -48,7 +48,7 @@ fn parse_history_items(strings: Vec<String>) -> Vec<HistoryItem> {
|
||||
items
|
||||
}
|
||||
|
||||
pub fn push_note(set_id: u32, item: HistoryItem) {
|
||||
pub fn push_note(set_id: Id, item: HistoryItem) {
|
||||
let app_dir = history_dir();
|
||||
let path = app_dir.clone().join(format!("set_{}_history.csv", set_id));
|
||||
|
||||
@@ -70,7 +70,7 @@ pub fn push_note(set_id: u32, item: HistoryItem) {
|
||||
item.before,
|
||||
item.after
|
||||
);
|
||||
writeln!(&mut file, "{}", line_str.to_string()).unwrap();
|
||||
writeln!(&mut file, "{}", line_str).unwrap();
|
||||
}
|
||||
|
||||
pub fn history_dir() -> PathBuf {
|
||||
@@ -84,7 +84,7 @@ pub fn history_dir() -> PathBuf {
|
||||
#[derive(Clone)]
|
||||
pub struct HistoryItem {
|
||||
pub timestamp: DateTime<Utc>,
|
||||
pub word_id: u32,
|
||||
pub word_id: Id,
|
||||
pub mode: WordOpenMode,
|
||||
pub before: u8,
|
||||
pub after: u8,
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
use hashbrown::HashMap;
|
||||
use rusqlite::Connection;
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ImportData(pub(crate) Vec<ImportGroup>);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ImportGroup {
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub fields: Vec<String>,
|
||||
pub length: u64,
|
||||
pub mapping: HashMap<String, String>,
|
||||
pub imported: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ImportNote {
|
||||
pub tags: String,
|
||||
pub fields: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn load_groups(connection: &Connection) -> ImportData {
|
||||
let json_models: String = connection
|
||||
.query_one("select models from col", (), |row| row.get(0))
|
||||
.unwrap();
|
||||
let raw: Value = serde_json::from_str(json_models.as_str()).unwrap();
|
||||
let sets = raw.as_object().unwrap();
|
||||
let mut total_data = ImportData(vec![]);
|
||||
|
||||
let mut count_stmt = connection
|
||||
.prepare("select mid, count(id) from notes group by mid")
|
||||
.unwrap();
|
||||
|
||||
let counts = count_stmt
|
||||
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))
|
||||
.unwrap()
|
||||
.map(|x| x.unwrap())
|
||||
.collect::<Vec<(i64, i64)>>();
|
||||
|
||||
for (_, collection) in sets {
|
||||
let fields = collection["flds"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|x| x["name"].as_str().unwrap().to_string())
|
||||
.collect();
|
||||
let mut group = ImportGroup {
|
||||
id: collection["id"].as_u64().unwrap(),
|
||||
name: collection["name"].as_str().unwrap().to_string(),
|
||||
fields,
|
||||
mapping: Default::default(),
|
||||
length: 0,
|
||||
imported: false,
|
||||
};
|
||||
if let Some((_, count)) = counts.iter().find(|(id, _)| *id == group.id as i64) {
|
||||
group.length = *count as u64
|
||||
}
|
||||
println!("{:?}", group);
|
||||
total_data.0.push(group);
|
||||
}
|
||||
total_data
|
||||
}
|
||||
|
||||
pub fn get_words_of_group(connection: &Connection, group_id: u64) -> Vec<ImportNote> {
|
||||
let mut count_stmt = connection
|
||||
.prepare("select tags, flds from notes where mid == ?1;")
|
||||
.unwrap();
|
||||
|
||||
count_stmt
|
||||
.query_map((group_id as i64,), |row| {
|
||||
Ok(ImportNote {
|
||||
tags: row.get(0)?,
|
||||
fields: row
|
||||
.get::<usize, String>(1)?
|
||||
.split('')
|
||||
.map(|x| x.to_string())
|
||||
.collect(),
|
||||
})
|
||||
})
|
||||
.unwrap()
|
||||
.map(|x| x.unwrap())
|
||||
.collect::<Vec<ImportNote>>()
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
pub(crate) mod card_sets;
|
||||
pub(crate) mod card_stats;
|
||||
pub(crate) mod history;
|
||||
pub(crate) mod import;
|
||||
pub(crate) mod settings;
|
||||
pub(crate) mod sqlite;
|
||||
pub(crate) mod voice;
|
||||
pub(crate) mod words;
|
||||
pub(crate) mod web_api;
|
||||
pub(crate) mod words;
|
||||
|
||||
@@ -4,14 +4,14 @@ pub fn get_setting(key: String, connection: &Connection) -> Option<String> {
|
||||
let mut stmt = connection
|
||||
.prepare("SELECT value FROM settings WHERE id = ?1")
|
||||
.unwrap();
|
||||
let iter = stmt.query_map((key,), |row| row.get(0)).unwrap();
|
||||
let mut iter = stmt.query_map((key,), |row| row.get(0)).unwrap();
|
||||
|
||||
for row in iter {
|
||||
if let Ok(value) = row {
|
||||
if let Some(row) = iter.next()
|
||||
&& let Ok(value) = row
|
||||
{
|
||||
return Some(value);
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::dictionary::app_data_dir;
|
||||
use std::io;
|
||||
use tokio::fs::{File, OpenOptions};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use zstd::{Decoder, Encoder, DEFAULT_COMPRESSION_LEVEL};
|
||||
use zstd::{DEFAULT_COMPRESSION_LEVEL, Decoder, Encoder};
|
||||
|
||||
// const API_URL: &str = "http://127.0.0.1:8089/";
|
||||
const API_URL: &str = "https://learning.micialware.ru/";
|
||||
@@ -17,15 +17,22 @@ pub async fn send_data(id: String) {
|
||||
let id_url = format!("{api_url}upload/stream/{id}");
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let new_version = client.post(&id_url).body(data).send().await.unwrap().text().await.unwrap();
|
||||
let new_version = client
|
||||
.post(&id_url)
|
||||
.body(data)
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.text()
|
||||
.await
|
||||
.unwrap();
|
||||
set_local_version(new_version.parse::<u32>().unwrap()).await;
|
||||
}
|
||||
|
||||
fn compress(data: Vec<u8>) -> Vec<u8> {
|
||||
let mut encoder = Encoder::new(Vec::new(), DEFAULT_COMPRESSION_LEVEL).unwrap();
|
||||
io::copy(&mut &data[..], &mut encoder).unwrap();
|
||||
let compressed = encoder.finish().unwrap();
|
||||
compressed
|
||||
encoder.finish().unwrap()
|
||||
}
|
||||
|
||||
pub async fn load_data(id: String, temp: bool) {
|
||||
@@ -50,7 +57,14 @@ pub async fn load_data(id: String, temp: bool) {
|
||||
tokio::fs::write(db_file, data).await.unwrap();
|
||||
|
||||
let version_url = format!("{API_URL}{id}/version");
|
||||
let version = client.get(&version_url).send().await.unwrap().text().await.unwrap();
|
||||
let version = client
|
||||
.get(&version_url)
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.text()
|
||||
.await
|
||||
.unwrap();
|
||||
set_local_version(version.parse::<u32>().unwrap()).await;
|
||||
}
|
||||
|
||||
@@ -84,25 +98,44 @@ pub async fn get_web_version(key: &str) -> Result<u32, reqwest::Error> {
|
||||
let id_url = format!("{API_URL}{key}/version");
|
||||
let client = reqwest::Client::new();
|
||||
let version = client.get(&id_url).send().await?.text().await?;
|
||||
return Ok(version.parse::<u32>().unwrap());
|
||||
println!("version: {}", version);
|
||||
Ok(version.parse::<u32>().unwrap_or_default())
|
||||
}
|
||||
|
||||
pub async fn get_local_version() -> u32 {
|
||||
let file = app_data_dir().join("data.meta");
|
||||
if file.exists() {
|
||||
let mut data = String::new();
|
||||
File::open(file.clone()).await.unwrap().read_to_string(&mut data).await.unwrap();
|
||||
File::open(file.clone())
|
||||
.await
|
||||
.unwrap()
|
||||
.read_to_string(&mut data)
|
||||
.await
|
||||
.unwrap();
|
||||
return data.parse::<u32>().unwrap();
|
||||
}
|
||||
|
||||
let mut file = OpenOptions::new().write(true).create(true).open(file).await.unwrap();
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(file)
|
||||
.await
|
||||
.unwrap();
|
||||
file.write_all("0".as_bytes()).await.unwrap();
|
||||
0
|
||||
}
|
||||
|
||||
pub async fn set_local_version(version: u32) {
|
||||
let file_path = app_data_dir().join("data.meta");
|
||||
let mut file = OpenOptions::new().write(true).create(true).truncate(true).open(file_path).await.unwrap();
|
||||
file.write_all(version.to_string().as_bytes()).await.unwrap();
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(file_path)
|
||||
.await
|
||||
.unwrap();
|
||||
file.write_all(version.to_string().as_bytes())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
||||
+45
-12
@@ -1,12 +1,11 @@
|
||||
use crate::lang::{WordData, WordGroup};
|
||||
use rusqlite::Connection;
|
||||
use rusqlite::{params, Connection};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn add_word(word: &mut WordData, connection: &Connection) {
|
||||
let index = connection
|
||||
.query_row(
|
||||
"INSERT INTO words (key, value, tags, more, group_id) VALUES (?1, ?2, ?3, ?4, ?5\
|
||||
) RETURNING id",
|
||||
"INSERT INTO words (key, value, tags, more, group_id) VALUES (?1, ?2, ?3, ?4, ?5) RETURNING id",
|
||||
(
|
||||
&word.key,
|
||||
&word.value,
|
||||
@@ -21,12 +20,46 @@ pub fn add_word(word: &mut WordData, connection: &Connection) {
|
||||
0
|
||||
});
|
||||
|
||||
word.id = index;
|
||||
word.id = index.into();
|
||||
}
|
||||
|
||||
pub fn add_words(words: &mut [WordData], connection: &mut Connection) {
|
||||
let tx = connection.transaction().unwrap();
|
||||
let count = words.len();
|
||||
|
||||
{
|
||||
let mut stmt = tx
|
||||
.prepare(
|
||||
"INSERT INTO words (key, value, tags, more, group_id) VALUES (?1, ?2, ?3, ?4, ?5)",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
for word in words.iter() {
|
||||
stmt.execute(params![
|
||||
word.key,
|
||||
word.value,
|
||||
word.tags,
|
||||
serde_json::to_string(&word.additional).unwrap(),
|
||||
word.group_id
|
||||
])
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
let last_index: u32 = tx.last_insert_rowid() as u32;
|
||||
tx.commit().unwrap();
|
||||
|
||||
|
||||
let start_index = last_index - (count as u32) + 1;
|
||||
|
||||
for (index, id) in (start_index..=last_index).enumerate() {
|
||||
words[index].id = id.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_word(word: &mut WordData, connection: &Connection) {
|
||||
if word.id == 0 {
|
||||
add_word(word, &connection);
|
||||
if !word.id.is_valid() {
|
||||
add_word(word, connection);
|
||||
} else {
|
||||
connection
|
||||
.execute(
|
||||
@@ -47,7 +80,7 @@ pub fn update_word(word: &mut WordData, connection: &Connection) {
|
||||
}
|
||||
|
||||
pub fn delete_word(word: &WordData, connection: &Connection) {
|
||||
if word.id == 0 {
|
||||
if !word.id.is_valid() {
|
||||
return;
|
||||
}
|
||||
connection
|
||||
@@ -117,16 +150,16 @@ pub fn add_group(group: &mut WordGroup, connection: &Connection) {
|
||||
0
|
||||
});
|
||||
|
||||
group.id = index;
|
||||
group.id = index.into();
|
||||
}
|
||||
|
||||
pub fn update_group(group: &mut WordGroup, connection: &Connection) {
|
||||
if group.id == 0 {
|
||||
add_group(group, &connection);
|
||||
if !group.id.is_valid() {
|
||||
add_group(group, connection);
|
||||
} else {
|
||||
connection
|
||||
.execute(
|
||||
"UPDATE word_group SET name = ?1 WHERE id = ?5",
|
||||
"UPDATE word_group SET name = ?1 WHERE id = ?2",
|
||||
(&group.name, &group.id),
|
||||
)
|
||||
.unwrap_or_else(|e| {
|
||||
@@ -137,7 +170,7 @@ pub fn update_group(group: &mut WordGroup, connection: &Connection) {
|
||||
}
|
||||
|
||||
pub fn delete_group(group: &WordGroup, connection: &Connection) {
|
||||
if group.id == 0 {
|
||||
if !group.id.is_valid() {
|
||||
return;
|
||||
}
|
||||
connection
|
||||
|
||||
+131
-103
@@ -1,22 +1,24 @@
|
||||
use crate::data_provider::words::{delete_group, delete_word, update_group, update_word};
|
||||
use crate::dictionary::DictionaryMessage::*;
|
||||
use crate::dictionary_test::DictionaryQuizState;
|
||||
use crate::import::ImportState;
|
||||
use crate::lang::{WordData, WordGroup};
|
||||
use crate::navigation::Page::Word;
|
||||
use crate::navigation::Page::{Import, Word};
|
||||
use crate::navigation::{NavigatedPage, Page};
|
||||
use crate::styling::*;
|
||||
use crate::word::WordState;
|
||||
use crate::{AppState, RootMessage};
|
||||
use chrono::{DateTime, TimeDelta, Utc};
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
use iced::alignment::Vertical::Center;
|
||||
use iced::widget::button::Style;
|
||||
use iced::widget::button::{danger, text};
|
||||
use iced::widget::space::horizontal;
|
||||
use iced::widget::text_input::default;
|
||||
use iced::widget::*;
|
||||
use iced::{Border, Color, Length, Shadow, Task};
|
||||
use iced::{Border, Color, Shadow, Task};
|
||||
use iced_core::Length::Fill;
|
||||
use rand::random_range;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs;
|
||||
use std::ops::Add;
|
||||
use std::path::PathBuf;
|
||||
@@ -59,15 +61,17 @@ pub enum DictionaryMessage {
|
||||
DeleteGroup,
|
||||
ChangeDirection,
|
||||
TrySave(usize),
|
||||
ToImport,
|
||||
}
|
||||
|
||||
impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
fn navigate(&self, message: &DictionaryMessage) -> Option<Page> {
|
||||
fn navigate(&mut self, message: &DictionaryMessage) -> Option<Page> {
|
||||
if let Back = message {
|
||||
return Some(Page::PreviousPage);
|
||||
}
|
||||
if let Test = message {
|
||||
if self.include_map.iter().any(|x| *x) {
|
||||
if let Test = message
|
||||
&& self.include_map.iter().any(|x| *x)
|
||||
{
|
||||
let mut words = vec![];
|
||||
let dict = &self.state.lock().unwrap().dictionary;
|
||||
|
||||
@@ -85,7 +89,6 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
self.no_typing,
|
||||
)));
|
||||
}
|
||||
}
|
||||
if let WordAction(index) = message {
|
||||
let word: WordData;
|
||||
{
|
||||
@@ -93,44 +96,30 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
let dict = &state.dictionary;
|
||||
word = dict[*index].clone();
|
||||
}
|
||||
if word.id != 0 {
|
||||
if word.id.is_valid() {
|
||||
return Some(Word(WordState::new(word, *index, self.state.clone())));
|
||||
}
|
||||
}
|
||||
if let ToImport = message {
|
||||
return Some(Import(ImportState::new(self.state.clone())));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn navigated(&mut self) {
|
||||
}
|
||||
let len = self.state.lock().unwrap().dictionary.len();
|
||||
|
||||
self.include_map = vec![false; len];
|
||||
self.tag_map = Default::default();
|
||||
self.update_tags();
|
||||
}
|
||||
|
||||
impl DictionaryState {
|
||||
pub fn new(state: Arc<Mutex<AppState>>) -> Self {
|
||||
let len = state.lock().unwrap().dictionary.len();
|
||||
|
||||
let mut result = DictionaryState {
|
||||
include_map: vec![false; len],
|
||||
selected_group_index: 0,
|
||||
state,
|
||||
tag_map: HashMap::new(),
|
||||
reverse: false,
|
||||
search: "".to_string(),
|
||||
no_typing: true,
|
||||
reverse_list: true,
|
||||
auto_save_queue: HashMap::new(),
|
||||
};
|
||||
|
||||
result.update_tags();
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> {
|
||||
fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
NewWord => {
|
||||
let mut state = self.state.lock().unwrap();
|
||||
let mut word = WordData::new();
|
||||
word.group_id = state.word_groups[self.selected_group_index].id.clone();
|
||||
word.group_id = state.word_groups[self.selected_group_index].id;
|
||||
|
||||
let dict = &mut state.dictionary;
|
||||
dict.push(word);
|
||||
@@ -161,12 +150,11 @@ impl DictionaryState {
|
||||
v = v[..v.len() - 2].to_string()
|
||||
}
|
||||
|
||||
while v.contains(",,") {
|
||||
let index = v.find(",,").unwrap();
|
||||
while let Some(index) = v.find(",,") {
|
||||
v.remove(index);
|
||||
}
|
||||
|
||||
dict.get_mut(i).unwrap().tags = v;
|
||||
dict[i].tags = v;
|
||||
}
|
||||
|
||||
self.update_tags();
|
||||
@@ -183,7 +171,7 @@ impl DictionaryState {
|
||||
}
|
||||
Include(i, b) => self.include_map[i] = b,
|
||||
IncludeTag(t, v) => {
|
||||
let index: u32;
|
||||
let index;
|
||||
{
|
||||
let state = self.state.lock().unwrap();
|
||||
index = state.word_groups[self.selected_group_index].id;
|
||||
@@ -208,7 +196,7 @@ impl DictionaryState {
|
||||
let state = &mut self.state.lock().unwrap();
|
||||
|
||||
state.word_groups.push(WordGroup {
|
||||
id: 0,
|
||||
id: 0.into(),
|
||||
name: format!("Группа слов {}", random_range(100..1000)),
|
||||
});
|
||||
}
|
||||
@@ -222,18 +210,16 @@ impl DictionaryState {
|
||||
SaveGroup => {
|
||||
let state = &mut self.state.lock().unwrap();
|
||||
let connection = &state.connection;
|
||||
let group = &mut state
|
||||
.word_groups
|
||||
.get(self.selected_group_index)
|
||||
.unwrap()
|
||||
let mut group = state
|
||||
.word_groups[self.selected_group_index]
|
||||
.clone();
|
||||
|
||||
update_group(group, connection);
|
||||
state.word_groups[self.selected_group_index] = group.clone();
|
||||
update_group(&mut group, connection);
|
||||
state.word_groups[self.selected_group_index] = group;
|
||||
}
|
||||
SelectGroup(i) => {
|
||||
self.selected_group_index = i;
|
||||
let index: u32;
|
||||
let index;
|
||||
{
|
||||
let state = self.state.lock().unwrap();
|
||||
index = state.word_groups[i].id;
|
||||
@@ -244,16 +230,24 @@ impl DictionaryState {
|
||||
if self.selected_group_index == 0 {
|
||||
return Task::none();
|
||||
}
|
||||
{
|
||||
let state = &mut self.state.lock().unwrap();
|
||||
|
||||
if let Some(group) = state.word_groups.get(self.selected_group_index) {
|
||||
let remove_group_id = group.id;
|
||||
let connection = &state.connection;
|
||||
|
||||
delete_group(group, connection);
|
||||
state.word_groups.remove(self.selected_group_index);
|
||||
state
|
||||
.dictionary
|
||||
.retain(|word| word.group_id != remove_group_id);
|
||||
self.selected_group_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
self.update_tags()
|
||||
}
|
||||
ChangeDirection => {
|
||||
self.reverse_list = !self.reverse_list;
|
||||
}
|
||||
@@ -267,17 +261,61 @@ impl DictionaryState {
|
||||
self.save_word(word_index);
|
||||
}
|
||||
}
|
||||
ToImport => {}
|
||||
}
|
||||
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
back_overlay(
|
||||
row![
|
||||
iced::widget::column![
|
||||
self.groups_panel(),
|
||||
row![horizontal().width(8), self.words_list(),],
|
||||
row![
|
||||
button("Добавить слово").style(jl_button).on_press(NewWord),
|
||||
horizontal().width(Fill),
|
||||
button("Импорт").style(text).on_press(ToImport),
|
||||
]
|
||||
]
|
||||
.spacing(5),
|
||||
self.filters(),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.into(),
|
||||
Back,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl DictionaryState {
|
||||
pub fn new(state: Arc<Mutex<AppState>>) -> Self {
|
||||
let len = state.lock().unwrap().dictionary.len();
|
||||
|
||||
let mut result = DictionaryState {
|
||||
include_map: vec![false; len],
|
||||
selected_group_index: 0,
|
||||
state,
|
||||
tag_map: HashMap::new(),
|
||||
reverse: false,
|
||||
search: "".to_string(),
|
||||
no_typing: true,
|
||||
reverse_list: true,
|
||||
auto_save_queue: HashMap::new(),
|
||||
};
|
||||
|
||||
result.update_tags();
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
fn save_word(&mut self, i: usize) {
|
||||
let state = &mut self.state.lock().unwrap();
|
||||
let connection = &state.connection;
|
||||
let word = &mut state.dictionary.get(i).unwrap().clone();
|
||||
let word = &mut state.dictionary[i].clone();
|
||||
|
||||
update_word(word, &connection);
|
||||
update_word(word, connection);
|
||||
state.dictionary[i] = word.clone();
|
||||
}
|
||||
|
||||
@@ -291,50 +329,32 @@ impl DictionaryState {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn view(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
back_overlay(
|
||||
row![
|
||||
iced::widget::column![
|
||||
self.groups_panel(),
|
||||
row![horizontal().width(8), self.words_list(),],
|
||||
button("Добавить слово").style(jl_button).on_press(NewWord),
|
||||
]
|
||||
.spacing(5),
|
||||
self.filters(),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.into(),
|
||||
Back,
|
||||
)
|
||||
}
|
||||
|
||||
fn words_list(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
let time = Instant::now();
|
||||
let mut col = Column::new().width(Length::Fill);
|
||||
let mut col = Column::new().width(Fill);
|
||||
|
||||
let mut range = (0..self.include_map.len()).collect::<Vec<_>>();
|
||||
let state = self.state.lock().unwrap();
|
||||
let group_id = state.word_groups[self.selected_group_index].id;
|
||||
let dict = &mut state.dictionary.clone();
|
||||
|
||||
let dict = &state.dictionary;
|
||||
|
||||
let mut index = 0;
|
||||
|
||||
for access_index in 0..dict.len() {
|
||||
let mut i = access_index;
|
||||
if self.reverse_list {
|
||||
dict.reverse()
|
||||
} else {
|
||||
range = range.iter().rev().map(|x| *x).collect::<Vec<usize>>();
|
||||
i = dict.len() - access_index - 1;
|
||||
}
|
||||
|
||||
for word in dict {
|
||||
let i = range.pop().unwrap();
|
||||
if !self.search.is_empty() {
|
||||
if word.key.contains(&self.search) == false
|
||||
&& word.value.contains(&self.search) == false
|
||||
&& word.tags.contains(&self.search) == false
|
||||
{
|
||||
let word = &dict[i];
|
||||
if word.group_id != group_id {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if word.group_id != group_id {
|
||||
if !self.search.is_empty()
|
||||
&& !word.key.contains(&self.search)
|
||||
&& !word.value.contains(&self.search)
|
||||
&& !word.tags.contains(&self.search)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -344,12 +364,14 @@ impl DictionaryState {
|
||||
value: word.value.clone(),
|
||||
tags: word.tags.clone(),
|
||||
id: word.id,
|
||||
index: i
|
||||
index: i,
|
||||
};
|
||||
|
||||
index += 1;
|
||||
|
||||
let lazy_line = lazy(word_line_data, move |data| {
|
||||
let index = data.index;
|
||||
let mut line = Row::new().width(Length::Fill).align_y(Center);
|
||||
let mut line = Row::new().width(Fill).align_y(Center);
|
||||
line = line.push(
|
||||
checkbox(data.is_included)
|
||||
.label("")
|
||||
@@ -360,7 +382,7 @@ impl DictionaryState {
|
||||
line = line.push(
|
||||
text_input("Слово", &data.key)
|
||||
.size(ACCENT_FONT_SIZE)
|
||||
.width(Length::Fill)
|
||||
.width(Fill)
|
||||
.on_input(move |string| SetKey(index, string))
|
||||
.on_submit(SubmitWord(index))
|
||||
.style(|x, status| {
|
||||
@@ -372,7 +394,7 @@ impl DictionaryState {
|
||||
line = line.push(
|
||||
text_input("Перевод", &data.value)
|
||||
.size(ACCENT_FONT_SIZE)
|
||||
.width(Length::Fill)
|
||||
.width(Fill)
|
||||
.on_input(move |string| SetValue(index, string))
|
||||
.on_submit(SubmitWord(index))
|
||||
.style(|x, status| {
|
||||
@@ -385,7 +407,7 @@ impl DictionaryState {
|
||||
line = line.push(
|
||||
text_input("Теги", &data.tags)
|
||||
.size(ACCENT_FONT_SIZE)
|
||||
.width(Length::Fill)
|
||||
.width(Fill)
|
||||
.on_input(move |string| SetTags(index, string))
|
||||
.on_submit(SubmitWord(index))
|
||||
.style(|x, status| {
|
||||
@@ -398,7 +420,7 @@ impl DictionaryState {
|
||||
let line_button = || {
|
||||
let action = WordAction(index);
|
||||
|
||||
if data.id == 0 {
|
||||
if !data.id.is_valid() {
|
||||
return button("-").on_press(action).style(|_x, _status| Style {
|
||||
background: None,
|
||||
text_color: Color::BLACK,
|
||||
@@ -414,14 +436,12 @@ impl DictionaryState {
|
||||
line
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
col = col.push(lazy_line);
|
||||
}
|
||||
|
||||
println!("Drawing {index} lines");
|
||||
println!("Words rendering time: {:?}", time.elapsed());
|
||||
scrollable(col).height(Length::Fill).into()
|
||||
scrollable(col).height(Fill).into()
|
||||
}
|
||||
|
||||
fn filters(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
@@ -430,7 +450,7 @@ impl DictionaryState {
|
||||
iced::widget::column![
|
||||
text_input("Поиск", &self.search)
|
||||
.on_input(Search)
|
||||
.width(Length::Fill),
|
||||
.width(Fill),
|
||||
text!("Всего слов: {}", dict.len()),
|
||||
text!(
|
||||
"Выбрано слов: {}",
|
||||
@@ -443,10 +463,10 @@ impl DictionaryState {
|
||||
toggler(self.reverse)
|
||||
.label("Обратный тест")
|
||||
.on_toggle(SetReverse),
|
||||
button(text!("Тест").center().width(Length::Fill))
|
||||
button(text!("Тест").center().width(Fill))
|
||||
.style(cta_button)
|
||||
.on_press(Test)
|
||||
.width(Length::Fill),
|
||||
.width(Fill),
|
||||
]
|
||||
.width(250)
|
||||
.spacing(DEFAULT_SPACING)
|
||||
@@ -454,7 +474,7 @@ impl DictionaryState {
|
||||
}
|
||||
|
||||
fn tags_selector(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
let mut col = Column::new().width(Length::Fill);
|
||||
let mut col = Column::new().width(Fill);
|
||||
col = col.push(
|
||||
button("Сбросить")
|
||||
.on_press(ResetTags)
|
||||
@@ -476,7 +496,7 @@ impl DictionaryState {
|
||||
)
|
||||
}
|
||||
|
||||
container(scrollable(col)).height(Length::Fill).into()
|
||||
container(scrollable(col)).height(Fill).into()
|
||||
}
|
||||
|
||||
fn update_tags(&mut self) {
|
||||
@@ -509,7 +529,7 @@ impl DictionaryState {
|
||||
});
|
||||
}
|
||||
|
||||
fn update_words_include(&mut self, group_id: u32) {
|
||||
fn update_words_include(&mut self, group_id: crate::lang::Id) {
|
||||
let include_tags = self
|
||||
.tag_map
|
||||
.iter()
|
||||
@@ -529,7 +549,9 @@ impl DictionaryState {
|
||||
.iter()
|
||||
.map(|word| (split_with_coma(word.tags.as_str()), word.group_id))
|
||||
.map(|(tags, word_group_id)| {
|
||||
tags.iter().all(|t| include_tags.contains(t)) && word_group_id == group_id
|
||||
!tags.is_empty()
|
||||
&& tags.iter().all(|t| include_tags.contains(t))
|
||||
&& word_group_id == group_id
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -543,20 +565,18 @@ impl DictionaryState {
|
||||
let state = &self.state.lock().unwrap();
|
||||
let groups = &state.word_groups;
|
||||
|
||||
let mut index = 0;
|
||||
for group in groups {
|
||||
for (index, group) in groups.iter().enumerate() {
|
||||
row = row.push(
|
||||
button(text!("{}", group.name.clone()))
|
||||
.style(text)
|
||||
.on_press(SelectGroup(index)),
|
||||
);
|
||||
index = index + 1;
|
||||
}
|
||||
|
||||
let group = state.word_groups[self.selected_group_index].clone();
|
||||
|
||||
iced::widget::column![
|
||||
scrollable(row).width(Length::Fill).horizontal(),
|
||||
scrollable(row).width(Fill).horizontal(),
|
||||
row![
|
||||
button("⇳").on_press(ChangeDirection).style(jl_button),
|
||||
text_input("Название группы слов", &group.name)
|
||||
@@ -564,12 +584,20 @@ impl DictionaryState {
|
||||
.width(250)
|
||||
.on_submit(SaveGroup),
|
||||
horizontal(),
|
||||
button("Удалить").style(danger).on_press(DeleteGroup),
|
||||
self.group_delete_button(),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING / 2.0)
|
||||
]
|
||||
.into()
|
||||
}
|
||||
|
||||
fn group_delete_button(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||
if self.selected_group_index != 0 {
|
||||
button("Удалить").style(danger).on_press(DeleteGroup).into()
|
||||
} else {
|
||||
space().into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn split_with_coma(ts: &str) -> Vec<String> {
|
||||
@@ -583,7 +611,7 @@ pub fn app_data_dir() -> PathBuf {
|
||||
let mut dir = dirs::data_dir().unwrap();
|
||||
dir.push("jap_learn");
|
||||
if !dir.exists() {
|
||||
fs::create_dir(dir.clone()).unwrap();
|
||||
fs::create_dir_all(dir.clone()).unwrap();
|
||||
}
|
||||
|
||||
dir
|
||||
@@ -595,6 +623,6 @@ struct WordLineState{
|
||||
key: String,
|
||||
value: String,
|
||||
tags: String,
|
||||
id: u32,
|
||||
id: crate::lang::Id,
|
||||
index: usize,
|
||||
}
|
||||
+37
-31
@@ -1,3 +1,4 @@
|
||||
use crate::RootMessage;
|
||||
use crate::dictionary::split_with_coma;
|
||||
use crate::dictionary_test::DictionaryQuizMessage::*;
|
||||
use crate::lang::WordData;
|
||||
@@ -5,12 +6,11 @@ use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::*;
|
||||
use crate::quiz::Score;
|
||||
use crate::styling::*;
|
||||
use crate::RootMessage;
|
||||
use iced::Background::Color;
|
||||
use iced::border::Radius;
|
||||
use iced::widget::container::Style;
|
||||
use iced::widget::{button, container, row, space, text, text_input, Row};
|
||||
use iced::Background::Color;
|
||||
use iced::{alignment, Border, Element, Fill, Task, Theme};
|
||||
use iced::widget::{Row, button, container, row, space, text, text_input};
|
||||
use iced::{Border, Element, Fill, Task, Theme, alignment};
|
||||
use rand::prelude::SliceRandom;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -35,34 +35,16 @@ pub enum DictionaryQuizMessage {
|
||||
}
|
||||
|
||||
impl NavigatedPage<DictionaryQuizMessage> for DictionaryQuizState {
|
||||
fn navigate(&self, message: &DictionaryQuizMessage) -> Option<Page> {
|
||||
fn navigate(&mut self, message: &DictionaryQuizMessage) -> Option<Page> {
|
||||
match message {
|
||||
Back => Some(PreviousPage),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn navigated(&mut self) {
|
||||
}
|
||||
}
|
||||
fn navigated(&mut self) {}
|
||||
|
||||
impl DictionaryQuizState {
|
||||
pub fn new(words: Vec<WordData>, reverse: bool, no_typing: bool) -> DictionaryQuizState {
|
||||
DictionaryQuizState {
|
||||
words,
|
||||
current_set: Vec::new(),
|
||||
answer: "".to_string(),
|
||||
view: "---".to_string(),
|
||||
correct: "".to_string(),
|
||||
score: Default::default(),
|
||||
is_help: false,
|
||||
reverse,
|
||||
laps: 0,
|
||||
no_typing,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: DictionaryQuizMessage) -> Task<RootMessage> {
|
||||
fn update(&mut self, message: DictionaryQuizMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
Back => {}
|
||||
AnswerChanged(c) => self.answer = c.clone(),
|
||||
@@ -72,7 +54,7 @@ impl DictionaryQuizState {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, DictionaryQuizMessage> {
|
||||
fn view(&self) -> Element<'_, DictionaryQuizMessage> {
|
||||
container(
|
||||
iced::widget::column![
|
||||
self.laps(),
|
||||
@@ -119,6 +101,24 @@ impl DictionaryQuizState {
|
||||
.center_x(Fill)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl DictionaryQuizState {
|
||||
pub fn new(words: Vec<WordData>, reverse: bool, no_typing: bool) -> DictionaryQuizState {
|
||||
DictionaryQuizState {
|
||||
words,
|
||||
current_set: Vec::new(),
|
||||
answer: "".to_string(),
|
||||
view: "---".to_string(),
|
||||
correct: "".to_string(),
|
||||
score: Default::default(),
|
||||
is_help: false,
|
||||
reverse,
|
||||
laps: 0,
|
||||
no_typing,
|
||||
}
|
||||
}
|
||||
|
||||
fn submit(&mut self) {
|
||||
if self.view == "---" {
|
||||
self.show_next();
|
||||
@@ -149,7 +149,7 @@ impl DictionaryQuizState {
|
||||
if self.answer == self.correct
|
||||
|| split_with_coma(self.correct.as_str()).contains(&self.answer)
|
||||
{
|
||||
if self.is_help == false {
|
||||
if !self.is_help {
|
||||
self.score.correct += 1;
|
||||
}
|
||||
self.show_next()
|
||||
@@ -171,11 +171,17 @@ impl DictionaryQuizState {
|
||||
self.is_help = false;
|
||||
self.answer = String::new();
|
||||
|
||||
if self.current_set.is_empty() {
|
||||
self.update_set();
|
||||
let next : WordData =
|
||||
match self.current_set.pop() {
|
||||
Some(word) => {
|
||||
word
|
||||
}
|
||||
None => {
|
||||
self.update_set();
|
||||
self.current_set.pop().expect("Empty set")
|
||||
}
|
||||
};
|
||||
|
||||
let next = self.current_set.pop().unwrap();
|
||||
if self.reverse {
|
||||
self.view = next.value.clone();
|
||||
self.correct = next.key.clone();
|
||||
@@ -206,7 +212,7 @@ impl DictionaryQuizState {
|
||||
}
|
||||
|
||||
fn appeal_button(&self) -> Element<'_, DictionaryQuizMessage> {
|
||||
if self.is_help && self.no_typing == false {
|
||||
if self.is_help && !self.no_typing {
|
||||
return button("Апелляция").style(jl_button).on_press(Appeal).into();
|
||||
}
|
||||
space().into()
|
||||
|
||||
+25
-25
@@ -18,17 +18,35 @@ pub struct HistoryState {
|
||||
}
|
||||
|
||||
impl NavigatedPage<HistoryMessage> for HistoryState {
|
||||
fn navigate(&self, message: &HistoryMessage) -> Option<Page> {
|
||||
fn navigate(&mut self, message: &HistoryMessage) -> Option<Page> {
|
||||
match message {
|
||||
Back => Some(Page::PreviousPage),
|
||||
}
|
||||
}
|
||||
fn navigated(&mut self) {
|
||||
fn navigated(&mut self) {}
|
||||
fn update(&mut self, _: HistoryMessage) -> Task<RootMessage> {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<'_, HistoryMessage> {
|
||||
back_overlay(
|
||||
iced::widget::row![
|
||||
horizontal().width(FillPortion(1)),
|
||||
scrollable(self.history_lines().padding(DEFAULT_SPACING))
|
||||
.height(Fill)
|
||||
.width(FillPortion(5)),
|
||||
horizontal().width(FillPortion(1))
|
||||
]
|
||||
.height(Fill)
|
||||
.width(Fill)
|
||||
.into(),
|
||||
Back,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl HistoryState {
|
||||
pub fn new(id: u32, state: Arc<Mutex<AppState>>) -> Self {
|
||||
pub fn new(id: crate::lang::Id, state: Arc<Mutex<AppState>>) -> Self {
|
||||
let state = state.lock().unwrap();
|
||||
let history = get_history_of_set(id);
|
||||
let words = history
|
||||
@@ -49,26 +67,6 @@ impl HistoryState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, _: HistoryMessage) -> Task<RootMessage> {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, HistoryMessage> {
|
||||
back_overlay(
|
||||
iced::widget::row![
|
||||
horizontal().width(FillPortion(1)),
|
||||
scrollable(self.history_lines().padding(DEFAULT_SPACING))
|
||||
.height(Fill)
|
||||
.width(FillPortion(5)),
|
||||
horizontal().width(FillPortion(1))
|
||||
]
|
||||
.height(Fill)
|
||||
.width(Fill)
|
||||
.into(),
|
||||
Back,
|
||||
)
|
||||
}
|
||||
|
||||
fn history_lines(&self) -> Column<'_, HistoryMessage> {
|
||||
let mut column = Column::new();
|
||||
for (item, index) in self.list.iter().zip(0..self.list.len()) {
|
||||
@@ -85,11 +83,13 @@ impl HistoryState {
|
||||
.align_x(Center),
|
||||
iced::widget::column![
|
||||
text!("{} ➞ {}", item.before, item.after),
|
||||
text!("{}", item.timestamp.with_timezone(&Local).format("%d.%m %H:%M"))
|
||||
text!(
|
||||
"{}",
|
||||
item.timestamp.with_timezone(&Local).format("%d.%m %H:%M")
|
||||
)
|
||||
]
|
||||
.spacing(5)
|
||||
.align_x(Center)
|
||||
|
||||
]
|
||||
.spacing(5),
|
||||
);
|
||||
|
||||
+552
@@ -0,0 +1,552 @@
|
||||
use crate::data_provider::import::{get_words_of_group, load_groups, ImportData, ImportGroup};
|
||||
use crate::data_provider::words::{add_group, add_words};
|
||||
use crate::dictionary::app_data_dir;
|
||||
use crate::import::ImportMessage::*;
|
||||
use crate::lang::{WordData, WordGroup};
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::styling::*;
|
||||
use crate::AppState;
|
||||
use iced::widget::button::danger;
|
||||
use iced::widget::container::success;
|
||||
use iced::widget::{
|
||||
button, checkbox, column, container, progress_bar, row, rule, text, text_input, Row,
|
||||
};
|
||||
use iced::widget::{scrollable, space};
|
||||
use iced::{Element, Task};
|
||||
use iced_core::Alignment::Center;
|
||||
use iced_core::Length::Fill;
|
||||
use iced_core::Padding;
|
||||
use rfd::AsyncFileDialog;
|
||||
use rusqlite::Connection;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::BufReader;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tokio::task::spawn_blocking;
|
||||
use zip::ZipArchive;
|
||||
|
||||
const DEFAULT_FIELDS: [&str; 6] = ["key", "value", "tags", "reading", "context", "description"];
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ImportState {
|
||||
state: Arc<Mutex<AppState>>,
|
||||
path: Option<PathBuf>,
|
||||
import_data: Option<ImportData>,
|
||||
selected_index: usize,
|
||||
selected_property: Option<String>,
|
||||
custom_property_name: String,
|
||||
skip_empty: bool,
|
||||
separator: String,
|
||||
progress: Option<Arc<Mutex<f32>>>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ImportMessage {
|
||||
Back,
|
||||
SelectFile,
|
||||
UpdateFile(PathBuf),
|
||||
UpdateImport(ImportData),
|
||||
NextGroup,
|
||||
PreviousGroup,
|
||||
OpenPropertyMapper(String),
|
||||
EditCustomProperty(String),
|
||||
SetupCustomProperty,
|
||||
SetupDefaultProperty(String),
|
||||
SetupDirect,
|
||||
RemoveMapping(String),
|
||||
SwitchSkipEmpty(bool),
|
||||
EditSeparator(String),
|
||||
StartImport,
|
||||
NextProgress,
|
||||
ImportFinished,
|
||||
}
|
||||
|
||||
impl NavigatedPage<ImportMessage> for ImportState {
|
||||
fn navigate(&mut self, message: &ImportMessage) -> Option<Page> {
|
||||
if self.progress.is_some() {
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Back = message {
|
||||
return Some(Page::PreviousPage);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn navigated(&mut self) {}
|
||||
|
||||
fn update(&mut self, message: ImportMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
Back => {}
|
||||
UpdateFile(path) => {
|
||||
self.path = Some(path);
|
||||
self.import_data = None;
|
||||
return self.load_package();
|
||||
}
|
||||
SelectFile => return Self::select_import_file(),
|
||||
UpdateImport(import) => {
|
||||
self.selected_index = 0;
|
||||
self.import_data = Some(import);
|
||||
}
|
||||
NextGroup => {
|
||||
self.selected_index += 1;
|
||||
self.selected_property = None;
|
||||
self.custom_property_name.clear();
|
||||
}
|
||||
PreviousGroup => {
|
||||
self.selected_index -= 1;
|
||||
self.selected_property = None;
|
||||
self.custom_property_name.clear();
|
||||
}
|
||||
OpenPropertyMapper(prop) => self.selected_property = Some(prop),
|
||||
EditCustomProperty(prop_name) => self.custom_property_name = prop_name,
|
||||
SetupCustomProperty => {
|
||||
self.setup_mapping(self.custom_property_name.clone());
|
||||
}
|
||||
SetupDefaultProperty(prop_name) => {
|
||||
self.setup_mapping(prop_name);
|
||||
}
|
||||
SetupDirect => {
|
||||
self.setup_mapping(self.selected_property.clone().unwrap());
|
||||
}
|
||||
RemoveMapping(pro_name) => {
|
||||
self.remove_mapping(pro_name);
|
||||
}
|
||||
SwitchSkipEmpty(skip) => {
|
||||
self.skip_empty = skip;
|
||||
}
|
||||
EditSeparator(separator) => {
|
||||
self.separator = separator.clone();
|
||||
}
|
||||
StartImport => {
|
||||
self.progress = Some(Arc::new(Mutex::new(0.0)));
|
||||
return Task::batch([self.start_import(), self.next_progress()]);
|
||||
}
|
||||
NextProgress => {
|
||||
if self.progress.is_none() {
|
||||
return Task::none();
|
||||
}
|
||||
return self.next_progress();
|
||||
}
|
||||
ImportFinished => {
|
||||
self.progress = None;
|
||||
let group = &mut self.import_data.as_mut().unwrap().0[self.selected_index];
|
||||
group.imported = true;
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<'_, ImportMessage> {
|
||||
back_overlay(
|
||||
{
|
||||
if let Some(value) = &self.progress {
|
||||
column![progress_bar(0f32..=1f32, *value.lock().unwrap()),]
|
||||
.spacing(QUARTER_SPACING)
|
||||
.into()
|
||||
} else {
|
||||
scrollable(
|
||||
column![
|
||||
row![
|
||||
button("Выбрать файл").style(jl_button).on_press(SelectFile),
|
||||
text!("{}", {
|
||||
if let Some(path) = &self.path {
|
||||
path.to_string_lossy().to_string()
|
||||
} else {
|
||||
"Файл не выбран".to_string()
|
||||
}
|
||||
})
|
||||
]
|
||||
.align_y(Center)
|
||||
.spacing(DEFAULT_SPACING),
|
||||
self.selected_group()
|
||||
]
|
||||
.spacing(DEFAULT_SPACING),
|
||||
)
|
||||
.into()
|
||||
}
|
||||
},
|
||||
Back,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ImportState {
|
||||
fn selected_group(&self) -> Element<'_, ImportMessage> {
|
||||
if let Some(data) = &self.import_data {
|
||||
let group = &data.0[self.selected_index];
|
||||
return column![
|
||||
row![
|
||||
self.back_button(),
|
||||
space().width(Fill),
|
||||
text!("{}", group.name.clone()),
|
||||
space().width(Fill),
|
||||
self.next_button()
|
||||
]
|
||||
.width(Fill),
|
||||
text!("Количество карточек: {}", group.length),
|
||||
self.property_mapper(group),
|
||||
self.import_settings(),
|
||||
self.import_button(group),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.into();
|
||||
}
|
||||
space().into()
|
||||
}
|
||||
|
||||
fn import_button(&self, group: &ImportGroup) -> Element<'_, ImportMessage> {
|
||||
if group.imported {
|
||||
return container(text!("Группа слов успешно импортирована"))
|
||||
.padding(HALF_SPACING)
|
||||
.align_x(Center)
|
||||
.style(success)
|
||||
.width(Fill)
|
||||
.into();
|
||||
}
|
||||
button("Начать импорт")
|
||||
.style(cta_button)
|
||||
.on_press(StartImport)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn property_mapper(&self, group: &ImportGroup) -> Element<'_, ImportMessage> {
|
||||
column![
|
||||
self.property_list(group),
|
||||
rule::horizontal(2),
|
||||
self.property_selector()
|
||||
]
|
||||
.spacing(HALF_SPACING)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn property_list(&self, group: &ImportGroup) -> Element<'_, ImportMessage> {
|
||||
let mut row = Row::new();
|
||||
for prop in &group.fields {
|
||||
let primary_button_name = (*prop).clone();
|
||||
if let Some(mapped) = group.mapping.get(prop.clone().as_str()) {
|
||||
row = row.push(
|
||||
column![
|
||||
button(text!("{}", primary_button_name)),
|
||||
"↕",
|
||||
button(text!("{}", mapped))
|
||||
.style(danger)
|
||||
.on_press(RemoveMapping(mapped.as_str().to_string())),
|
||||
]
|
||||
.align_x(Center),
|
||||
);
|
||||
} else {
|
||||
row = row.push(
|
||||
button(text!("{}", primary_button_name))
|
||||
.on_press(OpenPropertyMapper(prop.clone())),
|
||||
);
|
||||
}
|
||||
}
|
||||
scrollable(row.spacing(HALF_SPACING).padding(Padding {
|
||||
top: 0.0,
|
||||
right: 0.0,
|
||||
bottom: DEFAULT_SPACING,
|
||||
left: 0.0,
|
||||
}))
|
||||
.horizontal()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn property_selector(&self) -> Element<'_, ImportMessage> {
|
||||
if self.selected_property.is_none() {
|
||||
return space().into();
|
||||
}
|
||||
column![
|
||||
self.available_properties(),
|
||||
button("Добавить напрямую").on_press(SetupDirect),
|
||||
row![
|
||||
text_input("Пользовательское поле", &self.custom_property_name)
|
||||
.on_input(EditCustomProperty),
|
||||
button("Установить привязку").on_press(SetupCustomProperty)
|
||||
]
|
||||
.spacing(QUARTER_SPACING)
|
||||
]
|
||||
.spacing(HALF_SPACING)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn available_properties(&self) -> Element<'_, ImportMessage> {
|
||||
let mut row = Row::new();
|
||||
|
||||
for default in DEFAULT_FIELDS {
|
||||
// if group.mapping.values().any(|name| name == default) {
|
||||
// continue;
|
||||
// }
|
||||
row = row.push(
|
||||
button(text!("{default}")).on_press(SetupDefaultProperty(default.to_string())),
|
||||
);
|
||||
}
|
||||
row.spacing(HALF_SPACING).into()
|
||||
}
|
||||
|
||||
fn import_settings(&self) -> Element<'_, ImportMessage> {
|
||||
column![
|
||||
checkbox(self.skip_empty)
|
||||
.label("Пропускать пустые строки")
|
||||
.on_toggle(SwitchSkipEmpty),
|
||||
column![
|
||||
text!("Разделитель при множественном объединении"),
|
||||
text_input("", &self.separator).on_input(EditSeparator)
|
||||
]
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn back_button(&self) -> Element<'_, ImportMessage> {
|
||||
let mut button = button("←").style(button::text);
|
||||
if self.selected_index > 0 {
|
||||
button = button.on_press(PreviousGroup);
|
||||
}
|
||||
button.into()
|
||||
}
|
||||
|
||||
fn next_button(&self) -> Element<'_, ImportMessage> {
|
||||
let mut button = button("→").style(button::text);
|
||||
if self.selected_index < self.import_data.as_ref().unwrap().0.len() - 1 {
|
||||
button = button.on_press(NextGroup);
|
||||
}
|
||||
button.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl ImportState {
|
||||
pub fn new(state: Arc<Mutex<AppState>>) -> ImportState {
|
||||
ImportState {
|
||||
state,
|
||||
path: None,
|
||||
import_data: None,
|
||||
selected_index: 0,
|
||||
selected_property: None,
|
||||
custom_property_name: "".to_string(),
|
||||
skip_empty: true,
|
||||
separator: ", ".to_string(),
|
||||
progress: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn select_import_file() -> Task<RootMessage> {
|
||||
Task::perform(
|
||||
async {
|
||||
let file = AsyncFileDialog::new()
|
||||
.add_filter("Anki", &["apkg"])
|
||||
.pick_file()
|
||||
.await;
|
||||
if let Some(file) = file {
|
||||
return Some(file.path().into());
|
||||
}
|
||||
None
|
||||
},
|
||||
|result| {
|
||||
if let Some(path) = result {
|
||||
RootMessage::Import(UpdateFile(path))
|
||||
} else {
|
||||
RootMessage::None
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn load_package(&self) -> Task<RootMessage> {
|
||||
let path = self.path.clone().unwrap();
|
||||
Task::perform(
|
||||
async {
|
||||
spawn_blocking(move || {
|
||||
Self::extract_import_file(path)?;
|
||||
let data = Self::read_import_file()?;
|
||||
Ok(data)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
},
|
||||
|result: Result<ImportData, ()>| {
|
||||
if let Ok(import) = result {
|
||||
RootMessage::Import(UpdateImport(import))
|
||||
} else {
|
||||
RootMessage::None
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn extract_import_file(path: PathBuf) -> Result<(), ()> {
|
||||
let file = File::open(path).map_err(|_| ())?;
|
||||
let reader = BufReader::new(file);
|
||||
let mut archive = ZipArchive::new(reader).map_err(|_| ())?;
|
||||
let temp_file_path = app_data_dir().join("import");
|
||||
let mut temp_file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(&temp_file_path)
|
||||
.map_err(|_| ())?;
|
||||
if let Ok(mut file) = archive.by_name("collection.anki21") {
|
||||
std::io::copy(&mut file, &mut temp_file).map_err(|_| ())?;
|
||||
Ok(())
|
||||
} else if let Ok(mut file) = archive.by_name("collection.anki2") {
|
||||
std::io::copy(&mut file, &mut temp_file).map_err(|_| ())?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
fn read_import_file() -> Result<ImportData, ()> {
|
||||
let temp_file_path = app_data_dir().join("import");
|
||||
let connection = Connection::open(&temp_file_path).map_err(|_| ())?;
|
||||
let data = load_groups(&connection);
|
||||
Ok(data)
|
||||
}
|
||||
fn setup_mapping(&mut self, property_name: String) {
|
||||
let group = self.import_data.as_mut().unwrap();
|
||||
let group = &mut group.0[self.selected_index];
|
||||
group
|
||||
.mapping
|
||||
.insert(self.selected_property.clone().unwrap(), property_name);
|
||||
self.selected_property = None;
|
||||
self.custom_property_name.clear();
|
||||
}
|
||||
fn remove_mapping(&mut self, property_name: String) {
|
||||
let group = self.import_data.as_mut().unwrap();
|
||||
let group = &mut group.0[self.selected_index];
|
||||
let remove_key = group
|
||||
.mapping
|
||||
.keys()
|
||||
.find(|key| group.mapping[*key] == property_name)
|
||||
.unwrap();
|
||||
group.mapping.remove(remove_key.clone().as_str());
|
||||
self.selected_property = None;
|
||||
self.custom_property_name.clear();
|
||||
}
|
||||
|
||||
fn start_import(&self) -> Task<RootMessage> {
|
||||
let state = self.state.clone();
|
||||
let separator = self.separator.clone();
|
||||
let skip_empty = self.skip_empty;
|
||||
let group = self.import_data.as_ref().unwrap().0[self.selected_index].clone();
|
||||
let progress = self.progress.clone().unwrap();
|
||||
println!("{}", group.name);
|
||||
Task::perform(
|
||||
async move {
|
||||
spawn_blocking(move || {
|
||||
let temp_file_path = app_data_dir().join("import");
|
||||
let connection = Connection::open(&temp_file_path).map_err(|_| ())?;
|
||||
let import_list = get_words_of_group(&connection, group.id);
|
||||
let mut words_list = Vec::with_capacity(import_list.len());
|
||||
|
||||
let map_indices = Self::get_mapping_indices(&group);
|
||||
let mut group_entity = WordGroup {
|
||||
id: 0.into(),
|
||||
name: group.name.clone(),
|
||||
};
|
||||
{
|
||||
let state = state.lock().unwrap();
|
||||
add_group(&mut group_entity, &state.connection);
|
||||
}
|
||||
|
||||
let group_id = group_entity.id;
|
||||
for import in import_list {
|
||||
let mut word = WordData::new();
|
||||
|
||||
word.tags = import.tags.trim().replace(" ", ", ");
|
||||
word.group_id = group_id;
|
||||
for (dest, indices) in &map_indices {
|
||||
let collected_string = Self::collect_strings(
|
||||
&import.fields,
|
||||
indices,
|
||||
&separator,
|
||||
skip_empty,
|
||||
);
|
||||
match dest.as_str() {
|
||||
"key" => {
|
||||
word.key = collected_string;
|
||||
}
|
||||
"value" => {
|
||||
word.value = collected_string;
|
||||
}
|
||||
"tags" => {
|
||||
word.tags = collected_string;
|
||||
}
|
||||
&_ => {
|
||||
word.additional.insert((*dest).clone(), collected_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
words_list.push(word);
|
||||
}
|
||||
|
||||
let mut state = state.lock().unwrap();
|
||||
let connection = &mut state.connection;
|
||||
let mut index = 0;
|
||||
let total_len = words_list.len() as f32 / 1024.0;
|
||||
for word in &mut words_list.chunks_mut(1024) {
|
||||
add_words(word, connection);
|
||||
index += 1;
|
||||
let mut progress = progress.lock().unwrap();
|
||||
*progress = index as f32 / total_len;
|
||||
}
|
||||
|
||||
state.dictionary.append(&mut words_list);
|
||||
state.word_groups.push(group_entity);
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
},
|
||||
|_: Result<(), ()>| RootMessage::Import(ImportFinished),
|
||||
)
|
||||
}
|
||||
|
||||
fn get_mapping_indices(group: &ImportGroup) -> Vec<(String, Vec<usize>)> {
|
||||
let mut final_props = group.mapping.values().cloned().collect::<Vec<_>>();
|
||||
final_props.sort();
|
||||
final_props.dedup();
|
||||
let mut result = final_props
|
||||
.iter()
|
||||
.map(|name| (name.clone(), Vec::<usize>::with_capacity(1)))
|
||||
.collect::<Vec<_>>();
|
||||
for (key, endpoint) in &group.mapping {
|
||||
let property_index = group.fields.iter().position(|f| f == key).expect("Unknown property");
|
||||
let group_index = result
|
||||
.iter()
|
||||
.position(|(name, _)| name == endpoint)
|
||||
.unwrap();
|
||||
result[group_index].1.push(property_index);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
fn collect_strings(
|
||||
properties: &[String],
|
||||
indices: &[usize],
|
||||
separator: &str,
|
||||
skip_empty: bool,
|
||||
) -> String {
|
||||
let mut working_words = Vec::with_capacity(indices.len());
|
||||
for index in indices {
|
||||
let str = &properties[*index];
|
||||
if skip_empty && str.is_empty() {
|
||||
continue;
|
||||
}
|
||||
working_words.push(str.as_str());
|
||||
}
|
||||
|
||||
working_words.join(separator)
|
||||
}
|
||||
|
||||
fn next_progress(&self) -> Task<RootMessage> {
|
||||
Task::perform(
|
||||
async {
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
|
||||
},
|
||||
|_| RootMessage::Import(NextProgress),
|
||||
)
|
||||
}
|
||||
}
|
||||
+207
-121
@@ -1,18 +1,23 @@
|
||||
use crate::data_provider::card_stats::{
|
||||
add_stat_list, delete_stat, load_stats_of_set, update_stat_score,
|
||||
};
|
||||
use crate::data_provider::history::{push_note, HistoryItem};
|
||||
use crate::repetitions::CardSetSettings;
|
||||
use crate::AppState;
|
||||
use crate::data_provider::card_stats::{delete_stat, load_stats_of_deck, update_stat_score};
|
||||
use crate::data_provider::history::{HistoryItem, push_note};
|
||||
use chrono::{DateTime, Utc};
|
||||
use rand::distr::weighted::WeightedIndex;
|
||||
use rand::distr::Distribution;
|
||||
use rand::distr::weighted::WeightedIndex;
|
||||
use rand::prelude::SliceRandom;
|
||||
use rand::rng;
|
||||
use rand::rngs::ThreadRng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::min;
|
||||
use rayon::iter::IndexedParallelIterator;
|
||||
use rayon::iter::IntoParallelRefIterator;
|
||||
use rayon::iter::ParallelIterator;
|
||||
use rhai::{Engine, Scope};
|
||||
use rusqlite::ToSql;
|
||||
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef};
|
||||
use std::cmp::PartialEq;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::num::ParseIntError;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Instant;
|
||||
|
||||
@@ -20,6 +25,55 @@ const MAX_HISTORY_LEN: usize = 20;
|
||||
const MAX_HISTORY_LEN_PART: f32 = 0.33;
|
||||
const MAX_SCORE: u8 = 25;
|
||||
const FADE_PER_DAY: f32 = 0.95;
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Hash, Copy)]
|
||||
pub struct Id(u32);
|
||||
pub const INVALID_ID: Id = Id(0);
|
||||
impl FromStr for Id {
|
||||
type Err = ParseIntError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(Id(s.parse::<u32>()?))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for Id {
|
||||
fn from(value: u32) -> Self {
|
||||
Id(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<u32> for Id {
|
||||
fn into(self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
impl Display for Id {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromSql for Id {
|
||||
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
|
||||
match value {
|
||||
ValueRef::Integer(i) => Ok(Id(i as u32)),
|
||||
_ => Err(FromSqlError::InvalidType),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToSql for Id {
|
||||
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput<'_>> {
|
||||
Ok(ToSqlOutput::from(self.0 as i64))
|
||||
}
|
||||
}
|
||||
|
||||
impl Id {
|
||||
pub(crate) fn is_valid(self) -> bool {
|
||||
self.0 != 0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct KanaSet {
|
||||
name: String,
|
||||
@@ -27,13 +81,11 @@ pub struct KanaSet {
|
||||
pub(crate) dictionary: Vec<Vec<(String, String)>>,
|
||||
pub(crate) include_map: [bool; 10],
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum KanaType {
|
||||
Hiragana,
|
||||
Katakana,
|
||||
}
|
||||
|
||||
impl KanaSet {
|
||||
pub fn hiragana() -> Self {
|
||||
Self {
|
||||
@@ -199,14 +251,6 @@ impl KanaSet {
|
||||
}
|
||||
}
|
||||
|
||||
/* pub fn next(&mut self) -> (String, String) {
|
||||
let current_set = self.list();
|
||||
|
||||
let mut rand = rand::rng();
|
||||
let index: u32 = rand.random();
|
||||
current_set[index as usize % current_set.len()].clone()
|
||||
}*/
|
||||
|
||||
pub fn list(&self) -> Vec<(String, String)> {
|
||||
let mut current_set: Vec<(String, String)> = Vec::new();
|
||||
|
||||
@@ -221,7 +265,6 @@ impl KanaSet {
|
||||
current_set
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for KanaSet {
|
||||
fn default() -> Self {
|
||||
KanaSet::hiragana()
|
||||
@@ -232,45 +275,40 @@ impl PartialEq<Self> for KanaSet {
|
||||
self.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct WordData {
|
||||
pub id: u32,
|
||||
pub id: Id,
|
||||
pub key: String,
|
||||
pub value: String,
|
||||
pub tags: String,
|
||||
pub additional: HashMap<String, String>,
|
||||
pub group_id: u32,
|
||||
pub group_id: Id,
|
||||
}
|
||||
|
||||
impl WordData {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
id: 0,
|
||||
id: INVALID_ID,
|
||||
key: String::new(),
|
||||
value: String::new(),
|
||||
tags: String::new(),
|
||||
additional: Default::default(),
|
||||
group_id: 1,
|
||||
group_id: 1.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct WordGroup {
|
||||
pub id: u32,
|
||||
pub id: Id,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct CardStatistics {
|
||||
pub id: u32,
|
||||
pub word_id: u32,
|
||||
pub set_id: u32,
|
||||
pub id: Id,
|
||||
pub word_id: Id,
|
||||
pub set_id: Id,
|
||||
pub last_open: DateTime<Utc>,
|
||||
pub score: u8,
|
||||
}
|
||||
|
||||
impl CardStatistics {
|
||||
pub fn update(&mut self, status: WordOpenMode) {
|
||||
match status {
|
||||
@@ -286,11 +324,7 @@ impl CardStatistics {
|
||||
}
|
||||
}
|
||||
|
||||
if self.score < 1 {
|
||||
self.score = 1
|
||||
} else if self.score > MAX_SCORE {
|
||||
self.score = MAX_SCORE
|
||||
}
|
||||
self.score = self.score.clamp(1, MAX_SCORE);
|
||||
self.last_open = Utc::now();
|
||||
}
|
||||
|
||||
@@ -301,7 +335,6 @@ impl CardStatistics {
|
||||
(self.score as f32 * multiplier).max(1.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum WordOpenMode {
|
||||
Easy,
|
||||
@@ -309,51 +342,29 @@ pub enum WordOpenMode {
|
||||
Hard,
|
||||
None,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CardSet {
|
||||
pub struct DeckData {
|
||||
words: Vec<WordData>,
|
||||
set: Vec<CardStatistics>,
|
||||
current_word_index: Option<usize>,
|
||||
state: Arc<Mutex<AppState>>,
|
||||
order_module: OrderModule,
|
||||
settings: CardSetSettings,
|
||||
settings: DeckSettings,
|
||||
}
|
||||
|
||||
impl CardSet {
|
||||
pub fn new(settings: &CardSetSettings, state: Arc<Mutex<AppState>>) -> Self {
|
||||
impl DeckData {
|
||||
pub fn new(settings: &DeckSettings, state: Arc<Mutex<AppState>>) -> Self {
|
||||
let state_for = state.clone();
|
||||
let state_locked = state.lock().unwrap();
|
||||
|
||||
let mut current_set = load_stats_of_set(&settings, &state_locked.connection);
|
||||
let last_list = settings.get_word_list(&state_locked);
|
||||
let saved_ids = current_set.iter().map(|l| l.word_id).collect::<Vec<u32>>();
|
||||
let word_ids = last_list.iter().map(|l| l.id).collect::<Vec<u32>>();
|
||||
|
||||
let new_stats: &mut Vec<CardStatistics> = &mut last_list
|
||||
let mut current_set = load_stats_of_deck(settings, &state_locked.connection);
|
||||
let last_list: Vec<_> = settings
|
||||
.get_word_list(&state_locked)
|
||||
.iter()
|
||||
.filter(|word| !saved_ids.contains(&word.id))
|
||||
.map(|word| CardStatistics {
|
||||
id: 0,
|
||||
word_id: word.id.clone(),
|
||||
last_open: Utc::now(),
|
||||
score: 1,
|
||||
set_id: settings.id.clone(),
|
||||
})
|
||||
.map(|w| &state_locked.dictionary[*w])
|
||||
.cloned()
|
||||
.collect();
|
||||
let word_ids = last_list.iter().map(|l| l.id).collect::<Vec<Id>>();
|
||||
|
||||
let time = Instant::now();
|
||||
|
||||
if !new_stats.is_empty() {
|
||||
add_stat_list(new_stats, &state_locked.connection);
|
||||
current_set.append(new_stats);
|
||||
}
|
||||
|
||||
println!(
|
||||
"Added {} stats: {}",
|
||||
new_stats.len(),
|
||||
time.elapsed().as_millis()
|
||||
);
|
||||
let mut index = 0;
|
||||
for stat in current_set.clone() {
|
||||
if !word_ids.contains(&stat.word_id) {
|
||||
@@ -370,20 +381,19 @@ impl CardSet {
|
||||
current_word_index: None,
|
||||
state: state_for,
|
||||
order_module: match settings.open_mode {
|
||||
SetOrderMode::Default => OrderModule::SemiRandomSRS(SemiRandomSRSModule::new()),
|
||||
SetOrderMode::TrainWorstFirst => {
|
||||
OrderMode::Default => OrderModule::SemiRandomSRS(SemiRandomSRSModule::new()),
|
||||
OrderMode::TrainWorstFirst => {
|
||||
OrderModule::WorstWordsSRS(WorstWordsSRSModule::new())
|
||||
}
|
||||
SetOrderMode::FullRandom => OrderModule::RandomSRS(RandomSRSModule::new()),
|
||||
OrderMode::FullRandom => OrderModule::RandomSRS(RandomSRSModule::new()),
|
||||
},
|
||||
settings: settings.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn next(&mut self) -> (WordData, CardStatistics) {
|
||||
let index = match self.order_module.clone() {
|
||||
OrderModule::SemiRandomSRS(mut module) => {
|
||||
if module.initialized == false {
|
||||
if !module.initialized {
|
||||
module.init(self)
|
||||
}
|
||||
let index = module.next(self);
|
||||
@@ -391,7 +401,7 @@ impl CardSet {
|
||||
index
|
||||
}
|
||||
OrderModule::RandomSRS(mut module) => {
|
||||
if module.initialized == false {
|
||||
if !module.initialized {
|
||||
module.init(self)
|
||||
}
|
||||
let index = module.next(self);
|
||||
@@ -399,7 +409,7 @@ impl CardSet {
|
||||
index
|
||||
}
|
||||
OrderModule::WorstWordsSRS(mut module) => {
|
||||
if module.initialized == false {
|
||||
if !module.initialized {
|
||||
module.init(self)
|
||||
}
|
||||
let index = module.next(self);
|
||||
@@ -411,9 +421,8 @@ impl CardSet {
|
||||
self.current_word_index = Some(index);
|
||||
(self.words[index].clone(), self.set[index].clone())
|
||||
}
|
||||
|
||||
pub fn open(&mut self, status: WordOpenMode) {
|
||||
if let None = self.current_word_index {
|
||||
if self.current_word_index.is_none() {
|
||||
return;
|
||||
}
|
||||
let index = self.current_word_index.unwrap();
|
||||
@@ -443,44 +452,44 @@ impl CardSet {
|
||||
HistoryItem {
|
||||
timestamp: Utc::now(),
|
||||
word_id: word.word_id,
|
||||
mode: WordOpenMode::Easy,
|
||||
mode: status,
|
||||
before: old_score,
|
||||
after: new_score,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.set.len()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Copy, Eq)]
|
||||
pub enum SetOrderMode {
|
||||
pub enum OrderMode {
|
||||
Default,
|
||||
TrainWorstFirst,
|
||||
FullRandom,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Default)]
|
||||
pub enum AppendMode {
|
||||
Full,
|
||||
#[default]
|
||||
Manual,
|
||||
}
|
||||
#[derive(Clone)]
|
||||
enum OrderModule {
|
||||
SemiRandomSRS(SemiRandomSRSModule),
|
||||
RandomSRS(RandomSRSModule),
|
||||
WorstWordsSRS(WorstWordsSRSModule),
|
||||
}
|
||||
|
||||
trait SRSModule {
|
||||
fn next(&mut self, set: &mut CardSet) -> usize;
|
||||
fn next(&mut self, set: &mut DeckData) -> usize;
|
||||
fn open(&mut self, status: WordOpenMode, index: usize, updated_word: CardStatistics);
|
||||
fn init(&mut self, set: &mut CardSet);
|
||||
fn init(&mut self, set: &mut DeckData);
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct RandomSRSModule {
|
||||
basket: Vec<usize>,
|
||||
initialized: bool,
|
||||
}
|
||||
|
||||
impl RandomSRSModule {
|
||||
fn new() -> RandomSRSModule {
|
||||
Self {
|
||||
@@ -489,26 +498,26 @@ impl RandomSRSModule {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SRSModule for RandomSRSModule {
|
||||
fn next(&mut self, set: &mut CardSet) -> usize {
|
||||
if self.basket.is_empty() {
|
||||
fn next(&mut self, set: &mut DeckData) -> usize {
|
||||
match self.basket.pop() {
|
||||
Some(index) => index,
|
||||
None => {
|
||||
self.basket = (0..set.words.len()).collect::<Vec<usize>>();
|
||||
self.basket.shuffle(&mut rand::rng())
|
||||
self.basket.shuffle(&mut rand::rng());
|
||||
self.basket.pop().expect("empty basket")
|
||||
}
|
||||
}
|
||||
|
||||
self.basket.pop().unwrap()
|
||||
}
|
||||
|
||||
fn open(&mut self, _: WordOpenMode, _: usize, _: CardStatistics) {}
|
||||
|
||||
fn init(&mut self, set: &mut CardSet) {
|
||||
fn init(&mut self, set: &mut DeckData) {
|
||||
self.initialized = true;
|
||||
self.basket = (0..set.words.len()).collect::<Vec<usize>>();
|
||||
self.basket.shuffle(&mut rand::rng())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct SemiRandomSRSModule {
|
||||
history: Vec<usize>,
|
||||
@@ -516,7 +525,6 @@ struct SemiRandomSRSModule {
|
||||
generator: ThreadRng,
|
||||
initialized: bool,
|
||||
}
|
||||
|
||||
impl SemiRandomSRSModule {
|
||||
fn new() -> SemiRandomSRSModule {
|
||||
SemiRandomSRSModule {
|
||||
@@ -527,9 +535,8 @@ impl SemiRandomSRSModule {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SRSModule for SemiRandomSRSModule {
|
||||
fn next(&mut self, set: &mut CardSet) -> usize {
|
||||
fn next(&mut self, set: &mut DeckData) -> usize {
|
||||
let index = self.last_weights.sample(&mut self.generator);
|
||||
|
||||
if self.history.contains(&index) {
|
||||
@@ -543,15 +550,13 @@ impl SRSModule for SemiRandomSRSModule {
|
||||
|
||||
index
|
||||
}
|
||||
|
||||
fn open(&mut self, _: WordOpenMode, index: usize, word: CardStatistics) {
|
||||
let new_weight = (100.0 / word.calculated_score()).powf(2.0);
|
||||
self.last_weights
|
||||
.update_weights(&[(index, &new_weight)])
|
||||
.unwrap();
|
||||
.expect("update weights error");
|
||||
}
|
||||
|
||||
fn init(&mut self, set: &mut CardSet) {
|
||||
fn init(&mut self, set: &mut DeckData) {
|
||||
self.initialized = true;
|
||||
let weights = set
|
||||
.set
|
||||
@@ -561,16 +566,11 @@ impl SRSModule for SemiRandomSRSModule {
|
||||
self.last_weights = WeightedIndex::new(weights).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl SemiRandomSRSModule {
|
||||
fn history_len(&self, set: &CardSet) -> usize {
|
||||
min(
|
||||
MAX_HISTORY_LEN,
|
||||
(set.len() as f32 * MAX_HISTORY_LEN_PART) as usize,
|
||||
)
|
||||
fn history_len(&self, set: &DeckData) -> usize {
|
||||
((set.len() as f32 * MAX_HISTORY_LEN_PART) as usize).clamp(1, MAX_HISTORY_LEN)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct WorstWordsSRSModule {
|
||||
initialized: bool,
|
||||
@@ -580,29 +580,31 @@ struct WorstWordsSRSModule {
|
||||
queue: Vec<usize>,
|
||||
rounds_count: u8,
|
||||
}
|
||||
|
||||
impl SRSModule for WorstWordsSRSModule {
|
||||
fn next(&mut self, set: &mut CardSet) -> usize {
|
||||
fn next(&mut self, set: &mut DeckData) -> usize {
|
||||
if self.rounds_remaining == 0 {
|
||||
self.fill_pool(set);
|
||||
self.rounds_remaining = self.rounds_count;
|
||||
}
|
||||
|
||||
if self.queue.is_empty() {
|
||||
match self.queue.pop() {
|
||||
Some(index) => {
|
||||
index
|
||||
}
|
||||
None => {
|
||||
self.queue.append(&mut self.pool.clone());
|
||||
self.rounds_remaining -= 1;
|
||||
self.queue.pop().expect("empty queue")
|
||||
}
|
||||
}
|
||||
|
||||
self.queue.pop().unwrap()
|
||||
}
|
||||
|
||||
fn open(&mut self, _: WordOpenMode, _: usize, _: CardStatistics) {}
|
||||
|
||||
fn init(&mut self, _: &mut CardSet) {
|
||||
fn init(&mut self, _: &mut DeckData) {
|
||||
self.initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
impl WorstWordsSRSModule {
|
||||
fn new() -> WorstWordsSRSModule {
|
||||
WorstWordsSRSModule {
|
||||
@@ -614,8 +616,7 @@ impl WorstWordsSRSModule {
|
||||
queue: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn fill_pool(&mut self, set: &CardSet) {
|
||||
fn fill_pool(&mut self, set: &DeckData) {
|
||||
let mut sorted = set
|
||||
.set
|
||||
.clone()
|
||||
@@ -631,3 +632,88 @@ impl WorstWordsSRSModule {
|
||||
self.pool = worst;
|
||||
}
|
||||
}
|
||||
#[derive(Clone)]
|
||||
pub struct DeckSettings {
|
||||
pub id: Id,
|
||||
pub name: String,
|
||||
pub forward: String,
|
||||
pub backward: String,
|
||||
pub filter: String,
|
||||
pub count: Option<usize>,
|
||||
pub worst_words_list: Option<Vec<WordData>>,
|
||||
pub open_mode: OrderMode,
|
||||
}
|
||||
impl DeckSettings {
|
||||
pub(crate) fn with_name(name: String) -> DeckSettings {
|
||||
DeckSettings {
|
||||
id: 0.into(),
|
||||
name,
|
||||
forward: "".to_string(),
|
||||
backward: "".to_string(),
|
||||
filter: "true".to_string(),
|
||||
count: None,
|
||||
worst_words_list: None,
|
||||
open_mode: OrderMode::Default,
|
||||
}
|
||||
}
|
||||
pub fn check_filter(&self) -> bool {
|
||||
let time = Instant::now();
|
||||
let engine = Engine::new();
|
||||
let ast = engine.compile(&self.filter);
|
||||
println!("Compile time is {:?}", time.elapsed());
|
||||
ast.is_ok()
|
||||
}
|
||||
pub fn get_word_list(&self, state: &AppState) -> Vec<usize> {
|
||||
let time = Instant::now();
|
||||
let mut list = vec![];
|
||||
let engine = Engine::new();
|
||||
|
||||
let ast = engine.compile(&self.filter);
|
||||
if ast.is_err() {
|
||||
return list;
|
||||
}
|
||||
|
||||
let ast = ast.unwrap();
|
||||
|
||||
let groups = &state.word_groups;
|
||||
|
||||
list = state
|
||||
.dictionary
|
||||
.par_iter()
|
||||
.enumerate()
|
||||
.filter(|(_, word)| {
|
||||
let mut more = rhai::Map::new();
|
||||
for iced in &word.additional {
|
||||
more.insert(iced.0.clone().into(), iced.1.clone().into());
|
||||
}
|
||||
let mut scope = Scope::new();
|
||||
scope
|
||||
.push_constant("id", word.id.0)
|
||||
.push_constant("key", word.key.clone())
|
||||
.push_constant("value", word.value.clone())
|
||||
.push_constant("tags", word.tags.clone())
|
||||
.push_constant("more", more)
|
||||
.push_constant(
|
||||
"group",
|
||||
groups
|
||||
.iter()
|
||||
.find(|g| g.id == word.group_id)
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.name,
|
||||
);
|
||||
|
||||
let result = engine.eval_ast_with_scope::<bool>(&mut scope, &ast);
|
||||
result.is_ok() && result.unwrap()
|
||||
})
|
||||
.map(|(index, _)| index)
|
||||
.collect();
|
||||
|
||||
println!("Collecting available words is {:?}", time.elapsed());
|
||||
|
||||
list
|
||||
}
|
||||
pub fn require_speech(&self) -> bool {
|
||||
self.forward == "speech" || self.backward == "speech"
|
||||
}
|
||||
}
|
||||
|
||||
+55
-27
@@ -3,50 +3,47 @@ mod data_provider;
|
||||
mod dictionary;
|
||||
mod dictionary_test;
|
||||
mod history;
|
||||
pub mod import;
|
||||
mod lang;
|
||||
pub mod navigation;
|
||||
mod quiz;
|
||||
mod randomizer;
|
||||
mod repetition;
|
||||
mod repetition_settings;
|
||||
mod repetitions;
|
||||
mod selector;
|
||||
pub mod styling;
|
||||
mod sync;
|
||||
mod word;
|
||||
mod writing;
|
||||
mod repetition_settings;
|
||||
|
||||
use crate::RootMessage::Keyboard;
|
||||
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::{WordData, WordGroup};
|
||||
use crate::lang::{DeckSettings, Id, WordData, WordGroup};
|
||||
use crate::navigation::{AppSettings, RootMessage, ScreenState};
|
||||
use crate::quiz::*;
|
||||
use crate::repetitions::CardSetSettings;
|
||||
use crate::RootMessage::Keyboard;
|
||||
use chrono::NaiveDate;
|
||||
use iced::{keyboard, Subscription, Theme};
|
||||
use iced::{window, Font};
|
||||
use iced_core::window::Position;
|
||||
use hashbrown::HashMap;
|
||||
use iced::{Font, window};
|
||||
use iced::{Subscription, Theme, keyboard};
|
||||
use iced_core::Size;
|
||||
use iced_core::window::Position;
|
||||
use mimalloc::MiMalloc;
|
||||
use rusqlite::Connection;
|
||||
use std::collections::HashMap;
|
||||
#[cfg(target_os = "linux")]
|
||||
use iced_core::window::settings::PlatformSpecific;
|
||||
#[global_allocator]
|
||||
static GLOBAL: MiMalloc = MiMalloc;
|
||||
|
||||
const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
||||
|
||||
fn main() -> iced::Result {
|
||||
println!("Welcome to JapLearn");
|
||||
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view).window(window::Settings{
|
||||
position: Position::Centered,
|
||||
min_size: Some(Size::new(700.0_f32.into(), 700.0_f32.into())),
|
||||
platform_specific: PlatformSpecific {
|
||||
application_id: "JapLearn".to_string(),
|
||||
override_redirect: false
|
||||
},
|
||||
.. Default::default()
|
||||
})
|
||||
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view)
|
||||
.window(window_settings())
|
||||
.subscription(subscription)
|
||||
.title("JapLearn")
|
||||
.settings(iced::Settings {
|
||||
@@ -59,29 +56,54 @@ fn main() -> iced::Result {
|
||||
.run()
|
||||
}
|
||||
|
||||
fn window_settings() -> window::Settings {
|
||||
let mut settings = window::Settings {
|
||||
position: Position::Centered,
|
||||
min_size: Some(Size::new(700.0_f32, 700.0_f32)),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
settings.platform_specific = PlatformSpecific {
|
||||
application_id: "JapLearn".to_string(),
|
||||
override_redirect: false,
|
||||
};
|
||||
}
|
||||
|
||||
settings
|
||||
}
|
||||
|
||||
fn subscription(_state: &ScreenState) -> Subscription<RootMessage> {
|
||||
keyboard::listen().map(|e| Keyboard(e))
|
||||
keyboard::listen().map(Keyboard)
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
pub dictionary: Vec<WordData>,
|
||||
pub card_sets: Vec<CardSetSettings>,
|
||||
pub decks: Vec<DeckSettings>,
|
||||
pub word_groups: Vec<WordGroup>,
|
||||
pub connection: Connection,
|
||||
pub sync_data: AppSettings,
|
||||
pub activity: HashMap<u32, Vec<(NaiveDate, u32)>>
|
||||
pub activity: HashMap<Id, Vec<(NaiveDate, u32)>>,
|
||||
}
|
||||
|
||||
impl Default for AppState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new() -> Self {
|
||||
|
||||
|
||||
Self {
|
||||
dictionary: vec![],
|
||||
card_sets: vec![],
|
||||
decks: vec![],
|
||||
word_groups: vec![],
|
||||
connection: default_connection(),
|
||||
sync_data: AppSettings { key: None, auto_web_fetch: false },
|
||||
sync_data: AppSettings {
|
||||
key: None,
|
||||
auto_web_fetch: false,
|
||||
},
|
||||
activity: Default::default(),
|
||||
}
|
||||
}
|
||||
@@ -94,13 +116,19 @@ fn fill_state(state: &mut AppState) {
|
||||
let setting = load_settings(&state.connection);
|
||||
|
||||
state.dictionary = list;
|
||||
state.card_sets = sets;
|
||||
state.decks = sets;
|
||||
state.word_groups = groups;
|
||||
state.sync_data = setting
|
||||
}
|
||||
|
||||
fn load_settings(connection: &Connection) -> AppSettings {
|
||||
let key = get_setting("SYNC_KEY".to_string(), connection);
|
||||
let fetch = get_setting("AUTO_WEB_FETCH".to_string(), connection).unwrap_or("false".to_string()).parse::<bool>().unwrap();
|
||||
AppSettings { key, auto_web_fetch: fetch }
|
||||
let fetch = get_setting("AUTO_WEB_FETCH".to_string(), connection)
|
||||
.unwrap_or("false".to_string())
|
||||
.parse::<bool>()
|
||||
.unwrap();
|
||||
AppSettings {
|
||||
key,
|
||||
auto_web_fetch: fetch,
|
||||
}
|
||||
}
|
||||
|
||||
+38
-16
@@ -1,9 +1,13 @@
|
||||
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::data_provider::web_api::{
|
||||
get_local_version, get_web_version, load_data, set_local_version,
|
||||
};
|
||||
use crate::dictionary::{app_data_dir, DictionaryMessage, DictionaryState};
|
||||
use crate::dictionary_test::{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};
|
||||
@@ -19,12 +23,13 @@ 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::{Element, Task};
|
||||
use reqwest::Error;
|
||||
use std::collections::HashMap;
|
||||
use rusqlite::Connection;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Instant;
|
||||
|
||||
@@ -54,8 +59,9 @@ pub enum RootMessage {
|
||||
Sync(SyncMessage),
|
||||
History(HistoryMessage),
|
||||
RepetitionSettings(RepetitionSettingsMessage),
|
||||
Import(ImportMessage),
|
||||
Keyboard(Event),
|
||||
DataLoaded(HashMap<u32, Vec<(NaiveDate, u32)>>),
|
||||
DataLoaded(HashMap<Id, Vec<(NaiveDate, u32)>>),
|
||||
None,
|
||||
UpdateData,
|
||||
}
|
||||
@@ -73,7 +79,7 @@ pub enum Page {
|
||||
Sync(SyncState),
|
||||
History(HistoryState),
|
||||
RepetitionSettings(RepetitionSettingsState),
|
||||
|
||||
Import(ImportState),
|
||||
PreviousPage,
|
||||
}
|
||||
|
||||
@@ -97,7 +103,9 @@ impl ScreenState {
|
||||
final_task = Task::batch([
|
||||
reading_additional_task,
|
||||
Task::perform(Self::load_web_backup(key), |result| {
|
||||
if let Ok(update) = result && update {
|
||||
if let Ok(update) = result
|
||||
&& update
|
||||
{
|
||||
UpdateData
|
||||
} else {
|
||||
RootMessage::None
|
||||
@@ -116,12 +124,15 @@ impl ScreenState {
|
||||
async fn load_additional_data() -> RootMessage {
|
||||
let directory = history_dir();
|
||||
let mut map = HashMap::new();
|
||||
for file in directory.read_dir().unwrap() {
|
||||
if let Ok(file) = file {
|
||||
for file in directory.read_dir().unwrap().flatten() {
|
||||
let mut vec = vec![];
|
||||
let history_file_name = file.file_name().into_string().unwrap();
|
||||
let id = history_file_name[4..history_file_name.len() - 12]
|
||||
.parse::<u32>()
|
||||
let history_file_name = match file.file_name().into_string() {
|
||||
Err(_) => continue,
|
||||
Ok(v) => v,
|
||||
};
|
||||
|
||||
let id: Id = history_file_name[4..history_file_name.len() - 12]
|
||||
.parse::<Id>()
|
||||
.unwrap();
|
||||
|
||||
let history = get_history_of_set(id);
|
||||
@@ -133,13 +144,13 @@ impl ScreenState {
|
||||
}
|
||||
map.insert(id, vec);
|
||||
}
|
||||
}
|
||||
DataLoaded(map)
|
||||
}
|
||||
|
||||
async fn load_web_backup(string: String) -> Result<bool, Error> {
|
||||
let local = get_local_version().await;
|
||||
let web = get_web_version(string.as_str()).await?;
|
||||
println!("{} {}", local, web);
|
||||
if web > local {
|
||||
println!("Web version is newer than local version");
|
||||
load_data(string, true).await;
|
||||
@@ -165,6 +176,9 @@ impl ScreenState {
|
||||
if let UpdateData = message {
|
||||
println!("Loading data");
|
||||
let mut state = self.app_state.lock().unwrap();
|
||||
if cfg!(windows) {
|
||||
state.connection = Connection::open_in_memory().unwrap();
|
||||
}
|
||||
let path = app_data_dir();
|
||||
let db_file = path.join("data.db");
|
||||
let temp_db_file = path.join("data.db.tmp");
|
||||
@@ -190,7 +204,8 @@ impl ScreenState {
|
||||
Word,
|
||||
Sync,
|
||||
History,
|
||||
RepetitionSettings
|
||||
RepetitionSettings,
|
||||
Import
|
||||
);
|
||||
}
|
||||
println!("Update took {:?}", time.elapsed());
|
||||
@@ -213,7 +228,8 @@ impl ScreenState {
|
||||
Word,
|
||||
Sync,
|
||||
History,
|
||||
RepetitionSettings
|
||||
RepetitionSettings,
|
||||
Import
|
||||
)
|
||||
}
|
||||
|
||||
@@ -233,7 +249,8 @@ impl ScreenState {
|
||||
Word,
|
||||
Sync,
|
||||
History,
|
||||
RepetitionSettings
|
||||
RepetitionSettings,
|
||||
Import
|
||||
);
|
||||
|
||||
println!("View took {:?}", time.elapsed());
|
||||
@@ -290,7 +307,10 @@ macro_rules! message_navigation {
|
||||
($msg:expr, $stack:expr, $state:expr) => {
|
||||
if let Some(new_page) = $state.navigate(&$msg) {
|
||||
if let Page::PreviousPage = new_page {
|
||||
if $stack.len() > 1 {
|
||||
$stack.pop();
|
||||
}
|
||||
|
||||
return (Task::<RootMessage>::none(), true);
|
||||
} else {
|
||||
$stack.push(new_page);
|
||||
@@ -318,8 +338,10 @@ macro_rules! state_navigate_handle {
|
||||
}
|
||||
|
||||
pub trait NavigatedPage<T> {
|
||||
fn navigate(&self, message: &T) -> Option<Page>;
|
||||
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 {
|
||||
|
||||
+78
-74
@@ -5,7 +5,7 @@ use crate::quiz::QuizMessage::*;
|
||||
use crate::styling::*;
|
||||
use crate::{RootMessage, USER_FONT};
|
||||
use iced::widget::*;
|
||||
use iced::{alignment, Element, Fill, Task};
|
||||
use iced::{Element, Fill, Task, alignment};
|
||||
use rand::seq::SliceRandom;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -20,7 +20,7 @@ pub struct QuizState {
|
||||
}
|
||||
|
||||
impl NavigatedPage<QuizMessage> for QuizState {
|
||||
fn navigate(&self, message: &QuizMessage) -> Option<Page> {
|
||||
fn navigate(&mut self, message: &QuizMessage) -> Option<Page> {
|
||||
if let Back = message {
|
||||
Some(PreviousPage)
|
||||
} else {
|
||||
@@ -28,8 +28,83 @@ impl NavigatedPage<QuizMessage> for QuizState {
|
||||
}
|
||||
}
|
||||
|
||||
fn navigated(&mut self) {
|
||||
fn navigated(&mut self) {}
|
||||
|
||||
fn update(&mut self, message: QuizMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
ContentChanged(content) => {
|
||||
if content.contains("`") {
|
||||
self.is_help = true;
|
||||
self.score.fail += 1;
|
||||
|
||||
return Task::none();
|
||||
}
|
||||
self.current_roman = content;
|
||||
if self.correct_roman == self.current_roman {
|
||||
if !self.is_help {
|
||||
self.score.correct += 1;
|
||||
}
|
||||
|
||||
self.is_help = false;
|
||||
self.score.total += 1;
|
||||
self.update_showed()
|
||||
} else if self.current_roman.len() == self.correct_roman.len() {
|
||||
self.score.total += 1;
|
||||
self.score.fail += 1;
|
||||
self.update_showed()
|
||||
}
|
||||
}
|
||||
Back => {},
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<'_, QuizMessage> {
|
||||
container(
|
||||
iced::widget::column![
|
||||
row![
|
||||
text!("{}", self.kana.to_lowercase())
|
||||
.size(54)
|
||||
.font(USER_FONT),
|
||||
text!(
|
||||
"{}",
|
||||
if self.is_help {
|
||||
self.correct_roman.clone()
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
),
|
||||
]
|
||||
.align_y(alignment::Vertical::Center)
|
||||
.spacing(20),
|
||||
text_input("Романдзи", &self.current_roman)
|
||||
.size(28)
|
||||
.width(150)
|
||||
.on_input(ContentChanged),
|
||||
score_display(&self.score),
|
||||
button("Закончить").style(jl_button).on_press(Back),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.align_x(alignment::Horizontal::Center),
|
||||
)
|
||||
.center_y(Fill)
|
||||
.center_x(Fill)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
fn score_display<'a, T: 'a>(score: &Score) -> Element<'a, T> {
|
||||
row![
|
||||
text!("{}", score.total.to_string()).size(25),
|
||||
text!("{}", score.correct.to_string())
|
||||
.size(25)
|
||||
.color(iced::Color::from_rgb8(60, 170, 60)),
|
||||
text!("{}", score.fail.to_string())
|
||||
.color(iced::Color::from_rgb8(255, 79, 0))
|
||||
.size(25),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.into()
|
||||
}
|
||||
|
||||
impl QuizState {
|
||||
@@ -57,35 +132,6 @@ impl Default for QuizState {
|
||||
}
|
||||
|
||||
impl QuizState {
|
||||
pub fn update(&mut self, message: QuizMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
ContentChanged(content) => {
|
||||
if content.contains("`") {
|
||||
self.is_help = true;
|
||||
self.score.fail += 1;
|
||||
|
||||
return Task::none();
|
||||
}
|
||||
self.current_roman = content;
|
||||
if self.correct_roman == self.current_roman {
|
||||
if self.is_help == false {
|
||||
self.score.correct += 1;
|
||||
}
|
||||
|
||||
self.is_help = false;
|
||||
self.score.total += 1;
|
||||
self.update_showed()
|
||||
} else if self.current_roman.len() == self.correct_roman.len() {
|
||||
self.score.total += 1;
|
||||
self.score.fail += 1;
|
||||
self.update_showed()
|
||||
}
|
||||
}
|
||||
Back => todo!(),
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn update_showed(&mut self) {
|
||||
self.current_roman = String::new();
|
||||
let queue = &mut self.queue;
|
||||
@@ -102,48 +148,6 @@ impl QuizState {
|
||||
self.kana = pair.0;
|
||||
self.correct_roman = pair.1;
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, QuizMessage> {
|
||||
container(
|
||||
iced::widget::column![
|
||||
row![
|
||||
text!("{}", self.kana.to_lowercase())
|
||||
.size(54)
|
||||
.font(USER_FONT),
|
||||
text!(
|
||||
"{}",
|
||||
if self.is_help {
|
||||
self.correct_roman.clone()
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
),
|
||||
]
|
||||
.align_y(alignment::Vertical::Center)
|
||||
.spacing(20),
|
||||
text_input("Романдзи", &self.current_roman)
|
||||
.size(28)
|
||||
.width(150)
|
||||
.on_input(ContentChanged),
|
||||
row![
|
||||
text!("{}", self.score.total.to_string()).size(25),
|
||||
text!("{}", self.score.correct.to_string())
|
||||
.size(25)
|
||||
.color(iced::Color::from_rgb8(60, 170, 60)),
|
||||
text!("{}", self.score.fail.to_string())
|
||||
.color(iced::Color::from_rgb8(255, 79, 0))
|
||||
.size(25),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING),
|
||||
button("Закончить").style(jl_button).on_press(Back),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.align_x(alignment::Horizontal::Center),
|
||||
)
|
||||
.center_y(Fill)
|
||||
.center_x(Fill)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum QuizMessage {
|
||||
|
||||
+22
-24
@@ -1,9 +1,9 @@
|
||||
use crate::RootMessage;
|
||||
use crate::navigation::{NavigatedPage, Page};
|
||||
use crate::randomizer::RandomizerMessage::{Back, Edit, Start};
|
||||
use crate::styling::{back_overlay, jl_button, HALF_SPACING};
|
||||
use crate::RootMessage;
|
||||
use iced::widget::{button, text_editor};
|
||||
use crate::styling::{HALF_SPACING, back_overlay, jl_button};
|
||||
use iced::Task;
|
||||
use iced::widget::{button, text_editor};
|
||||
use rand::prelude::SliceRandom;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -20,32 +20,15 @@ pub enum RandomizerMessage {
|
||||
}
|
||||
|
||||
impl NavigatedPage<RandomizerMessage> for RandomizerState {
|
||||
fn navigate(&self, message: &RandomizerMessage) -> Option<Page> {
|
||||
fn navigate(&mut self, message: &RandomizerMessage) -> Option<Page> {
|
||||
if let Back = message {
|
||||
return Some(Page::PreviousPage);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn navigated(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for RandomizerState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl RandomizerState {
|
||||
pub fn new() -> RandomizerState {
|
||||
RandomizerState {
|
||||
text: Default::default(),
|
||||
list: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: RandomizerMessage) -> Task<RootMessage> {
|
||||
fn navigated(&mut self) {}
|
||||
fn update(&mut self, message: RandomizerMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
Edit(action) => {
|
||||
self.text.perform(action);
|
||||
@@ -65,7 +48,7 @@ impl RandomizerState {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> iced::Element<'_, RandomizerMessage> {
|
||||
fn view(&self) -> iced::Element<'_, RandomizerMessage> {
|
||||
back_overlay(
|
||||
iced::widget::column![
|
||||
text_editor(&self.text)
|
||||
@@ -81,3 +64,18 @@ impl RandomizerState {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for RandomizerState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl RandomizerState {
|
||||
pub fn new() -> RandomizerState {
|
||||
RandomizerState {
|
||||
text: Default::default(),
|
||||
list: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+70
-65
@@ -1,8 +1,8 @@
|
||||
use crate::data_provider::voice::get_voice;
|
||||
use crate::lang::{CardSet, CardStatistics, WordData, WordOpenMode};
|
||||
use crate::lang::Id;
|
||||
use crate::lang::{CardStatistics, DeckData, DeckSettings, WordData, WordOpenMode};
|
||||
use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{KeyPressedPage, NavigatedPage, Page};
|
||||
use crate::repetitions::CardSetSettings;
|
||||
use crate::styling::*;
|
||||
use crate::{AppState, RootMessage};
|
||||
use chrono::Local;
|
||||
@@ -18,18 +18,18 @@ use tokio::task::spawn_blocking;
|
||||
|
||||
pub struct RepetitionState {
|
||||
state: Arc<Mutex<AppState>>,
|
||||
pub settings: CardSetSettings,
|
||||
pub set: CardSet,
|
||||
pub settings: DeckSettings,
|
||||
pub set: DeckData,
|
||||
current_word: WordData,
|
||||
current_statistic: CardStatistics,
|
||||
open: bool,
|
||||
can_play: bool,
|
||||
sink: Arc<MixerDeviceSink>,
|
||||
opened: HashSet<u32>,
|
||||
opened: HashSet<Id>,
|
||||
}
|
||||
|
||||
impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
||||
fn navigate(&self, message: &RepetitionMessage) -> Option<Page> {
|
||||
fn navigate(&mut self, message: &RepetitionMessage) -> Option<Page> {
|
||||
if let RepetitionMessage::Back = message {
|
||||
Some(PreviousPage)
|
||||
} else {
|
||||
@@ -37,32 +37,8 @@ impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
||||
}
|
||||
}
|
||||
|
||||
fn navigated(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
impl RepetitionState {
|
||||
pub(crate) fn new(set: CardSetSettings, state: Arc<Mutex<AppState>>) -> RepetitionState {
|
||||
let mut card_set = CardSet::new(&set, state.clone());
|
||||
let (word, stat) = card_set.next();
|
||||
let sink_handle = rodio::DeviceSinkBuilder::open_default_sink().unwrap();
|
||||
|
||||
RepetitionState {
|
||||
state,
|
||||
settings: set,
|
||||
set: card_set,
|
||||
current_word: word,
|
||||
current_statistic: stat,
|
||||
open: false,
|
||||
can_play: true,
|
||||
sink: Arc::new(sink_handle),
|
||||
opened: HashSet::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RepetitionState {
|
||||
pub fn update(&mut self, message: RepetitionMessage) -> Task<RootMessage> {
|
||||
fn navigated(&mut self) {}
|
||||
fn update(&mut self, message: RepetitionMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
RepetitionMessage::Back => {}
|
||||
RepetitionMessage::Next => return self.next(),
|
||||
@@ -87,7 +63,59 @@ impl RepetitionState {
|
||||
|
||||
Task::none()
|
||||
}
|
||||
fn view(&self) -> Element<'_, RepetitionMessage> {
|
||||
back_overlay(
|
||||
column![
|
||||
container(self.draw_forward())
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.align_x(Center)
|
||||
.align_y(alignment::Vertical::Center),
|
||||
rule::horizontal(2),
|
||||
container(self.draw_backward())
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.align_x(Center)
|
||||
.align_y(alignment::Vertical::Center),
|
||||
container(self.answer_bar())
|
||||
.width(Fill)
|
||||
.align_x(Center)
|
||||
.height(80),
|
||||
text!(
|
||||
"Затронуто слов {}, {}%",
|
||||
self.opened.len(),
|
||||
(self.opened.len() as f32 / self.set.len() as f32 * 10000.0).round() / 100.0
|
||||
)
|
||||
]
|
||||
.height(Fill)
|
||||
.width(Fill)
|
||||
.into(),
|
||||
RepetitionMessage::Back,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl RepetitionState {
|
||||
pub(crate) fn new(set: DeckSettings, state: Arc<Mutex<AppState>>) -> RepetitionState {
|
||||
let mut card_set = DeckData::new(&set, state.clone());
|
||||
let (word, stat) = card_set.next();
|
||||
let sink_handle = rodio::DeviceSinkBuilder::open_default_sink().unwrap();
|
||||
|
||||
RepetitionState {
|
||||
state,
|
||||
settings: set,
|
||||
set: card_set,
|
||||
current_word: word,
|
||||
current_statistic: stat,
|
||||
open: false,
|
||||
can_play: true,
|
||||
sink: Arc::new(sink_handle),
|
||||
opened: HashSet::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RepetitionState {
|
||||
fn next(&mut self) -> Task<RootMessage> {
|
||||
if self.open {
|
||||
self.answer(WordOpenMode::None)
|
||||
@@ -137,36 +165,6 @@ impl RepetitionState {
|
||||
state.activity.insert(id, vec![(now, 1)]);
|
||||
}
|
||||
}
|
||||
pub fn view(&self) -> Element<'_, RepetitionMessage> {
|
||||
back_overlay(
|
||||
column![
|
||||
container(self.draw_forward())
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.align_x(Center)
|
||||
.align_y(alignment::Vertical::Center),
|
||||
rule::horizontal(2),
|
||||
container(self.draw_backward())
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.align_x(Center)
|
||||
.align_y(alignment::Vertical::Center),
|
||||
container(self.answer_bar())
|
||||
.width(Fill)
|
||||
.align_x(Center)
|
||||
.height(80),
|
||||
text!(
|
||||
"Затронуто слов {}, {}%",
|
||||
self.opened.len(),
|
||||
(self.opened.len() as f32 / self.set.len() as f32 * 10000.0).round() / 100.0
|
||||
)
|
||||
]
|
||||
.height(Fill)
|
||||
.width(Fill)
|
||||
.into(),
|
||||
RepetitionMessage::Back,
|
||||
)
|
||||
}
|
||||
|
||||
fn draw_forward(&self) -> Element<'_, RepetitionMessage> {
|
||||
self.draw_card_view(self.settings.forward.as_str())
|
||||
@@ -197,6 +195,7 @@ impl RepetitionState {
|
||||
"speech" => self.draw_voice(),
|
||||
"reading" => self.draw_reading(word),
|
||||
"context" => self.draw_context(word),
|
||||
"description" => self.draw_description(word),
|
||||
_ => space().into(),
|
||||
})
|
||||
}
|
||||
@@ -272,6 +271,12 @@ impl RepetitionState {
|
||||
Some(context) => text!("{}", context).size(24).into(),
|
||||
}
|
||||
}
|
||||
fn draw_description(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||
match word.additional.get("context") {
|
||||
None => space().into(),
|
||||
Some(context) => text!("{}", context).size(24).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyPressedPage for RepetitionState {
|
||||
@@ -285,8 +290,8 @@ impl KeyPressedPage for RepetitionState {
|
||||
text: _,
|
||||
repeat: _,
|
||||
} = message
|
||||
&& let Code(code) = pk
|
||||
{
|
||||
if let Code(code) = pk {
|
||||
return match code {
|
||||
keyboard::key::Code::Space => self.next(),
|
||||
keyboard::key::Code::Digit1 => self.answer(WordOpenMode::None),
|
||||
@@ -296,7 +301,7 @@ impl KeyPressedPage for RepetitionState {
|
||||
_ => Task::none(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
@@ -313,7 +318,7 @@ pub enum RepetitionMessage {
|
||||
async fn play_sound(sink: Arc<MixerDeviceSink>, text: String) {
|
||||
let data = get_voice(text.as_str()).await;
|
||||
spawn_blocking(move || {
|
||||
rodio::play(&sink.mixer(), data).unwrap().sleep_until_end();
|
||||
rodio::play(sink.mixer(), data).unwrap().sleep_until_end();
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
+32
-22
@@ -1,23 +1,25 @@
|
||||
use crate::data_provider::card_sets::{delete_set, update_card_set};
|
||||
use crate::AppState;
|
||||
use crate::data_provider::card_sets::{delete_set, update_deck};
|
||||
use crate::lang::DeckSettings;
|
||||
use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::repetition_settings::RepetitionSettingsMessage::*;
|
||||
use crate::repetitions::CardSetSettings;
|
||||
use crate::styling::*;
|
||||
use crate::AppState;
|
||||
use iced::widget::button::danger;
|
||||
use iced::widget::{button, column, row, scrollable, space, text, text_input};
|
||||
use iced::{Element, Task};
|
||||
use iced_core::Length::Fill;
|
||||
use iced_core::Padding;
|
||||
use iced_core::{color, Padding, Theme};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
use iced::widget::text_input::Catalog;
|
||||
|
||||
pub struct RepetitionSettingsState {
|
||||
set: CardSetSettings,
|
||||
set: DeckSettings,
|
||||
index: usize,
|
||||
state: Arc<Mutex<AppState>>,
|
||||
real_delete: bool,
|
||||
correct_filter: bool,
|
||||
}
|
||||
|
||||
impl RepetitionSettingsState {
|
||||
@@ -25,19 +27,22 @@ impl RepetitionSettingsState {
|
||||
let set;
|
||||
{
|
||||
let local_state = p1.lock().unwrap();
|
||||
set = local_state.card_sets[index].clone();
|
||||
set = local_state.decks[index].clone();
|
||||
}
|
||||
let filter_state = set.check_filter();
|
||||
|
||||
RepetitionSettingsState {
|
||||
index,
|
||||
set,
|
||||
state: p1,
|
||||
real_delete: false,
|
||||
correct_filter: filter_state,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
|
||||
fn navigate(&self, message: &RepetitionSettingsMessage) -> Option<Page> {
|
||||
fn navigate(&mut self, message: &RepetitionSettingsMessage) -> Option<Page> {
|
||||
if let Back = message {
|
||||
Some(PreviousPage)
|
||||
} else {
|
||||
@@ -45,18 +50,14 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
|
||||
}
|
||||
}
|
||||
|
||||
fn navigated(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
impl RepetitionSettingsState {
|
||||
pub fn update(&mut self, message: RepetitionSettingsMessage) -> Task<RootMessage> {
|
||||
fn navigated(&mut self) {}
|
||||
fn update(&mut self, message: RepetitionSettingsMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
Back => {}
|
||||
Save => {
|
||||
let mut state = self.state.lock().unwrap();
|
||||
update_card_set(&mut self.set, &state.connection);
|
||||
state.card_sets[self.index] = self.set.clone();
|
||||
update_deck(&mut self.set, &state.connection);
|
||||
state.decks[self.index] = self.set.clone();
|
||||
}
|
||||
SetName(new) => {
|
||||
self.set.name = new;
|
||||
@@ -69,6 +70,7 @@ impl RepetitionSettingsState {
|
||||
}
|
||||
SetFilter(new) => {
|
||||
self.set.filter = new;
|
||||
self.correct_filter = self.set.check_filter();
|
||||
}
|
||||
TryFilter => {
|
||||
let state = self.state.lock().unwrap();
|
||||
@@ -76,24 +78,24 @@ impl RepetitionSettingsState {
|
||||
self.set.count = Some(count);
|
||||
}
|
||||
DeleteSet => {
|
||||
if self.real_delete == false {
|
||||
if !self.real_delete {
|
||||
self.real_delete = true;
|
||||
return Task::future(async {
|
||||
tokio::time::sleep(Duration::from_millis(3000)).await;
|
||||
return RootMessage::RepetitionSettings(RevertDeleteSet);
|
||||
RootMessage::RepetitionSettings(RevertDeleteSet)
|
||||
});
|
||||
}
|
||||
let mut state = self.state.lock().unwrap();
|
||||
delete_set(&self.set, &state.connection);
|
||||
state.card_sets.remove(self.index);
|
||||
state.decks.remove(self.index);
|
||||
return Task::done(RootMessage::RepetitionSettings(Back));
|
||||
},
|
||||
}
|
||||
RevertDeleteSet => self.real_delete = false,
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, RepetitionSettingsMessage> {
|
||||
fn view(&self) -> Element<'_, RepetitionSettingsMessage> {
|
||||
back_overlay(
|
||||
iced::widget::column![
|
||||
scrollable(
|
||||
@@ -115,7 +117,13 @@ impl RepetitionSettingsState {
|
||||
.spacing(QUARTER_SPACING),
|
||||
column![
|
||||
text!("Фильтр"),
|
||||
text_input("", &self.set.filter).on_input(SetFilter),
|
||||
text_input("", &self.set.filter).style(|x, status| {
|
||||
let mut primary = Theme::default()(x, status);
|
||||
if !self.correct_filter {
|
||||
primary.border.color = color!(255, 255, 0);
|
||||
}
|
||||
primary
|
||||
}).on_input(SetFilter),
|
||||
button("Проверить фильтр")
|
||||
.style(jl_button)
|
||||
.on_press(TryFilter),
|
||||
@@ -150,8 +158,10 @@ impl RepetitionSettingsState {
|
||||
Back,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn count_view(&self, set: &CardSetSettings) -> Element<'_, RepetitionSettingsMessage> {
|
||||
impl RepetitionSettingsState {
|
||||
fn count_view(&self, set: &DeckSettings) -> Element<'_, RepetitionSettingsMessage> {
|
||||
if let Some(count) = set.count {
|
||||
return text!("Количество слов: {}", count).into();
|
||||
}
|
||||
|
||||
+385
-265
@@ -1,7 +1,7 @@
|
||||
use crate::data_provider::card_sets::{delete_set, update_card_set};
|
||||
use crate::data_provider::card_stats::load_stats_of_set;
|
||||
use crate::data_provider::card_sets::update_deck;
|
||||
use crate::data_provider::card_stats::{add_stat_list, load_stats_of_deck};
|
||||
use crate::history::HistoryState;
|
||||
use crate::lang::{SetOrderMode, WordData};
|
||||
use crate::lang::{AppendMode, CardStatistics, DeckSettings, Id, OrderMode};
|
||||
use crate::navigation::Page::{History, PreviousPage, Repetition, RepetitionSettings};
|
||||
use crate::navigation::{NavigatedPage, Page};
|
||||
use crate::repetition::RepetitionState;
|
||||
@@ -9,141 +9,229 @@ use crate::repetition_settings::RepetitionSettingsState;
|
||||
use crate::repetitions::RepetitionsMessage::*;
|
||||
use crate::styling::*;
|
||||
use crate::{AppState, RootMessage};
|
||||
use chrono::{Days, Local};
|
||||
use iced::widget::button::{danger, Status};
|
||||
use chrono::{Days, Local, Utc};
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
pub use iced::widget::button::{Catalog, Style};
|
||||
use iced::widget::container::bordered_box;
|
||||
use iced::widget::button::{Status, danger};
|
||||
use iced::widget::tooltip::Position::Top;
|
||||
use iced::widget::{button, column, container, lazy, radio, row, scrollable, space, svg, text, text_input, tooltip, Column, Row};
|
||||
use iced::widget::{
|
||||
Column, Row, button, column, container, lazy, radio, row, scrollable, space, svg, text,
|
||||
text_input, tooltip,
|
||||
};
|
||||
use iced::{Background, Border, Center, Color, Element, Fill, Length, Shadow, Task, Theme};
|
||||
use iced_core::Padding;
|
||||
use iced_core::border::Radius;
|
||||
use iced_core::svg::Handle;
|
||||
use iced_core::Padding;
|
||||
use rhai::{Engine, Scope};
|
||||
use std::ops::Deref;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RepetitionsState {
|
||||
selected_set: Option<usize>,
|
||||
correct_filters: Vec<bool>,
|
||||
pub state: Arc<Mutex<AppState>>,
|
||||
word_id_index_map: HashMap<Id, usize>,
|
||||
selected_deck_index: Option<usize>,
|
||||
decks: Vec<DeckViewData>,
|
||||
state: Arc<Mutex<AppState>>,
|
||||
}
|
||||
|
||||
impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
|
||||
fn navigate(&self, message: &RepetitionsMessage) -> Option<Page> {
|
||||
fn navigate(&mut self, message: &RepetitionsMessage) -> Option<Page> {
|
||||
if let Back = message {
|
||||
Some(PreviousPage)
|
||||
} else if let GoToHistory = message {
|
||||
let card_set;
|
||||
{
|
||||
card_set = self.state.lock().unwrap().card_sets[self.selected_set.unwrap()].id;
|
||||
}
|
||||
Some(History(HistoryState::new(card_set, self.state.clone())))
|
||||
Some(History(HistoryState::new(
|
||||
self.selected_deck().unwrap().id,
|
||||
self.state.clone(),
|
||||
)))
|
||||
} else if let GoToRepetition = message {
|
||||
let clone = self.state.clone();
|
||||
let card_set;
|
||||
|
||||
let selected_set = self.selected_deck_mut().unwrap();
|
||||
if selected_set.append_mode == AppendMode::Full {
|
||||
Self::append_all_words(&mut clone.lock().unwrap(), selected_set);
|
||||
selected_set.existing_words_indices = selected_set.available_words_indices.clone();
|
||||
} else {
|
||||
if selected_set
|
||||
.available_words_indices
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
|| selected_set
|
||||
.existing_words_indices
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
{
|
||||
card_set = self.state.lock().unwrap().card_sets[self.selected_set.unwrap()].clone();
|
||||
return None;
|
||||
}
|
||||
Some(Repetition(RepetitionState::new(card_set, clone)))
|
||||
}
|
||||
|
||||
Some(Repetition(RepetitionState::new(
|
||||
selected_set.general_settings.clone(),
|
||||
clone,
|
||||
)))
|
||||
} else if let GoToSettings = message {
|
||||
Some(RepetitionSettings(RepetitionSettingsState::new(
|
||||
self.selected_set.unwrap(),
|
||||
self.selected_deck().unwrap().index.unwrap(),
|
||||
self.state.clone(),
|
||||
)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn navigated(&mut self) {
|
||||
self.selected_set = None;
|
||||
let index = self.selected_deck_index.unwrap();
|
||||
let state = self.state.lock().unwrap();
|
||||
if let Some(global_deck) = state.decks.get(index) {
|
||||
if global_deck.id != self.selected_deck().unwrap().id {
|
||||
drop(state);
|
||||
self.decks.remove(index);
|
||||
self.clear_selection();
|
||||
}
|
||||
} else {
|
||||
drop(state);
|
||||
self.decks.remove(index);
|
||||
self.clear_selection()
|
||||
}
|
||||
}
|
||||
|
||||
impl RepetitionsState {
|
||||
pub(crate) fn new(state: Arc<Mutex<AppState>>) -> RepetitionsState {
|
||||
let count = state.lock().unwrap().card_sets.len();
|
||||
RepetitionsState {
|
||||
selected_set: None,
|
||||
correct_filters: vec![true; count],
|
||||
state,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RepetitionsState {
|
||||
pub fn update(&mut self, message: RepetitionsMessage) -> Task<RootMessage> {
|
||||
let mut state = self.state.lock().unwrap();
|
||||
fn update(&mut self, message: RepetitionsMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
Next => {}
|
||||
Back => {}
|
||||
GoToRepetition => {}
|
||||
GoToHistory => {}
|
||||
GoToSettings => {}
|
||||
|
||||
CreateSet => {
|
||||
let index = state.card_sets.len() + 1;
|
||||
state
|
||||
.card_sets
|
||||
.push(CardSetSettings::with_name(format!("Card set #{}", index)));
|
||||
self.correct_filters.push(true);
|
||||
let index = self.decks.len() + 1;
|
||||
self.decks.push(DeckViewData {
|
||||
general_settings: DeckSettings::with_name(format!("Колода #{}", index)),
|
||||
existing_words_indices: None,
|
||||
available_words_indices: None,
|
||||
append_mode: Default::default(),
|
||||
index: None,
|
||||
});
|
||||
}
|
||||
DeleteSet => {
|
||||
let set = state.card_sets.remove(self.selected_set.unwrap());
|
||||
self.correct_filters.remove(self.selected_set.unwrap());
|
||||
self.selected_set = None;
|
||||
delete_set(&set, &state.connection);
|
||||
let index = self.selected_deck_index.unwrap();
|
||||
self.clear_selection();
|
||||
let deck = self.decks.remove(index);
|
||||
if deck.id.is_valid() {
|
||||
let mut state = self.state.lock().unwrap();
|
||||
state.decks.remove(index);
|
||||
self.decks = self
|
||||
.decks
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|mut deck| {
|
||||
deck.index = state.decks.iter().position(|d| d.id == deck.id);
|
||||
deck
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
}
|
||||
SetName(value) => {
|
||||
let deck = self.selected_deck_mut().unwrap();
|
||||
deck.general_settings.name = value;
|
||||
}
|
||||
SelectSet(index) => {
|
||||
self.selected_set = Some(index);
|
||||
let mut set = state.card_sets.get(index).unwrap().clone();
|
||||
set.update_worst_words(&state);
|
||||
state.card_sets[index] = set;
|
||||
self.select_deck(index);
|
||||
let deck = self.selected_deck().unwrap();
|
||||
if deck.existing_words_indices.is_none() {
|
||||
let state = self.state.lock().unwrap();
|
||||
let added: Vec<_> = load_stats_of_deck(deck, &state.connection)
|
||||
.iter()
|
||||
.map(|c| self.word_id_index_map[&c.word_id])
|
||||
.collect();
|
||||
let total = deck.get_word_list(&state);
|
||||
drop(state);
|
||||
let deck = self.selected_deck_mut().unwrap();
|
||||
deck.existing_words_indices = Some(added);
|
||||
deck.available_words_indices = Some(total);
|
||||
}
|
||||
SetName(new) => {
|
||||
state.card_sets[self.selected_set.unwrap()].name = new;
|
||||
}
|
||||
Save => {
|
||||
for i in 0..state.card_sets.len() {
|
||||
self.correct_filters[i] = state.card_sets[i].check_filter();
|
||||
let mut deck = self.selected_deck().unwrap().clone();
|
||||
let mut state = self.state.lock().unwrap();
|
||||
{
|
||||
update_deck(&mut deck.general_settings, &state.connection);
|
||||
if let Some(index) = deck.index {
|
||||
state.decks[index] = deck.general_settings.clone();
|
||||
} else {
|
||||
state.decks.push(deck.general_settings.clone());
|
||||
deck.index = Some(state.decks.len() - 1);
|
||||
self.decks[self.selected_deck_index.unwrap()] = deck.clone();
|
||||
}
|
||||
|
||||
let set = &mut state.card_sets[self.selected_set.unwrap()].clone();
|
||||
|
||||
update_card_set(set, &state.connection);
|
||||
|
||||
state.card_sets[self.selected_set.unwrap()] = set.clone();
|
||||
}
|
||||
SetForward(new) => {
|
||||
state.card_sets[self.selected_set.unwrap()].forward = new;
|
||||
}
|
||||
SetBackward(new) => {
|
||||
state.card_sets[self.selected_set.unwrap()].backward = new;
|
||||
SetForward(value) => {
|
||||
let deck = self.selected_deck_mut().unwrap();
|
||||
deck.general_settings.forward = value;
|
||||
}
|
||||
SetFilter(new) => {
|
||||
state.card_sets[self.selected_set.unwrap()].filter = new;
|
||||
SetBackward(value) => {
|
||||
let deck = self.selected_deck_mut().unwrap();
|
||||
deck.general_settings.backward = value;
|
||||
}
|
||||
SetFilter(value) => {
|
||||
let deck = self.selected_deck_mut().unwrap();
|
||||
deck.general_settings.filter = value;
|
||||
}
|
||||
TryFilter => {
|
||||
let set = state.card_sets.get(self.selected_set.unwrap()).unwrap();
|
||||
let count = set.get_word_list(&state).len();
|
||||
state.card_sets[self.selected_set.unwrap()].count = Some(count);
|
||||
let state = self.state.lock().unwrap();
|
||||
let deck = self.selected_deck().unwrap();
|
||||
let count = deck.get_word_list(&state).len();
|
||||
drop(state);
|
||||
let deck = self.selected_deck_mut().unwrap();
|
||||
deck.general_settings.count = Some(count);
|
||||
}
|
||||
SetOpenMode(mode) => {
|
||||
state
|
||||
.card_sets
|
||||
.get_mut(self.selected_set.unwrap())
|
||||
let deck = self.selected_deck_mut().unwrap();
|
||||
deck.general_settings.open_mode = mode;
|
||||
}
|
||||
SetAppendMode(mode) => {
|
||||
let deck = self.selected_deck_mut().unwrap();
|
||||
deck.append_mode = mode;
|
||||
}
|
||||
AppendWords(count) => {
|
||||
let adding: Vec<usize>;
|
||||
{
|
||||
{
|
||||
let deck = self.selected_deck().unwrap();
|
||||
let existing_words_indices = deck.existing_words_indices.as_ref().unwrap();
|
||||
let mut created_set = HashSet::with_capacity(existing_words_indices.len());
|
||||
existing_words_indices.iter().for_each(|c| {
|
||||
created_set.insert(c);
|
||||
});
|
||||
adding = deck
|
||||
.available_words_indices
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.open_mode = mode;
|
||||
.iter()
|
||||
.filter(|c| !created_set.contains(c))
|
||||
.take(count)
|
||||
.cloned()
|
||||
.collect();
|
||||
}
|
||||
|
||||
let deck = self.selected_deck_mut().unwrap();
|
||||
deck.existing_words_indices
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.append(&mut adding.clone());
|
||||
}
|
||||
|
||||
let deck = self.selected_deck().unwrap();
|
||||
let mut state = self.state.lock().unwrap();
|
||||
Self::append_words(&mut state, &deck.general_settings, adding.into_iter());
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, RepetitionsMessage> {
|
||||
fn view(&self) -> Element<'_, RepetitionsMessage> {
|
||||
back_overlay(
|
||||
row![
|
||||
column![
|
||||
scrollable(self.sets_list()).height(Fill),
|
||||
scrollable(self.decks_list()).height(Fill),
|
||||
button("Добавить")
|
||||
.style(jl_button)
|
||||
.width(Fill)
|
||||
@@ -151,7 +239,7 @@ impl RepetitionsState {
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.width(Length::FillPortion(1)),
|
||||
self.selected_set_view(),
|
||||
self.selected_deck_view(),
|
||||
]
|
||||
.align_y(Center)
|
||||
.spacing(DEFAULT_SPACING)
|
||||
@@ -161,9 +249,55 @@ impl RepetitionsState {
|
||||
Back,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn launch_delete_button(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
|
||||
if set.id != 0 {
|
||||
impl RepetitionsState {
|
||||
pub(crate) fn new(state: Arc<Mutex<AppState>>) -> RepetitionsState {
|
||||
let state_ = state.lock().unwrap();
|
||||
let mut map = HashMap::with_capacity(state_.dictionary.len());
|
||||
|
||||
state_
|
||||
.dictionary
|
||||
.iter()
|
||||
.enumerate()
|
||||
.for_each(|(index, word)| {
|
||||
map.insert(word.id, index);
|
||||
});
|
||||
|
||||
let decks = Self::get_decks_from_state(&state_);
|
||||
drop(state_);
|
||||
RepetitionsState {
|
||||
word_id_index_map: map,
|
||||
selected_deck_index: None,
|
||||
decks,
|
||||
state,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_decks_from_state(state: &AppState) -> Vec<DeckViewData> {
|
||||
state
|
||||
.decks
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, deck)| DeckViewData {
|
||||
general_settings: deck.clone(),
|
||||
existing_words_indices: None,
|
||||
available_words_indices: None,
|
||||
append_mode: Default::default(),
|
||||
index: Some(index),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl RepetitionsState {
|
||||
fn launch_delete_button(&self, deck: &DeckViewData) -> Element<'_, RepetitionsMessage> {
|
||||
if deck.id.is_valid() {
|
||||
if deck.append_mode == AppendMode::Manual
|
||||
&& deck.existing_words_indices.as_ref().unwrap().is_empty()
|
||||
{
|
||||
return text!("Добавьте карточки или измените фильтр").into();
|
||||
}
|
||||
return row![
|
||||
space().width(Fill),
|
||||
button(text!("Начать повторение").width(200).center())
|
||||
@@ -174,24 +308,15 @@ impl RepetitionsState {
|
||||
}
|
||||
button("Удалить").style(danger).on_press(DeleteSet).into()
|
||||
}
|
||||
|
||||
fn selected_set_view(&self) -> Element<'_, RepetitionsMessage> {
|
||||
if let Some(index) = self.selected_set {
|
||||
let set;
|
||||
{
|
||||
let state = self.state.lock().unwrap();
|
||||
if state.card_sets.len() <= index {
|
||||
return space().width(Length::FillPortion(3)).into();
|
||||
}
|
||||
set = state.card_sets[index].clone();
|
||||
}
|
||||
fn selected_deck_view(&self) -> Element<'_, RepetitionsMessage> {
|
||||
if let Some(deck) = &self.selected_deck() {
|
||||
return column![
|
||||
scrollable(
|
||||
column![
|
||||
column![
|
||||
text!("Название набора"),
|
||||
row![
|
||||
text_input("", &set.name).on_input(SetName),
|
||||
text_input("", &deck.name).on_input(SetName),
|
||||
button(svg(Handle::from_memory(SETTINGS_ICON)))
|
||||
.width(43)
|
||||
.on_press(GoToSettings),
|
||||
@@ -200,42 +325,58 @@ impl RepetitionsState {
|
||||
]
|
||||
.spacing(QUARTER_SPACING),
|
||||
{
|
||||
if set.id == 0 {
|
||||
if !deck.id.is_valid() {
|
||||
column![
|
||||
column![
|
||||
text!("Передняя сторона"),
|
||||
text_input("", &set.forward).on_input(SetForward),
|
||||
text_input("", &deck.forward).on_input(SetForward),
|
||||
]
|
||||
.spacing(QUARTER_SPACING),
|
||||
column![
|
||||
text!("Задняя сторона"),
|
||||
text_input("", &set.backward).on_input(SetBackward),
|
||||
text_input("", &deck.backward).on_input(SetBackward),
|
||||
]
|
||||
.spacing(QUARTER_SPACING),
|
||||
column![
|
||||
text!("Фильтр"),
|
||||
text_input("", &set.filter).on_input(SetFilter),
|
||||
text_input("", &deck.filter).on_input(SetFilter),
|
||||
button("Проверить фильтр")
|
||||
.style(jl_button)
|
||||
.on_press(TryFilter),
|
||||
self.count_view(&set),
|
||||
self.count_view(deck),
|
||||
]
|
||||
.spacing(QUARTER_SPACING),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
} else {
|
||||
self.filled_set_data_view(&set)
|
||||
}
|
||||
},
|
||||
column![
|
||||
self.filled_deck_data_view(deck),
|
||||
self.word_append_panel(deck),
|
||||
radio(
|
||||
"Обычный режим",
|
||||
SetOrderMode::Default,
|
||||
Some(set.open_mode),
|
||||
OrderMode::Default,
|
||||
Some(deck.open_mode),
|
||||
SetOpenMode
|
||||
),
|
||||
radio(
|
||||
"Начать с плохих слов",
|
||||
OrderMode::TrainWorstFirst,
|
||||
Some(deck.open_mode),
|
||||
SetOpenMode
|
||||
),
|
||||
radio(
|
||||
"Полностью случайно",
|
||||
OrderMode::FullRandom,
|
||||
Some(deck.open_mode),
|
||||
SetOpenMode
|
||||
),
|
||||
self.words_words_view(&set),
|
||||
button("История").style(jl_button).on_press(GoToHistory),
|
||||
]
|
||||
.spacing(HALF_SPACING)
|
||||
}
|
||||
},
|
||||
// self.words_words_view(&set),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.padding(Padding {
|
||||
top: 0.0,
|
||||
@@ -247,40 +388,36 @@ impl RepetitionsState {
|
||||
.height(Fill),
|
||||
row![
|
||||
button("Сохранить").style(jl_button).on_press(Save),
|
||||
self.launch_delete_button(&set)
|
||||
]
|
||||
.spacing(DEFAULT_SPACING),
|
||||
self.launch_delete_button(deck)
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.width(Length::FillPortion(3))
|
||||
.align_y(Center),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.width(Length::FillPortion(2))
|
||||
.into();
|
||||
}
|
||||
space().width(Length::FillPortion(3)).into()
|
||||
space().width(Length::FillPortion(2)).into()
|
||||
}
|
||||
|
||||
fn filled_set_data_view(&self, set: &CardSetSettings) -> Column<'_, RepetitionsMessage> {
|
||||
column![self.activity_bar(set)].align_x(Center)
|
||||
fn filled_deck_data_view(&self, deck: &DeckSettings) -> Column<'_, RepetitionsMessage> {
|
||||
column![self.activity_bar(deck), self.count_comparator_view()]
|
||||
.align_x(Center)
|
||||
.width(Fill)
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.into()
|
||||
}
|
||||
fn activity_bar(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
|
||||
fn activity_bar(&self, deck: &DeckSettings) -> Element<'_, RepetitionsMessage> {
|
||||
const MAX_DAY_COUNT: f32 = 128.0;
|
||||
|
||||
let state = self.state.lock().unwrap();
|
||||
let history = state.activity.get(&set.id);
|
||||
let history = state.activity.get(&deck.id);
|
||||
let mut counts: Vec<u32> = vec![0; 30 * 7];
|
||||
let now = Local::now().date_naive();
|
||||
|
||||
|
||||
if let Some(history) = history {
|
||||
for (date, activity) in history {
|
||||
let distance = now - *date;
|
||||
let index = counts.len() as i64 - distance.num_days() - 1;
|
||||
|
||||
if index == 210 {
|
||||
println!("invalid index")
|
||||
}
|
||||
if index < 0 {
|
||||
continue;
|
||||
}
|
||||
@@ -299,8 +436,7 @@ impl RepetitionsState {
|
||||
})
|
||||
.spacing(QUARTER_SPACING);
|
||||
|
||||
|
||||
let mut iter = counts.into_iter();
|
||||
let mut iter = counts.iter();
|
||||
for i in 0..30 {
|
||||
let mut column = Column::new().spacing(QUARTER_SPACING);
|
||||
|
||||
@@ -308,13 +444,17 @@ impl RepetitionsState {
|
||||
let value = *iter.next().unwrap() as f32;
|
||||
let k = (value / MAX_DAY_COUNT).min(1.0) * 0.9 + 0.1;
|
||||
|
||||
let date = now.clone().checked_sub_days(Days::new(30 * 7 - i * 7 - j - 1)).unwrap();
|
||||
let date = (*now)
|
||||
.checked_sub_days(Days::new(30 * 7 - i * 7 - j - 1))
|
||||
.unwrap();
|
||||
|
||||
column = column.push(tooltip(
|
||||
iced::widget::container(space().height(15).width(15)).style(
|
||||
move |x: &Theme| container::Style {
|
||||
text_color: None,
|
||||
background: Some(Background::Color(x.palette().primary.scale_alpha(k))),
|
||||
background: Some(Background::Color(
|
||||
x.palette().primary.scale_alpha(k),
|
||||
)),
|
||||
border: Border {
|
||||
color: Default::default(),
|
||||
width: 0.0,
|
||||
@@ -331,67 +471,81 @@ impl RepetitionsState {
|
||||
|
||||
row = row.push(column);
|
||||
}
|
||||
scrollable(column!["Карта активности", row].spacing(QUARTER_SPACING).align_x(Center))
|
||||
}).into()
|
||||
|
||||
}
|
||||
|
||||
fn words_words_view(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
|
||||
column![
|
||||
text!("Худшие слова"),
|
||||
container(scrollable(self.worst_words_list(&set)).height(200)).style(bordered_box),
|
||||
radio(
|
||||
"Начать с плохих слов",
|
||||
SetOrderMode::TrainWorstFirst,
|
||||
Some(set.open_mode),
|
||||
SetOpenMode
|
||||
),
|
||||
radio(
|
||||
"Полностью случайно",
|
||||
SetOrderMode::FullRandom,
|
||||
Some(set.open_mode),
|
||||
SetOpenMode
|
||||
scrollable(
|
||||
column!["Карта активности", row]
|
||||
.spacing(QUARTER_SPACING)
|
||||
.align_x(Center),
|
||||
)
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
})
|
||||
.into()
|
||||
}
|
||||
|
||||
fn worst_words_list(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
|
||||
let mut column = Column::new();
|
||||
|
||||
for word in set.worst_words_list.clone().unwrap() {
|
||||
column = column.push(text!("{} | {}", &word.key, &word.value));
|
||||
fn word_append_panel(&self, deck: &DeckViewData) -> Element<'_, RepetitionsMessage> {
|
||||
column![
|
||||
text!("Режим добавления карточек"),
|
||||
row![
|
||||
radio(
|
||||
"Добавлять все доступные",
|
||||
AppendMode::Full,
|
||||
Some(deck.append_mode),
|
||||
SetAppendMode
|
||||
),
|
||||
radio(
|
||||
"Добавлять вручную",
|
||||
AppendMode::Manual,
|
||||
Some(deck.append_mode),
|
||||
SetAppendMode
|
||||
)
|
||||
]
|
||||
.spacing(HALF_SPACING),
|
||||
self.adder_panel(deck),
|
||||
]
|
||||
.spacing(HALF_SPACING)
|
||||
.into()
|
||||
}
|
||||
fn adder_panel(&self, deck: &DeckViewData) -> Element<'_, RepetitionsMessage> {
|
||||
match deck.append_mode {
|
||||
AppendMode::Full => space().into(),
|
||||
AppendMode::Manual => row![
|
||||
button("+5").on_press(AppendWords(5)),
|
||||
button("+10").on_press(AppendWords(10)),
|
||||
button("+15").on_press(AppendWords(15)),
|
||||
button("+20").on_press(AppendWords(20))
|
||||
]
|
||||
.spacing(HALF_SPACING)
|
||||
.into(),
|
||||
}
|
||||
column.into()
|
||||
}
|
||||
|
||||
fn count_view(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
|
||||
if let Some(count) = set.count {
|
||||
fn count_comparator_view(&self) -> Element<'_, RepetitionsMessage> {
|
||||
let selected_deck = self.selected_deck().unwrap();
|
||||
let now = selected_deck.existing_words_indices.as_ref().unwrap().len();
|
||||
let available = selected_deck
|
||||
.available_words_indices
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.len();
|
||||
text!("{} слова добавлено из {}", now, available).into()
|
||||
}
|
||||
fn count_view(&self, deck: &DeckSettings) -> Element<'_, RepetitionsMessage> {
|
||||
if let Some(count) = deck.count {
|
||||
return text!("Количество слов: {}", count).into();
|
||||
}
|
||||
space().into()
|
||||
}
|
||||
|
||||
fn sets_list(&self) -> Column<'_, RepetitionsMessage> {
|
||||
fn decks_list(&self) -> Column<'_, RepetitionsMessage> {
|
||||
let mut column = Column::new();
|
||||
let mut i = 0;
|
||||
let sets = &self.state.lock().unwrap().card_sets;
|
||||
for set in sets {
|
||||
|
||||
for (i, deck) in self.decks.iter().enumerate() {
|
||||
column = column.push(
|
||||
button(text!("{}", set.name.clone()))
|
||||
.on_press_with(move || SelectSet(i.clone()))
|
||||
button(text!("{}", &deck.name))
|
||||
.on_press_with(move || SelectSet(i))
|
||||
.style(move |_x: &Theme, status: Status| Style {
|
||||
background: if status == Status::Hovered {
|
||||
Some(Background::Color(Color::WHITE.scale_alpha(0.2)))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
text_color: if self.correct_filters[i.clone()] {
|
||||
_x.palette().primary
|
||||
} else {
|
||||
_x.palette().warning
|
||||
},
|
||||
text_color: _x.palette().primary,
|
||||
border: Border {
|
||||
color: Default::default(),
|
||||
width: 0.0,
|
||||
@@ -401,13 +555,65 @@ impl RepetitionsState {
|
||||
snap: false,
|
||||
}),
|
||||
);
|
||||
i += 1;
|
||||
}
|
||||
|
||||
column
|
||||
}
|
||||
}
|
||||
|
||||
impl RepetitionsState {
|
||||
fn append_all_words(state: &mut AppState, deck: &DeckViewData) {
|
||||
let existing = deck.existing_words_indices.as_ref().unwrap();
|
||||
let mut created_set = HashSet::with_capacity(existing.len());
|
||||
existing.iter().for_each(|c| {
|
||||
created_set.insert(c);
|
||||
});
|
||||
let required = deck
|
||||
.available_words_indices
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|i| !created_set.contains(i))
|
||||
.cloned();
|
||||
Self::append_words(state, deck, required);
|
||||
}
|
||||
fn append_words(state: &mut AppState, deck: &DeckSettings, indices: impl Iterator<Item = usize>) {
|
||||
let words = &state.dictionary;
|
||||
let stats = &mut indices
|
||||
.map(|i| {
|
||||
let word = &words[i];
|
||||
CardStatistics {
|
||||
id: 0.into(),
|
||||
word_id: word.id,
|
||||
last_open: Utc::now(),
|
||||
score: 1,
|
||||
set_id: deck.id,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !stats.is_empty() {
|
||||
add_stat_list(stats, &mut state.connection);
|
||||
}
|
||||
}
|
||||
|
||||
fn select_deck(&mut self, index: usize) {
|
||||
if self.decks.get(index).is_some() {
|
||||
self.selected_deck_index = Some(index);
|
||||
}
|
||||
}
|
||||
|
||||
fn selected_deck(&self) -> Option<&DeckViewData> {
|
||||
self.decks.get(self.selected_deck_index?)
|
||||
}
|
||||
fn selected_deck_mut(&mut self) -> Option<&mut DeckViewData> {
|
||||
self.decks.get_mut(self.selected_deck_index?)
|
||||
}
|
||||
|
||||
fn clear_selection(&mut self) {
|
||||
self.selected_deck_index = None;
|
||||
}
|
||||
}
|
||||
#[derive(Clone)]
|
||||
pub enum RepetitionsMessage {
|
||||
Next,
|
||||
@@ -422,111 +628,25 @@ pub enum RepetitionsMessage {
|
||||
SetBackward(String),
|
||||
SetFilter(String),
|
||||
TryFilter,
|
||||
SetOpenMode(SetOrderMode),
|
||||
SetOpenMode(OrderMode),
|
||||
SetAppendMode(AppendMode),
|
||||
GoToHistory,
|
||||
GoToSettings,
|
||||
AppendWords(usize),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CardSetSettings {
|
||||
pub id: u32,
|
||||
pub name: String,
|
||||
pub forward: String,
|
||||
pub backward: String,
|
||||
pub filter: String,
|
||||
pub count: Option<usize>,
|
||||
pub worst_words_list: Option<Vec<WordData>>,
|
||||
pub open_mode: SetOrderMode,
|
||||
struct DeckViewData {
|
||||
general_settings: DeckSettings,
|
||||
existing_words_indices: Option<Vec<usize>>,
|
||||
available_words_indices: Option<Vec<usize>>,
|
||||
append_mode: AppendMode,
|
||||
index: Option<usize>,
|
||||
}
|
||||
impl Deref for DeckViewData {
|
||||
type Target = DeckSettings;
|
||||
|
||||
impl CardSetSettings {
|
||||
fn with_name(name: String) -> CardSetSettings {
|
||||
CardSetSettings {
|
||||
id: 0,
|
||||
name,
|
||||
forward: "".to_string(),
|
||||
backward: "".to_string(),
|
||||
filter: "true".to_string(),
|
||||
count: None,
|
||||
worst_words_list: None,
|
||||
open_mode: SetOrderMode::Default,
|
||||
}
|
||||
}
|
||||
|
||||
fn check_filter(&self) -> bool {
|
||||
let engine = Engine::new();
|
||||
let ast = engine.compile(&self.filter);
|
||||
ast.is_ok()
|
||||
}
|
||||
|
||||
pub fn get_word_list(&self, state: &AppState) -> Vec<WordData> {
|
||||
let mut list = vec![];
|
||||
let engine = Engine::new();
|
||||
let ast = engine.compile(&self.filter);
|
||||
if ast.is_err() {
|
||||
return list;
|
||||
}
|
||||
|
||||
let ast = ast.unwrap();
|
||||
|
||||
let groups = &state.word_groups;
|
||||
|
||||
for word in &state.dictionary {
|
||||
let mut more = rhai::Map::new();
|
||||
for iced in &word.additional {
|
||||
more.insert(iced.0.clone().into(), iced.1.clone().into());
|
||||
}
|
||||
let mut scope = Scope::new();
|
||||
scope
|
||||
.push_constant("key", word.key.clone())
|
||||
.push_constant("value", word.value.clone())
|
||||
.push_constant("tags", word.tags.clone())
|
||||
.push_constant("more", more)
|
||||
.push_constant(
|
||||
"group",
|
||||
groups
|
||||
.iter()
|
||||
.find(|g| g.id == word.group_id)
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.name,
|
||||
);
|
||||
|
||||
let result = engine.eval_ast_with_scope::<bool>(&mut scope, &ast);
|
||||
if result.is_ok() && result.unwrap() {
|
||||
list.push(word.clone());
|
||||
}
|
||||
}
|
||||
|
||||
list
|
||||
}
|
||||
|
||||
pub fn require_speech(&self) -> bool {
|
||||
self.forward == "speech" || self.backward == "speech"
|
||||
}
|
||||
|
||||
fn update_worst_words(&mut self, state: &AppState) {
|
||||
if let Some(_) = self.worst_words_list {
|
||||
return;
|
||||
}
|
||||
|
||||
let connection = &state.connection;
|
||||
let mut stats = load_stats_of_set(self, connection);
|
||||
stats.sort_by_key(|s| s.calculated_score() as i32);
|
||||
let avg = stats.iter().map(|s| s.calculated_score()).sum::<f32>() / stats.len() as f32;
|
||||
let avg = avg * 0.7;
|
||||
let bad: Vec<WordData> = stats
|
||||
.iter()
|
||||
.take_while(|word| word.calculated_score() < avg)
|
||||
.map(|stat| {
|
||||
state.dictionary[state
|
||||
.dictionary
|
||||
.binary_search_by_key(&stat.word_id, |x| x.id)
|
||||
.unwrap()]
|
||||
.clone()
|
||||
})
|
||||
.collect();
|
||||
|
||||
self.worst_words_list = Some(bad.clone());
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.general_settings
|
||||
}
|
||||
}
|
||||
|
||||
+25
-27
@@ -36,7 +36,7 @@ pub enum SelectorMessage {
|
||||
}
|
||||
|
||||
impl NavigatedPage<SelectorMessage> for SelectorState {
|
||||
fn navigate(&self, message: &SelectorMessage) -> Option<Page> {
|
||||
fn navigate(&mut self, message: &SelectorMessage) -> Option<Page> {
|
||||
if let SelectorMessage::Goto = message {
|
||||
return if self.is_writing {
|
||||
let writing = WritingState::new(&self.set);
|
||||
@@ -62,19 +62,8 @@ impl NavigatedPage<SelectorMessage> for SelectorState {
|
||||
None
|
||||
}
|
||||
|
||||
fn navigated(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
impl SelectorState {
|
||||
pub fn new(state: Arc<Mutex<AppState>>) -> Self {
|
||||
Self {
|
||||
set: Default::default(),
|
||||
is_writing: false,
|
||||
state,
|
||||
}
|
||||
}
|
||||
pub fn update(&mut self, message: SelectorMessage) -> Task<RootMessage> {
|
||||
fn navigated(&mut self) {}
|
||||
fn update(&mut self, message: SelectorMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
SelectorMessage::Change => match self.set.chars_type {
|
||||
KanaType::Katakana => self.set = KanaSet::hiragana(),
|
||||
@@ -86,19 +75,7 @@ impl SelectorState {
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn nav_style(theme: &Theme, status: Status) -> Style {
|
||||
let mut basic = button::text(theme, status);
|
||||
basic.background = if status == Status::Hovered {
|
||||
Some(Background::Color(Color::WHITE.scale_alpha(0.1)))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
basic.border.radius = BUTTON_RADIUS.into();
|
||||
basic
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, SelectorMessage> {
|
||||
fn view(&self) -> Element<'_, SelectorMessage> {
|
||||
container(
|
||||
iced::widget::column![
|
||||
row![
|
||||
@@ -132,6 +109,27 @@ impl SelectorState {
|
||||
.padding(10)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl SelectorState {
|
||||
pub fn new(state: Arc<Mutex<AppState>>) -> Self {
|
||||
Self {
|
||||
set: Default::default(),
|
||||
is_writing: false,
|
||||
state,
|
||||
}
|
||||
}
|
||||
|
||||
fn nav_style(theme: &Theme, status: Status) -> Style {
|
||||
let mut basic = button::text(theme, status);
|
||||
basic.background = if status == Status::Hovered {
|
||||
Some(Background::Color(Color::WHITE.scale_alpha(0.1)))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
basic.border.radius = BUTTON_RADIUS.into();
|
||||
basic
|
||||
}
|
||||
|
||||
fn rows_selector(&self) -> Element<'_, SelectorMessage> {
|
||||
let mut row = Row::new();
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
use crate::repetitions::Style;
|
||||
use iced::Element;
|
||||
use iced::border::Radius;
|
||||
use iced::widget::button::*;
|
||||
use iced::widget::{button, container};
|
||||
use iced::Element;
|
||||
use iced_core::alignment::Horizontal::Left;
|
||||
use iced_core::Length::Fill;
|
||||
use iced_core::alignment::Horizontal::Left;
|
||||
use iced_core::{Border, Theme};
|
||||
|
||||
pub const HALF_SPACING: f32 = DEFAULT_SPACING / 2.0;
|
||||
|
||||
+29
-26
@@ -4,7 +4,7 @@ use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{NavigatedPage, Page};
|
||||
use crate::styling::*;
|
||||
use crate::sync::SyncMessage::*;
|
||||
use crate::{fill_state, AppState, RootMessage};
|
||||
use crate::{AppState, RootMessage, fill_state};
|
||||
use iced::widget::button::danger;
|
||||
use iced::widget::container::rounded_box;
|
||||
use iced::widget::{button, column, container, progress_bar, row, space, text, toggler};
|
||||
@@ -12,7 +12,6 @@ use iced::{Center, Element, Fill, Font, Length, Task};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum SyncMessage {
|
||||
Back,
|
||||
@@ -38,7 +37,7 @@ pub struct SyncState {
|
||||
}
|
||||
|
||||
impl NavigatedPage<SyncMessage> for SyncState {
|
||||
fn navigate(&self, message: &SyncMessage) -> Option<Page> {
|
||||
fn navigate(&mut self, message: &SyncMessage) -> Option<Page> {
|
||||
if let Back = message
|
||||
&& !self.frozen
|
||||
{
|
||||
@@ -49,23 +48,7 @@ impl NavigatedPage<SyncMessage> for SyncState {
|
||||
}
|
||||
|
||||
fn navigated(&mut self) {}
|
||||
}
|
||||
|
||||
impl SyncState {
|
||||
pub fn new(state: Arc<Mutex<AppState>>) -> SyncState {
|
||||
let auto_fetch;
|
||||
{
|
||||
auto_fetch = state.lock().unwrap().sync_data.auto_web_fetch;
|
||||
}
|
||||
Self {
|
||||
auto_fetch,
|
||||
state,
|
||||
frozen: false,
|
||||
progress: 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: SyncMessage) -> Task<RootMessage> {
|
||||
fn update(&mut self, message: SyncMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
Back => {}
|
||||
CopyKey => {
|
||||
@@ -83,7 +66,7 @@ impl SyncState {
|
||||
}
|
||||
KeyCopied => {}
|
||||
IdReceived(new_id) => {
|
||||
if validate_id(&new_id) == false {
|
||||
if !validate_id(&new_id) {
|
||||
return Task::none();
|
||||
}
|
||||
let mut state = self.state.lock().unwrap();
|
||||
@@ -136,7 +119,7 @@ impl SyncState {
|
||||
let mut state = self.state.lock().unwrap();
|
||||
state.sync_data = updated_state.sync_data;
|
||||
state.connection = updated_state.connection;
|
||||
state.card_sets = updated_state.card_sets;
|
||||
state.decks = updated_state.decks;
|
||||
state.dictionary = updated_state.dictionary;
|
||||
state.word_groups = updated_state.word_groups;
|
||||
}
|
||||
@@ -146,19 +129,22 @@ impl SyncState {
|
||||
state.sync_data.key = None;
|
||||
delete_settings("SYNC_KEY".to_string(), &state.connection);
|
||||
delete_settings("AUTO_WEB_FETCH".to_string(), &state.connection);
|
||||
|
||||
}
|
||||
SwitchAutoSync => {
|
||||
self.auto_fetch = !self.auto_fetch;
|
||||
let mut state = self.state.lock().unwrap();
|
||||
state.sync_data.auto_web_fetch = self.auto_fetch;
|
||||
set_setting("AUTO_WEB_FETCH".to_string(), self.auto_fetch.to_string(), &state.connection);
|
||||
set_setting(
|
||||
"AUTO_WEB_FETCH".to_string(),
|
||||
self.auto_fetch.to_string(),
|
||||
&state.connection,
|
||||
);
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, SyncMessage> {
|
||||
fn view(&self) -> Element<'_, SyncMessage> {
|
||||
back_overlay(
|
||||
row![space().width(Fill), self.sync_column(), space().width(Fill)]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
@@ -167,6 +153,21 @@ impl SyncState {
|
||||
Back,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl SyncState {
|
||||
pub fn new(state: Arc<Mutex<AppState>>) -> SyncState {
|
||||
let auto_fetch;
|
||||
{
|
||||
auto_fetch = state.lock().unwrap().sync_data.auto_web_fetch;
|
||||
}
|
||||
Self {
|
||||
auto_fetch,
|
||||
state,
|
||||
frozen: false,
|
||||
progress: 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
fn sync_column(&self) -> Element<'_, SyncMessage> {
|
||||
let network_view: Element<'_, SyncMessage> = if self.frozen {
|
||||
@@ -197,7 +198,9 @@ impl SyncState {
|
||||
button("↓ Скачать").style(jl_button).on_press(GetLast)
|
||||
]
|
||||
.spacing(DEFAULT_SPACING),
|
||||
toggler(self.auto_fetch).label("Автоматическая синхронизация").on_toggle(|_| SwitchAutoSync),
|
||||
toggler(self.auto_fetch)
|
||||
.label("Автоматическая синхронизация")
|
||||
.on_toggle(|_| SwitchAutoSync),
|
||||
container(network_view).width(Fill),
|
||||
button("Отключить синхронизацию")
|
||||
.style(danger)
|
||||
|
||||
+23
-33
@@ -6,7 +6,7 @@ use crate::styling::*;
|
||||
use crate::word::WordMessage::*;
|
||||
use crate::{AppState, RootMessage};
|
||||
use iced::widget::button::danger;
|
||||
use iced::widget::{button, column, row, rule, scrollable, space, text, text_input};
|
||||
use iced::widget::{button, column, row, rule, scrollable, text, text_input};
|
||||
use iced::{Element, Fill, Task};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
@@ -18,7 +18,7 @@ pub struct WordState {
|
||||
}
|
||||
|
||||
impl NavigatedPage<WordMessage> for WordState {
|
||||
fn navigate(&self, message: &WordMessage) -> Option<Page> {
|
||||
fn navigate(&mut self, message: &WordMessage) -> Option<Page> {
|
||||
if let Back = message {
|
||||
Some(PreviousPage)
|
||||
} else {
|
||||
@@ -26,18 +26,8 @@ impl NavigatedPage<WordMessage> for WordState {
|
||||
}
|
||||
}
|
||||
|
||||
fn navigated(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
impl WordState {
|
||||
pub(crate) fn new(word: WordData, index: usize, state: Arc<Mutex<AppState>>) -> WordState {
|
||||
WordState { state, index, word }
|
||||
}
|
||||
}
|
||||
|
||||
impl WordState {
|
||||
pub fn update(&mut self, message: WordMessage) -> Task<RootMessage> {
|
||||
fn navigated(&mut self) {}
|
||||
fn update(&mut self, message: WordMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
Back => {}
|
||||
Save => {
|
||||
@@ -59,11 +49,9 @@ impl WordState {
|
||||
SetValue(n) => {
|
||||
self.word.value = n;
|
||||
}
|
||||
SetAdditional(key, value) => match key.as_str() {
|
||||
_ => {
|
||||
SetAdditional(key, value) => {
|
||||
self.word.additional.insert(key, value.clone());
|
||||
}
|
||||
},
|
||||
AddAdditional(key) => {
|
||||
self.word.additional.insert(key, "".to_string());
|
||||
}
|
||||
@@ -74,7 +62,7 @@ impl WordState {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, WordMessage> {
|
||||
fn view(&self) -> Element<'_, WordMessage> {
|
||||
let mut fast_add = row![];
|
||||
if !self.word.additional.contains_key("reading") {
|
||||
fast_add = fast_add.push(
|
||||
@@ -137,38 +125,40 @@ impl WordState {
|
||||
Back,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl WordState {
|
||||
pub(crate) fn new(word: WordData, index: usize, state: Arc<Mutex<AppState>>) -> WordState {
|
||||
WordState { state, index, word }
|
||||
}
|
||||
}
|
||||
|
||||
impl WordState {
|
||||
fn get_view_for_more(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
||||
match value.0.as_str() {
|
||||
"reading" => self.reading_field(value),
|
||||
"description" => self.description_field(value),
|
||||
"context" => self.context_field(value),
|
||||
_ => space().into(),
|
||||
"reading" => self.reading_field(value.1),
|
||||
"description" => self.description_field(value.1),
|
||||
"context" => self.context_field(value.1),
|
||||
_ => self.additional_field(value.1, value.0.clone(), value.0.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
fn reading_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
||||
fn reading_field(&self, value: &str) -> Element<'_, WordMessage> {
|
||||
self.additional_field(value, "Чтение слова".to_string(), "reading".to_string())
|
||||
}
|
||||
|
||||
fn description_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
||||
fn description_field(&self, value: &str) -> Element<'_, WordMessage> {
|
||||
self.additional_field(value, "Описание".to_string(), "description".to_string())
|
||||
}
|
||||
|
||||
fn context_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
||||
fn context_field(&self, value: &str) -> Element<'_, WordMessage> {
|
||||
self.additional_field(value, "В контексте".to_string(), "context".to_string())
|
||||
}
|
||||
|
||||
fn additional_field(
|
||||
&self,
|
||||
value: (&String, &String),
|
||||
name: String,
|
||||
id: String,
|
||||
) -> Element<'_, WordMessage> {
|
||||
fn additional_field(&self, value: &str, name: String, id: String) -> Element<'_, WordMessage> {
|
||||
column![
|
||||
text!("{}", name),
|
||||
row![
|
||||
text_input(id.clone().as_str(), &value.1)
|
||||
text_input(id.clone().as_str(), value)
|
||||
.on_input({
|
||||
let value = id.clone();
|
||||
move |string| SetAdditional(value.clone(), string)
|
||||
|
||||
+53
-56
@@ -1,10 +1,10 @@
|
||||
use crate::RootMessage;
|
||||
use crate::lang::KanaSet;
|
||||
use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{NavigatedPage, Page};
|
||||
use crate::styling::*;
|
||||
use crate::RootMessage;
|
||||
use iced::widget::*;
|
||||
use iced::{alignment, Element, Fill, Task};
|
||||
use iced::{Element, Fill, Task, alignment};
|
||||
use rand::seq::SliceRandom;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -19,7 +19,7 @@ pub struct WritingState {
|
||||
}
|
||||
|
||||
impl NavigatedPage<WritingMessage> for WritingState {
|
||||
fn navigate(&self, message: &WritingMessage) -> Option<Page> {
|
||||
fn navigate(&mut self, message: &WritingMessage) -> Option<Page> {
|
||||
if let WritingMessage::Back = message {
|
||||
Some(PreviousPage)
|
||||
} else {
|
||||
@@ -27,65 +27,16 @@ impl NavigatedPage<WritingMessage> for WritingState {
|
||||
}
|
||||
}
|
||||
|
||||
fn navigated(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
impl WritingState {
|
||||
pub(crate) fn new(set: &KanaSet) -> WritingState {
|
||||
let mut list = set.list();
|
||||
list.shuffle(&mut rand::rng());
|
||||
WritingState {
|
||||
kana: "".to_string(),
|
||||
set: list.clone(),
|
||||
original_set: list,
|
||||
kana_total: "".to_string(),
|
||||
roman_total: "".to_string(),
|
||||
next_text: "Дальше".to_string(),
|
||||
show_all: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WritingState {
|
||||
pub fn update(&mut self, message: WritingMessage) -> Task<RootMessage> {
|
||||
fn navigated(&mut self) {}
|
||||
fn update(&mut self, message: WritingMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
WritingMessage::Back => todo!(),
|
||||
WritingMessage::Back => {},
|
||||
WritingMessage::Next => self.next(),
|
||||
WritingMessage::SwitchShowMode(b) => self.show_all = b,
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn next(&mut self) {
|
||||
if self.set.is_empty() {
|
||||
self.kana = "".to_string();
|
||||
self.roman_total = "".to_string();
|
||||
self.kana_total = "".to_string();
|
||||
|
||||
self.set = self.original_set.clone();
|
||||
self.set.shuffle(&mut rand::rng());
|
||||
return;
|
||||
}
|
||||
|
||||
if self.show_all {
|
||||
if self.set.is_empty() == false && self.kana_total.is_empty() == false {
|
||||
self.set.clear();
|
||||
}
|
||||
for pair in &self.set {
|
||||
self.kana = "---".to_string();
|
||||
self.roman_total += &*format!("{} ", &pair.1.clone()).to_string();
|
||||
self.kana_total += &*format!("{} ", &pair.0).to_string();
|
||||
}
|
||||
} else {
|
||||
let current = self.set.pop().unwrap();
|
||||
self.kana_total += &*format!("{} ", ¤t.0).to_string();
|
||||
self.roman_total += &*format!("{} ", ¤t.1.clone()).to_string();
|
||||
self.kana = current.1;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, WritingMessage> {
|
||||
fn view(&self) -> Element<'_, WritingMessage> {
|
||||
container(
|
||||
iced::widget::column![
|
||||
checkbox(self.show_all)
|
||||
@@ -112,6 +63,52 @@ impl WritingState {
|
||||
.padding(10)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl WritingState {
|
||||
pub(crate) fn new(set: &KanaSet) -> WritingState {
|
||||
let mut list = set.list();
|
||||
list.shuffle(&mut rand::rng());
|
||||
WritingState {
|
||||
kana: "".to_string(),
|
||||
set: list.clone(),
|
||||
original_set: list,
|
||||
kana_total: "".to_string(),
|
||||
roman_total: "".to_string(),
|
||||
next_text: "Дальше".to_string(),
|
||||
show_all: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WritingState {
|
||||
fn next(&mut self) {
|
||||
if self.set.is_empty() {
|
||||
self.kana = "".to_string();
|
||||
self.roman_total = "".to_string();
|
||||
self.kana_total = "".to_string();
|
||||
|
||||
self.set = self.original_set.clone();
|
||||
self.set.shuffle(&mut rand::rng());
|
||||
return;
|
||||
}
|
||||
|
||||
if self.show_all {
|
||||
if !self.set.is_empty() && !self.kana_total.is_empty() {
|
||||
self.set.clear();
|
||||
}
|
||||
for pair in &self.set {
|
||||
self.kana = "---".to_string();
|
||||
self.roman_total += &*format!("{} ", pair.1.clone()).to_string();
|
||||
self.kana_total += &*format!("{} ", pair.0).to_string();
|
||||
}
|
||||
} else {
|
||||
let current = self.set.pop().unwrap();
|
||||
self.kana_total += &*format!("{} ", current.0).to_string();
|
||||
self.roman_total += &*format!("{} ", current.1.clone()).to_string();
|
||||
self.kana = current.1;
|
||||
}
|
||||
}
|
||||
|
||||
fn answers(&self) -> Element<'_, WritingMessage> {
|
||||
if self.set.is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user