1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-10-16 06:00:45 +00:00
msfs-popout-panel-manager/MainApp/ViewModel/ProfileCardListViewModel.cs
2024-02-27 21:44:21 -05:00

84 lines
2.9 KiB
C#

using MaterialDesignThemes.Wpf;
using MSFSPopoutPanelManager.DomainModel.Profile;
using MSFSPopoutPanelManager.Orchestration;
using Prism.Commands;
using System;
using System.Windows.Input;
using MSFSPopoutPanelManager.MainApp.AppUserControl.Dialog;
namespace MSFSPopoutPanelManager.MainApp.ViewModel
{
public class ProfileCardListViewModel : BaseViewModel
{
private readonly ProfileOrchestrator _profileOrchestrator;
private readonly PanelSourceOrchestrator _panelSourceOrchestrator;
public ICommand AddProfileCommand { get; }
public ICommand NextProfileCommand { get; }
public ICommand PreviousProfileCommand { get; }
public ICommand SearchProfileSelectedCommand { get; set; }
public UserProfile SearchProfileSelectedItem { get; set; }
public int ProfileTransitionIndex { get; set; }
public event EventHandler OnProfileSelected;
public ProfileCardListViewModel(SharedStorage sharedStorage, ProfileOrchestrator profileOrchestrator, PanelSourceOrchestrator panelSourceOrchestrator) : base(sharedStorage)
{
_profileOrchestrator = profileOrchestrator;
_panelSourceOrchestrator = panelSourceOrchestrator;
AddProfileCommand = new DelegateCommand(OnAddProfile);
NextProfileCommand = new DelegateCommand(OnNextProfile);
PreviousProfileCommand = new DelegateCommand(OnPreviousProfile);
SearchProfileSelectedCommand = new DelegateCommand(OnSearchProfileSelected);
ProfileTransitionIndex = 0;
}
private async void OnAddProfile()
{
var dialog = new AddProfileDialog();
var result = await DialogHost.Show(dialog, ROOT_DIALOG_HOST, null, dialog.ClosingEventHandler, null);
if (result != null && result.ToString() == "ADD")
UpdateProfileTransitionIndex();
}
private void OnNextProfile()
{
ProfileData.ResetActiveProfile();
_panelSourceOrchestrator.CloseAllPanelSource();
_profileOrchestrator.MoveToNextProfile();
UpdateProfileTransitionIndex();
}
private void OnPreviousProfile()
{
ProfileData.ResetActiveProfile();
_panelSourceOrchestrator.CloseAllPanelSource();
_profileOrchestrator.MoveToPreviousProfile();
UpdateProfileTransitionIndex();
}
private void OnSearchProfileSelected()
{
if (SearchProfileSelectedItem == null)
return;
_profileOrchestrator.ChangeProfile(SearchProfileSelectedItem);
UpdateProfileTransitionIndex();
OnProfileSelected?.Invoke(this, EventArgs.Empty);
}
private void UpdateProfileTransitionIndex()
{
ProfileTransitionIndex = ProfileTransitionIndex == 1 ? 0 : 1;
}
}
}