Repetition settings base
This commit is contained in:
+50
-37
@@ -2,21 +2,24 @@ use crate::data_provider::card_sets::{delete_set, update_card_set};
|
||||
use crate::data_provider::card_stats::load_stats_of_set;
|
||||
use crate::history::HistoryState;
|
||||
use crate::lang::{SetOrderMode, WordData};
|
||||
use crate::navigation::Page::{History, PreviousPage, Repetition};
|
||||
use crate::navigation::Page::{History, PreviousPage, Repetition, RepetitionSettings};
|
||||
use crate::navigation::{NavigatedPage, Page};
|
||||
use crate::repetition::RepetitionState;
|
||||
use crate::styling::*;
|
||||
use crate::{AppState, RootMessage};
|
||||
use iced::widget::button::{danger, Status};
|
||||
pub use iced::widget::button::{Catalog, Style};
|
||||
use iced::widget::button::{Status, danger};
|
||||
use iced::widget::container::bordered_box;
|
||||
use iced::widget::{
|
||||
button, column, container, radio, row, scrollable, space, text, text_input, Column,
|
||||
Column, button, column, container, radio, row, scrollable, space, svg, text, text_input,
|
||||
};
|
||||
use iced::{Background, Border, Center, Color, Element, Fill, Length, Shadow, Task, Theme};
|
||||
use iced_core::Padding;
|
||||
use iced_core::svg::Handle;
|
||||
use rhai::{Engine, Scope};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use crate::repetition_settings::RepetitionSettingsState;
|
||||
use crate::repetitions::RepetitionsMessage::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RepetitionsState {
|
||||
@@ -28,22 +31,26 @@ pub struct RepetitionsState {
|
||||
|
||||
impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
|
||||
fn navigate(&self, message: &RepetitionsMessage) -> Option<Page> {
|
||||
if let RepetitionsMessage::Back = message {
|
||||
if let Back = message {
|
||||
Some(PreviousPage)
|
||||
} else if let RepetitionsMessage::GoToHistory = message {
|
||||
} 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())))
|
||||
} else if let RepetitionsMessage::GoToRepetition = message {
|
||||
} else if let GoToRepetition = message {
|
||||
let clone = self.state.clone();
|
||||
let card_set;
|
||||
{
|
||||
card_set = self.state.lock().unwrap().card_sets[self.selected_set.unwrap()].clone();
|
||||
}
|
||||
Some(Repetition(RepetitionState::new(card_set, clone)))
|
||||
} else {
|
||||
}
|
||||
else if let GoToSettings = message {
|
||||
Some(RepetitionSettings(RepetitionSettingsState {}))
|
||||
}
|
||||
else {
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -64,33 +71,34 @@ impl RepetitionsState {
|
||||
pub fn update(&mut self, message: RepetitionsMessage) -> Task<RootMessage> {
|
||||
let mut state = self.state.lock().unwrap();
|
||||
match message {
|
||||
RepetitionsMessage::Next => {}
|
||||
RepetitionsMessage::Back => {}
|
||||
RepetitionsMessage::GoToRepetition => {}
|
||||
RepetitionsMessage::GoToHistory => {}
|
||||
RepetitionsMessage::CreateSet => {
|
||||
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);
|
||||
}
|
||||
RepetitionsMessage::DeleteSet => {
|
||||
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);
|
||||
}
|
||||
RepetitionsMessage::SelectSet(index) => {
|
||||
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;
|
||||
}
|
||||
RepetitionsMessage::SetName(new) => {
|
||||
SetName(new) => {
|
||||
state.card_sets[self.selected_set.unwrap()].name = new;
|
||||
}
|
||||
RepetitionsMessage::Save => {
|
||||
Save => {
|
||||
for i in 0..state.card_sets.len() {
|
||||
self.correct_filters[i] = state.card_sets[i].check_filter();
|
||||
}
|
||||
@@ -101,27 +109,27 @@ impl RepetitionsState {
|
||||
|
||||
state.card_sets[self.selected_set.unwrap()] = word.clone();
|
||||
}
|
||||
RepetitionsMessage::SetForward(new) => {
|
||||
SetForward(new) => {
|
||||
state.card_sets[self.selected_set.unwrap()].forward = new;
|
||||
}
|
||||
RepetitionsMessage::SetBackward(new) => {
|
||||
SetBackward(new) => {
|
||||
state.card_sets[self.selected_set.unwrap()].backward = new;
|
||||
}
|
||||
RepetitionsMessage::SetFilter(new) => {
|
||||
SetFilter(new) => {
|
||||
state.card_sets[self.selected_set.unwrap()].filter = new;
|
||||
}
|
||||
RepetitionsMessage::TryFilter => {
|
||||
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);
|
||||
}
|
||||
RepetitionsMessage::SetOpenMode(mode) => {
|
||||
SetOpenMode(mode) => {
|
||||
state
|
||||
.card_sets
|
||||
.get_mut(self.selected_set.unwrap())
|
||||
.unwrap()
|
||||
.open_mode = mode;
|
||||
}
|
||||
},
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
@@ -134,7 +142,7 @@ impl RepetitionsState {
|
||||
button("Добавить")
|
||||
.style(jl_button)
|
||||
.width(Fill)
|
||||
.on_press(RepetitionsMessage::CreateSet),
|
||||
.on_press(CreateSet),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.width(Length::FillPortion(1)),
|
||||
@@ -145,7 +153,7 @@ impl RepetitionsState {
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.into(),
|
||||
RepetitionsMessage::Back,
|
||||
Back,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -155,7 +163,7 @@ impl RepetitionsState {
|
||||
{
|
||||
return button(text!("Начать повторение").width(200).center())
|
||||
.style(cta_button)
|
||||
.on_press(RepetitionsMessage::GoToRepetition)
|
||||
.on_press(GoToRepetition)
|
||||
.into();
|
||||
}
|
||||
space().into()
|
||||
@@ -172,25 +180,29 @@ impl RepetitionsState {
|
||||
column![
|
||||
column![
|
||||
text!("Название набора"),
|
||||
text_input("", &set.name).on_input(RepetitionsMessage::SetName)
|
||||
row![
|
||||
text_input("", &set.name).on_input(SetName),
|
||||
button(svg(Handle::from_memory(SETTINGS_ICON))).width(43).on_press(GoToSettings),
|
||||
]
|
||||
.spacing(HALF_SPACING)
|
||||
]
|
||||
.spacing(QUARTER_SPACING),
|
||||
column![
|
||||
text!("Передняя сторона"),
|
||||
text_input("", &set.forward).on_input(RepetitionsMessage::SetForward),
|
||||
text_input("", &set.forward).on_input(SetForward),
|
||||
]
|
||||
.spacing(QUARTER_SPACING),
|
||||
column![
|
||||
text!("Задняя сторона"),
|
||||
text_input("", &set.backward).on_input(RepetitionsMessage::SetBackward),
|
||||
text_input("", &set.backward).on_input(SetBackward),
|
||||
]
|
||||
.spacing(QUARTER_SPACING),
|
||||
column![
|
||||
text!("Фильтр"),
|
||||
text_input("", &set.filter).on_input(RepetitionsMessage::SetFilter),
|
||||
text_input("", &set.filter).on_input(SetFilter),
|
||||
button("Проверить фильтр")
|
||||
.style(jl_button)
|
||||
.on_press(RepetitionsMessage::TryFilter),
|
||||
.on_press(TryFilter),
|
||||
self.count_view(&set),
|
||||
]
|
||||
.spacing(QUARTER_SPACING),
|
||||
@@ -198,12 +210,12 @@ impl RepetitionsState {
|
||||
"Обычный режим",
|
||||
SetOrderMode::Default,
|
||||
Some(set.open_mode),
|
||||
RepetitionsMessage::SetOpenMode
|
||||
SetOpenMode
|
||||
),
|
||||
self.words_words_view(&set),
|
||||
button("История")
|
||||
.style(jl_button)
|
||||
.on_press(RepetitionsMessage::GoToHistory),
|
||||
.on_press(GoToHistory),
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
.padding(Padding {
|
||||
@@ -217,10 +229,10 @@ impl RepetitionsState {
|
||||
row![
|
||||
button("Сохранить")
|
||||
.style(jl_button)
|
||||
.on_press(RepetitionsMessage::Save),
|
||||
.on_press(Save),
|
||||
button("Удалить")
|
||||
.style(danger)
|
||||
.on_press(RepetitionsMessage::DeleteSet),
|
||||
.on_press(DeleteSet),
|
||||
space().width(Fill),
|
||||
self.launch_button()
|
||||
]
|
||||
@@ -241,13 +253,13 @@ impl RepetitionsState {
|
||||
"Начать с плохих слов",
|
||||
SetOrderMode::TrainWorstFirst,
|
||||
Some(set.open_mode),
|
||||
RepetitionsMessage::SetOpenMode
|
||||
SetOpenMode
|
||||
),
|
||||
radio(
|
||||
"Полностью случайно",
|
||||
SetOrderMode::FullRandom,
|
||||
Some(set.open_mode),
|
||||
RepetitionsMessage::SetOpenMode
|
||||
SetOpenMode
|
||||
)
|
||||
]
|
||||
.spacing(DEFAULT_SPACING)
|
||||
@@ -277,7 +289,7 @@ impl RepetitionsState {
|
||||
for set in sets {
|
||||
column = column.push(
|
||||
button(text!("{}", set.name.clone()))
|
||||
.on_press_with(move || RepetitionsMessage::SelectSet(i.clone()))
|
||||
.on_press_with(move || SelectSet(i.clone()))
|
||||
.style(move |_x: &Theme, status: Status| Style {
|
||||
background: if status == Status::Hovered {
|
||||
Some(Background::Color(Color::WHITE.scale_alpha(0.2)))
|
||||
@@ -321,6 +333,7 @@ pub enum RepetitionsMessage {
|
||||
TryFilter,
|
||||
SetOpenMode(SetOrderMode),
|
||||
GoToHistory,
|
||||
GoToSettings,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
||||
Reference in New Issue
Block a user