From abbd5ea223d488d1e443d6e6a34a935f32c77458 Mon Sep 17 00:00:00 2001 From: Duck <61479436+duck-dev@users.noreply.github.com> Date: Sat, 6 May 2023 12:15:32 +0200 Subject: [PATCH] Add display for learning progress in LessonModesView.axaml - Added two progress bars for the learning progress (known and wrong words) to the LessonModesView, which is displayed in the LessonView (LessonView.axaml), meaning the view of an opened already existing lesson, which can be edited. --- src/ViewModels/LearningModesViewModel.cs | 41 +++++++ src/Views/OpenLesson/LearningModesView.axaml | 118 +++++++++++++------ 2 files changed, 121 insertions(+), 38 deletions(-) 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