Added language & time page

This commit is contained in:
Aleh Khantsevich
2024-04-27 13:50:18 +02:00
parent 75863faf58
commit f543953389
13 changed files with 154 additions and 82 deletions

View File

@@ -20,6 +20,7 @@
MessageListPage,
MailListPage,
ReadingPanePage,
SettingOptionsPage
LanguageTimePage,
SettingOptionsPage,
}
}

View File

@@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Navigation;
using Wino.Core.Domain.Models.Translations;
namespace Wino.Mail.ViewModels
{
public partial class LanguageTimePageViewModel(IDialogService dialogService,
IPreferencesService preferencesService,
ITranslationService translationService) : BaseViewModel(dialogService)
{
public IPreferencesService PreferencesService { get; } = preferencesService;
private readonly ITranslationService _translationService = translationService;
[ObservableProperty]
private List<AppLanguageModel> _availableLanguages;
[ObservableProperty]
private AppLanguageModel _selectedLanguage;
private bool isInitialized = false;
public override void OnNavigatedTo(NavigationMode mode, object parameters)
{
base.OnNavigatedTo(mode, parameters);
AvailableLanguages = _translationService.GetAvailableLanguages();
SelectedLanguage = AvailableLanguages.FirstOrDefault(a => a.Language == PreferencesService.CurrentLanguage);
isInitialized = true;
}
protected override async void OnPropertyChanged(PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (!isInitialized) return;
if (e.PropertyName == nameof(SelectedLanguage))
{
await _translationService.InitializeLanguageAsync(SelectedLanguage.Language);
}
}
}
}

View File

@@ -1,37 +1,15 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Navigation;
using Wino.Core.Domain.Models.Translations;
using Wino.Core.Messages.Navigation;
namespace Wino.Mail.ViewModels
{
public partial class SettingOptionsPageViewModel : BaseViewModel
{
private readonly ITranslationService _translationService;
private readonly IPreferencesService _preferencesService;
[ObservableProperty]
private List<AppLanguageModel> _availableLanguages;
[ObservableProperty]
private AppLanguageModel _selectedLanguage;
private bool isInitialized = false;
public SettingOptionsPageViewModel(IDialogService dialogService,
ITranslationService translationService,
IPreferencesService preferencesService) : base(dialogService)
{
_translationService = translationService;
_preferencesService = preferencesService;
}
public SettingOptionsPageViewModel(IDialogService dialogService) : base(dialogService) { }
[RelayCommand]
private void GoAccountSettings() => Messenger.Send<NavigateSettingsRequested>();
@@ -39,24 +17,6 @@ namespace Wino.Mail.ViewModels
public override void OnNavigatedTo(NavigationMode mode, object parameters)
{
base.OnNavigatedTo(mode, parameters);
AvailableLanguages = _translationService.GetAvailableLanguages();
SelectedLanguage = AvailableLanguages.FirstOrDefault(a => a.Language == _preferencesService.CurrentLanguage);
isInitialized = true;
}
protected override async void OnPropertyChanged(PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (!isInitialized) return;
if (e.PropertyName == nameof(SelectedLanguage))
{
await _translationService.InitializeLanguageAsync(SelectedLanguage.Language);
}
}
[RelayCommand]
@@ -77,6 +37,8 @@ namespace Wino.Mail.ViewModels
pageType = WinoPage.MessageListPage;
else if (stringParameter == "Reading Pane")
pageType = WinoPage.ReadingPanePage;
else if (stringParameter == "Language And Time")
pageType = WinoPage.LanguageTimePage;
Messenger.Send(new BreadcrumbNavigationRequested(pageTitle, pageType));
}

View File

@@ -141,6 +141,7 @@ namespace Wino
services.AddTransient(typeof(MessageListPageViewModel));
services.AddTransient(typeof(ReadingPanePageViewModel));
services.AddTransient(typeof(MergedAccountDetailsPageViewModel));
services.AddTransient(typeof(LanguageTimePageViewModel));
}
#endregion

View File

