From 12283fe61bb7e177c03bf368f05f8df7daeb66b3 Mon Sep 17 00:00:00 2001 From: Emiliano Magliocca Date: Fri, 5 Jun 2020 18:21:10 +0300 Subject: [PATCH 1/8] Add progress --- Yugen.Mosaic.Uwp/Interfaces/IMosaicService.cs | 3 +- Yugen.Mosaic.Uwp/Services/MosaicService.cs | 37 ++++++++++++++----- Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs | 16 +++++++- Yugen.Mosaic.Uwp/Views/MainPage.xaml | 1 + 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/Yugen.Mosaic.Uwp/Interfaces/IMosaicService.cs b/Yugen.Mosaic.Uwp/Interfaces/IMosaicService.cs index f1780e2..d60e492 100644 --- a/Yugen.Mosaic.Uwp/Interfaces/IMosaicService.cs +++ b/Yugen.Mosaic.Uwp/Interfaces/IMosaicService.cs @@ -1,5 +1,6 @@ using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; +using System; using System.Threading.Tasks; using Windows.Storage; using Windows.Storage.Streams; @@ -13,7 +14,7 @@ public interface IMosaicService void AddTileImage(string name, StorageFile file); - Task> GenerateMosaic(Size outputSize, Size tileSize, MosaicTypeEnum selectedMosaicType); + Task> GenerateMosaic(Size outputSize, Size tileSize, MosaicTypeEnum selectedMosaicType, Progress progress); Image GetResizedImage(Image image, int size); diff --git a/Yugen.Mosaic.Uwp/Services/MosaicService.cs b/Yugen.Mosaic.Uwp/Services/MosaicService.cs index 2be357c..365165f 100644 --- a/Yugen.Mosaic.Uwp/Services/MosaicService.cs +++ b/Yugen.Mosaic.Uwp/Services/MosaicService.cs @@ -25,9 +25,10 @@ public class MosaicService : IMosaicService internal List _tileImageList = new List(); private Image _masterImage; - private int _progressMax; private Size _tileSize; + private Progress myProgress; + public async Task AddMasterImage(StorageFile file) { using (var inputStream = await file.OpenReadAsync()) @@ -44,7 +45,7 @@ public void AddTileImage(string name, StorageFile file) _tileImageList.Add(new Tile(name, file)); } - public async Task> GenerateMosaic(Size outputSize, Size tileSize, MosaicTypeEnum selectedMosaicType) + public async Task> GenerateMosaic(Size outputSize, Size tileSize, MosaicTypeEnum selectedMosaicType, Progress progress) { if (_masterImage == null || (selectedMosaicType != MosaicTypeEnum.PlainColor && _tileImageList.Count < 1)) { @@ -57,6 +58,8 @@ public async Task> GenerateMosaic(Size outputSize, Size tileSize, _tX = resizedMasterImage.Width / tileSize.Width; _tY = resizedMasterImage.Height / tileSize.Height; _avgsMaster = new Rgba32[_tX, _tY]; + myProgress = progress; + _progress = 0; GetTilesAverage(resizedMasterImage); @@ -103,7 +106,7 @@ public void Reset() } private void GetTilesAverage(Image masterImage) - { + { Parallel.For(0, _tY, y => { Span rowSpan = masterImage.GetPixelRowSpan(y); @@ -112,27 +115,39 @@ private void GetTilesAverage(Image masterImage) { _avgsMaster[x, y].FromRgba32(ColorHelper.GetAverageColor(masterImage, x, y, _tileSize)); } + + ProcessProgress(myProgress, 0, 33, _tY); }); } + private void ProcessProgress(IProgress progress, int start, int end, int count) + { + _progress++; + var currentPercentage = _progress * end / count; + var totalPercentage = start + currentPercentage; + progress.Report(totalPercentage); + } + private async Task LoadTilesAndResize() { - _progressMax = _tileImageList.Count; _progress = 0; - var processTiles = _tileImageList.Select(ProcessTile).ToArray(); - await Task.WhenAll(processTiles); + var processTiles = _tileImageList.AsParallel().Select(tile => ProcessTile(tile)); - _progress++; + await Task.WhenAll(processTiles); } - private async Task ProcessTile(Tile tile) => - await tile.Process(_tileSize); + private async Task ProcessTile(Tile tile) + { + await tile.Process(_tileSize); + + ProcessProgress(myProgress, 33, 33, _tileImageList.Count); + } private Image SearchAndReplace(Size tileSize, MosaicTypeEnum selectedMosaicType, Size outputSize) { var outputImage = new Image(outputSize.Width, outputSize.Height); - _progressMax = _tileImageList.Count; + _progress = 0; ISearchAndReplaceService SearchAndReplaceService; @@ -162,6 +177,8 @@ private Image SearchAndReplace(Size tileSize, MosaicTypeEnum selectedMos GC.Collect(); + ProcessProgress(myProgress, 66, 34, 1); + return outputImage; } } diff --git a/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs b/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs index c9d6482..5a0ea15 100644 --- a/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs +++ b/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs @@ -47,6 +47,7 @@ public class MainViewModel : ViewModelBase private ObservableCollection _tileBmpCollection = new ObservableCollection(); private int _tileHeight = 25; private int _tileWidth = 25; + private int _progress = 0; private ICommand _pointerEnteredCommand; private ICommand _pointerExitedCommand; private ICommand _addMasterImmageCommand; @@ -167,6 +168,12 @@ public int TileWidth set => Set(ref _tileWidth, value); } + public int Progress + { + get => _progress; + set => Set(ref _progress, value); + } + public ICommand PointerEnteredCommand => _pointerEnteredCommand ?? (_pointerEnteredCommand = new RelayCommand(PointerEnteredCommandBehavior)); public ICommand PointerExitedCommand => _pointerExitedCommand ?? (_pointerExitedCommand = new RelayCommand(PointerExitedCommandBehavior)); public ICommand AddMasterImmageCommand => _addMasterImmageCommand ?? (_addMasterImmageCommand = new AsyncRelayCommand(AddMasterImmageCommandBehavior)); @@ -315,8 +322,15 @@ private async Task GenerateCommandBehavior() IsButtonEnabled = false; IsLoading = true; + // The Progress constructor captures our UI context, + // so the lambda will be run on the UI thread. + var progress = new Progress(percent => + { + Progress = percent; + }); + await Task.Run(async () => - _outputImage = await _mosaicService.GenerateMosaic(OutputSize, TileSize, SelectedMosaicType.MosaicTypeEnum)); + _outputImage = await _mosaicService.GenerateMosaic(OutputSize, TileSize, SelectedMosaicType.MosaicTypeEnum, progress)); if (_outputImage != null) { diff --git a/Yugen.Mosaic.Uwp/Views/MainPage.xaml b/Yugen.Mosaic.Uwp/Views/MainPage.xaml index 27e32d4..1d1e9bd 100644 --- a/Yugen.Mosaic.Uwp/Views/MainPage.xaml +++ b/Yugen.Mosaic.Uwp/Views/MainPage.xaml @@ -370,6 +370,7 @@ Visibility="{x:Bind ViewModel.IsLoading, Mode=OneWay}" IsEnabled="{x:Bind ViewModel.IsLoading, Mode=OneWay}" />--> + From 6bb1efe4e31f9967405f2dbe47faa1ebbe7b2ce0 Mon Sep 17 00:00:00 2001 From: Emiliano Magliocca Date: Sun, 7 Jun 2020 20:37:14 +0300 Subject: [PATCH 2/8] Add progress --- Yugen.Mosaic.Uwp/Helpers/ProgressHelper.cs | 29 +++++++++++++++++++ Yugen.Mosaic.Uwp/Interfaces/IMosaicService.cs | 2 +- Yugen.Mosaic.Uwp/Models/TileFound.cs | 15 ++++++++++ .../AdjustHueSearchAndReplaceService.cs | 11 +++++-- .../ClassicSearchAndReplaceService.cs | 23 +++++---------- Yugen.Mosaic.Uwp/Services/MosaicService.cs | 29 +++++-------------- .../PlainColorSearchAndReplaceService.cs | 12 ++++++-- .../Services/RandomSearchAndReplaceService.cs | 10 +++++-- Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs | 22 ++++++++++---- Yugen.Mosaic.Uwp/Views/MainPage.xaml | 29 ++++++++++--------- Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj | 2 ++ 11 files changed, 120 insertions(+), 64 deletions(-) create mode 100644 Yugen.Mosaic.Uwp/Helpers/ProgressHelper.cs create mode 100644 Yugen.Mosaic.Uwp/Models/TileFound.cs diff --git a/Yugen.Mosaic.Uwp/Helpers/ProgressHelper.cs b/Yugen.Mosaic.Uwp/Helpers/ProgressHelper.cs new file mode 100644 index 0000000..c38b8f9 --- /dev/null +++ b/Yugen.Mosaic.Uwp/Helpers/ProgressHelper.cs @@ -0,0 +1,29 @@ +using System; + +namespace Yugen.Mosaic.Uwp.Helpers +{ + public static class ProgressHelper + { + private static int _progress; + + public static Progress Progress; + + public static void Init(Progress progress) => Progress = progress; + + public static void ResetProgress() => _progress = 0; + + public static void IncrementProgress(int start, int end, int count) + { + IncrementProgress(Progress, start, end, count); + } + + private static void IncrementProgress(IProgress progress, int start, int end, int count) + { + _progress++; + var currentPercentage = _progress * end / count; + var totalPercentage = start + currentPercentage; + progress.Report(totalPercentage); + } + } + +} \ No newline at end of file diff --git a/Yugen.Mosaic.Uwp/Interfaces/IMosaicService.cs b/Yugen.Mosaic.Uwp/Interfaces/IMosaicService.cs index d60e492..ab6c30e 100644 --- a/Yugen.Mosaic.Uwp/Interfaces/IMosaicService.cs +++ b/Yugen.Mosaic.Uwp/Interfaces/IMosaicService.cs @@ -14,7 +14,7 @@ public interface IMosaicService void AddTileImage(string name, StorageFile file); - Task> GenerateMosaic(Size outputSize, Size tileSize, MosaicTypeEnum selectedMosaicType, Progress progress); + Task> GenerateMosaic(Size outputSize, Size tileSize, MosaicTypeEnum selectedMosaicType); Image GetResizedImage(Image image, int size); diff --git a/Yugen.Mosaic.Uwp/Models/TileFound.cs b/Yugen.Mosaic.Uwp/Models/TileFound.cs new file mode 100644 index 0000000..727a2d7 --- /dev/null +++ b/Yugen.Mosaic.Uwp/Models/TileFound.cs @@ -0,0 +1,15 @@ +namespace Yugen.Mosaic.Uwp.Models +{ + public class TileFound + { + public TileFound(Tile tile, int difference) + { + Tile = tile; + Difference = difference; + } + + public Tile Tile { get; set; } + public int Difference { get; set; } + + } +} \ No newline at end of file diff --git a/Yugen.Mosaic.Uwp/Services/AdjustHueSearchAndReplaceService.cs b/Yugen.Mosaic.Uwp/Services/AdjustHueSearchAndReplaceService.cs index 239a96e..df22dfe 100644 --- a/Yugen.Mosaic.Uwp/Services/AdjustHueSearchAndReplaceService.cs +++ b/Yugen.Mosaic.Uwp/Services/AdjustHueSearchAndReplaceService.cs @@ -5,13 +5,16 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Yugen.Mosaic.Uwp.Helpers; using Yugen.Mosaic.Uwp.Models; namespace Yugen.Mosaic.Uwp.Services { public class AdjustHueSearchAndReplaceService : SearchAndReplaceService { - public AdjustHueSearchAndReplaceService(Image outputImage, Size tileSize, int tX, int tY, List tileImageList, Rgba32[,] avgsMaster) : base(outputImage, tileSize, tX, tY, tileImageList, avgsMaster) + public AdjustHueSearchAndReplaceService(Image outputImage, Size tileSize, + int tX, int tY, List tileImageList, Rgba32[,] avgsMaster) + : base(outputImage, tileSize, tX, tY, tileImageList, avgsMaster) { } @@ -22,6 +25,10 @@ public override void SearchAndReplace() var seq = Enumerable.Range(0, _tX * _tY).Select(x => x % _tileImageList.Count); var tileShuffledList = seq.OrderBy(a => r.Next()); + ProgressHelper.ResetProgress(); + + int max = _tX * _tY; + Parallel.For(0, _tX * _tY, xy => { var y = xy / _tX; @@ -41,7 +48,7 @@ public override void SearchAndReplace() // Apply found tile to section ApplyTileFound(x, y, adjustedImage); - //_progress++; + ProgressHelper.IncrementProgress(66, 34, max); }); } diff --git a/Yugen.Mosaic.Uwp/Services/ClassicSearchAndReplaceService.cs b/Yugen.Mosaic.Uwp/Services/ClassicSearchAndReplaceService.cs index d810614..6346f0e 100644 --- a/Yugen.Mosaic.Uwp/Services/ClassicSearchAndReplaceService.cs +++ b/Yugen.Mosaic.Uwp/Services/ClassicSearchAndReplaceService.cs @@ -11,12 +11,18 @@ namespace Yugen.Mosaic.Uwp.Services { public class ClassicSearchAndReplaceService : SearchAndReplaceService { - public ClassicSearchAndReplaceService(Image outputImage, Size tileSize, int tX, int tY, List tileImageList, Rgba32[,] avgsMaster) : base(outputImage, tileSize, tX, tY, tileImageList, avgsMaster) + public ClassicSearchAndReplaceService(Image outputImage, Size tileSize, + int tX, int tY, List tileImageList, Rgba32[,] avgsMaster) + : base(outputImage, tileSize, tX, tY, tileImageList, avgsMaster) { } public override void SearchAndReplace() { + ProgressHelper.ResetProgress(); + + int max = _tX * _tY; + Parallel.For(0, _tX * _tY, xy => { int y = xy / _tX; @@ -46,21 +52,8 @@ public override void SearchAndReplace() // Apply found tile to section ApplyTileFound(x, y, tileFound.ResizedImage); - //_progress++; + ProgressHelper.IncrementProgress(66, 34, max); }); } } - - public class TileFound - { - public TileFound(Tile tile, int difference) - { - Tile = tile; - Difference = difference; - } - - public Tile Tile { get; set; } - public int Difference { get; set; } - - } } \ No newline at end of file diff --git a/Yugen.Mosaic.Uwp/Services/MosaicService.cs b/Yugen.Mosaic.Uwp/Services/MosaicService.cs index 365165f..b81b05e 100644 --- a/Yugen.Mosaic.Uwp/Services/MosaicService.cs +++ b/Yugen.Mosaic.Uwp/Services/MosaicService.cs @@ -19,7 +19,6 @@ namespace Yugen.Mosaic.Uwp.Services public class MosaicService : IMosaicService { internal Rgba32[,] _avgsMaster; - internal int _progress; internal int _tX; internal int _tY; internal List _tileImageList = new List(); @@ -27,8 +26,6 @@ public class MosaicService : IMosaicService private Image _masterImage; private Size _tileSize; - private Progress myProgress; - public async Task AddMasterImage(StorageFile file) { using (var inputStream = await file.OpenReadAsync()) @@ -45,7 +42,7 @@ public void AddTileImage(string name, StorageFile file) _tileImageList.Add(new Tile(name, file)); } - public async Task> GenerateMosaic(Size outputSize, Size tileSize, MosaicTypeEnum selectedMosaicType, Progress progress) + public async Task> GenerateMosaic(Size outputSize, Size tileSize, MosaicTypeEnum selectedMosaicType) { if (_masterImage == null || (selectedMosaicType != MosaicTypeEnum.PlainColor && _tileImageList.Count < 1)) { @@ -58,8 +55,6 @@ public async Task> GenerateMosaic(Size outputSize, Size tileSize, _tX = resizedMasterImage.Width / tileSize.Width; _tY = resizedMasterImage.Height / tileSize.Height; _avgsMaster = new Rgba32[_tX, _tY]; - myProgress = progress; - _progress = 0; GetTilesAverage(resizedMasterImage); @@ -106,7 +101,9 @@ public void Reset() } private void GetTilesAverage(Image masterImage) - { + { + ProgressHelper.ResetProgress(); + Parallel.For(0, _tY, y => { Span rowSpan = masterImage.GetPixelRowSpan(y); @@ -116,21 +113,13 @@ private void GetTilesAverage(Image masterImage) _avgsMaster[x, y].FromRgba32(ColorHelper.GetAverageColor(masterImage, x, y, _tileSize)); } - ProcessProgress(myProgress, 0, 33, _tY); + ProgressHelper.IncrementProgress(0, 33, _tY); }); } - private void ProcessProgress(IProgress progress, int start, int end, int count) - { - _progress++; - var currentPercentage = _progress * end / count; - var totalPercentage = start + currentPercentage; - progress.Report(totalPercentage); - } - private async Task LoadTilesAndResize() { - _progress = 0; + ProgressHelper.ResetProgress(); var processTiles = _tileImageList.AsParallel().Select(tile => ProcessTile(tile)); @@ -141,14 +130,12 @@ private async Task ProcessTile(Tile tile) { await tile.Process(_tileSize); - ProcessProgress(myProgress, 33, 33, _tileImageList.Count); + ProgressHelper.IncrementProgress(33, 33, _tileImageList.Count); } private Image SearchAndReplace(Size tileSize, MosaicTypeEnum selectedMosaicType, Size outputSize) { var outputImage = new Image(outputSize.Width, outputSize.Height); - - _progress = 0; ISearchAndReplaceService SearchAndReplaceService; @@ -177,8 +164,6 @@ private Image SearchAndReplace(Size tileSize, MosaicTypeEnum selectedMos GC.Collect(); - ProcessProgress(myProgress, 66, 34, 1); - return outputImage; } } diff --git a/Yugen.Mosaic.Uwp/Services/PlainColorSearchAndReplaceService.cs b/Yugen.Mosaic.Uwp/Services/PlainColorSearchAndReplaceService.cs index 324a37b..065639f 100644 --- a/Yugen.Mosaic.Uwp/Services/PlainColorSearchAndReplaceService.cs +++ b/Yugen.Mosaic.Uwp/Services/PlainColorSearchAndReplaceService.cs @@ -1,22 +1,30 @@ using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; +using System; using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; +using Yugen.Mosaic.Uwp.Helpers; using Yugen.Mosaic.Uwp.Models; namespace Yugen.Mosaic.Uwp.Services { public class PlainColorSearchAndReplaceService : SearchAndReplaceService { - public PlainColorSearchAndReplaceService(Image outputImage, Size tileSize, int tX, int tY, List tileImageList, Rgba32[,] avgsMaster) : base(outputImage, tileSize, tX, tY, tileImageList, avgsMaster) + public PlainColorSearchAndReplaceService(Image outputImage, Size tileSize, + int tX, int tY, List tileImageList, Rgba32[,] avgsMaster) + : base(outputImage, tileSize, tX, tY, tileImageList, avgsMaster) { } // Use just mosic colored tiles public override void SearchAndReplace() { + ProgressHelper.ResetProgress(); + + int max = _tX * _tY; + Parallel.For(0, _tX * _tY, xy => { int y = xy / _tX; @@ -37,7 +45,7 @@ public override void SearchAndReplace() // Apply found tile to section ApplyTileFound(x, y, adjustedImage); - //_progress++; + ProgressHelper.IncrementProgress(66, 34, max); }); } } diff --git a/Yugen.Mosaic.Uwp/Services/RandomSearchAndReplaceService.cs b/Yugen.Mosaic.Uwp/Services/RandomSearchAndReplaceService.cs index d44e716..52534fe 100644 --- a/Yugen.Mosaic.Uwp/Services/RandomSearchAndReplaceService.cs +++ b/Yugen.Mosaic.Uwp/Services/RandomSearchAndReplaceService.cs @@ -10,7 +10,9 @@ namespace Yugen.Mosaic.Uwp.Services { public class RandomSearchAndReplaceService : SearchAndReplaceService { - public RandomSearchAndReplaceService(Image outputImage, Size tileSize, int tX, int tY, List tileImageList, Rgba32[,] avgsMaster) : base(outputImage, tileSize, tX, tY, tileImageList, avgsMaster) + public RandomSearchAndReplaceService(Image outputImage, Size tileSize, int tX, int tY, + List tileImageList, Rgba32[,] avgsMaster) + : base(outputImage, tileSize, tX, tY, tileImageList, avgsMaster) { } @@ -19,6 +21,10 @@ public override void SearchAndReplace() { var r = new Random(); + ProgressHelper.ResetProgress(); + + int max = _tX * _tY; + Parallel.For(0, _tX * _tY, xy => { var y = xy / _tX; @@ -51,7 +57,7 @@ public override void SearchAndReplace() // Apply found tile to section ApplyTileFound(x, y, tileFound.ResizedImage); - //_progress++; + ProgressHelper.IncrementProgress(66, 34, max); }); } } diff --git a/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs b/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs index 5a0ea15..c152331 100644 --- a/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs +++ b/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs @@ -32,6 +32,7 @@ public class MainViewModel : ViewModelBase private bool _isAddMasterUIVisible = true; private bool _isAlignmentGridVisibile = true; + private bool _isIndeterminateLoading; private bool _isLoading; private bool _isTeachingTipOpen; private bool _isButtonEnabled = true; @@ -76,6 +77,12 @@ public bool IsAlignmentGridVisibile set => Set(ref _isAlignmentGridVisibile, value); } + public bool IsIndeterminateLoading + { + get => _isIndeterminateLoading; + set => Set(ref _isIndeterminateLoading, value); + } + public bool IsLoading { get => _isLoading; @@ -237,7 +244,7 @@ private async Task AddMasterImmageCommandBehavior() if (masterFile != null) { IsButtonEnabled = false; - IsLoading = true; + IsIndeterminateLoading = true; using (var inputStream = await masterFile.OpenReadAsync()) { @@ -258,7 +265,7 @@ await DispatcherHelper.ExecuteOnUIThreadAsync(async () => OutputWidth = newSize.Item1; OutputHeight = newSize.Item2; - IsLoading = false; + IsIndeterminateLoading = false; IsButtonEnabled = true; } @@ -277,7 +284,7 @@ private async Task AddTilesCommandBehavior() } IsButtonEnabled = false; - IsLoading = true; + IsIndeterminateLoading = true; await Task.Run(() => Parallel.ForEach(files, async file => @@ -300,7 +307,7 @@ await DispatcherHelper.ExecuteOnUIThreadAsync(async () => }) ); - IsLoading = false; + IsIndeterminateLoading = false; IsButtonEnabled = true; } @@ -329,8 +336,10 @@ private async Task GenerateCommandBehavior() Progress = percent; }); + ProgressHelper.Init(progress); + await Task.Run(async () => - _outputImage = await _mosaicService.GenerateMosaic(OutputSize, TileSize, SelectedMosaicType.MosaicTypeEnum, progress)); + _outputImage = await _mosaicService.GenerateMosaic(OutputSize, TileSize, SelectedMosaicType.MosaicTypeEnum)); if (_outputImage != null) { @@ -404,6 +413,7 @@ private async Task SettingsCommandBehavior() await settingsDialog.ShowAsync(); } - private void UpdateIsAddMasterUIVisible() => IsAddMasterUIVisible = MasterBpmSource.PixelWidth <= 0 || MasterBpmSource.PixelHeight <= 0; + private void UpdateIsAddMasterUIVisible() => + IsAddMasterUIVisible = MasterBpmSource.PixelWidth <= 0 || MasterBpmSource.PixelHeight <= 0; } } \ No newline at end of file diff --git a/Yugen.Mosaic.Uwp/Views/MainPage.xaml b/Yugen.Mosaic.Uwp/Views/MainPage.xaml index 1d1e9bd..bd13126 100644 --- a/Yugen.Mosaic.Uwp/Views/MainPage.xaml +++ b/Yugen.Mosaic.Uwp/Views/MainPage.xaml @@ -8,7 +8,7 @@ xmlns:models="using:Yugen.Mosaic.Uwp.Models" xmlns:validation="using:Yugen.Toolkit.Uwp.Controls.Validation" xmlns:controls="using:Yugen.Toolkit.Uwp.Controls.UI" - xmlns:winUiControls="using:Microsoft.UI.Xaml.Controls" + xmlns:muxc="using:Microsoft.UI.Xaml.Controls" xmlns:interactivity="using:Microsoft.Xaml.Interactivity" xmlns:core="using:Microsoft.Xaml.Interactions.Core" xmlns:viewmodels="using:Yugen.Mosaic.Uwp.ViewModels" @@ -352,23 +352,24 @@ - + + - + Visibility="{x:Bind ViewModel.IsLoading, Mode=OneWay}" /> @@ -405,7 +406,7 @@ - + + MainPage.xaml From 00baee70c4acbe531f185a14ec1f7f88005f5ab8 Mon Sep 17 00:00:00 2001 From: Emiliano Magliocca Date: Wed, 1 Jul 2020 18:12:21 +0300 Subject: [PATCH 3/8] Fix progress --- Yugen.Mosaic.Uwp/Helpers/ProgressHelper.cs | 29 ----------------- .../AdjustHueSearchAndReplaceService.cs | 5 +-- .../ClassicSearchAndReplaceService.cs | 5 +-- Yugen.Mosaic.Uwp/Services/MosaicService.cs | 11 +++---- .../PlainColorSearchAndReplaceService.cs | 5 +-- Yugen.Mosaic.Uwp/Services/ProgressService.cs | 32 +++++++++++++++++++ .../Services/RandomSearchAndReplaceService.cs | 5 +-- Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs | 6 +--- Yugen.Mosaic.Uwp/Views/MainPage.xaml | 17 +++++----- Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj | 2 +- 10 files changed, 60 insertions(+), 57 deletions(-) delete mode 100644 Yugen.Mosaic.Uwp/Helpers/ProgressHelper.cs create mode 100644 Yugen.Mosaic.Uwp/Services/ProgressService.cs diff --git a/Yugen.Mosaic.Uwp/Helpers/ProgressHelper.cs b/Yugen.Mosaic.Uwp/Helpers/ProgressHelper.cs deleted file mode 100644 index c38b8f9..0000000 --- a/Yugen.Mosaic.Uwp/Helpers/ProgressHelper.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; - -namespace Yugen.Mosaic.Uwp.Helpers -{ - public static class ProgressHelper - { - private static int _progress; - - public static Progress Progress; - - public static void Init(Progress progress) => Progress = progress; - - public static void ResetProgress() => _progress = 0; - - public static void IncrementProgress(int start, int end, int count) - { - IncrementProgress(Progress, start, end, count); - } - - private static void IncrementProgress(IProgress progress, int start, int end, int count) - { - _progress++; - var currentPercentage = _progress * end / count; - var totalPercentage = start + currentPercentage; - progress.Report(totalPercentage); - } - } - -} \ No newline at end of file diff --git a/Yugen.Mosaic.Uwp/Services/AdjustHueSearchAndReplaceService.cs b/Yugen.Mosaic.Uwp/Services/AdjustHueSearchAndReplaceService.cs index df22dfe..162a6e6 100644 --- a/Yugen.Mosaic.Uwp/Services/AdjustHueSearchAndReplaceService.cs +++ b/Yugen.Mosaic.Uwp/Services/AdjustHueSearchAndReplaceService.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Yugen.Mosaic.Uwp.Helpers; using Yugen.Mosaic.Uwp.Models; +using Yugen.Mosaic.Uwp.ViewModels; namespace Yugen.Mosaic.Uwp.Services { @@ -25,7 +26,7 @@ public override void SearchAndReplace() var seq = Enumerable.Range(0, _tX * _tY).Select(x => x % _tileImageList.Count); var tileShuffledList = seq.OrderBy(a => r.Next()); - ProgressHelper.ResetProgress(); + ProgressService.Instance.Reset(); int max = _tX * _tY; @@ -48,7 +49,7 @@ public override void SearchAndReplace() // Apply found tile to section ApplyTileFound(x, y, adjustedImage); - ProgressHelper.IncrementProgress(66, 34, max); + ProgressService.Instance.IncrementProgress(max, 66, 100); }); } diff --git a/Yugen.Mosaic.Uwp/Services/ClassicSearchAndReplaceService.cs b/Yugen.Mosaic.Uwp/Services/ClassicSearchAndReplaceService.cs index 6346f0e..e369cec 100644 --- a/Yugen.Mosaic.Uwp/Services/ClassicSearchAndReplaceService.cs +++ b/Yugen.Mosaic.Uwp/Services/ClassicSearchAndReplaceService.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Yugen.Mosaic.Uwp.Helpers; using Yugen.Mosaic.Uwp.Models; +using Yugen.Mosaic.Uwp.ViewModels; namespace Yugen.Mosaic.Uwp.Services { @@ -19,7 +20,7 @@ public ClassicSearchAndReplaceService(Image outputImage, Size tileSize, public override void SearchAndReplace() { - ProgressHelper.ResetProgress(); + ProgressService.Instance.Reset(); int max = _tX * _tY; @@ -52,7 +53,7 @@ public override void SearchAndReplace() // Apply found tile to section ApplyTileFound(x, y, tileFound.ResizedImage); - ProgressHelper.IncrementProgress(66, 34, max); + ProgressService.Instance.IncrementProgress(max, 66, 100); }); } } diff --git a/Yugen.Mosaic.Uwp/Services/MosaicService.cs b/Yugen.Mosaic.Uwp/Services/MosaicService.cs index b81b05e..6219d59 100644 --- a/Yugen.Mosaic.Uwp/Services/MosaicService.cs +++ b/Yugen.Mosaic.Uwp/Services/MosaicService.cs @@ -13,6 +13,7 @@ using Yugen.Mosaic.Uwp.Helpers; using Yugen.Mosaic.Uwp.Interfaces; using Yugen.Mosaic.Uwp.Models; +using Yugen.Mosaic.Uwp.ViewModels; namespace Yugen.Mosaic.Uwp.Services { @@ -102,8 +103,6 @@ public void Reset() private void GetTilesAverage(Image masterImage) { - ProgressHelper.ResetProgress(); - Parallel.For(0, _tY, y => { Span rowSpan = masterImage.GetPixelRowSpan(y); @@ -113,14 +112,14 @@ private void GetTilesAverage(Image masterImage) _avgsMaster[x, y].FromRgba32(ColorHelper.GetAverageColor(masterImage, x, y, _tileSize)); } - ProgressHelper.IncrementProgress(0, 33, _tY); + ProgressService.Instance.IncrementProgress(_tY, 0, 33); }); } private async Task LoadTilesAndResize() { - ProgressHelper.ResetProgress(); - + ProgressService.Instance.Reset(); + var processTiles = _tileImageList.AsParallel().Select(tile => ProcessTile(tile)); await Task.WhenAll(processTiles); @@ -130,7 +129,7 @@ private async Task ProcessTile(Tile tile) { await tile.Process(_tileSize); - ProgressHelper.IncrementProgress(33, 33, _tileImageList.Count); + ProgressService.Instance.IncrementProgress(_tileImageList.Count, 33, 66); } private Image SearchAndReplace(Size tileSize, MosaicTypeEnum selectedMosaicType, Size outputSize) diff --git a/Yugen.Mosaic.Uwp/Services/PlainColorSearchAndReplaceService.cs b/Yugen.Mosaic.Uwp/Services/PlainColorSearchAndReplaceService.cs index 065639f..23e6609 100644 --- a/Yugen.Mosaic.Uwp/Services/PlainColorSearchAndReplaceService.cs +++ b/Yugen.Mosaic.Uwp/Services/PlainColorSearchAndReplaceService.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Yugen.Mosaic.Uwp.Helpers; using Yugen.Mosaic.Uwp.Models; +using Yugen.Mosaic.Uwp.ViewModels; namespace Yugen.Mosaic.Uwp.Services { @@ -21,7 +22,7 @@ public PlainColorSearchAndReplaceService(Image outputImage, Size tileSiz // Use just mosic colored tiles public override void SearchAndReplace() { - ProgressHelper.ResetProgress(); + ProgressService.Instance.Reset(); int max = _tX * _tY; @@ -45,7 +46,7 @@ public override void SearchAndReplace() // Apply found tile to section ApplyTileFound(x, y, adjustedImage); - ProgressHelper.IncrementProgress(66, 34, max); + ProgressService.Instance.IncrementProgress(max, 66, 100); }); } } diff --git a/Yugen.Mosaic.Uwp/Services/ProgressService.cs b/Yugen.Mosaic.Uwp/Services/ProgressService.cs new file mode 100644 index 0000000..9566479 --- /dev/null +++ b/Yugen.Mosaic.Uwp/Services/ProgressService.cs @@ -0,0 +1,32 @@ +using System; + +namespace Yugen.Mosaic.Uwp.ViewModels +{ + public class ProgressService + { + private IProgress _progress; + private int current; + + public static ProgressService Instance { get; } = new ProgressService(); + + public void Init(Action progress) + { + // The Progress constructor captures our UI context, + // so the lambda will be run on the UI thread. + _progress = new Progress(progress); + current = 0; + } + + public void Reset() + { + current = 0; + } + + public void IncrementProgress(int total, int startPercentage = 0, int maxPercentage = 100) + { + var currentPercentage = current * (maxPercentage - startPercentage ) / total; + ++current; + _progress.Report(startPercentage + currentPercentage); + } + } +} \ No newline at end of file diff --git a/Yugen.Mosaic.Uwp/Services/RandomSearchAndReplaceService.cs b/Yugen.Mosaic.Uwp/Services/RandomSearchAndReplaceService.cs index 52534fe..70f0e01 100644 --- a/Yugen.Mosaic.Uwp/Services/RandomSearchAndReplaceService.cs +++ b/Yugen.Mosaic.Uwp/Services/RandomSearchAndReplaceService.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Yugen.Mosaic.Uwp.Helpers; using Yugen.Mosaic.Uwp.Models; +using Yugen.Mosaic.Uwp.ViewModels; namespace Yugen.Mosaic.Uwp.Services { @@ -21,7 +22,7 @@ public override void SearchAndReplace() { var r = new Random(); - ProgressHelper.ResetProgress(); + ProgressService.Instance.Reset(); int max = _tX * _tY; @@ -57,7 +58,7 @@ public override void SearchAndReplace() // Apply found tile to section ApplyTileFound(x, y, tileFound.ResizedImage); - ProgressHelper.IncrementProgress(66, 34, max); + ProgressService.Instance.IncrementProgress(max, 66, 100); }); } } diff --git a/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs b/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs index 29bc799..1be30ee 100644 --- a/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs +++ b/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs @@ -335,15 +335,11 @@ private async Task GenerateCommandBehavior() IsButtonEnabled = false; IsLoading = true; - // The Progress constructor captures our UI context, - // so the lambda will be run on the UI thread. - var progress = new Progress(percent => + ProgressService.Instance.Init(percent => { Progress = percent; }); - ProgressHelper.Init(progress); - await Task.Run(async () => _outputImage = await _mosaicService.GenerateMosaic(OutputSize, TileSize, SelectedMosaicType.MosaicTypeEnum)); diff --git a/Yugen.Mosaic.Uwp/Views/MainPage.xaml b/Yugen.Mosaic.Uwp/Views/MainPage.xaml index 1cd6db6..46d65d9 100644 --- a/Yugen.Mosaic.Uwp/Views/MainPage.xaml +++ b/Yugen.Mosaic.Uwp/Views/MainPage.xaml @@ -353,26 +353,27 @@ - + Visibility="{x:Bind ViewModel.IsIndeterminateLoading, Mode=OneWay}"/> - diff --git a/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj b/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj index 0a2ba45..a53537f 100644 --- a/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj +++ b/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj @@ -131,8 +131,8 @@ - + MainPage.xaml From 62456a4a3a92fd7f83e54c48bf79d31b016df6cb Mon Sep 17 00:00:00 2001 From: Emiliano Magliocca Date: Wed, 1 Jul 2020 18:14:20 +0300 Subject: [PATCH 4/8] Update nugets --- Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj b/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj index a53537f..9eb9bf3 100644 --- a/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj +++ b/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj @@ -241,13 +241,13 @@ 6.2.10 - 6.0.0 + 6.1.0 - 6.0.0 + 6.1.0 - 6.0.0 + 6.1.0 2.4.2 @@ -259,13 +259,13 @@ 1.6.5 - 1.0.27 + 1.0.36 - 1.0.27 + 1.0.36 - 1.0.27 + 1.0.36 From affecc5e21a71b60b75f1b63e3266e0e94c77c37 Mon Sep 17 00:00:00 2001 From: Emiliano Magliocca Date: Wed, 1 Jul 2020 18:31:58 +0300 Subject: [PATCH 5/8] Add *.jpeg support --- Yugen.Mosaic.Uwp/Enums/FileFormat.cs | 3 +++ Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Yugen.Mosaic.Uwp/Enums/FileFormat.cs b/Yugen.Mosaic.Uwp/Enums/FileFormat.cs index a5358af..b9b8b2a 100644 --- a/Yugen.Mosaic.Uwp/Enums/FileFormat.cs +++ b/Yugen.Mosaic.Uwp/Enums/FileFormat.cs @@ -7,6 +7,9 @@ public enum FileFormat [Description(".jpg")] Jpg, + [Description(".jpeg")] + Jpeg, + [Description(".png")] Png, diff --git a/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs b/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs index 1be30ee..04f094f 100644 --- a/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs +++ b/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs @@ -244,7 +244,11 @@ public void TeachingTipClosingCommandBehavior() private async Task AddMasterImmageCommandBehavior() { StorageFile masterFile = await FilePickerHelper.OpenFile( - new List { FileFormat.Jpg.GetStringRepresentation(), FileFormat.Png.GetStringRepresentation() }, + new List { + FileFormat.Jpg.GetStringRepresentation(), + FileFormat.Jpeg.GetStringRepresentation(), + FileFormat.Png.GetStringRepresentation() + }, Windows.Storage.Pickers.PickerLocationId.PicturesLibrary); if (masterFile != null) @@ -281,7 +285,11 @@ await DispatcherHelper.ExecuteOnUIThreadAsync(async () => private async Task AddTilesCommandBehavior() { IReadOnlyList files = await FilePickerHelper.OpenFiles( - new List { FileFormat.Jpg.GetStringRepresentation(), FileFormat.Png.GetStringRepresentation() }, + new List { + FileFormat.Jpg.GetStringRepresentation(), + FileFormat.Jpeg.GetStringRepresentation(), + FileFormat.Png.GetStringRepresentation() + }, Windows.Storage.Pickers.PickerLocationId.PicturesLibrary); if (files == null) From 9baac136d4df16db85500828789d0364bc2ae1ea Mon Sep 17 00:00:00 2001 From: Emiliano Magliocca Date: Wed, 1 Jul 2020 18:56:56 +0300 Subject: [PATCH 6/8] Add tiles from folder --- Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw | 3 ++ Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs | 29 +++++++++++++++++-- Yugen.Mosaic.Uwp/Views/MainPage.xaml | 11 +++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw b/Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw index 74fd2a2..6e54b16 100644 --- a/Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw +++ b/Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw @@ -120,6 +120,9 @@ Click here to choose a Master image + + Add Tiles From Folder + Add Tiles diff --git a/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs b/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs index 04f094f..5277e99 100644 --- a/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs +++ b/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs @@ -52,6 +52,7 @@ public class MainViewModel : ViewModelBase private ICommand _pointerExitedCommand; private ICommand _addMasterImmageCommand; private ICommand _addTilesCommand; + private ICommand _addTilesFolderCommand; private ICommand _clickTileCommand; private ICommand _generateCommand; private ICommand _saveCommand; @@ -187,6 +188,7 @@ public int Progress public ICommand PointerExitedCommand => _pointerExitedCommand ?? (_pointerExitedCommand = new RelayCommand(PointerExitedCommandBehavior)); public ICommand AddMasterImmageCommand => _addMasterImmageCommand ?? (_addMasterImmageCommand = new AsyncRelayCommand(AddMasterImmageCommandBehavior)); public ICommand AddTilesCommand => _addTilesCommand ?? (_addTilesCommand = new AsyncRelayCommand(AddTilesCommandBehavior)); + public ICommand AddTilesFolderCommand => _addTilesFolderCommand ?? (_addTilesFolderCommand = new AsyncRelayCommand(AddTilesFolderCommandBehavior)); public ICommand ClickTileCommand => _clickTileCommand ?? (_clickTileCommand = new AsyncRelayCommand(ClickTileCommandBehavior)); public ICommand GenerateCommand => _generateCommand ?? (_generateCommand = new AsyncRelayCommand(GenerateCommandBehavior)); public ICommand SaveCommand => _saveCommand ?? (_saveCommand = new AsyncRelayCommand(SaveCommandBehavior)); @@ -292,11 +294,34 @@ private async Task AddTilesCommandBehavior() }, Windows.Storage.Pickers.PickerLocationId.PicturesLibrary); - if (files == null) + if (files != null) { - return; + await AddTiles(files); + } + } + + private async Task AddTilesFolderCommandBehavior() + { + var folderPicker = new Windows.Storage.Pickers.FolderPicker(); + folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; + folderPicker.FileTypeFilter.Add(FileFormat.Jpg.GetStringRepresentation()); + folderPicker.FileTypeFilter.Add(FileFormat.Jpg.GetStringRepresentation()); + folderPicker.FileTypeFilter.Add(FileFormat.Png.GetStringRepresentation()); + + StorageFolder folder = await folderPicker.PickSingleFolderAsync(); + if (folder != null) + { + // Application now has read/write access to all contents in the picked folder + // (including other sub-folder contents) + Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder); + + var files = await folder.GetFilesAsync(); + await AddTiles(files); } + } + private async Task AddTiles(IReadOnlyList files) + { IsButtonEnabled = false; IsIndeterminateLoading = true; diff --git a/Yugen.Mosaic.Uwp/Views/MainPage.xaml b/Yugen.Mosaic.Uwp/Views/MainPage.xaml index 46d65d9..77b4d77 100644 --- a/Yugen.Mosaic.Uwp/Views/MainPage.xaml +++ b/Yugen.Mosaic.Uwp/Views/MainPage.xaml @@ -131,6 +131,17 @@ + + Date: Thu, 2 Jul 2020 15:40:41 +0300 Subject: [PATCH 7/8] Move from messagedialog to contentdialog --- Yugen.Mosaic.Uwp/Package.appxmanifest | 4 ++-- Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw | 9 ++++++++ Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs | 21 +++++++++---------- Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj | 6 +++--- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Yugen.Mosaic.Uwp/Package.appxmanifest b/Yugen.Mosaic.Uwp/Package.appxmanifest index 773b22f..93986d6 100644 --- a/Yugen.Mosaic.Uwp/Package.appxmanifest +++ b/Yugen.Mosaic.Uwp/Package.appxmanifest @@ -36,7 +36,7 @@ Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="Yugen.Mosaic.Uwp" - BackgroundColor="#C93535"> + BackgroundColor="transparent"> @@ -44,7 +44,7 @@ - + diff --git a/Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw b/Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw index 6e54b16..76c4b08 100644 --- a/Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw +++ b/Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw @@ -117,6 +117,15 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Do you want to Remove this picture? + + + No + + + Yes + Click here to choose a Master image diff --git a/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs b/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs index 5277e99..60985ba 100644 --- a/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs +++ b/Yugen.Mosaic.Uwp/ViewModels/MainViewModel.cs @@ -302,8 +302,10 @@ private async Task AddTilesCommandBehavior() private async Task AddTilesFolderCommandBehavior() { - var folderPicker = new Windows.Storage.Pickers.FolderPicker(); - folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; + var folderPicker = new Windows.Storage.Pickers.FolderPicker + { + SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary + }; folderPicker.FileTypeFilter.Add(FileFormat.Jpg.GetStringRepresentation()); folderPicker.FileTypeFilter.Add(FileFormat.Jpg.GetStringRepresentation()); folderPicker.FileTypeFilter.Add(FileFormat.Png.GetStringRepresentation()); @@ -352,15 +354,12 @@ await DispatcherHelper.ExecuteOnUIThreadAsync(async () => private async Task ClickTileCommandBehavior(TileBmp item) { - await MessageDialogHelper.Confirm("Do you want to Remove this picture?", - "", - new UICommand("Yes", - action => - { - TileBmpCollection.Remove(item); - _mosaicService.RemoveTileImage(item.Name); - }), - new UICommand("No")); + await ContentDialogHelper.Confirm(ResourceHelper.GetText("DefaultDeletePicture"), "", ResourceHelper.GetText("DefaultNo"), + new RelayCommand(() => + { + TileBmpCollection.Remove(item); + _mosaicService.RemoveTileImage(item.Name); + }), ResourceHelper.GetText("DefaultYes")); } private async Task GenerateCommandBehavior() diff --git a/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj b/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj index 9eb9bf3..98e37c3 100644 --- a/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj +++ b/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj @@ -259,13 +259,13 @@ 1.6.5 - 1.0.36 + 1.0.37 - 1.0.36 + 1.0.37 - 1.0.36 + 1.0.37 From d325450ffc5cd057164fc8dc8c368c95c863d9fd Mon Sep 17 00:00:00 2001 From: Emiliano Magliocca Date: Wed, 8 Jul 2020 17:01:15 +0300 Subject: [PATCH 8/8] Fix string Update nugets Update pipeline with git version --- Yugen.Mosaic.Uwp.sln | 1 + Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw | 2 +- Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj | 6 ++--- build-pipelines.yml | 23 +++++++------------ 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/Yugen.Mosaic.Uwp.sln b/Yugen.Mosaic.Uwp.sln index 72d5923..7bda10a 100644 --- a/Yugen.Mosaic.Uwp.sln +++ b/Yugen.Mosaic.Uwp.sln @@ -8,6 +8,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Azure", "Azure", "{E44DE1EE-E0B3-4250-8CBE-F9B13C6DF19A}" ProjectSection(SolutionItems) = preProject build-pipelines.yml = build-pipelines.yml + GitVersion.yml = GitVersion.yml EndProjectSection EndProject Global diff --git a/Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw b/Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw index 76c4b08..af6b7e9 100644 --- a/Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw +++ b/Yugen.Mosaic.Uwp/Strings/en-US/Resources.resw @@ -130,7 +130,7 @@ Click here to choose a Master image - Add Tiles From Folder + Add Tiles from Folder Add Tiles diff --git a/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj b/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj index 98e37c3..a1ba929 100644 --- a/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj +++ b/Yugen.Mosaic.Uwp/Yugen.Mosaic.Uwp.csproj @@ -232,10 +232,10 @@ - 3.2.2 + 3.3.0 - 3.2.2 + 3.3.0 6.2.10 @@ -256,7 +256,7 @@ 1.0.0-rc0001 - 1.6.5 + 1.6.7 1.0.37 diff --git a/build-pipelines.yml b/build-pipelines.yml index cf7f302..7bf3e1f 100644 --- a/build-pipelines.yml +++ b/build-pipelines.yml @@ -17,24 +17,16 @@ variables: appxPackageDir: '$(build.artifactStagingDirectory)\AppxPackages\\' appxmanifest: '**/*.appxmanifest' versionNumber: 'Set dynamically below in a task' - -name: '$(Rev:r)' + +name: $(GITVERSION_AssemblySemFileVer) steps: -- task: PowerShell@2 +- task: UseGitVersion@5 + displayName: GitVersion + continueOnError: true inputs: - targetType: 'inline' - script: | - [xml] $manifestXml = Get-Content '$(appxmanifest)' - $version = [version]$manifestXml.Package.Identity.Version - - [string] $newVersion = "{0}.{1}.{2}.{3}" -f $version.Major, $version.Minor, $(Build.BuildNumber), 0 - Write-Host "Setting the release version number variable to '$newVersion'." - Write-Host "##vso[task.setvariable variable=versionNumber]$newVersion" - - Write-Host "Setting the name of the build to '$newVersion'." - Write-Host "##vso[build.updatebuildnumber]$newVersion" + versionSpec: '5.x' - task: NuGetToolInstaller@1 @@ -48,7 +40,8 @@ steps: restoreSolution: '$(solution)' - task: VersionAPPX@2 - displayName: 'Version MSIX' + inputs: + VersionNumber: '$(GitVersion.AssemblySemFileVer)' - task: VSBuild@1 inputs: