some changes for progress

This commit is contained in:
Burak Kaan Köse
2025-10-31 01:41:51 +01:00
parent 4bf8f8b3d3
commit 3cc1d10b87
8 changed files with 170 additions and 53 deletions
+32 -5
View File
@@ -571,7 +571,7 @@ public partial class MailListPageViewModel : MailBaseViewModel,
return;
}
var viewModels = PrepareMailViewModels(items);
var viewModels = await PrepareMailViewModelsAsync(items).ConfigureAwait(false);
await MailCollection.AddRangeAsync(viewModels, false);
await ExecuteUIThread(() => { IsInitializingFolder = false; });
@@ -738,9 +738,19 @@ public partial class MailListPageViewModel : MailBaseViewModel,
}
}
private List<MailItemViewModel> PrepareMailViewModels(IEnumerable<MailCopy> mailItems)
private async Task<List<MailItemViewModel>> PrepareMailViewModelsAsync(IEnumerable<MailCopy> mailItems, CancellationToken cancellationToken = default)
{
return mailItems.Select(a => new MailItemViewModel(a)).ToList();
// Run ViewModel creation on background thread to avoid blocking UI
return await Task.Run(() =>
{
var viewModels = new List<MailItemViewModel>();
foreach (var mailItem in mailItems)
{
cancellationToken.ThrowIfCancellationRequested();
viewModels.Add(new MailItemViewModel(mailItem));
}
return viewModels;
}, cancellationToken).ConfigureAwait(false);
}
[RelayCommand]
@@ -764,7 +774,11 @@ public partial class MailListPageViewModel : MailBaseViewModel,
if (ActiveFolder == null)
return;
await ExecuteUIThread(() => { IsInitializingFolder = true; });
await ExecuteUIThread(() => {
IsInitializingFolder = true;
// Show initial loading progress
UpdateBarMessage(InfoBarMessageType.Information, ActiveFolder.FolderName, "Loading emails...");
});
// Folder is changed during initialization.
// Just cancel the existing one and wait for new initialization.
@@ -855,11 +869,21 @@ public partial class MailListPageViewModel : MailBaseViewModel,
if (!listManipulationCancellationTokenSource.IsCancellationRequested)
{
// Update progress: Creating view models
await ExecuteUIThread(() => {
UpdateBarMessage(InfoBarMessageType.Information, ActiveFolder.FolderName, $"Processing {items.Count} emails...");
});
// Here they are already threaded if needed.
// We don't need to insert them one by one.
// Just create VMs and do bulk insert.
var viewModels = PrepareMailViewModels(items);
var viewModels = await PrepareMailViewModelsAsync(items, cancellationToken).ConfigureAwait(false);
// Update progress: Adding to collection
await ExecuteUIThread(() => {
UpdateBarMessage(InfoBarMessageType.Information, ActiveFolder.FolderName, "Finalizing...");
});
await MailCollection.AddRangeAsync(viewModels, clearIdCache: true);
@@ -895,6 +919,9 @@ public partial class MailListPageViewModel : MailBaseViewModel,
OnPropertyChanged(nameof(CanSynchronize));
NotifyItemFoundState();
// Clear the loading message after completion
IsBarOpen = false;
});
}
}