2023-07-12 22:41:31 +00:00
|
|
|
|
using MaterialDesignThemes.Wpf;
|
|
|
|
|
using MSFSPopoutPanelManager.DomainModel.Profile;
|
|
|
|
|
using MSFSPopoutPanelManager.Orchestration;
|
|
|
|
|
using Prism.Commands;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Input;
|
2024-02-28 02:44:21 +00:00
|
|
|
|
using MSFSPopoutPanelManager.MainApp.AppUserControl.Dialog;
|
2023-07-12 22:41:31 +00:00
|
|
|
|
|
|
|
|
|
namespace MSFSPopoutPanelManager.MainApp.ViewModel
|
|
|
|
|
{
|
|
|
|
|
public class ProfileCardListViewModel : BaseViewModel
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
private readonly ProfileOrchestrator _profileOrchestrator;
|
|
|
|
|
private readonly PanelSourceOrchestrator _panelSourceOrchestrator;
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
public ProfileCardListViewModel(SharedStorage sharedStorage, ProfileOrchestrator profileOrchestrator, PanelSourceOrchestrator panelSourceOrchestrator) : base(sharedStorage)
|
2023-07-12 22:41:31 +00:00
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
_profileOrchestrator = profileOrchestrator;
|
|
|
|
|
_panelSourceOrchestrator = panelSourceOrchestrator;
|
|
|
|
|
|
2023-07-12 22:41:31 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (result != null && result.ToString() == "ADD")
|
2023-07-12 22:41:31 +00:00
|
|
|
|
UpdateProfileTransitionIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnNextProfile()
|
|
|
|
|
{
|
|
|
|
|
ProfileData.ResetActiveProfile();
|
2024-02-28 02:44:21 +00:00
|
|
|
|
_panelSourceOrchestrator.CloseAllPanelSource();
|
|
|
|
|
_profileOrchestrator.MoveToNextProfile();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
UpdateProfileTransitionIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPreviousProfile()
|
|
|
|
|
{
|
|
|
|
|
ProfileData.ResetActiveProfile();
|
2024-02-28 02:44:21 +00:00
|
|
|
|
_panelSourceOrchestrator.CloseAllPanelSource();
|
|
|
|
|
_profileOrchestrator.MoveToPreviousProfile();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
UpdateProfileTransitionIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnSearchProfileSelected()
|
|
|
|
|
{
|
2024-02-28 02:44:21 +00:00
|
|
|
|
if (SearchProfileSelectedItem == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_profileOrchestrator.ChangeProfile(SearchProfileSelectedItem);
|
|
|
|
|
UpdateProfileTransitionIndex();
|
2023-07-12 22:41:31 +00:00
|
|
|
|
|
2024-02-28 02:44:21 +00:00
|
|
|
|
OnProfileSelected?.Invoke(this, EventArgs.Empty);
|
2023-07-12 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateProfileTransitionIndex()
|
|
|
|
|
{
|
|
|
|
|
ProfileTransitionIndex = ProfileTransitionIndex == 1 ? 0 : 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|