diff --git a/src/ViewModels/LearningModesViewModel.cs b/src/ViewModels/LearningModesViewModel.cs index 5f2384b..8c11b5a 100644 --- a/src/ViewModels/LearningModesViewModel.cs +++ b/src/ViewModels/LearningModesViewModel.cs @@ -1,12 +1,32 @@ using System; +using System.Collections.Generic; +using System.Linq; +using ReactiveUI; using VocabularyTrainer.Enums; +using VocabularyTrainer.Extensions; using VocabularyTrainer.Models; +using VocabularyTrainer.UtilityCollection; using VocabularyTrainer.ViewModels.LearningModes; namespace VocabularyTrainer.ViewModels; public sealed class LearningModesViewModel : ViewModelBase { + private readonly Lesson? _currentLesson; + private int _knownWords; + private int _wrongWords; + + public LearningModesViewModel() + { + _currentLesson = MainWindowViewModel.CurrentLesson; + if (_currentLesson is null) + return; + + var words = _currentLesson.VocabularyItems; + words.CollectionChanged += (sender, args) => RetrieveLearningProgress(words); + RetrieveLearningProgress(words); + } + private LearningModeItem[] LearningModes { get; } = { new ("Flashcards.png", "Flashcards", "Memorize vocabulary super fast by flipping flashcards.", @@ -23,6 +43,27 @@ public sealed class LearningModesViewModel : ViewModelBase OpenLearningMode, LearningModeType.VocabularyList), }; + private int MaximumItems => _currentLesson is not { } lesson ? 0 : lesson.VocabularyItems.Count; + + private int KnownWords + { + get => _knownWords; + set => this.RaiseAndSetIfChanged(ref _knownWords, value); + } + + private int WrongWords + { + get => _wrongWords; + set => this.RaiseAndSetIfChanged(ref _wrongWords, value); + } + + private void RetrieveLearningProgress(ICollection words) + { + this.KnownWords = words.Count(x => x.LearningStatus.CustomHasFlag(Utilities.KnownFlags)); + this.WrongWords = words.Count(x => x.LearningStatus.CustomHasFlag(Utilities.WrongFlags)); + this.RaisePropertyChanged(nameof(MaximumItems)); + } + private static void OpenLearningMode() where T : LearningModeViewModelBase { if (MainWindowViewModel.CurrentLesson is null) diff --git a/src/Views/OpenLesson/LearningModesView.axaml b/src/Views/OpenLesson/LearningModesView.axaml index e395b0a..1245575 100644 --- a/src/Views/OpenLesson/LearningModesView.axaml +++ b/src/Views/OpenLesson/LearningModesView.axaml @@ -9,44 +9,86 @@ + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file