mirror of
https://github.com/ivuorinen/hiha-arvio.git
synced 2026-01-26 11:24:04 +00:00
Implemented all ViewModels using strict TDD (RED-GREEN-REFACTOR) with CommunityToolkit.Mvvm. **ViewModels Implemented:** - MainViewModel: Coordinates shake detection, estimate generation, and display - HistoryViewModel: Manages estimate history display and clearing - SettingsViewModel: Handles app settings (mode selection, history size) **MainViewModel Features:** - Subscribes to ShakeDetectionService events - Generates estimates when shake stops (transition from shaking→not shaking) - Automatically saves estimates to storage - Resets shake detection after estimate generation - Loads and saves settings (SelectedMode) - Proper disposal pattern (unsubscribe, stop monitoring) **HistoryViewModel Features:** - ObservableCollection<EstimateResult> for UI binding - LoadHistoryCommand to fetch from storage - ClearHistoryCommand to remove all history - IsEmpty property for conditional UI display - Replaces collection contents on reload **SettingsViewModel Features:** - SelectedMode property (Work/Generic) - MaxHistorySize property - SaveSettingsCommand to persist changes - Loads settings on initialization **Tests:** - MainViewModel: 18 tests (RED-GREEN-REFACTOR) - HistoryViewModel: 15 tests (RED-GREEN-REFACTOR) - SettingsViewModel: 13 tests (RED-GREEN-REFACTOR) - Total: 165 tests, all passing (48 models + 71 services + 46 ViewModels) **Quality:** - Build: 0 warnings, 0 errors across all platforms - All tests use NSubstitute for mocking - Property change notifications verified - Async operations properly tested 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
52 lines
1.2 KiB
C#
52 lines
1.2 KiB
C#
using System.Collections.ObjectModel;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using HihaArvio.Models;
|
|
using HihaArvio.Services.Interfaces;
|
|
|
|
namespace HihaArvio.ViewModels;
|
|
|
|
/// <summary>
|
|
/// ViewModel for displaying and managing estimate history.
|
|
/// </summary>
|
|
public partial class HistoryViewModel : ObservableObject
|
|
{
|
|
private readonly IStorageService _storageService;
|
|
|
|
[ObservableProperty]
|
|
private ObservableCollection<EstimateResult> _history;
|
|
|
|
[ObservableProperty]
|
|
private bool _isEmpty;
|
|
|
|
public HistoryViewModel(IStorageService storageService)
|
|
{
|
|
_storageService = storageService;
|
|
_history = new ObservableCollection<EstimateResult>();
|
|
_isEmpty = true;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task LoadHistoryAsync()
|
|
{
|
|
var estimates = await _storageService.GetHistoryAsync();
|
|
|
|
History.Clear();
|
|
foreach (var estimate in estimates)
|
|
{
|
|
History.Add(estimate);
|
|
}
|
|
|
|
IsEmpty = History.Count == 0;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task ClearHistoryAsync()
|
|
{
|
|
await _storageService.ClearHistoryAsync();
|
|
|
|
History.Clear();
|
|
IsEmpty = true;
|
|
}
|
|
}
|