Skip to content

Commit

Permalink
[WIP] Experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-lerch committed Jul 11, 2023
1 parent be6d689 commit 1dc5480
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/Vocup.Core/Models/BookPracticeState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using DynamicData;
using DynamicData.Binding;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
using Vocup.Settings;

namespace Vocup.Models;

public class BookPracticeState : ReactiveObject
{
private readonly IObservableList<PracticeState> practiceStates;

public BookPracticeState(Book book, IVocupSettings settings)
{
book.Words.ToObservableChangeSet()
.AutoRefresh(word => word.ForeignLanguagePracticeState)
.AutoRefresh(word => word.MotherTonguePracticeState)
.AutoRefreshOnObservable(_ => book.WhenAnyValue(x => x.PracticeMode))
.AutoRefreshOnObservable(_ => settings.WhenAnyValue(x => x.MaxPracticeCount))
.Transform(word => book.PracticeMode != PracticeMode.AskForMotherTongue ? word.ForeignLanguagePracticeState : word.MotherTonguePracticeState)
.Transform(practiceStateNumber => PracticeStateHelper.Parse(practiceStateNumber, settings.MaxPracticeCount))
.BindToObservableList(out practiceStates)
.Subscribe();
}

public WordPracticeState this[Word word] => null;

Check warning on line 27 in src/Vocup.Core/Models/BookPracticeState.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Possible null reference return.

Check warning on line 27 in src/Vocup.Core/Models/BookPracticeState.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Possible null reference return.

Check warning on line 27 in src/Vocup.Core/Models/BookPracticeState.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Possible null reference return.

[ObservableAsProperty] public int Unpracticed { get; }
[ObservableAsProperty] public int WronglyPracticed { get; }
[ObservableAsProperty] public int CorrectlyPracticed { get; }
[ObservableAsProperty] public int FullyPracticed { get; }
[ObservableAsProperty] public int NotFullyPracticed { get; }
}
6 changes: 6 additions & 0 deletions src/Vocup.Core/Models/Word.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ public override int GetHashCode()
return HashCode.Combine(CreationDate, MotherTongue, ForeignLanguage);
}

/// <summary>
/// A comma separated list of mother tongue synonyms
/// </summary>
public string MotherTongueCombined => motherTongueCombined.Value;
/// <summary>
/// A comma separated list of foreign language synonyms
/// </summary>
public string ForeignLanguageCombined => foreignLanguageCombined.Value;
public int MotherTonguePracticeState => motherTonguePracticeState.Value;
public int ForeignLanguagePracticeState => foreignLanguagePracticeState.Value;
Expand Down
25 changes: 25 additions & 0 deletions src/Vocup.Core/Models/WordPracticeState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using ReactiveUI;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Linq;
using Vocup.Settings;

namespace Vocup.Models;

public class WordPracticeState : ReactiveObject
{
public WordPracticeState(Book book, Word word, IVocupSettings settings)
{
book.WhenAnyValue(x => x.PracticeMode)
.Select(practiceMode => practiceMode != PracticeMode.AskForMotherTongue ? word.ForeignLanguage : word.MotherTongue);

//PracticeState = Reactive(() =>
//{
// ObservableCollection<Synonym> synonyms = book.PracticeMode != PracticeMode.AskForMotherTongue ? word.ForeignLanguage : word.MotherTongue;
// int practiceStateNumber = synonyms.MaxBy(synonym => synonym.PracticeState)?.PracticeState ?? 0;
// return PracticeStateHelper.Parse(practiceStateNumber, settings.MaxPracticeCount);
//});
}

PracticeState PracticeState { get; }
}
2 changes: 1 addition & 1 deletion src/Vocup/Models/VocabularyWordController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public VocabularyWordController(Word vocabularyWord)
praticeDateColumn = ListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(ListViewItem, ""));

VocabularyWord = vocabularyWord;
VocabularyWord.PropertyChanged += (a0, a1) => UpdateUI();
VocabularyWord.PropertyChanged += (_, _) => UpdateUI();
UpdateUI();
}

Expand Down

0 comments on commit 1dc5480

Please sign in to comment.