mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-21 06:45:32 -06:00
PhotoFrame cleanup: Second batch - UI
This commit is contained in:
parent
c13965514d
commit
b7a182a343
13 changed files with 36 additions and 72 deletions
|
|
@ -1,8 +1,4 @@
|
||||||
using System;
|
namespace PhotoFrame.Logic.UI.ViewModels
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace PhotoFrame.Logic.UI.ViewModels
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Marker interface for view models
|
/// Marker interface for view models
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
using PhotoFrame.Logic.BL;
|
using PhotoFrame.Logic.BL;
|
||||||
using PhotoFrame.Logic.Config;
|
using PhotoFrame.Logic.Config;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace PhotoFrame.Logic.UI.ViewModels
|
namespace PhotoFrame.Logic.UI.ViewModels
|
||||||
{
|
{
|
||||||
|
|
@ -12,26 +10,22 @@ namespace PhotoFrame.Logic.UI.ViewModels
|
||||||
{
|
{
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
protected IFrameController FrameController { get; }
|
protected IFrameController FrameController { get; }
|
||||||
protected IFrameConfig FrameConfig;
|
protected readonly IFrameConfig FrameConfig;
|
||||||
|
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
public bool IsStopped { get; private set; }
|
public bool IsStopped { get; private set; }
|
||||||
|
|
||||||
private string _ImageUri = "";
|
private string _imageUri = "";
|
||||||
public string ImageUri
|
public string ImageUri
|
||||||
{
|
{
|
||||||
get
|
get => _imageUri;
|
||||||
{
|
|
||||||
return _ImageUri;
|
|
||||||
}
|
|
||||||
private set
|
private set
|
||||||
{
|
{
|
||||||
if(!string.Equals(_ImageUri, value))
|
if (string.Equals(_imageUri, value)) return;
|
||||||
{
|
_imageUri = value;
|
||||||
_ImageUri = value;
|
|
||||||
RaisePropertyChanged();
|
RaisePropertyChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
|
|
@ -39,16 +33,16 @@ namespace PhotoFrame.Logic.UI.ViewModels
|
||||||
FrameController.CurrentPhotoChanged -= FrameController_CurrentPhotoChanged;
|
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;
|
FrameController = frameController;
|
||||||
FrameConfig = config;
|
FrameConfig = config;
|
||||||
ImageUri = frameController.CurrentPhoto;
|
ImageUri = frameController.CurrentPhoto;
|
||||||
FrameController.CurrentPhotoChanged += FrameController_CurrentPhotoChanged;
|
FrameController.CurrentPhotoChanged += FrameController_CurrentPhotoChanged;
|
||||||
_Counter++;
|
_counter++;
|
||||||
Console.WriteLine($"Number of ViewModels: {_Counter}");
|
Console.WriteLine($"Number of ViewModels: {_counter}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FrameController_CurrentPhotoChanged(object sender, CurrentPhotoChangedEventArgs e)
|
private void FrameController_CurrentPhotoChanged(object sender, CurrentPhotoChangedEventArgs e)
|
||||||
|
|
@ -61,8 +55,8 @@ namespace PhotoFrame.Logic.UI.ViewModels
|
||||||
|
|
||||||
~ViewModelBase()
|
~ViewModelBase()
|
||||||
{
|
{
|
||||||
_Counter--;
|
_counter--;
|
||||||
Console.WriteLine($"Number of ViewModels: {_Counter}");
|
Console.WriteLine($"Number of ViewModels: {_counter}");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void RaisePropertyChanged([CallerMemberName]string propertyName = "")
|
protected void RaisePropertyChanged([CallerMemberName]string propertyName = "")
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
using PhotoFrame.Logic.BL;
|
using PhotoFrame.Logic.BL;
|
||||||
using PhotoFrame.Logic.Config;
|
using PhotoFrame.Logic.Config;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace PhotoFrame.Logic.UI.ViewModels
|
namespace PhotoFrame.Logic.UI.ViewModels
|
||||||
{
|
{
|
||||||
|
|
@ -22,7 +19,7 @@ namespace PhotoFrame.Logic.UI.ViewModels
|
||||||
|
|
||||||
private string ColorToString(Color color)
|
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}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
using PhotoFrame.Logic.BL;
|
using PhotoFrame.Logic.BL;
|
||||||
using PhotoFrame.Logic.Config;
|
using PhotoFrame.Logic.Config;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace PhotoFrame.Logic.UI.ViewModels
|
namespace PhotoFrame.Logic.UI.ViewModels
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
using PhotoFrame.Logic.BL;
|
using PhotoFrame.Logic.BL;
|
||||||
using PhotoFrame.Logic.Config;
|
using PhotoFrame.Logic.Config;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace PhotoFrame.Logic.UI.ViewModels
|
namespace PhotoFrame.Logic.UI.ViewModels
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
using PhotoFrame.Logic.BL;
|
using PhotoFrame.Logic.BL;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace PhotoFrame.Logic.UI.ViewModels
|
namespace PhotoFrame.Logic.UI.ViewModels
|
||||||
{
|
{
|
||||||
|
|
@ -14,9 +11,13 @@ namespace PhotoFrame.Logic.UI.ViewModels
|
||||||
SwitchType = switchType;
|
SwitchType = switchType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Local
|
||||||
public string ViewResourceId { get; private set; }
|
public string ViewResourceId { get; private set; }
|
||||||
|
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Local
|
||||||
public IViewModel ViewModel { get; private set; }
|
public IViewModel ViewModel { get; private set; }
|
||||||
|
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Local
|
||||||
public ViewSwitchType SwitchType { get; private set; }
|
public ViewSwitchType SwitchType { get; private set; }
|
||||||
|
// ReSharper disable once UnusedMember.Global
|
||||||
public string SwitchTypeString => SwitchType.ToString();
|
public string SwitchTypeString => SwitchType.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
using PhotoFrame.Logic.BL;
|
using PhotoFrame.Logic.BL;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace PhotoFrame.Logic.UI.Views
|
namespace PhotoFrame.Logic.UI.Views
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
using PhotoFrame.Logic.BL;
|
using PhotoFrame.Logic.BL;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace PhotoFrame.Logic.UI.Views
|
namespace PhotoFrame.Logic.UI.Views
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,17 @@ namespace PhotoFrame.Logic.UI.Views
|
||||||
{
|
{
|
||||||
public abstract class ViewBase : IView
|
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 IFrameController FrameController { get; }
|
||||||
protected IFrameConfig FrameConfig { get; }
|
protected IFrameConfig FrameConfig { get; }
|
||||||
|
|
||||||
public IViewModel ViewModel { get; private set; }
|
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;
|
AppModel = appModel;
|
||||||
FrameController = frameController;
|
FrameController = frameController;
|
||||||
FrameConfig = frameConfig;
|
FrameConfig = frameConfig;
|
||||||
|
|
@ -25,7 +25,7 @@ namespace PhotoFrame.Logic.UI.Views
|
||||||
public void Activate(ViewSwitchType switchType)
|
public void Activate(ViewSwitchType switchType)
|
||||||
{
|
{
|
||||||
ViewModel = CreateViewModel();
|
ViewModel = CreateViewModel();
|
||||||
AppModel.SwitchToView(new ViewSwitchInfo(_Uri, ViewModel, switchType));
|
AppModel.SwitchToView(new ViewSwitchInfo(_uri, ViewModel, switchType));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deactivate()
|
public void Deactivate()
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,4 @@
|
||||||
using System;
|
using PhotoFrame.Logic.BL;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Text;
|
|
||||||
using PhotoFrame.Logic.BL;
|
|
||||||
using PhotoFrame.Logic.Config;
|
using PhotoFrame.Logic.Config;
|
||||||
using PhotoFrame.Logic.UI.ViewModels;
|
using PhotoFrame.Logic.UI.ViewModels;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
using PhotoFrame.Logic.BL;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using PhotoFrame.Logic.BL;
|
|
||||||
using PhotoFrame.Logic.Config;
|
using PhotoFrame.Logic.Config;
|
||||||
using PhotoFrame.Logic.UI.ViewModels;
|
using PhotoFrame.Logic.UI.ViewModels;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using PhotoFrame.Logic.BL;
|
using PhotoFrame.Logic.BL;
|
||||||
using PhotoFrame.Logic.Config;
|
using PhotoFrame.Logic.Config;
|
||||||
|
|
||||||
|
|
@ -8,15 +6,15 @@ namespace PhotoFrame.Logic.UI.Views
|
||||||
{
|
{
|
||||||
public class ViewManager : IViewManager
|
public class ViewManager : IViewManager
|
||||||
{
|
{
|
||||||
private IAppModel _AppModel;
|
private readonly IAppModel _appModel;
|
||||||
private IFrameController _FrameController;
|
private readonly IFrameController _frameController;
|
||||||
private IFrameConfig _FrameConfig;
|
private readonly IFrameConfig _frameConfig;
|
||||||
|
|
||||||
public ViewManager(IAppModel appModel, IFrameController frameController, IFrameConfig frameConfig)
|
public ViewManager(IAppModel appModel, IFrameController frameController, IFrameConfig frameConfig)
|
||||||
{
|
{
|
||||||
_AppModel = appModel;
|
_appModel = appModel;
|
||||||
_FrameController = frameController;
|
_frameController = frameController;
|
||||||
_FrameConfig = frameConfig;
|
_frameConfig = frameConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IView CreateView(ViewType viewType)
|
public IView CreateView(ViewType viewType)
|
||||||
|
|
@ -24,11 +22,11 @@ namespace PhotoFrame.Logic.UI.Views
|
||||||
switch(viewType)
|
switch(viewType)
|
||||||
{
|
{
|
||||||
case ViewType.Normal:
|
case ViewType.Normal:
|
||||||
return new ViewNormal(_AppModel, _FrameController, _FrameConfig);
|
return new ViewNormal(_appModel, _frameController, _frameConfig);
|
||||||
case ViewType.Border:
|
case ViewType.Border:
|
||||||
return new ViewBorder(_AppModel, _FrameController, _FrameConfig);
|
return new ViewBorder(_appModel, _frameController, _frameConfig);
|
||||||
case ViewType.Colorized:
|
case ViewType.Colorized:
|
||||||
return new ViewColorize(_AppModel, _FrameController, _FrameConfig);
|
return new ViewColorize(_appModel, _frameController, _frameConfig);
|
||||||
default:
|
default:
|
||||||
throw new NotSupportedException($"ViewType [{viewType}] not supported!");
|
throw new NotSupportedException($"ViewType [{viewType}] not supported!");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
using PhotoFrame.Logic.BL;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using PhotoFrame.Logic.BL;
|
|
||||||
using PhotoFrame.Logic.Config;
|
using PhotoFrame.Logic.Config;
|
||||||
using PhotoFrame.Logic.UI.ViewModels;
|
using PhotoFrame.Logic.UI.ViewModels;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue