PhotoFrame cleanup: Second batch - UI

This commit is contained in:
Michael Lamers 2018-08-09 18:54:07 +02:00 committed by Paul Knopf
parent c13965514d
commit b7a182a343
13 changed files with 36 additions and 72 deletions

View file

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace PhotoFrame.Logic.UI.ViewModels
namespace PhotoFrame.Logic.UI.ViewModels
{
/// <summary>
/// Marker interface for view models

View file

@ -1,10 +1,8 @@
using PhotoFrame.Logic.BL;
using PhotoFrame.Logic.Config;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text;
namespace PhotoFrame.Logic.UI.ViewModels
{
@ -12,24 +10,20 @@ namespace PhotoFrame.Logic.UI.ViewModels
{
public event PropertyChangedEventHandler PropertyChanged;
protected IFrameController FrameController { get; }
protected IFrameConfig FrameConfig;
protected readonly IFrameConfig FrameConfig;
// ReSharper disable once MemberCanBePrivate.Global
public bool IsStopped { get; private set; }
private string _ImageUri = "";
private string _imageUri = "";
public string ImageUri
{
get
{
return _ImageUri;
}
get => _imageUri;
private set
{
if(!string.Equals(_ImageUri, value))
{
_ImageUri = value;
RaisePropertyChanged();
}
if (string.Equals(_imageUri, value)) return;
_imageUri = value;
RaisePropertyChanged();
}
}
@ -39,16 +33,16 @@ namespace PhotoFrame.Logic.UI.ViewModels
FrameController.CurrentPhotoChanged -= FrameController_CurrentPhotoChanged;
}
private static int _Counter = 0;
private static int _counter;
public ViewModelBase(IFrameController frameController, IFrameConfig config)
protected ViewModelBase(IFrameController frameController, IFrameConfig config)
{
FrameController = frameController;
FrameConfig = config;
ImageUri = frameController.CurrentPhoto;
FrameController.CurrentPhotoChanged += FrameController_CurrentPhotoChanged;
_Counter++;
Console.WriteLine($"Number of ViewModels: {_Counter}");
_counter++;
Console.WriteLine($"Number of ViewModels: {_counter}");
}
private void FrameController_CurrentPhotoChanged(object sender, CurrentPhotoChangedEventArgs e)
@ -61,8 +55,8 @@ namespace PhotoFrame.Logic.UI.ViewModels
~ViewModelBase()
{
_Counter--;
Console.WriteLine($"Number of ViewModels: {_Counter}");
_counter--;
Console.WriteLine($"Number of ViewModels: {_counter}");
}
protected void RaisePropertyChanged([CallerMemberName]string propertyName = "")

View file

@ -1,9 +1,6 @@
using PhotoFrame.Logic.BL;
using PhotoFrame.Logic.Config;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
namespace PhotoFrame.Logic.UI.ViewModels
{
@ -22,7 +19,7 @@ namespace PhotoFrame.Logic.UI.ViewModels
private string ColorToString(Color color)
{
return $"#{color.R.ToString("x2")}{color.G.ToString("x2")}{color.B.ToString("x2")}";
return $"#{color.R:x2}{color.G:x2}{color.B:x2}";
}
}
}

View file

@ -1,8 +1,5 @@
using PhotoFrame.Logic.BL;
using PhotoFrame.Logic.Config;
using System;
using System.Collections.Generic;
using System.Text;
namespace PhotoFrame.Logic.UI.ViewModels
{

View file

@ -1,8 +1,5 @@
using PhotoFrame.Logic.BL;
using PhotoFrame.Logic.Config;
using System;
using System.Collections.Generic;
using System.Text;
namespace PhotoFrame.Logic.UI.ViewModels
{

View file

@ -1,7 +1,4 @@
using PhotoFrame.Logic.BL;
using System;
using System.Collections.Generic;
using System.Text;
namespace PhotoFrame.Logic.UI.ViewModels
{
@ -14,9 +11,13 @@ namespace PhotoFrame.Logic.UI.ViewModels
SwitchType = switchType;
}
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Local
public string ViewResourceId { get; private set; }
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Local
public IViewModel ViewModel { get; private set; }
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Local
public ViewSwitchType SwitchType { get; private set; }
// ReSharper disable once UnusedMember.Global
public string SwitchTypeString => SwitchType.ToString();
}
}

View file

@ -1,7 +1,4 @@
using PhotoFrame.Logic.BL;
using System;
using System.Collections.Generic;
using System.Text;
namespace PhotoFrame.Logic.UI.Views
{

View file

@ -1,7 +1,4 @@
using PhotoFrame.Logic.BL;
using System;
using System.Collections.Generic;
using System.Text;
namespace PhotoFrame.Logic.UI.Views
{

View file

@ -6,17 +6,17 @@ namespace PhotoFrame.Logic.UI.Views
{
public abstract class ViewBase : IView
{
private string _Uri;
private readonly string _uri;
protected IAppModel AppModel { get; }
private IAppModel AppModel { get; }
protected IFrameController FrameController { get; }
protected IFrameConfig FrameConfig { get; }
public IViewModel ViewModel { get; private set; }
public ViewBase(string uri, IAppModel appModel, IFrameController frameController, IFrameConfig frameConfig)
protected ViewBase(string uri, IAppModel appModel, IFrameController frameController, IFrameConfig frameConfig)
{
_Uri = uri;
_uri = uri;
AppModel = appModel;
FrameController = frameController;
FrameConfig = frameConfig;
@ -25,7 +25,7 @@ namespace PhotoFrame.Logic.UI.Views
public void Activate(ViewSwitchType switchType)
{
ViewModel = CreateViewModel();
AppModel.SwitchToView(new ViewSwitchInfo(_Uri, ViewModel, switchType));
AppModel.SwitchToView(new ViewSwitchInfo(_uri, ViewModel, switchType));
}
public void Deactivate()

View file

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using PhotoFrame.Logic.BL;
using PhotoFrame.Logic.BL;
using PhotoFrame.Logic.Config;
using PhotoFrame.Logic.UI.ViewModels;

View file

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using PhotoFrame.Logic.BL;
using PhotoFrame.Logic.BL;
using PhotoFrame.Logic.Config;
using PhotoFrame.Logic.UI.ViewModels;

View file

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using PhotoFrame.Logic.BL;
using PhotoFrame.Logic.Config;
@ -8,15 +6,15 @@ namespace PhotoFrame.Logic.UI.Views
{
public class ViewManager : IViewManager
{
private IAppModel _AppModel;
private IFrameController _FrameController;
private IFrameConfig _FrameConfig;
private readonly IAppModel _appModel;
private readonly IFrameController _frameController;
private readonly IFrameConfig _frameConfig;
public ViewManager(IAppModel appModel, IFrameController frameController, IFrameConfig frameConfig)
{
_AppModel = appModel;
_FrameController = frameController;
_FrameConfig = frameConfig;
_appModel = appModel;
_frameController = frameController;
_frameConfig = frameConfig;
}
public IView CreateView(ViewType viewType)
@ -24,11 +22,11 @@ namespace PhotoFrame.Logic.UI.Views
switch(viewType)
{
case ViewType.Normal:
return new ViewNormal(_AppModel, _FrameController, _FrameConfig);
return new ViewNormal(_appModel, _frameController, _frameConfig);
case ViewType.Border:
return new ViewBorder(_AppModel, _FrameController, _FrameConfig);
return new ViewBorder(_appModel, _frameController, _frameConfig);
case ViewType.Colorized:
return new ViewColorize(_AppModel, _FrameController, _FrameConfig);
return new ViewColorize(_appModel, _frameController, _frameConfig);
default:
throw new NotSupportedException($"ViewType [{viewType}] not supported!");
}

View file

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using PhotoFrame.Logic.BL;
using PhotoFrame.Logic.BL;
using PhotoFrame.Logic.Config;
using PhotoFrame.Logic.UI.ViewModels;