134 lines
3.4 KiB
C#
134 lines
3.4 KiB
C#
using System.ComponentModel;
|
|
using System.Windows;
|
|
|
|
using CamBooth.App.Core.AppSettings;
|
|
using CamBooth.App.Core.Logging;
|
|
using CamBooth.App.Features.Camera;
|
|
using CamBooth.App.Features.DebugConsole;
|
|
using CamBooth.App.Features.LiveView;
|
|
using CamBooth.App.Features.PictureGallery;
|
|
|
|
namespace CamBooth.App;
|
|
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
private readonly Logger _logger;
|
|
|
|
private readonly AppSettingsService _appSettings;
|
|
|
|
private readonly PictureGalleryService _pictureGalleryService;
|
|
|
|
private readonly CameraService _cameraService;
|
|
|
|
private bool _isDebugConsoleVisible = true;
|
|
|
|
private bool _isPicturePanelVisible = false;
|
|
|
|
private LiveViewPage? _liveViewPage;
|
|
|
|
|
|
public MainWindow(
|
|
Logger logger,
|
|
AppSettingsService appSettings,
|
|
PictureGalleryService pictureGalleryService,
|
|
CameraService cameraService)
|
|
{
|
|
this._logger = logger;
|
|
this._appSettings = appSettings;
|
|
this._pictureGalleryService = pictureGalleryService;
|
|
this._cameraService = cameraService;
|
|
InitializeComponent();
|
|
this.SetVisibilityDebugConsole(this._isDebugConsoleVisible);
|
|
this.SetVisibilityPicturePanel(this._isPicturePanelVisible);
|
|
_ = this._pictureGalleryService.LoadThumbnailsToCache();
|
|
this.Closing += OnClosing;
|
|
TimerControlRectangleAnimation.OnTimerEllapsed += TimerControlRectangleAnimation_OnTimerEllapsed;
|
|
logger.Info("MainWindow initialized");
|
|
}
|
|
|
|
|
|
private void TimerControlRectangleAnimation_OnTimerEllapsed()
|
|
{
|
|
try
|
|
{
|
|
this._cameraService.TakePhoto();
|
|
SwitchButtonAndTimerPanel();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
//TODO: mit content dialog ersetzen
|
|
System.Windows.MessageBox.Show("Sorry, da ging was schief!");
|
|
this._logger.Info(exception.Message);
|
|
}
|
|
}
|
|
|
|
|
|
private void SetVisibilityPicturePanel(bool visibility)
|
|
{
|
|
if (visibility)
|
|
{
|
|
this.PicturePanel.Navigate(new PictureGalleryPage(this._appSettings, this._logger, this._pictureGalleryService));
|
|
}
|
|
else
|
|
{
|
|
this.PicturePanel.ClearValue(MainWindow.ContentProperty);
|
|
}
|
|
|
|
this._isPicturePanelVisible = !visibility;
|
|
}
|
|
|
|
|
|
private void OnClosing(object? sender, CancelEventArgs e)
|
|
{
|
|
this._liveViewPage?.Dispose();
|
|
}
|
|
|
|
|
|
private void NavToLiveView(object sender, RoutedEventArgs e)
|
|
{
|
|
_liveViewPage = new LiveViewPage(this._logger, this._appSettings, this._cameraService);
|
|
MainFrame.Navigate(this._liveViewPage);
|
|
}
|
|
|
|
|
|
private void SetVisibilityDebugConsole(object sender, RoutedEventArgs e)
|
|
{
|
|
this.SetVisibilityDebugConsole(this._isDebugConsoleVisible);
|
|
}
|
|
|
|
|
|
private void SetVisibilityDebugConsole(bool visibility)
|
|
{
|
|
if (visibility)
|
|
{
|
|
this.DebugFrame.Navigate(new DebugConsolePage(this._logger));
|
|
}
|
|
else
|
|
{
|
|
this.DebugFrame.ClearValue(MainWindow.ContentProperty);
|
|
}
|
|
|
|
this._isDebugConsoleVisible = !visibility;
|
|
}
|
|
|
|
|
|
private void StartTakePhotoProcess(object sender, RoutedEventArgs e)
|
|
{
|
|
TimerControlRectangleAnimation.StartTimer(5);
|
|
SwitchButtonAndTimerPanel();
|
|
}
|
|
|
|
private void SwitchButtonAndTimerPanel()
|
|
{
|
|
this.ButtonPanel.Visibility = this.ButtonPanel.Visibility == Visibility.Hidden ? Visibility.Visible : Visibility.Hidden;
|
|
this.TimerPanel.Visibility = this.TimerPanel.Visibility == Visibility.Hidden ? Visibility.Visible : Visibility.Hidden;
|
|
}
|
|
|
|
private void SetVisibilityPicturePanel(object sender, RoutedEventArgs e)
|
|
{
|
|
this.SetVisibilityPicturePanel(this._isPicturePanelVisible);
|
|
}
|
|
} |