Skip to content

Commit

Permalink
Merge pull request #32 from DSaladinCH/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
DominicSaladin authored Mar 3, 2024
2 parents 644e0a8 + c036d19 commit 5d3061d
Show file tree
Hide file tree
Showing 19 changed files with 215 additions and 116 deletions.
27 changes: 21 additions & 6 deletions speed-time/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,27 @@ record AppVersion(Version Version, DateTime ReleaseDate);
private TrackTime? trackTimeBeforePause;
private TrackTime? trackTimePause;

public CultureInfo CurrentUiLanguage { get; private set; }
public CultureInfo CurrentDateLanguage { get; private set; }

protected override async void OnStartup(StartupEventArgs e)
{
await dbContext.Database.MigrateAsync();
await DataService.LoadSettings();

if (string.IsNullOrEmpty(SettingsModel.Instance.SelectedUiLanguage))
Language.SpeedTime.Culture = new CultureInfo(Thread.CurrentThread.CurrentCulture.Name);
CurrentUiLanguage = new CultureInfo(Thread.CurrentThread.CurrentCulture.Name);
else
CurrentUiLanguage = new CultureInfo(SettingsModel.Instance.SelectedUiLanguage);

if (string.IsNullOrEmpty(SettingsModel.Instance.SelectedDateLanguage))
CurrentDateLanguage = new CultureInfo(Thread.CurrentThread.CurrentCulture.Name);
else
Language.SpeedTime.Culture = new CultureInfo(SettingsModel.Instance.SelectedUiLanguage);
CurrentDateLanguage = new CultureInfo(SettingsModel.Instance.SelectedDateLanguage);

Thread.CurrentThread.CurrentCulture = Language.SpeedTime.Culture;
Thread.CurrentThread.CurrentUICulture = Language.SpeedTime.Culture;
Language.SpeedTime.Culture = CurrentUiLanguage;
Thread.CurrentThread.CurrentCulture = CurrentUiLanguage;
Thread.CurrentThread.CurrentUICulture = CurrentUiLanguage;

TrackTime? lastTrackedTime = await dbContext.TrackedTimes.OrderBy(tt => tt.Id).LastOrDefaultAsync();
if (lastTrackedTime is not null && !lastTrackedTime.IsTimeStopped)
Expand Down Expand Up @@ -126,6 +135,12 @@ private LvcColor ResourceToLvcColor(string resourceName)
return LvcColor.FromArgb(alpha, red, green, blue);
}

internal string FormatDate(DateTime dateTime, string formatString)
{

return dateTime.ToString(formatString, CurrentUiLanguage);
}

internal bool RegisterQuickTimeHotkey(HotKey newHotKey)
{
if (currentQuickTimeHotKey is not null)
Expand Down Expand Up @@ -157,11 +172,11 @@ private async void HotKeyManagerPressed(object? sender, KeyPressedEventArgs e)
{
if (e.HotKey.Equals(currentQuickTimeHotKey))
{
TrackTime? trackTime = QuickTimeTracker.Open(await dbContext.TrackedTimes.OrderBy(tt => tt.Id).LastOrDefaultAsync());
TrackTime? lastTrackedTime = await dbContext.TrackedTimes.OrderBy(tt => tt.TrackingStarted).ThenBy(tt => tt.TrackingStopped).LastOrDefaultAsync();
TrackTime? trackTime = QuickTimeTracker.Open(lastTrackedTime);
if (trackTime is null)
return;

TrackTime? lastTrackedTime = await dbContext.TrackedTimes.OrderBy(tt => tt.Id).LastOrDefaultAsync();
if (lastTrackedTime is not null && !lastTrackedTime.IsTimeStopped)
{
lastTrackedTime.StopTime();
Expand Down
2 changes: 1 addition & 1 deletion speed-time/Converter/DateTimeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
return value;

SourceValue = (DateTime)value;
return ((DateTime)value).ToString((string)parameter, Language.SpeedTime.Culture);
return ((App)Application.Current).FormatDate((DateTime)value, (string)parameter);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
3 changes: 2 additions & 1 deletion speed-time/Converter/TranslatedEnumConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace DSaladin.SpeedTime.Converter
Expand All @@ -32,7 +33,7 @@ public static string GetEnumDescription(Enum value)
FieldInfo? fi = value.GetType().GetField(value.ToString());

if (fi is not null && fi.GetCustomAttributes(typeof(DescriptionAttribute), false) is DescriptionAttribute[] attributes && attributes.Any())
return Language.SpeedTime.ResourceManager.GetString(attributes.First().Description, Language.SpeedTime.Culture) ?? value.ToString();
return Language.SpeedTime.ResourceManager.GetString(attributes.First().Description, ((App)Application.Current).CurrentUiLanguage) ?? value.ToString();

return value.ToString();
}
Expand Down
23 changes: 14 additions & 9 deletions speed-time/Dialogs/TimeStatistics.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public string RangeDisplay

private Axis[] xAxes =
{
new DateTimeAxis(TimeSpan.FromDays(2), date => date.ToString("M", SpeedTime.Language.SpeedTime.Culture.DateTimeFormat))
new DateTimeAxis(TimeSpan.FromDays(2), date => ((App)Application.Current).FormatDate(date, "M"))
};
public Axis[] XAxes
{
Expand Down Expand Up @@ -171,7 +171,11 @@ public TimeStatistics(DateTime start, DateTime end)
await LoadData();
});

Loaded += async (s, e) => await LoadData();
Loaded += async (s, e) =>
{
UpdateDatesAfterGrouping();
await LoadData();
};
}

private void UpdateDatesAfterGrouping()
Expand All @@ -189,20 +193,21 @@ private void UpdateDatesAfterGrouping()
break;
}

string dailyFormat = SpeedTime.Language.SpeedTime.ResourceManager.GetString("statistics.daily-date-format", ((App)Application.Current).CurrentDateLanguage)!;
switch (RangeGrouping)
{
case StatisticsGrouping.WeekDaily:
XAxes = new Axis[] { new DateTimeAxis(TimeSpan.FromDays(2), date => date.ToString("M", SpeedTime.Language.SpeedTime.Culture.DateTimeFormat)) };
XAxes = [new DateTimeAxis(TimeSpan.FromDays(2), date => ((App)Application.Current).FormatDate(date, dailyFormat))];
break;
case StatisticsGrouping.MonthDaily:
XAxes = new Axis[] { new DateTimeAxis(TimeSpan.FromDays(7), date => date.ToString("M", SpeedTime.Language.SpeedTime.Culture.DateTimeFormat)) };
XAxes = [new DateTimeAxis(TimeSpan.FromDays(7), date => ((App)Application.Current).FormatDate(date, dailyFormat))];
break;
case StatisticsGrouping.MonthWeekly:
XAxes = new Axis[] { new DateTimeAxis(TimeSpan.FromDays(7),
XAxes = [ new DateTimeAxis(TimeSpan.FromDays(7),
date => string.Format(SpeedTime.Language.SpeedTime.statistics_week_placeholder, GetIso8601WeekOfYear(date))) {
LabelsAlignment = LiveChartsCore.Drawing.Align.End
}
};
];
break;
}
}
Expand All @@ -216,7 +221,7 @@ private async Task LoadData()
break;
case StatisticsGrouping.MonthDaily:
case StatisticsGrouping.MonthWeekly:
RangeDisplay = StartDate.ToString("MMMM", SpeedTime.Language.SpeedTime.Culture.DateTimeFormat);
RangeDisplay = ((App)Application.Current).FormatDate(StartDate, "MMMM");
break;
}

Expand Down Expand Up @@ -284,7 +289,7 @@ private void Close_Click(object sender, RoutedEventArgs e)

private int GetIso8601WeekOfYear(DateTime date)
{
System.Globalization.Calendar calendar = CultureInfo.InvariantCulture.Calendar;
System.Globalization.Calendar calendar = ((App)Application.Current).CurrentDateLanguage.Calendar;

// ISO 8601 specifies that the first week of the year is the one with January 4th
// or the week that includes the first Thursday of the year
Expand All @@ -293,7 +298,7 @@ private int GetIso8601WeekOfYear(DateTime date)
date = date.AddDays(3);

// Return the week of our adjusted day
return calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
return calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, ((App)Application.Current).CurrentDateLanguage.DateTimeFormat.FirstDayOfWeek);
}

public enum StatisticsGrouping
Expand Down
4 changes: 2 additions & 2 deletions speed-time/Dialogs/UpdateApp.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public UpdateApp(Version version, DateTime releaseDate)
Version = string.Join('.', components.Take(nonZeroIndex + 1));