@@ -62,10 +62,10 @@ namespace Wino.Helpers
}
}
public static string GetCreationDateString(DateTime date)
public static string GetCreationDateString(DateTime date, bool prefer24HourTime)
{
var localTime = date.ToLocalTime();
return $"{localTime.ToLongDateString()} {localTime.ToLongTimeString()}";
return $"{localTime.ToLongDateString()} {(prefer24HourTime ? localTime.ToString("HH:mm:ss") : localTime.ToLongTimeString())}";
}
public static string GetMailGroupDateString(object groupObject)

View File

@@ -0,0 +1,6 @@
using Wino.Mail.ViewModels;
namespace Wino.Views.Abstract
{
public abstract class LanguageTimePageAbstract : BasePage<LanguageTimePageViewModel> { }
}

View File

@@ -196,7 +196,7 @@
<Run Text="&lt;" /><Run Text="{x:Bind ViewModel.FromAddress, Mode=OneWay}" /><Run Text="&gt;" />
</TextBlock>
</HyperlinkButton>
<TextBlock FontSize="12" Text="{x:Bind helpers:XamlHelpers.GetCreationDateString(ViewModel.CreationDate), Mode=OneWay}" />
<TextBlock FontSize="12" Text="{x:Bind helpers:XamlHelpers.GetCreationDateString(ViewModel.CreationDate, ViewModel.PreferencesService.Prefer24HourTimeFormat), Mode=OneWay}" />
</StackPanel>
</Grid>
</Grid>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,19 @@
using Wino.Views.Abstract;
namespace Wino.Views.Settings
{
public sealed partial class LanguageTimePage : LanguageTimePageAbstract
{
public LanguageTimePage()
{
this.InitializeComponent();
}
public override void OnLanguageChanged()
{
base.OnLanguageChanged();
Bindings.Update();
}
}
}

File diff suppressed because one or more lines are too long

View File

@@ -8,12 +8,5 @@ namespace Wino.Views.Settings
{
InitializeComponent();
}
public override void OnLanguageChanged()
{
base.OnLanguageChanged();
Bindings.Update();
}
}
}

View File

@@ -46,22 +46,15 @@ namespace Wino.Views
settingsHeader.Title = Translator.MenuSettings;
}
private Type GetNavigationPageType(WinoPage page)
private Type GetNavigationPageType(WinoPage page) => page switch
{
switch (page)
{
case WinoPage.AboutPage:
return typeof(AboutPage);
case WinoPage.PersonalizationPage:
return typeof(PersonalizationPage);
case WinoPage.MessageListPage:
return typeof(MessageListPage);
case WinoPage.ReadingPanePage:
return typeof(ReadingPanePage);
default:
return null;
}
}
WinoPage.AboutPage => typeof(AboutPage),
WinoPage.PersonalizationPage => typeof(PersonalizationPage),
WinoPage.MessageListPage => typeof(MessageListPage),
WinoPage.ReadingPanePage => typeof(ReadingPanePage),
WinoPage.LanguageTimePage => typeof(LanguageTimePage),
_ => null,
};
void IRecipient<BreadcrumbNavigationRequested>.Receive(BreadcrumbNavigationRequested message)
{

View File

@@ -356,6 +356,7 @@
<Compile Include="Views\Abstract\AppShellAbstract.cs" />
<Compile Include="Views\Abstract\ComposePageAbstract.cs" />
<Compile Include="Views\Abstract\IdlePageAbstract.cs" />
<Compile Include="Views\Abstract\LanguageTimePageAbstract.cs" />
<Compile Include="Views\Abstract\MailListPageAbstract.cs" />
<Compile Include="Views\Abstract\MailRenderingPageAbstract.cs" />
<Compile Include="Views\Abstract\MergedAccountDetailsPageAbstract.cs" />
@@ -413,6 +414,9 @@
<Compile Include="Views\Settings\AboutPage.xaml.cs">
<DependentUpon>AboutPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Settings\LanguageTimePage.xaml.cs">
<DependentUpon>LanguageTimePage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Settings\MessageListPage.xaml.cs">
<DependentUpon>MessageListPage.xaml</DependentUpon>
</Compile>
@@ -626,6 +630,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Settings\LanguageTimePage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Settings\MessageListPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>