mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Images WIP
This commit is contained in:
1 parent
6b4e84c95a
commit
0667d58ed8
56 files changed
+783
-454
No files matched your search
@@ -33,7 +33,7 @@ public class SubmissionWizardState : IDisposable
|
||||
|
||||
public List<long> Categories { get; set; } = new();
|
||||
public List<string> Tags { get; set; } = new();
|
||||
public List<Stream> Images { get; set; } = new();
|
||||
public List<ImageUploadRequest> Images { get; set; } = new();
|
||||
|
||||
public IEntrySource? EntrySource { get; set; }
|
||||
|
||||
@@ -67,7 +67,7 @@ public class SubmissionWizardState : IDisposable
|
||||
public void Dispose()
|
||||
{
|
||||
Icon?.Dispose();
|
||||
foreach (Stream stream in Images)
|
||||
stream.Dispose();
|
||||
foreach (ImageUploadRequest image in Images)
|
||||
image.File.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.UI.Screens.Workshop.Image;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
using DynamicData;
|
||||
using ReactiveUI;
|
||||
|
||||
@@ -16,37 +17,39 @@ public class ImagesStepViewModel : SubmissionViewModel
|
||||
{
|
||||
private const long MAX_FILE_SIZE = 10 * 1024 * 1024; // 10 MB
|
||||
private readonly IWindowService _windowService;
|
||||
private readonly SourceList<Stream> _imageStreams;
|
||||
private readonly Func<ImageUploadRequest, ImageSubmissionViewModel> _getImageSubmissionViewModel;
|
||||
private readonly SourceList<ImageUploadRequest> _stateImages;
|
||||
|
||||
public ImagesStepViewModel(IWindowService windowService, Func<Stream, ImageSubmissionViewModel> imageSubmissionViewModel)
|
||||
public ImagesStepViewModel(IWindowService windowService, Func<ImageUploadRequest, ImageSubmissionViewModel> getImageSubmissionViewModel)
|
||||
{
|
||||
_windowService = windowService;
|
||||
_getImageSubmissionViewModel = getImageSubmissionViewModel;
|
||||
|
||||
Continue = ReactiveCommand.Create(() => State.ChangeScreen<UploadStepViewModel>());
|
||||
GoBack = ReactiveCommand.Create(() => State.ChangeScreen<SpecificationsStepViewModel>());
|
||||
Secondary = ReactiveCommand.CreateFromTask(ExecuteAddImage);
|
||||
SecondaryText = "Add image";
|
||||
|
||||
_imageStreams = new SourceList<Stream>();
|
||||
_imageStreams.Connect()
|
||||
.Transform(p => CreateImageSubmissionViewModel(imageSubmissionViewModel, p))
|
||||
_stateImages = new SourceList<ImageUploadRequest>();
|
||||
_stateImages.Connect()
|
||||
.Transform(p => CreateImageSubmissionViewModel(p))
|
||||
.Bind(out ReadOnlyObservableCollection<ImageSubmissionViewModel> images)
|
||||
.Subscribe();
|
||||
Images = images;
|
||||
|
||||
this.WhenActivated((CompositeDisposable d) =>
|
||||
{
|
||||
_imageStreams.Clear();
|
||||
_imageStreams.AddRange(State.Images);
|
||||
_stateImages.Clear();
|
||||
_stateImages.AddRange(State.Images);
|
||||
});
|
||||
}
|
||||
|
||||
public ReadOnlyObservableCollection<ImageSubmissionViewModel> Images { get; }
|
||||
|
||||
private ImageSubmissionViewModel CreateImageSubmissionViewModel(Func<Stream, ImageSubmissionViewModel> imageSubmissionViewModel, Stream stream)
|
||||
private ImageSubmissionViewModel CreateImageSubmissionViewModel(ImageUploadRequest image)
|
||||
{
|
||||
ImageSubmissionViewModel viewModel = imageSubmissionViewModel(stream);
|
||||
viewModel.Remove = ReactiveCommand.Create(() => _imageStreams.Remove(stream));
|
||||
ImageSubmissionViewModel viewModel = _getImageSubmissionViewModel(image);
|
||||
viewModel.Remove = ReactiveCommand.Create(() => _stateImages.Remove(image));
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
@@ -58,7 +61,7 @@ public class ImagesStepViewModel : SubmissionViewModel
|
||||
|
||||
foreach (string path in result)
|
||||
{
|
||||
if (_imageStreams.Items.Any(i => i is FileStream fs && fs.Name == path))
|
||||
if (_stateImages.Items.Any(i => i.File is FileStream fs && fs.Name == path))
|
||||
continue;
|
||||
|
||||
FileStream stream = new(path, FileMode.Open, FileAccess.Read);
|
||||
@@ -69,8 +72,9 @@ public class ImagesStepViewModel : SubmissionViewModel
|
||||
continue;
|
||||
}
|
||||
|
||||
_imageStreams.Add(stream);
|
||||
State.Images.Add(stream);
|
||||
ImageUploadRequest request = new(stream, Path.GetFileName(path), string.Empty);
|
||||
_stateImages.Add(request);
|
||||
State.Images.Add(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -166,14 +166,14 @@ public partial class LayoutSelectionStepViewModel : SubmissionViewModel
|
||||
}
|
||||
|
||||
State.Icon?.Dispose();
|
||||
foreach (Stream stateImage in State.Images)
|
||||
stateImage.Dispose();
|
||||
foreach (ImageUploadRequest stateImage in State.Images)
|
||||
stateImage.File.Dispose();
|
||||
State.Images.Clear();
|
||||
|
||||
// Go through the hassle of resizing the image to 128x128 without losing aspect ratio, padding is added for this
|
||||
State.Icon = ResizeImage(deviceWithoutLeds, 128);
|
||||
State.Images.Add(deviceWithoutLeds);
|
||||
State.Images.Add(deviceWithLeds);
|
||||
State.Images.Add(new ImageUploadRequest(deviceWithoutLeds, "Layout preview (no LEDs)", "A preview of the device without its LEDs"));
|
||||
State.Images.Add(new ImageUploadRequest(deviceWithLeds, "Layout preview (with LEDs)", "A preview of the device with its LEDs"));
|
||||
}
|
||||
|
||||
private Stream ResizeImage(Stream image, int size)
|
||||
|
||||
@@ -11,6 +11,7 @@ using Artemis.WebClient.Workshop;
|
||||
using DynamicData;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
using ReactiveUI;
|
||||
using EntrySpecificationsViewModel = Artemis.UI.Screens.Workshop.Entries.Details.EntrySpecificationsViewModel;
|
||||
|
||||
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
|
||||
|
||||
|
||||
@@ -133,12 +133,12 @@ public partial class UploadStepViewModel : SubmissionViewModel
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (Stream image in State.Images.ToList())
|
||||
foreach (ImageUploadRequest image in State.Images.ToList())
|
||||
{
|
||||
// Upload image
|
||||
try
|
||||
{
|
||||
ImageUploadResult imageUploadResult = await _workshopService.UploadEntryImage(entryId.Value, _progress, image, cancellationToken);
|
||||
ImageUploadResult imageUploadResult = await _workshopService.UploadEntryImage(entryId.Value, image, _progress, cancellationToken);
|
||||
if (!imageUploadResult.IsSuccess)
|
||||
throw new ArtemisWorkshopException(imageUploadResult.Message);
|
||||
State.Images.Remove(image);
|
||||
|
||||
Reference in new issue
Block a user