if (releaseDate.Year == DateTime.Now.Year)
ReleaseDate = releaseDate.ToString("M", SpeedTime.Language.SpeedTime.Culture);
ReleaseDate = ((App)Application.Current).FormatDate(releaseDate, "M");
else
ReleaseDate = releaseDate.ToString("D", SpeedTime.Language.SpeedTime.Culture);
ReleaseDate = ((App)Application.Current).FormatDate(releaseDate, "D");

DenyCommand = new((_) => Close(false));
DownloadCommand = new((_) => Close(true));
Expand Down
3 changes: 3 additions & 0 deletions speed-time/Dialogs/UserSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
<settings:DropDownSetting Category="UI" OptionName="{x:Static language:SpeedTime.settings_ui_language}" DisplayMemberPath="Name" SelectedValuePath="Id"
List="{Binding Source={x:Static models:SettingsModel.AvailableLanguages}}"
Value="{Binding Source={x:Static models:SettingsModel.Instance}, Path=SelectedUiLanguage}" />
<settings:DropDownSetting Category="UI" OptionName="{x:Static language:SpeedTime.settings_date_language}" DisplayMemberPath="Name" SelectedValuePath="Id"
List="{Binding Source={x:Static models:SettingsModel.AvailableLanguages}}"
Value="{Binding Source={x:Static models:SettingsModel.Instance}, Path=SelectedDateLanguage}" />
<settings:DropDownSetting Category="UI" OptionName="{x:Static language:SpeedTime.settings_ui_theme}" DisplayMemberPath="ThemeName"
List="{Binding Source={x:Static potato:Themes.List}}"
Value="{Binding Source={x:Static potato:ColorManagement.Instance}, Path=CurrTheme}" />
Expand Down
2 changes: 1 addition & 1 deletion speed-time/Dialogs/UserSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void Close_Click(object sender, RoutedEventArgs e)
return;
}

Close(SpeedTime.Language.SpeedTime.Culture.Name != SettingsModel.Instance.SelectedUiLanguage);
Close(((App)Application.Current).CurrentUiLanguage.Name != SettingsModel.Instance.SelectedUiLanguage);
}

private void QuickEntry_OnLoadHotKey(object sender, HotKeyArgs e)
Expand Down
22 changes: 11 additions & 11 deletions speed-time/Dialogs/Workdays.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
xmlns:fa="https://dsaladin.dev/products/fontawesome/wpf/xaml"
d:DataContext="{d:DesignInstance local:Workdays}"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" MaxHeight="300">
d:DesignHeight="260" d:DesignWidth="400" MaxHeight="260">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
Expand All @@ -36,15 +36,14 @@
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="60" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" MaxWidth="400">
<Grid Grid.Row="0" MaxWidth="320">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
Expand All @@ -67,28 +66,29 @@
<Label Content="{Binding ThursdayTitle}" Grid.Column="3" Grid.Row="0" HorizontalContentAlignment="Center" FontWeight="Bold" />
<potato:DSTextBox Text="{Binding ThursdayHours, StringFormat=N2}" d:Text="8.00" Grid.Column="3" Grid.Row="1" Height="35"
HorizontalContentAlignment="Center" Margin="5,0,5,0" />

<Label Content="{Binding FridayTitle}" Grid.Column="4" Grid.Row="0" HorizontalContentAlignment="Center" FontWeight="Bold" />
<potato:DSTextBox Text="{Binding FridayHours, StringFormat=N2}" d:Text="8.00" Grid.Column="4" Grid.Row="1" Height="35"
HorizontalContentAlignment="Center" Margin="5,0,5,0" />
</Grid>

<Grid Grid.Row="1" MaxWidth="160">
<Grid Grid.Row="1" MaxWidth="240">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<Label Content="{Binding SaturdayTitle}" Grid.Column="0" Grid.Row="0" HorizontalContentAlignment="Center" FontWeight="Bold" />
<Label Content="{Binding FridayTitle}" Grid.Column="0" Grid.Row="0" HorizontalContentAlignment="Center" FontWeight="Bold" />
<potato:DSTextBox Text="{Binding FridayHours, StringFormat=N2}" d:Text="8.00" Grid.Column="4" Grid.Row="1" Height="35"
HorizontalContentAlignment="Center" Margin="5,0,5,0" />

<Label Content="{Binding SaturdayTitle}" Grid.Column="1" Grid.Row="0" HorizontalContentAlignment="Center" FontWeight="Bold" />
<potato:DSTextBox Text="{Binding SaturdayHours, StringFormat=N2}" d:Text="8.00" Grid.Column="0" Grid.Row="1" Height="35"
HorizontalContentAlignment="Center" Margin="5,0,5,0" />

<Label Content="{Binding SundayTitle}" Grid.Column="1" Grid.Row="0" HorizontalContentAlignment="Center" FontWeight="Bold" />
<Label Content="{Binding SundayTitle}" Grid.Column="2" Grid.Row="0" HorizontalContentAlignment="Center" FontWeight="Bold" />
<potato:DSTextBox Text="{Binding SundayHours, StringFormat=N2}" d:Text="8.00" Grid.Column="1" Grid.Row="1" Height="35"
HorizontalContentAlignment="Center" Margin="5,0,5,0" />
</Grid>
Expand Down
14 changes: 7 additions & 7 deletions speed-time/Dialogs/Workdays.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ public double SundayHours
}
}

public string MondayTitle { get => SpeedTime.Language.SpeedTime.Culture.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Monday); }
public string TuesdayTitle { get => SpeedTime.Language.SpeedTime.Culture.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Tuesday); }
public string WednesdayTitle { get => SpeedTime.Language.SpeedTime.Culture.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Wednesday); }
public string ThursdayTitle { get => SpeedTime.Language.SpeedTime.Culture.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Thursday); }
public string FridayTitle { get => SpeedTime.Language.SpeedTime.Culture.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Friday); }
public string SaturdayTitle { get => SpeedTime.Language.SpeedTime.Culture.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Saturday); }
public string SundayTitle { get => SpeedTime.Language.SpeedTime.Culture.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Sunday); }
public string MondayTitle { get => ((App)Application.Current).CurrentUiLanguage.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Monday); }
public string TuesdayTitle { get => ((App)Application.Current).CurrentUiLanguage.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Tuesday); }
public string WednesdayTitle { get => ((App)Application.Current).CurrentUiLanguage.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Wednesday); }
public string ThursdayTitle { get => ((App)Application.Current).CurrentUiLanguage.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Thursday); }
public string FridayTitle { get => ((App)Application.Current).CurrentUiLanguage.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Friday); }
public string SaturdayTitle { get => ((App)Application.Current).CurrentUiLanguage.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Saturday); }
public string SundayTitle { get => ((App)Application.Current).CurrentUiLanguage.DateTimeFormat.GetAbbreviatedDayName(DayOfWeek.Sunday); }

public double TotalWorkHours { get => MondayHours + TuesdayHours + WednesdayHours + ThursdayHours + FridayHours + SaturdayHours + SundayHours; }
public string TotalWorkHoursDisplay { get => $"{SpeedTime.Language.SpeedTime.workdays_total_hours}: {TotalWorkHours:N2}h"; }
Expand Down
20 changes: 19 additions & 1 deletion speed-time/Language/SpeedTime.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion speed-time/Language/SpeedTime.de-CH.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<value>Pause</value>
</data>
<data name="quicktimetracker.last-entry" xml:space="preserve">
<value>Letzter Eintrag: {0}</value>
<value>Letzter Eintrag um {0}</value>
</data>
<data name="quicktimetracker.placeholder" xml:space="preserve">
<value>Der Titel deiner Arbeit</value>
Expand All @@ -153,6 +153,9 @@
<data name="settings.behavior.title" xml:space="preserve">
<value>Verhalten</value>
</data>
<data name="settings.date-language" xml:space="preserve">
<value>Datums Sprache</value>
</data>
<data name="settings.hotkey-add-entry" xml:space="preserve">
<value>Neuer Eintrag Hotkey</value>
</data>
Expand Down Expand Up @@ -189,6 +192,9 @@
<data name="settings.workdays" xml:space="preserve">
<value>Arbeitstage</value>
</data>
<data name="statistics.daily-date-format" xml:space="preserve">
<value>dd. MMM</value>
</data>
<data name="statistics.grouping.month-daily" xml:space="preserve">
<value>Monat - Täglich</value>
</data>
Expand Down
Loading

0 comments on commit 5d3061d

Please sign in to comment.