2026-03-12 19:04:47 +01:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using Wino.Core.Domain;
|
|
|
|
|
using Wino.Core.Domain.Enums;
|
|
|
|
|
using Wino.Core.Domain.Interfaces;
|
|
|
|
|
using Wino.Core.Domain.Models.Settings;
|
2024-11-10 23:28:25 +01:00
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
namespace Wino.Core.ViewModels;
|
|
|
|
|
|
2026-03-12 19:04:47 +01:00
|
|
|
public partial class SettingsPageViewModel : CoreBaseViewModel
|
2024-11-10 23:28:25 +01:00
|
|
|
{
|
2026-03-12 19:04:47 +01:00
|
|
|
private readonly IAccountService _accountService;
|
|
|
|
|
|
|
|
|
|
public SettingsPageViewModel(
|
|
|
|
|
INavigationService navigationService,
|
|
|
|
|
IStatePersistanceService statePersistenceService,
|
|
|
|
|
IAccountService accountService)
|
2024-11-10 23:28:25 +01:00
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
NavigationService = navigationService;
|
2026-01-06 17:23:58 +01:00
|
|
|
StatePersistenceService = statePersistenceService;
|
2026-03-12 19:04:47 +01:00
|
|
|
_accountService = accountService;
|
2025-02-16 11:43:30 +01:00
|
|
|
}
|
2025-02-16 11:54:23 +01:00
|
|
|
|
|
|
|
|
public INavigationService NavigationService { get; }
|
2026-01-06 17:23:58 +01:00
|
|
|
public IStatePersistanceService StatePersistenceService { get; }
|
2026-03-12 19:04:47 +01:00
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public partial string CurrentDescription { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public partial string ManageAccountsDescription { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
public async Task UpdateActivePageAsync(WinoPage pageType)
|
|
|
|
|
{
|
|
|
|
|
await EnsureAccountSummaryAsync();
|
|
|
|
|
|
|
|
|
|
var info = SettingsNavigationInfoProvider.GetInfo(pageType, ManageAccountsDescription);
|
|
|
|
|
await ExecuteUIThread(() => CurrentDescription = info.Description);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task EnsureAccountSummaryAsync()
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(ManageAccountsDescription))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var accounts = await _accountService.GetAccountsAsync().ConfigureAwait(false);
|
|
|
|
|
var count = accounts?.Count ?? 0;
|
|
|
|
|
|
|
|
|
|
await ExecuteUIThread(() =>
|
|
|
|
|
{
|
|
|
|
|
ManageAccountsDescription = string.Format(Translator.SettingsOptions_AccountsSummary, count);
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-11-10 23:28:25 +01:00
|
|
|
}
|