Merge pull request #168 from Tiktack/language-time-page

Language & Time page
This commit is contained in:
Burak Kaan Köse
2024-04-28 18:08:39 +02:00
committed by GitHub
16 changed files with 183 additions and 606 deletions

View File

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

View File

@@ -377,6 +377,8 @@
"SettingsHoverActions_Title": "Hover Actions",
"SettingsLanguage_Description": "Change display language for Wino.",
"SettingsLanguage_Title": "Display Language",
"SettingsLanguageTime_Title": "Language & Time",
"SettingsLanguageTime_Description": "Wino display language, preferred time format.",
"CategoriesFolderNameOverride": "Categories",
"MoreFolderNameOverride": "More",
"SettingsOptions_Title": "Settings",

File diff suppressed because it is too large Load Diff

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,17 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Wino.Core.Domain;
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,44 +19,22 @@ 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]
public void NavigateSubDetail(object type)
{
if (type is string stringParameter)
if (type is WinoPage pageType)
{
WinoPage pageType = default;
string pageTitle = stringParameter;
// They are just params and don't have to be localized. Don't change.
if (stringParameter == "Personalization")
pageType = WinoPage.PersonalizationPage;
else if (stringParameter == "About")
pageType = WinoPage.AboutPage;
else if (stringParameter == "Message List")
pageType = WinoPage.MessageListPage;
else if (stringParameter == "Reading Pane")
pageType = WinoPage.ReadingPanePage;
string pageTitle = pageType switch
{
WinoPage.PersonalizationPage => Translator.SettingsPersonalization_Title,
WinoPage.AboutPage => Translator.SettingsAbout_Title,
WinoPage.MessageListPage => Translator.SettingsMessageList_Title,
WinoPage.ReadingPanePage => Translator.SettingsReadingPane_Title,
WinoPage.LanguageTimePage => Translator.SettingsLanguageTime_Title,
_ => throw new NotImplementedException()
};
Messenger.Send(new BreadcrumbNavigationRequested(pageTitle, pageType));
}

View File

@@ -113,7 +113,6 @@ namespace Wino
{
services.AddSingleton<IApplicationResourceManager<ResourceDictionary>, ApplicationResourceManager>();
services.AddSingleton<IThemeService, ThemeService>();
services.AddSingleton<IThemeService, ThemeService>();
services.AddSingleton<IPreferencesService, PreferencesService>();
services.AddSingleton<IStatePersistanceService, StatePersistenceService>();
services.AddSingleton<ILaunchProtocolService, LaunchProtocolService>();
@@ -141,6 +140,7 @@ namespace Wino
services.AddTransient(typeof(MessageListPageViewModel));
services.AddTransient(typeof(ReadingPanePageViewModel));
services.AddTransient(typeof(MergedAccountDetailsPageViewModel));
services.AddTransient(typeof(LanguageTimePageViewModel));
}
#endregion

View File

@@ -18,6 +18,8 @@ namespace Wino.Helpers
{
public static class XamlHelpers
{
private const string TwentyFourHourTimeFormat = "HH:mm";
private const string TwelveHourTimeFormat = "hh:mm tt";
#region Converters
public static Visibility ReverseBoolToVisibilityConverter(bool value) => value ? Visibility.Collapsed : Visibility.Visible;
@@ -58,14 +60,14 @@ namespace Wino.Helpers
{
var localTime = receivedDate.ToLocalTime();
return prefer24HourTime ? localTime.ToString("HH:mm") : localTime.ToString("hh:mm tt");
return prefer24HourTime ? localTime.ToString(TwentyFourHourTimeFormat) : localTime.ToString(TwelveHourTimeFormat);
}
}
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(TwentyFourHourTimeFormat) : localTime.ToString(TwelveHourTimeFormat))}";
}
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

@@ -195,7 +195,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

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>