| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using Avalonia.Media;
- using MiniMvvm;
- namespace ControlCatalog.Pages
- {
- public sealed class NavigationPageMvvmShellViewModel : ViewModelBase
- {
- private readonly ISampleNavigationService _navigationService;
- private string _currentPageHeader = "Not initialized";
- private string _lastAction = "Waiting for first load";
- private int _navigationDepth;
- private ProjectCardViewModel? _selectedProject;
- internal NavigationPageMvvmShellViewModel(ISampleNavigationService navigationService)
- {
- _navigationService = navigationService;
- _navigationService.StateChanged += OnStateChanged;
- Workspace = new WorkspaceViewModel(CreateProjects(navigationService));
- SelectedProject = Workspace.Projects[0];
- OpenSelectedProjectCommand = MiniCommand.CreateFromTask(OpenSelectedProjectAsync);
- GoBackCommand = MiniCommand.CreateFromTask(_navigationService.GoBackAsync);
- PopToRootCommand = MiniCommand.CreateFromTask(_navigationService.PopToRootAsync);
- }
- internal WorkspaceViewModel Workspace { get; }
- public IReadOnlyList<ProjectCardViewModel> Projects => Workspace.Projects;
- public MiniCommand OpenSelectedProjectCommand { get; }
- public MiniCommand GoBackCommand { get; }
- public MiniCommand PopToRootCommand { get; }
- public string CurrentPageHeader
- {
- get => _currentPageHeader;
- set => this.RaiseAndSetIfChanged(ref _currentPageHeader, value);
- }
- public int NavigationDepth
- {
- get => _navigationDepth;
- set => this.RaiseAndSetIfChanged(ref _navigationDepth, value);
- }
- public string LastAction
- {
- get => _lastAction;
- set => this.RaiseAndSetIfChanged(ref _lastAction, value);
- }
- public ProjectCardViewModel? SelectedProject
- {
- get => _selectedProject;
- set => this.RaiseAndSetIfChanged(ref _selectedProject, value);
- }
- public Task InitializeAsync() => _navigationService.NavigateToAsync(Workspace);
- private async Task OpenSelectedProjectAsync()
- {
- if (SelectedProject == null)
- return;
- await SelectedProject.OpenCommandAsync();
- }
- private void OnStateChanged(object? sender, NavigationStateChangedEventArgs e)
- {
- CurrentPageHeader = e.CurrentPageHeader;
- NavigationDepth = e.NavigationDepth;
- LastAction = e.LastAction;
- }
- private static IReadOnlyList<ProjectCardViewModel> CreateProjects(ISampleNavigationService navigationService) =>
- new[]
- {
- new ProjectCardViewModel(
- "Release Radar",
- "Marta Collins",
- "Ready for QA",
- "Coordinate the 11.0 release checklist and lock down the final regression window.",
- "Freeze build on Friday",
- Color.Parse("#0063B1"),
- navigationService,
- new[]
- {
- "Release notes draft updated with accessibility fixes.",
- "Package validation finished for desktop artifacts.",
- "Remaining task, confirm browser smoke test coverage."
- }),
- new ProjectCardViewModel(
- "Support Console",
- "Jae Kim",
- "Active Sprint",
- "Consolidate customer incidents into a triage board and route them to platform owners.",
- "Triage review in 2 hours",
- Color.Parse("#0F7B0F"),
- navigationService,
- new[]
- {
- "Five customer reports grouped under input routing.",
- "Hotfix candidate approved for preview branch.",
- "Awaiting macOS verification on native embed scenarios."
- }),
- new ProjectCardViewModel(
- "Docs Refresh",
- "Anika Patel",
- "Needs Review",
- "Refresh navigation samples and walkthrough docs so the gallery matches the current API.",
- "Sample review tomorrow",
- Color.Parse("#8E562E"),
- navigationService,
- new[]
- {
- "NavigationPage sample matrix reviewed with design.",
- "MVVM walkthrough draft linked from the docs backlog.",
- "Outstanding task, capture one more screenshot for drawer navigation."
- }),
- };
- }
- internal sealed class WorkspaceViewModel : ViewModelBase
- {
- public WorkspaceViewModel(IReadOnlyList<ProjectCardViewModel> projects)
- {
- Projects = projects;
- }
- public string Title => "Team Workspace";
- public string Description =>
- "Each card is a project view model with its own command. The command asks ISampleNavigationService to navigate with the next view model, and SamplePageFactory resolves the matching ContentPage.";
- public IReadOnlyList<ProjectCardViewModel> Projects { get; }
- }
- public sealed class ProjectCardViewModel : ViewModelBase
- {
- private readonly ISampleNavigationService _navigationService;
- internal ProjectCardViewModel(
- string name,
- string owner,
- string status,
- string summary,
- string nextMilestone,
- Color accentColor,
- ISampleNavigationService navigationService,
- IReadOnlyList<string> activityItems)
- {
- Name = name;
- Owner = owner;
- Status = status;
- Summary = summary;
- NextMilestone = nextMilestone;
- AccentColor = accentColor;
- ActivityItems = activityItems;
- _navigationService = navigationService;
- OpenCommand = MiniCommand.CreateFromTask(OpenCommandAsync);
- }
- public string Name { get; }
- public string Owner { get; }
- public string Status { get; }
- public string Summary { get; }
- public string NextMilestone { get; }
- public Color AccentColor { get; }
- public IReadOnlyList<string> ActivityItems { get; }
- public MiniCommand OpenCommand { get; }
- public Task OpenCommandAsync()
- {
- return _navigationService.NavigateToAsync(new ProjectDetailViewModel(this, _navigationService));
- }
- }
- internal sealed class ProjectDetailViewModel : ViewModelBase
- {
- private readonly ProjectCardViewModel _project;
- private readonly ISampleNavigationService _navigationService;
- public ProjectDetailViewModel(ProjectCardViewModel project, ISampleNavigationService navigationService)
- {
- _project = project;
- _navigationService = navigationService;
- OpenActivityCommand = MiniCommand.CreateFromTask(OpenActivityAsync);
- }
- public string Name => _project.Name;
- public string Owner => _project.Owner;
- public string Status => _project.Status;
- public string Summary => _project.Summary;
- public string NextMilestone => _project.NextMilestone;
- public Color AccentColor => _project.AccentColor;
- public MiniCommand OpenActivityCommand { get; }
- private Task OpenActivityAsync()
- {
- return _navigationService.NavigateToAsync(new ProjectActivityViewModel(_project));
- }
- }
- internal sealed class ProjectActivityViewModel : ViewModelBase
- {
- public ProjectActivityViewModel(ProjectCardViewModel project)
- {
- Name = project.Name;
- AccentColor = project.AccentColor;
- Items = project.ActivityItems;
- }
- public string Name { get; }
- public Color AccentColor { get; }
- public IReadOnlyList<string> Items { get; }
- }
- }
|