Implemented gif exportation and added some style (again)
This commit is contained in:
@@ -1,33 +1,62 @@
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using GifResizer.Models;
|
||||
using GifResizer.Service;
|
||||
|
||||
namespace GifResizer.ViewModels;
|
||||
|
||||
public class MainViewModel : INotifyPropertyChanged
|
||||
public sealed class MainViewModel : INotifyPropertyChanged
|
||||
{
|
||||
|
||||
private readonly ResizeService _resizeService;
|
||||
private readonly GifService _gifService;
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public MainViewModel(ResizeService service)
|
||||
public MainViewModel(GifService service)
|
||||
{
|
||||
_resizeService = service;
|
||||
FilePath = Directory.GetCurrentDirectory();
|
||||
_gifService = service;
|
||||
CommonFormats = [
|
||||
new Format(112, 112),
|
||||
new Format(500, 500),
|
||||
new Format(1000, 1000)
|
||||
];
|
||||
FilePath = null;
|
||||
}
|
||||
|
||||
|
||||
public string FilePath
|
||||
|
||||
public string? FilePath
|
||||
{
|
||||
get;
|
||||
set => SetField(ref field, value);
|
||||
}
|
||||
|
||||
public int? GifWidth
|
||||
{
|
||||
get;
|
||||
set => SetField(ref field, value);
|
||||
}
|
||||
|
||||
public int? GifHeight
|
||||
{
|
||||
get;
|
||||
set => SetField(ref field, value);
|
||||
}
|
||||
|
||||
public void ResizeGif(int width, int height)
|
||||
public List<Format> CommonFormats { get; }
|
||||
|
||||
public void LoadGifData(string filePath)
|
||||
{
|
||||
_resizeService.ResizeGif(FilePath, width, height);
|
||||
GifData data = _gifService.GetData(filePath);
|
||||
FilePath = filePath;
|
||||
GifWidth = data.Width;
|
||||
GifHeight = data.Height;
|
||||
}
|
||||
|
||||
public void ResizeGif()
|
||||
{
|
||||
if(FilePath == null && GifWidth == null && GifHeight == null) return;
|
||||
_gifService.ResizeGif(FilePath!, GifWidth!.Value, GifHeight!.Value);
|
||||
CommonFormats
|
||||
.Where(f => f.Checked)
|
||||
.ToList()
|
||||
.ForEach(f => _gifService.ResizeGif(FilePath!, f.Width, f.Height));
|
||||
}
|
||||
|
||||
private bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
|
||||
@@ -37,8 +66,8 @@ public class MainViewModel : INotifyPropertyChanged
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||
|
||||
private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user